/* BMessageRunner(BMessenger target, const BMessage *message, bigtime_t interval, int32 count, BMessenger replyTo) @case 3 target is valid, message is valid, interval == 0, count > 0 @results R5: InitCheck() should return B_ERROR. GetInfo() should return B_BAD_VALUE. OBOS: InitCheck() should return B_OK. GetInfo() should return B_OK. A minimal time interval is used (50000). */ void TBMessageRunnerTester::BMessageRunnerB3() { MessageRunnerTestApp app(kTesterSignature); MessageRunnerTestLooper *looper = app.TestLooper(); BMessenger target(looper); BMessage message(MSG_RUNNER_MESSAGE); bigtime_t interval = 0; int32 count = 5; MessageRunnerTestHandler *handler = app.TestHandler(); BMessenger replyTo(handler); BMessageRunner runner(target, &message, interval, count, replyTo); #ifdef TEST_R5 CHK(runner.InitCheck() == B_ERROR); check_message_runner_info(runner, B_BAD_VALUE); #else bigtime_t startTime = system_time(); CHK(runner.InitCheck() == B_OK); interval = max(interval, kMinTimeInterval); check_message_runner_info(runner, B_OK, interval, count); snooze((count + 1) * interval + 10000); CHK(looper->CheckMessages(startTime, interval, count)); CHK(app.CountReplies() == 0); CHK(handler->CountReplies() == count); #endif }
/* status_t Broadcast(BMessage *message, BMessenger replyTo) const @case 1 NULL message @results Should return B_BAD_VALUE. */ void BroadcastTester::BroadcastTestB1() { // R5: crashes when passing a NULL message. #ifndef TEST_R5 BMessenger replyTo(dynamic_cast<RosterLaunchApp*>(be_app)->Handler()); CHK(be_roster->Broadcast(NULL, replyTo) == B_BAD_VALUE); #endif }
int StreamMulticaster::onStreamPingI(const char *path, const char *types, lo_arg **argv, int argc, lo_message msg) { // send pong reply: lowrappers::Address replyTo(lo_message_get_source(msg), false); replyTo.sendFrom(streamIn_, streamPath_ + "pong" , "i", argv[0]->i); return 1; // returning 1 ensures that the call will also be passed to forwardMessage }
int StreamMulticaster::onUnknownConnectIn(const char *path, const char *types, lo_arg **argv, int argc, lo_message msg) { // create a reply adress from msg: WonderOscSender replyTo(lo_message_get_source(msg), false); // send reply: const std::string pathStr(path); replyTo.sendReply(pathStr, 1, "Unknown command: " + pathStr); return 0; }
/* BMessageRunner(BMessenger target, const BMessage *message, bigtime_t interval, int32 count, BMessenger replyTo) @case 6 target is valid, message is valid, interval > 0, count == 0 @results InitCheck() should return B_ERROR. GetInfo() should return B_BAD_VALUE. */ void TBMessageRunnerTester::BMessageRunnerB6() { MessageRunnerTestApp app(kTesterSignature); MessageRunnerTestLooper *looper = app.TestLooper(); BMessenger target(looper); BMessage message(MSG_RUNNER_MESSAGE); bigtime_t interval = 100000; int32 count = 0; MessageRunnerTestHandler *handler = app.TestHandler(); BMessenger replyTo(handler); BMessageRunner runner(target, &message, interval, count, replyTo); CHK(runner.InitCheck() == B_ERROR); check_message_runner_info(runner, B_BAD_VALUE); }
/* BMessageRunner(BMessenger target, const BMessage *message, bigtime_t interval, int32 count, BMessenger replyTo) @case 2 target is valid, message is NULL, interval > 0, count > 0 @results InitCheck() should return B_BAD_VALUE. GetInfo() should return B_BAD_VALUE. */ void TBMessageRunnerTester::BMessageRunnerB2() { // R5: chrashes when passing a NULL message #ifndef TEST_R5 MessageRunnerTestApp app(kTesterSignature); MessageRunnerTestLooper *looper = app.TestLooper(); BMessenger target(looper); bigtime_t interval = 100000; int32 count = 5; MessageRunnerTestHandler *handler = app.TestHandler(); BMessenger replyTo(handler); BMessageRunner runner(target, NULL, interval, count, replyTo); CHK(runner.InitCheck() == B_BAD_VALUE); check_message_runner_info(runner, B_BAD_VALUE); #endif }
/* BMessageRunner(BMessenger target, const BMessage *message, bigtime_t interval, int32 count, BMessenger replyTo) @case 1 target is invalid, message is valid, interval > 0, count > 0 @results InitCheck() should return B_OK. The message runner turns to unusable as soon as the first message had to be sent. GetInfo() should return B_OK. */ void TBMessageRunnerTester::BMessageRunnerB1() { MessageRunnerTestApp app(kTesterSignature); BMessenger target; BMessage message(MSG_RUNNER_MESSAGE); bigtime_t interval = 100000; int32 count = 5; MessageRunnerTestHandler *handler = app.TestHandler(); BMessenger replyTo(handler); BMessageRunner runner(target, &message, interval, count, replyTo); CHK(runner.InitCheck() == B_OK); check_message_runner_info(runner, B_OK, interval, count); snooze(interval + 10000); check_message_runner_info(runner, B_BAD_VALUE); CHK(app.CountReplies() == 0); CHK(handler->CountReplies() == 0); }
bool ZeroMqConnection::routerReceive() { zmq::message_t address; if (m_socket->recv(&address, ZMQ_NOBLOCK)) { int size = address.size(); EndpointIdType replyTo(static_cast<char*>(address.data()), size); // Now receive the message zmq::message_t message; if(!m_socket->recv(&message, ZMQ_NOBLOCK)) { qWarning() << "Error no message body received"; return true; } PacketType packet(static_cast<char*>(message.data()), message.size()); emit packetReceived(packet, replyTo); return true; } return false; }
/* BMessageRunner(BMessenger target, const BMessage *message, bigtime_t interval, int32 count, BMessenger replyTo) @case 5 target is valid, message is valid, interval == LONGLONG_MAX, count > 0 @results InitCheck() should return B_OK. GetInfo() should return B_OK. No message should be delivered. */ void TBMessageRunnerTester::BMessageRunnerB5() { // R5: doesn't behave very well. In worst case registrar time loop gets // locked up and system wide message runners don't get messages anymore. #ifndef TEST_R5 MessageRunnerTestApp app(kTesterSignature); MessageRunnerTestLooper *looper = app.TestLooper(); BMessenger target(looper); BMessage message(MSG_RUNNER_MESSAGE); bigtime_t interval = LONGLONG_MAX; int32 count = 5; MessageRunnerTestHandler *handler = app.TestHandler(); BMessenger replyTo(handler); BMessageRunner runner(target, &message, interval, count, replyTo); bigtime_t startTime = system_time(); CHK(runner.InitCheck() == B_OK); interval = max(interval, kMinTimeInterval); check_message_runner_info(runner, B_OK, interval, count); snooze(10000); CHK(looper->CheckMessages(startTime, interval, 0)); CHK(app.CountReplies() == 0); CHK(handler->CountReplies() == 0); #endif }
/* status_t Broadcast(BMessage *message, BMessenger replyTo) const @case 2 valid message, several apps, one is B_ARGV_ONLY @results Should return B_OK and send the message to all (including the B_ARGV_ONLY) apps. Replies go to the specified messenger. */ void BroadcastTester::BroadcastTestB2() { 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(dynamic_cast<RosterLaunchApp*>(be_app)->Handler()); 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_REPLY)); 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_REPLY)); 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_REPLY)); 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_REPLY)); CHK(context.CheckNextMessage(caller4, team4, cookie, MSG_QUIT_REQUESTED)); CHK(context.CheckNextMessage(caller4, team4, cookie, MSG_TERMINATED)); }
void NewsArticle::assemble() { Headers::Base *h; QCString newHead = ""; //Message-ID if((h = messageID(false)) != 0) newHead += h->as7BitString() + "\n"; //Control if((h = control(false)) != 0) newHead += h->as7BitString() + "\n"; //Supersedes if((h = supersedes(false)) != 0) newHead += h->as7BitString() + "\n"; //From h = from(); // "From" is mandatory newHead += h->as7BitString() + "\n"; //Subject h = subject(); // "Subject" is mandatory newHead += h->as7BitString() + "\n"; //To if((h = to(false)) != 0) newHead += h->as7BitString() + "\n"; //Newsgroups if((h = newsgroups(false)) != 0) newHead += h->as7BitString() + "\n"; //Followup-To if((h = followUpTo(false)) != 0) newHead += h->as7BitString() + "\n"; //Reply-To if((h = replyTo(false)) != 0) newHead += h->as7BitString() + "\n"; //Mail-Copies-To if((h = mailCopiesTo(false)) != 0) newHead += h->as7BitString() + "\n"; //Date h = date(); // "Date" is mandatory newHead += h->as7BitString() + "\n"; //References if((h = references(false)) != 0) newHead += h->as7BitString() + "\n"; //Lines h = lines(); // "Lines" is mandatory newHead += h->as7BitString() + "\n"; //Organization if((h = organization(false)) != 0) newHead += h->as7BitString() + "\n"; //User-Agent if((h = userAgent(false)) != 0) newHead += h->as7BitString() + "\n"; //Mime-Version newHead += "MIME-Version: 1.0\n"; //Content-Type newHead += contentType()->as7BitString() + "\n"; //Content-Transfer-Encoding newHead += contentTransferEncoding()->as7BitString() + "\n"; //X-Headers int pos = h_ead.find("\nX-"); if(pos > -1) //we already have some x-headers => "recycle" them newHead += h_ead.mid(pos + 1, h_ead.length() - pos); else if(h_eaders && !h_eaders->isEmpty()) { for(h = h_eaders->first(); h; h = h_eaders->next()) { if(h->isXHeader() && (strncasecmp(h->type(), "X-KNode", 7) != 0)) newHead += h->as7BitString() + "\n"; } } h_ead = newHead; }