当前位置: 首页>>代码示例>>C++>>正文


C++ BRoster::Broadcast方法代码示例

本文整理汇总了C++中BRoster::Broadcast方法的典型用法代码示例。如果您正苦于以下问题:C++ BRoster::Broadcast方法的具体用法?C++ BRoster::Broadcast怎么用?C++ BRoster::Broadcast使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BRoster的用法示例。


在下文中一共展示了BRoster::Broadcast方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Broadcast

/*
	status_t Broadcast(BMessage *message, BMessenger replyTo) const
	@case 3			valid message, several apps, one is B_ARGV_ONLY,
					invalid replyTo
	@results		Should return B_OK and send the message to all (including
					the B_ARGV_ONLY) apps. Replies go to the roster!
*/
void BroadcastTester::BroadcastTestB3()
{
	LaunchContext context;
	BRoster roster;
	// launch app 1
	entry_ref ref1(create_app(appFile1, appType1));
	SimpleAppLauncher caller1(ref1);
	team_id team1;
	CHK(context(caller1, appType1, &team1) == B_OK);
	// launch app 2
	entry_ref ref2(create_app(appFile2, appType2, false, true,
							  B_SINGLE_LAUNCH | B_ARGV_ONLY));
	SimpleAppLauncher caller2(ref2);
	team_id team2;
	CHK(context(caller2, appType2, &team2) == B_OK);
	// launch app 3
	entry_ref ref3(create_app(appFile3, appType3));
	SimpleAppLauncher caller3(ref3);
	team_id team3;
	CHK(context(caller3, appType3, &team3) == B_OK);
	// launch app 4
	entry_ref ref4(create_app(appFile4, appType4));
	SimpleAppLauncher caller4(ref4);
	team_id team4;
	CHK(context(caller4, appType4, &team4) == B_OK);
	// wait for the apps to run
	context.WaitForMessage(team1, MSG_READY_TO_RUN);
	context.WaitForMessage(team2, MSG_READY_TO_RUN);
	context.WaitForMessage(team3, MSG_READY_TO_RUN);
	context.WaitForMessage(team4, MSG_READY_TO_RUN);
	// broadcast a message
	BMessage message(MSG_1);
	BMessenger replyTo;
	CHK(roster.Broadcast(&message, replyTo) == B_OK);
	// wait for the apps to report the receipt of the message
	context.WaitForMessage(team1, MSG_MESSAGE_RECEIVED);
	context.WaitForMessage(team2, MSG_MESSAGE_RECEIVED);
	context.WaitForMessage(team3, MSG_MESSAGE_RECEIVED);
	context.WaitForMessage(team4, MSG_MESSAGE_RECEIVED);
	// check the messages
	context.Terminate();
	// app 1
	int32 cookie = 0;
	CHK(context.CheckNextMessage(caller1, team1, cookie, MSG_STARTED));
	CHK(context.CheckMainArgsMessage(caller1, team1, cookie, &ref1, false));
	CHK(context.CheckNextMessage(caller1, team1, cookie, MSG_READY_TO_RUN));
	CHK(context.CheckMessageMessage(caller1, team1, cookie, &message));
//	CHK(context.CheckNextMessage(caller1, team1, cookie, MSG_2));
	CHK(context.CheckNextMessage(caller1, team1, cookie, MSG_QUIT_REQUESTED));
	CHK(context.CheckNextMessage(caller1, team1, cookie, MSG_TERMINATED));
	// app 2
	cookie = 0;
	CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_STARTED));
	CHK(context.CheckMainArgsMessage(caller2, team2, cookie, &ref2, false));
	CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_READY_TO_RUN));
	CHK(context.CheckMessageMessage(caller2, team2, cookie, &message));
//	CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_2));
	CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_QUIT_REQUESTED));
	CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_TERMINATED));
	// app 3
	cookie = 0;
	CHK(context.CheckNextMessage(caller3, team3, cookie, MSG_STARTED));
	CHK(context.CheckMainArgsMessage(caller3, team3, cookie, &ref3, false));
	CHK(context.CheckNextMessage(caller3, team3, cookie, MSG_READY_TO_RUN));
	CHK(context.CheckMessageMessage(caller3, team3, cookie, &message));
//	CHK(context.CheckNextMessage(caller3, team3, cookie, MSG_2));
	CHK(context.CheckNextMessage(caller3, team3, cookie, MSG_QUIT_REQUESTED));
	CHK(context.CheckNextMessage(caller3, team3, cookie, MSG_TERMINATED));
	// app 4
	cookie = 0;
	CHK(context.CheckNextMessage(caller4, team4, cookie, MSG_STARTED));
	CHK(context.CheckMainArgsMessage(caller4, team4, cookie, &ref4, false));
	CHK(context.CheckNextMessage(caller4, team4, cookie, MSG_READY_TO_RUN));
	CHK(context.CheckMessageMessage(caller4, team4, cookie, &message));
//	CHK(context.CheckNextMessage(caller4, team4, cookie, MSG_2));
	CHK(context.CheckNextMessage(caller4, team4, cookie, MSG_QUIT_REQUESTED));
	CHK(context.CheckNextMessage(caller4, team4, cookie, MSG_TERMINATED));
}
开发者ID:mariuz,项目名称:haiku,代码行数:85,代码来源:BroadcastTester.cpp


注:本文中的BRoster::Broadcast方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。