| 50 | |
| 51 | |
| 52 | int |
| 53 | Writer::svc () |
| 54 | { |
| 55 | ACE_DEBUG((LM_DEBUG, |
| 56 | ACE_TEXT("(%P|%t) Writer::svc begins.\n"))); |
| 57 | |
| 58 | ::DDS::InstanceHandleSeq handles; |
| 59 | try |
| 60 | { |
| 61 | Messenger::MessageDataWriter_var message_dw |
| 62 | = Messenger::MessageDataWriter::_narrow (writer_.in ()); |
| 63 | if (CORBA::is_nil (message_dw.in ())) |
| 64 | { |
| 65 | cerr << "Data Writer could not be narrowed"<< endl; |
| 66 | exit(1); |
| 67 | } |
| 68 | |
| 69 | Messenger::Message message; |
| 70 | message.subject_id = 99; |
| 71 | ::DDS::InstanceHandle_t handle = message_dw->register_instance(message); |
| 72 | |
| 73 | message.from = CORBA::string_dup("Comic Book Guy"); |
| 74 | message.subject = CORBA::string_dup("Review"); |
| 75 | message.text = CORBA::string_dup("Worst. Movie. Ever."); |
| 76 | |
| 77 | ACE_DEBUG((LM_DEBUG, |
| 78 | ACE_TEXT("(%P|%t) %T Writer::svc starting to write.\n"))); |
| 79 | |
| 80 | write (message_dw.ptr(), handle, message, num_messages); |
| 81 | } |
| 82 | catch (CORBA::Exception& e) { |
| 83 | cerr << "Exception caught in svc:" << endl |
| 84 | << e << endl; |
| 85 | } |
| 86 | |
| 87 | ACE_DEBUG ((LM_DEBUG, "(%P|%t) Done writing.\n")); |
| 88 | |
| 89 | // After first thread sends all samples, the datareader started. |
| 90 | |
| 91 | // When the datawriter and datareader fully associated, change the start_ |
| 92 | // flag to let the second write thread start writing. |
| 93 | |
| 94 | // The datareader should receive all samples sent by two threads. |
| 95 | while (!dwl_servant_->publication_matched()) |
| 96 | { |
| 97 | ACE_OS::sleep(1); |
| 98 | } |
| 99 | |
| 100 | this->start_ = true; |
| 101 | |
| 102 | // wait for datareader finish. |
| 103 | while (1) |
| 104 | { |
| 105 | writer_->get_matched_subscriptions(handles); |
| 106 | if (handles.length() == 0) |
| 107 | break; |
| 108 | else |
| 109 | ACE_OS::sleep(1); |
nothing calls this directly
no test coverage detected