int run_test(int argc, ACE_TCHAR *argv[]) { using namespace DDS; using namespace OpenDDS::DCPS; WaitSet_var ws = new WaitSet; DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); DomainParticipant_var dp = dpf->create_participant(23, PARTICIPANT_QOS_DEFAULT, 0, ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); Messenger::MessageTypeSupport_var ts = new Messenger::MessageTypeSupportImpl; ts->register_type(dp, ts->get_type_name()); Topic_var topic = dp->create_topic("MyTopic", ts->get_type_name(), TOPIC_QOS_DEFAULT, 0, ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); Publisher_var pub = dp->create_publisher(PUBLISHER_QOS_DEFAULT, 0, ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); TransportImpl_rch pub_tport = TheTransportFactory->create_transport_impl(1, AUTO_CONFIG); PublisherImpl* pub_impl = dynamic_cast<PublisherImpl*> (pub.in()); pub_impl->attach_transport(pub_tport.in()); DataWriter_var dw = pub->create_datawriter(topic, DATAWRITER_QOS_DEFAULT, 0, ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); StatusCondition_var cond = dw->get_statuscondition(); cond->set_enabled_statuses(OFFERED_INCOMPATIBLE_QOS_STATUS); ws->attach_condition(cond); Subscriber_var sub = dp->create_subscriber(SUBSCRIBER_QOS_DEFAULT, 0, ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); TransportImpl_rch sub_tport = TheTransportFactory->create_transport_impl(2, AUTO_CONFIG); SubscriberImpl* sub_impl = dynamic_cast<SubscriberImpl*> (sub.in()); sub_impl->attach_transport(sub_tport.in()); DataReaderQos dr_qos; sub->get_default_datareader_qos(dr_qos); dr_qos.durability.kind = PERSISTENT_DURABILITY_QOS; Waiter w(ws); w.activate(); DataReader_var dr = sub->create_datareader(topic, dr_qos, 0, ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); w.wait(); bool passed = (w.result() == RETCODE_OK); ws->detach_condition(cond); dp->delete_contained_entities(); dpf->delete_participant(dp); return passed ? 0 : 1; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { // Initialize DomainParticipantFactory DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); int error; if ((error = parse_args(argc, argv)) != 0) { return error; } // Create DomainParticipant DDS::DomainParticipant_var participant = dpf->create_participant(111, PARTICIPANT_QOS_DEFAULT, DDS::DomainParticipantListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(participant.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: create_participant failed!\n")), -1); } // Register TypeSupport (Messenger::Message) Messenger::MessageTypeSupport_var mts = new Messenger::MessageTypeSupportImpl(); if (mts->register_type(participant.in(), "") != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: register_type failed!\n")), -1); } // Create Topic DDS::Topic_var topic = participant->create_topic("Movie Discussion List", CORBA::String_var(mts->get_type_name()), TOPIC_QOS_DEFAULT, DDS::TopicListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(topic.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: create_topic failed!\n")), -1); } ::DDS::PublisherQos publisher_qos; participant->get_default_publisher_qos (publisher_qos); publisher_qos.presentation.access_scope = DDS::GROUP_PRESENTATION_QOS; publisher_qos.presentation.coherent_access = true; publisher_qos.presentation.ordered_access = true; // Create Publisher DDS::Publisher_var pub = participant->create_publisher(publisher_qos, DDS::PublisherListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(pub.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: create_publisher failed!\n")), -1); } ::DDS::DataWriterQos dw_qos; pub->get_default_datawriter_qos (dw_qos); dw_qos.history.kind = ::DDS::KEEP_ALL_HISTORY_QOS; dw_qos.resource_limits.max_samples_per_instance = ::DDS::LENGTH_UNLIMITED; // Create DataWriter DDS::DataWriter_var dw1 = pub->create_datawriter(topic.in(), dw_qos, DDS::DataWriterListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(dw1.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: create_datawriter failed!\n")), -1); } DDS::DataWriter_var dw2 = pub->create_datawriter(topic.in(), dw_qos, DDS::DataWriterListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(dw2.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: create_datawriter failed!\n")), -1); } // Start writing threads Writer* writer1 = new Writer(pub.in(), dw1.in()); writer1->start(); Writer* writer2 = new Writer(pub.in(), dw2.in()); writer2->start(); while (!writer1->is_finished() || !writer2->is_finished()) { ACE_Time_Value small_time(0, 250000); ACE_OS::sleep(small_time); } writer1->end(); writer2->end(); delete writer1; delete writer2; // Clean-up! participant->delete_contained_entities(); dpf->delete_participant(participant.in()); TheServiceParticipant->shutdown(); } catch (const CORBA::Exception& e) { e._tao_print_exception("Exception caught in main():"); ACE_OS::exit(-1); } return 0; }
bool Publisher::run (void) { ::DDS::DomainId_t domain_id = 411; try { sync_client_->way_point_reached (1); sync_client_->get_notification (); ACE_High_Res_Timer participant_timer; participant_timer.start(); for (size_t count = 0; count < participant_count_; count++) { participant_[count] = dpf_->create_participant (domain_id, PARTICIPANT_QOS_DEFAULT, DDS::DomainParticipantListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (participant_[count].in ())) { cerr << "create_participant failed." << endl; return false; } } participant_timer.stop(); Messenger::MessageTypeSupport_var mts = new Messenger::MessageTypeSupportImpl(); for (size_t count = 0; count < participant_count_; count++) { if (DDS::RETCODE_OK != mts->register_type(participant_[count].in (), "")) { cerr << "register_type failed." << endl; return false; } } CORBA::String_var type_name = mts->get_type_name (); DDS::TopicQos topic_qos; participant_[0]->get_default_topic_qos(topic_qos); ACE_High_Res_Timer topic_timer; topic_timer.start(); for (size_t count = 0; count < topic_count_; count++) { topic_[count] = participant_[count % participant_count_]->create_topic ("Movie Discussion List", type_name.in (), topic_qos, DDS::TopicListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (topic_[count].in ())) { cerr << "create_topic failed." << endl; return false; } } topic_timer.stop(); ACE_High_Res_Timer pub_timer; pub_timer.start(); for (size_t count = 0; count < writer_count_; count++) { // Create the publisher pub_[count] = participant_[count]->create_publisher(PUBLISHER_QOS_DEFAULT, DDS::PublisherListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (pub_[count].in ())) { cerr << "create_publisher failed." << endl; return false; } } // Create the datawriter DDS::DataWriterQos dw_qos; pub_[0]->get_default_datawriter_qos (dw_qos); for (size_t count = 0; count < writer_count_; count++) { dw_[count] = pub_[count]->create_datawriter(topic_[count].in (), dw_qos, DDS::DataWriterListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (dw_[count].in ())) { cerr << "create_datawriter failed." << endl; return false; } } // Wait for all expected subscribers while (true) { ::DDS::InstanceHandleSeq handles; dw_[0]->get_matched_subscriptions(handles); //ACE_DEBUG ((LM_DEBUG, "(%P|%t) subs connected: %d\n", handles.length())); if (handles.length() >= subscriber_count_) { break; } ACE_OS::sleep (1); } pub_timer.stop (); // sync up sync_client_->way_point_reached (2); sync_client_->get_notification (); ACE_Time_Value tv; participant_timer.elapsed_time (tv); sync_client_->publish (SyncExt::Topic, static_cast<int>(topic_count_), tv.msec()); //ACE_DEBUG ((LM_DEBUG, "(%P|%t) Created %d participants in %d secs.\n" //, participant_count_, tv.sec())); topic_timer.elapsed_time (tv); sync_client_->publish (SyncExt::Participant, static_cast<int>(participant_count_), tv.msec()); //ACE_DEBUG ((LM_DEBUG, "(%P|%t) Created %d topics in %d secs.\n" //, topic_count_, tv.sec())); pub_timer.elapsed_time (tv); sync_client_->publish (SyncExt::Publisher, static_cast<int>(writer_count_), tv.msec()); //ACE_DEBUG ((LM_DEBUG, "(%P|%t) Created %d publishers in %d secs.\n" //, writer_count_, tv.sec())); /* std::auto_ptr<Writer> writer (new Writer(dw_[0].in())); writer->start (); while ( !writer->is_finished()) { ACE_Time_Value small(0,250000); ACE_OS::sleep (small); } // Cleanup writer->end (); //delete writer; */ for (size_t count = 0; count < participant_count_; count++) { participant_[count]->delete_contained_entities (); dpf_->delete_participant (participant_[count].in ()); } TheServiceParticipant->shutdown (); } catch (CORBA::Exception& e) { cerr << "PUB: Exception caught in Publisher::run():\n " << e << endl; return false; } return true; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { // Initialize DomainParticipantFactory DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); int error; if ((error = parse_args(argc, argv)) != 0) { return error; } // Create DomainParticipant DDS::DomainParticipant_var participant = dpf->create_participant(4, PARTICIPANT_QOS_DEFAULT, 0, OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (!participant) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: %N:%l: main() -") ACE_TEXT(" create_participant failed!\n")), -1); } ACE_DEBUG((LM_DEBUG, "(%P|%t) Start publisher\n")); { // Register TypeSupport (Messenger::Message) Messenger::MessageTypeSupport_var ts = new Messenger::MessageTypeSupportImpl; if (ts->register_type(participant, "Messenger") != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: %N:%l: main() -") ACE_TEXT(" register_type failed!\n")), -1); } // Create Topic (Movie Discussion List) CORBA::String_var type_name = ts->get_type_name(); ACE_DEBUG((LM_DEBUG, "registered type name = %s\n", type_name.in())); DDS::Topic_var topic = participant->create_topic("Movie Discussion List", type_name, TOPIC_QOS_DEFAULT, 0, OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (!topic) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: %N:%l: main() -") ACE_TEXT(" create_topic failed!\n")), -1); } // setup partition DDS::PublisherQos pub_qos; participant->get_default_publisher_qos(pub_qos); DDS::StringSeq my_partition; my_partition.length(1); my_partition[0] = "One"; pub_qos.partition.name = my_partition; // Create Publisher DDS::Publisher_var publisher = participant->create_publisher(pub_qos, 0, OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (!publisher) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: %N:%l: main() -") ACE_TEXT(" create_publisher failed!\n")), -1); } // Create DataWriter DDS::DataWriter_var writer = publisher->create_datawriter(topic, DATAWRITER_QOS_DEFAULT, 0, OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (!writer) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: %N:%l: main() -") ACE_TEXT(" create_datawriter failed!\n")), -1); } Messenger::MessageDataWriter_var message_writer = Messenger::MessageDataWriter::_narrow(writer); if (!message_writer) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: %N:%l: main() -") ACE_TEXT(" _narrow failed!\n")), -1); } // Block until Subscriber is available DDS::StatusCondition_var condition = writer->get_statuscondition(); condition->set_enabled_statuses(DDS::PUBLICATION_MATCHED_STATUS); DDS::WaitSet_var ws = new DDS::WaitSet; ws->attach_condition(condition); while (true) { DDS::PublicationMatchedStatus matches; if (writer->get_publication_matched_status(matches) != ::DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: %N:%l: main() -") ACE_TEXT(" get_publication_matched_status failed!\n")), -1); } if (matches.current_count >= 1) { break; } DDS::ConditionSeq conditions; DDS::Duration_t timeout = { 60, 0 }; if (ws->wait(conditions, timeout) != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: %N:%l: main() -") ACE_TEXT(" wait failed!\n")), -1); } } ws->detach_condition(condition); // Write samples Messenger::Message message; message.subject_id = 99; message.from = "Comic Book Guy"; message.subject = "Review"; message.text = "Worst. Movie. Ever."; message.count = 0; for (int i = 0; i < 10; ++i) { DDS::ReturnCode_t error = message_writer->write(message, DDS::HANDLE_NIL); ++message.count; ++message.subject_id; if (error != DDS::RETCODE_OK) { ACE_ERROR((LM_ERROR, ACE_TEXT("ERROR: %N:%l: main() -") ACE_TEXT(" write returned %d!\n"), error)); } } } ACE_DEBUG((LM_DEBUG, "(%P|%t) Stop publisher\n")); // Clean-up! participant->delete_contained_entities(); dpf->delete_participant(participant); TheServiceParticipant->shutdown(); } catch (const CORBA::Exception& e) { e._tao_print_exception("Exception caught in main():"); return -1; } ACE_DEBUG((LM_DEBUG, "(%P|%t) Publisher exiting\n")); return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { DDS::DomainParticipantFactory_var dpf; DDS::DomainParticipant_var participant; try { std::cout << "Starting publisher" << std::endl; { // Initialize DomainParticipantFactory dpf = TheParticipantFactoryWithArgs(argc, argv); std::cout << "Starting publisher with " << argc << " args" << std::endl; int error; if ((error = parse_args(argc, argv)) != 0) { return error; } // Create DomainParticipant participant = dpf->create_participant(4, PARTICIPANT_QOS_DEFAULT, DDS::DomainParticipantListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(participant.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: create_participant failed!\n")), -1); } // Register TypeSupport (Messenger::Message) Messenger::MessageTypeSupport_var mts = new Messenger::MessageTypeSupportImpl(); if (mts->register_type(participant.in(), "") != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: register_type failed!\n")), -1); } // Create Topic CORBA::String_var type_name = mts->get_type_name(); DDS::Topic_var topic = participant->create_topic("Movie Discussion List", type_name.in(), TOPIC_QOS_DEFAULT, DDS::TopicListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(topic.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: create_topic failed!\n")), -1); } // Create Publisher DDS::Publisher_var pub = participant->create_publisher(PUBLISHER_QOS_DEFAULT, DDS::PublisherListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(pub.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: create_publisher failed!\n")), -1); } DDS::DataWriterQos qos; pub->get_default_datawriter_qos(qos); if (dw_reliable()) { std::cout << "Reliable DataWriter" << std::endl; qos.history.kind = DDS::KEEP_ALL_HISTORY_QOS; qos.reliability.kind = DDS::RELIABLE_RELIABILITY_QOS; } // Create DataWriter DDS::DataWriter_var dw = pub->create_datawriter(topic.in(), qos, DDS::DataWriterListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(dw.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: create_datawriter failed!\n")), -1); } // Start writing threads std::cout << "Creating Writer" << std::endl; Writer* writer = new Writer(dw.in()); std::cout << "Starting Writer" << std::endl; writer->start(); while (!writer->is_finished()) { ACE_Time_Value small_time(0, 250000); ACE_OS::sleep(small_time); } std::cout << "Writer finished " << std::endl; writer->end(); if (wait_for_acks) { std::cout << "Writer wait for ACKS" << std::endl; DDS::Duration_t timeout = { DDS::DURATION_INFINITE_SEC, DDS::DURATION_INFINITE_NSEC }; dw->wait_for_acknowledgments(timeout); } else { // let any missed multicast/rtps messages get re-delivered ACE_Time_Value small_time(0, 250000); ACE_OS::sleep(small_time); } std::cout << "deleting DW" << std::endl; delete writer; } // Clean-up! participant->delete_contained_entities(); dpf->delete_participant(participant.in()); TheServiceParticipant->shutdown(); } catch (const CORBA::Exception& e) { e._tao_print_exception("Exception caught in main():"); ACE_OS::exit(-1); } return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { // Initialize DomainParticipantFactory DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); // Create DomainParticipant DDS::DomainParticipant_var participant = dpf->create_participant(42, PARTICIPANT_QOS_DEFAULT, DDS::DomainParticipantListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(participant.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: %N:%l: main() -") ACE_TEXT(" create_participant failed!\n")), -1); } // Register TypeSupport (Messenger::Message) Messenger::MessageTypeSupport_var ts = new Messenger::MessageTypeSupportImpl(); if (ts->register_type(participant.in(), "") != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: %N:%l: main() -") ACE_TEXT(" register_type failed!\n")), -1); } // Create Topic (Movie Discussion List) CORBA::String_var type_name = ts->get_type_name(); DDS::Topic_var topic = participant->create_topic("Movie Discussion List", type_name.in(), TOPIC_QOS_DEFAULT, DDS::TopicListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(topic.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: %N:%l: main() -") ACE_TEXT(" create_topic failed!\n")), -1); } // Create Publisher DDS::Publisher_var publisher = participant->create_publisher(PUBLISHER_QOS_DEFAULT, DDS::PublisherListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(publisher.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: %N:%l: main() -") ACE_TEXT(" create_publisher failed!\n")), -1); } // Create DataWriter DDS::DataWriter_var writer = publisher->create_datawriter(topic.in(), DATAWRITER_QOS_DEFAULT, DDS::DataWriterListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(writer.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: %N:%l: main() -") ACE_TEXT(" create_datawriter failed!\n")), -1); } Messenger::MessageDataWriter_var message_writer = Messenger::MessageDataWriter::_narrow(writer.in()); if (CORBA::is_nil(message_writer.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: %N:%l: main() -") ACE_TEXT(" _narrow failed!\n")), -1); } // Block until Subscriber is available DDS::StatusCondition_var condition = writer->get_statuscondition(); condition->set_enabled_statuses(DDS::PUBLICATION_MATCHED_STATUS); DDS::WaitSet_var ws = new DDS::WaitSet; ws->attach_condition(condition); DDS::ConditionSeq conditions; DDS::PublicationMatchedStatus matches = { 0, 0, 0, 0, 0 }; DDS::Duration_t timeout = { 30, 0 }; do { if (ws->wait(conditions, timeout) != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: %N:%l: main() -") ACE_TEXT(" wait failed!\n")), -1); } if (writer->get_publication_matched_status(matches) != ::DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: %N:%l: main() -") ACE_TEXT(" get_publication_matched_status failed!\n")), -1); } } while (matches.current_count < 1); ws->detach_condition(condition); // Write samples Messenger::Message message; message.subject_id = 99; message.from = CORBA::string_dup("Comic Book Guy"); message.subject = CORBA::string_dup("Review"); message.text = CORBA::string_dup("Worst. Movie. Ever."); message.count = 0; for (int i = 0; i < 10; i++) { DDS::ReturnCode_t error = message_writer->write(message, DDS::HANDLE_NIL); if (error != DDS::RETCODE_OK) { ACE_ERROR((LM_ERROR, ACE_TEXT("ERROR: %N:%l: main() -") ACE_TEXT(" write returned %d!\n"), error)); } } // Wait for samples to be acknowledged if (message_writer->wait_for_acknowledgments(timeout) != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: %N:%l: main() -") ACE_TEXT(" wait_for_acknowledgments failed!\n")), -1); } // Clean-up! participant->delete_contained_entities(); dpf->delete_participant(participant.in()); TheServiceParticipant->shutdown(); } catch (const CORBA::Exception& e) { e._tao_print_exception("Exception caught in main():"); return -1; } return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { bool ok = true; bool generated_config = false; try { //Look to see if the config file (.ini) was generated //for rtps participant processing for(int i = 0; i < argc; ++i) { if(ACE_OS::strstr(argv[i], ACE_TEXT("generated"))) { generated_config = true; } } // Initialize DomainParticipantFactory DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); // handle test performance issue on one platform #if defined (sun) const char* udpTransName = "udp"; OpenDDS::DCPS::TransportInst_rch inst = OpenDDS::DCPS::TransportRegistry::instance()->get_inst(udpTransName); if (inst != 0) { OpenDDS::DCPS::UdpInst_rch udp_inst = OpenDDS::DCPS::dynamic_rchandle_cast<OpenDDS::DCPS::UdpInst>(inst); if (udp_inst == 0) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: retrieving transport config for: %C failed!\n"), udpTransName), -1); } udp_inst->rcv_buffer_size_ = 0x40000; } #endif const Options options(argc, argv); // Create DomainParticipant typedef std::vector<DDS::DomainParticipant_var> Participants; Participants participants(options.num_sub_participants); // Register Type (Messenger::Message) Messenger::MessageTypeSupport_var ts = new Messenger::MessageTypeSupportImpl(); CORBA::String_var type_name = ts->get_type_name(); typedef std::vector<DataReaderListenerImpl*> ListenerServants; ListenerServants listener_servants; std::vector<DDS::DataReaderListener_var> listeners; std::stringstream ss; ss << std::setw(5) << ACE_OS::getpid(); const std::string pid = ss.str(); ACE_DEBUG((LM_DEBUG, ACE_TEXT("%T (%P|%t) Created dpf\n"))); unsigned int part_index = 0; for (Participants::iterator part = participants.begin(); part != participants.end(); ++part, ++part_index) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("%T (%P|%t) Creating participant\n"))); *part = dpf->create_participant(411, PARTICIPANT_QOS_DEFAULT, DDS::DomainParticipantListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(part->in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: create_participant() failed!\n")), -1); } if (generated_config) { std::stringstream domain_config_stream; std::string config_name = "domain_part_"; domain_config_stream << config_name << part_index; std::string config; config = domain_config_stream.str(); TheTransportRegistry->bind_config(config, *part); } if (ts->register_type(part->in(), "") != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: register_type() failed!\n")), -1); } // Create Topic (Movie Discussion List) DDS::Topic_var topic = (*part)->create_topic("Movie Discussion List", type_name.in(), TOPIC_QOS_DEFAULT, DDS::TopicListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(topic.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: create_topic() failed!\n")), -1); } // Create Subscriber DDS::Subscriber_var sub = (*part)->create_subscriber(SUBSCRIBER_QOS_DEFAULT, DDS::SubscriberListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(sub.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: create_subscriber() failed!\n")), -1); } DDS::DataReaderQos qos; sub->get_default_datareader_qos(qos); qos.liveliness.kind = DDS::AUTOMATIC_LIVELINESS_QOS; qos.liveliness.lease_duration.sec = 10; qos.liveliness.lease_duration.nanosec = 0; qos.history.kind = DDS::KEEP_ALL_HISTORY_QOS; if (options.reliable) { qos.reliability.kind = DDS::RELIABLE_RELIABILITY_QOS; } for (unsigned int reader = 0; reader < options.num_readers; ++reader) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("%T (%P|%t) Creating reader\n"))); // Create DataReader listener_servants.push_back(new DataReaderListenerImpl(options, pid, part_index, reader)); listeners.push_back(DDS::DataReaderListener_var(listener_servants.back())); DDS::DataReader_var data_reader = sub->create_datareader(topic.in(), qos, listeners.back().in(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(data_reader.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: create_datareader() failed!\n")), -1); } } } const unsigned int sleep_delay_msec = 500; unsigned int delay = 0; while (delay < options.total_duration_msec) { bool complete = true; for (ListenerServants::const_iterator listener = listener_servants.begin(); listener != listener_servants.end(); ++listener) { if (!(*listener)->done()) { complete = false; } } if (complete) break; delay += sleep_delay_msec; ACE_OS::sleep(ACE_Time_Value(0, sleep_delay_msec * 1000)); } ACE_DEBUG((LM_DEBUG, ACE_TEXT("%T (%P|%t) Listeners done (ran for %d msec)\n"), delay)); if (delay >= options.total_duration_msec) { for (ListenerServants::const_iterator listener = listener_servants.begin(); listener != listener_servants.end(); ++listener) { (*listener)->report_errors(); } if (options.reliable) { ok = false; } } // Clean-up! for (Participants::iterator part = participants.begin(); part != participants.end(); ++part) { (*part)->delete_contained_entities(); dpf->delete_participant(*part); } TheServiceParticipant->shutdown(); ACE_Thread_Manager::instance()->wait(); } catch (const CORBA::Exception& e) { e._tao_print_exception("Exception caught in main():"); return -1; } catch (const OpenDDS::DCPS::Transport::Exception& e) { ACE_DEBUG((LM_ERROR, "Transport exception caught in subscriber main\n")); return -1; } ACE_DEBUG((LM_DEBUG, ACE_TEXT("%T (%P|%t) Subscriber exiting\n"))); return ok ? EXIT_SUCCESS : EXIT_FAILURE; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { int status = EXIT_SUCCESS; try { // Initialize DomainParticipantFactory DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); bool reliable = true; int num_messages_expected = 40; parse_args(argc, argv, reliable, num_messages_expected); // handle test performance issue on one platform #if defined (sun) const char* udpTransName = "udp"; OpenDDS::DCPS::TransportInst_rch inst = OpenDDS::DCPS::TransportRegistry::instance()->get_inst(udpTransName); if (inst != 0) { OpenDDS::DCPS::UdpInst_rch udp_inst = OpenDDS::DCPS::dynamic_rchandle_cast<OpenDDS::DCPS::UdpInst>(inst); if (udp_inst == 0) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: retrieving transport config for: %C failed!\n"), udpTransName), -1); } udp_inst->rcv_buffer_size_ = 0x40000; } #endif // Create DomainParticipant DDS::DomainParticipant_var participant = dpf->create_participant(411, PARTICIPANT_QOS_DEFAULT, DDS::DomainParticipantListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(participant.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: create_participant() failed!\n")), -1); } // Register Type (Messenger::Message) Messenger::MessageTypeSupport_var ts = new Messenger::MessageTypeSupportImpl(); if (ts->register_type(participant.in(), "") != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: register_type() failed!\n")), -1); } // Create Topic (Movie Discussion List) CORBA::String_var type_name = ts->get_type_name(); DDS::Topic_var topic = participant->create_topic("Movie Discussion List", type_name.in(), TOPIC_QOS_DEFAULT, DDS::TopicListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(topic.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: create_topic() failed!\n")), -1); } // Create Subscriber DDS::Subscriber_var sub = participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT, DDS::SubscriberListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(sub.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: create_subscriber() failed!\n")), -1); } // Create DataReader DataReaderListenerImpl* listener_svt = new DataReaderListenerImpl; DDS::DataReaderListener_var listener(listener_svt); DDS::DataReaderQos qos; sub->get_default_datareader_qos(qos); qos.liveliness.kind = DDS::AUTOMATIC_LIVELINESS_QOS; qos.liveliness.lease_duration.sec = 10; qos.liveliness.lease_duration.nanosec = 0; qos.history.kind = DDS::KEEP_ALL_HISTORY_QOS; qos.durability.kind = DDS::TRANSIENT_LOCAL_DURABILITY_QOS; if (reliable) { qos.reliability.kind = DDS::RELIABLE_RELIABILITY_QOS; } DDS::DataReader_var reader = sub->create_datareader(topic.in(), qos, listener.in(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(reader.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: create_datareader() failed!\n")), -1); } for (int delay = 0; listener_svt->num_samples() != num_messages_expected && delay < 60; ++delay) { ACE_OS::sleep(1); } const long received = listener_svt->num_samples(); const bool data_consistent = reliable ? listener_svt->data_consistent() : true; std::string error = ""; bool show_data_loss = true; if (reliable && data_consistent && received < num_messages_expected) { error = "ERROR: "; status = EXIT_FAILURE; } else if (!data_consistent) { status = EXIT_FAILURE; show_data_loss = false; } if (show_data_loss && num_messages_expected) { const unsigned int missed_msgs = (num_messages_expected - received); const unsigned int percent = (missed_msgs * 100) / num_messages_expected; std::cout << error << "data loss == " << percent << "% (" << received << "/" << num_messages_expected << " received)\n"; } // Clean-up! ACE_DEBUG((LM_DEBUG, "Subscriber delete contained entities\n")); participant->delete_contained_entities(); ACE_DEBUG((LM_DEBUG, "Subscriber delete participant\n")); dpf->delete_participant(participant); ACE_DEBUG((LM_DEBUG, "Subscriber shutdown\n")); TheServiceParticipant->shutdown(); ACE_DEBUG((LM_DEBUG, "Subscriber wait for thread manager\n")); ACE_Thread_Manager::instance()->wait(); ACE_DEBUG((LM_DEBUG, "Subscriber vars going out of scope\n")); } catch (const CORBA::Exception& e) { e._tao_print_exception("Exception caught in main():"); status = EXIT_FAILURE; } ACE_DEBUG((LM_DEBUG, "Subscriber exiting with status=%d\n", status)); return status; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]){ try { DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); DDS::DomainParticipant_var participant = dpf->create_participant(11, PARTICIPANT_QOS_DEFAULT, DDS::DomainParticipantListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (participant.in ())) { cerr << "create_participant failed." << endl; return 1; } else { ACE_DEBUG ((LM_DEBUG, "Created participant 1 with instance handle %d\n", participant->get_instance_handle ())); } DDS::DomainParticipant_var participant2 = dpf->create_participant(11, PARTICIPANT_QOS_DEFAULT, DDS::DomainParticipantListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (participant2.in ())) { cerr << "create_participant2 failed." << endl; return 1; } else { ACE_DEBUG ((LM_DEBUG, "Created participant 2 with instance handle %d\n", participant2->get_instance_handle ())); } // Register TypeSupport (Messenger::Message) Messenger::MessageTypeSupport_var mts = new Messenger::MessageTypeSupportImpl(); if (mts->register_type(participant.in(), "") != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: register_type failed!\n")), -1); } // Create Topic CORBA::String_var type_name = mts->get_type_name(); DDS::Topic_var topic = participant->create_topic("Movie Discussion List", type_name.in(), TOPIC_QOS_DEFAULT, DDS::TopicListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(topic.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: create_topic failed!\n")), -1); } // Create Publisher DDS::Publisher_var pub = participant->create_publisher(PUBLISHER_QOS_DEFAULT, DDS::PublisherListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(pub.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: create_publisher failed!\n")), -1); } // Create DataWriter DDS::DataWriter_var dw = pub->create_datawriter(topic.in(), DATAWRITER_QOS_DEFAULT, DDS::DataWriterListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(dw.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: create_datawriter failed!\n")), -1); } DDS::ReturnCode_t retcode = participant2->delete_topic (topic.in ()); if (retcode != DDS::RETCODE_PRECONDITION_NOT_MET) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: should not be able to delete topic, not part of this participant!\n")), -1); } DDS::ReturnCode_t retcode5 = participant->delete_topic (topic.in ()); if (retcode5 != DDS::RETCODE_PRECONDITION_NOT_MET) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: should not be able to delete topic, still referenced by datawriter!\n")), -1); } DDS::ReturnCode_t retcode2 = pub->delete_datawriter (dw.in ()); if (retcode2 != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: should be able to delete datawriter\n")), -1); } dw = DDS::DataWriter::_nil (); DDS::Duration_t timeout; timeout.sec = 0; timeout.nanosec = 0; // Doing a find_topic will require us to call delete topic twice, see // 7.1.2.2.1.11 from the dds spec DDS::Topic_var topic2 = participant->find_topic ("Movie Discussion List", timeout); if (CORBA::is_nil (topic2.in ())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: Not able to find topic\n")), -1); } DDS::ReturnCode_t retcode4 = participant->delete_topic (topic.in ()); if (retcode4 != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: should be able to delete topic\n")), -1); } topic = DDS::Topic::_nil (); DDS::ReturnCode_t retcode6 = participant->delete_topic (topic2.in ()); if (retcode6 != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: should be able to delete topic\n")), -1); } topic2 = DDS::Topic::_nil (); DDS::ReturnCode_t retcode8 = participant->delete_publisher (pub.in ()); if (retcode8 != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: should be able to delete publisher\n")), -1); } pub = DDS::Publisher::_nil (); dpf->delete_participant(participant.in ()); participant = DDS::DomainParticipant::_nil (); dpf->delete_participant(participant2.in ()); participant2 = DDS::DomainParticipant::_nil (); TheServiceParticipant->shutdown (); } catch (CORBA::Exception& e) { cerr << "dp: Exception caught in main.cpp:" << endl << e << endl; exit(1); } return 0; }
int main (int argc, char *argv[]) { try { // initialize the participant. the same as in the publisher DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); DDS::DomainParticipant_var participant = dpf->create_participant(42, // Domain ID PARTICIPANT_QOS_DEFAULT, 0, // No listener required OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (!participant) { std::cerr << "create_participant failed." << std::endl; return 1 ; } Messenger::MessageTypeSupport_var mts = new Messenger::MessageTypeSupportImpl(); if (DDS::RETCODE_OK != mts->register_type(participant, "")) { std::cerr << "Failed to register the MessageTypeSupport." << std::endl; return 1; } CORBA::String_var type_name = mts->get_type_name (); DDS::Topic_var topic = participant->create_topic("Movie Discussion List", type_name, TOPIC_QOS_DEFAULT, 0, // No listener required OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (!topic) { std::cerr << "Failed to create_topic." << std::endl; return 1; } // Create the subscriber DDS::Subscriber_var sub = participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT, 0, // No listener required OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (!sub) { std::cerr << "Failed to create_subscriber." << std::endl; return 1; } // Associate a listener object with the data reader we create, // so we can use it to detect when data is available. // The listener is allocated on the heap and assigned to a// // DataReaderListener_var object. This type provides // reference counting behavior so the listener is // automatically cleaned up when the last reference to it is // removed. This usage is typical for heap allocations in // OpenDDS application code and frees the application // developer from having to actively manage the lifespan of // the allocated objects. DDS::DataReaderListener_var listener(new DataReaderListenerImpl); // Create the data reader DDS::DataReader_var dr = sub->create_datareader(topic, DATAREADER_QOS_DEFAULT, listener, OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (!dr) { std::cerr << "create_datareader failed." << std::endl; return 1; } // clean up //1. delete all the topics, subscribers and publishers create // with this participant //2. when done, use the factory to delete the domain participant. participant->delete_contained_entities(); dpf->delete_participant(participant); TheServiceParticipant->shutdown (); } catch(...) { std::cerr << "ERROR!!! exception caught" << std::endl; } }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { int status = 0; try { // Initialize DomainParticipantFactory DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); int error; if ((error = parse_args(argc, argv)) != 0) { return error; } // Create DomainParticipant DDS::DomainParticipant_var participant = dpf->create_participant(4, PARTICIPANT_QOS_DEFAULT, DDS::DomainParticipantListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(participant.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: create_participant() failed!\n")), -1); } // Register Type (Messenger::Message) Messenger::MessageTypeSupport_var ts = new Messenger::MessageTypeSupportImpl(); if (ts->register_type(participant.in(), "") != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: register_type() failed!\n")), -1); } // Create Topic (Movie Discussion List) CORBA::String_var type_name = ts->get_type_name(); DDS::Topic_var topic = participant->create_topic("Movie Discussion List", type_name.in(), TOPIC_QOS_DEFAULT, DDS::TopicListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(topic.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: create_topic() failed!\n")), -1); } // Create Subscriber DDS::Subscriber_var sub = participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT, DDS::SubscriberListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(sub.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: create_subscriber() failed!\n")), -1); } // Create DataReader DataReaderListenerImpl* const listener_servant = new DataReaderListenerImpl; DDS::DataReaderListener_var listener(listener_servant); DDS::DataReaderQos dr_qos; sub->get_default_datareader_qos(dr_qos); if (DataReaderListenerImpl::is_reliable()) { std::cout << "Reliable DataReader" << std::endl; dr_qos.reliability.kind = DDS::RELIABLE_RELIABILITY_QOS; } DDS::DataReader_var reader = sub->create_datareader(topic.in(), dr_qos, listener.in(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(reader.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: create_datareader() failed!\n")), -1); } // Block until Publisher completes DDS::StatusCondition_var condition = reader->get_statuscondition(); condition->set_enabled_statuses(DDS::SUBSCRIPTION_MATCHED_STATUS); DDS::WaitSet_var ws = new DDS::WaitSet; ws->attach_condition(condition); DDS::Duration_t timeout = { DDS::DURATION_INFINITE_SEC, DDS::DURATION_INFINITE_NSEC }; DDS::ConditionSeq conditions; DDS::SubscriptionMatchedStatus matches = { 0, 0, 0, 0, 0 }; while (true) { if (reader->get_subscription_matched_status(matches) != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: get_subscription_matched_status() failed!\n")), -1); } if (matches.current_count == 0 && matches.total_count > 0) { break; } if (ws->wait(conditions, timeout) != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: wait() failed!\n")), -1); } } status = listener_servant->is_valid() ? 0 : -1; ws->detach_condition(condition); // Clean-up! participant->delete_contained_entities(); dpf->delete_participant(participant.in()); TheServiceParticipant->shutdown(); } catch (const CORBA::Exception& e) { e._tao_print_exception("Exception caught in main():"); status = -1; } return status; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { // Initialize DomainParticipantFactory DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); DDS::DomainParticipant_var participant; bool result1, result2; int error; if ((error = parse_args(argc, argv)) != 0) { ACE_DEBUG((LM_ERROR, "(%P|%t) Parsing error, returning %d\n", error)); return error; } { // Scope of entities // Create DomainParticipant participant = dpf->create_participant(411, PARTICIPANT_QOS_DEFAULT, DDS::DomainParticipantListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(participant.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: create_participant() failed!\n")), -1); } // Register Type (Messenger::Message) Messenger::MessageTypeSupport_var ts = new Messenger::MessageTypeSupportImpl(); if (ts->register_type(participant.in(), "") != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: register_type() failed!\n")), -1); } // Create Topic (Movie Discussion List) DDS::Topic_var topic = participant->create_topic("Movie Discussion List", ts->get_type_name(), TOPIC_QOS_DEFAULT, DDS::TopicListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(topic.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: create_topic() failed!\n")), -1); } // Create Subscriber DDS::Subscriber_var sub = participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT, DDS::SubscriberListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(sub.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: create_subscriber() failed!\n")), -1); } // Create DataReader DataReaderListenerImpl* listener_svt1 = new DataReaderListenerImpl("DataReader1"); DataReaderListenerImpl* listener_svt2 = new DataReaderListenerImpl("DataReader2"); DDS::DataReaderListener_var listener1(listener_svt1); DDS::DataReaderListener_var listener2(listener_svt2); ::DDS::DataReaderQos dr_qos; sub->get_default_datareader_qos (dr_qos); dr_qos.ownership.kind = ::DDS::EXCLUSIVE_OWNERSHIP_QOS; dr_qos.deadline.period.sec = deadline.sec; dr_qos.deadline.period.nanosec = deadline.nanosec; dr_qos.liveliness.lease_duration.sec = liveliness.sec; dr_qos.liveliness.lease_duration.nanosec = liveliness.nanosec; DDS::DataReader_var reader1 = sub->create_datareader(topic.in(), dr_qos, listener1.in(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(reader1.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: create_datareader() failed!\n")), -1); } DDS::DataReader_var reader2 = sub->create_datareader(topic.in(), dr_qos, listener2.in(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(reader2.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: create_datareader() failed!\n")), -1); } // Block until Publisher completes DDS::StatusCondition_var condition1 = reader1->get_statuscondition(); DDS::StatusCondition_var condition2 = reader2->get_statuscondition(); condition1->set_enabled_statuses(DDS::SUBSCRIPTION_MATCHED_STATUS); condition2->set_enabled_statuses(DDS::SUBSCRIPTION_MATCHED_STATUS); DDS::WaitSet_var ws = new DDS::WaitSet; ws->attach_condition(condition1); ws->attach_condition(condition2); DDS::Duration_t timeout = { DDS::DURATION_INFINITE_SEC, DDS::DURATION_INFINITE_NSEC }; DDS::ConditionSeq conditions; DDS::SubscriptionMatchedStatus matches1 = { 0, 0, 0, 0, 0 }; DDS::SubscriptionMatchedStatus matches2 = { 0, 0, 0, 0, 0 }; while (true) { if (reader1->get_subscription_matched_status(matches1) != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: get_subscription_matched_status() failed!\n")), -1); } if (reader2->get_subscription_matched_status(matches2) != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: get_subscription_matched_status() failed!\n")), -1); } if ((matches1.current_count == 0 && matches1.total_count > 0) || (matches2.current_count == 0 && matches2.total_count > 0)) { break; } DDS::ReturnCode_t wait_status = ws->wait(conditions, timeout); if (wait_status != DDS::RETCODE_OK) { std::cerr << "ERROR: Subscriber failed during waiting on wait set with return code " << wait_status << std::endl; } } ws->detach_condition(condition1); ws->detach_condition(condition2); result1 = listener_svt1->verify_result(); result2 = listener_svt2->verify_result(); } // Scope of entities // Clean-up! participant->delete_contained_entities(); dpf->delete_participant(participant.in()); TheServiceParticipant->shutdown(); if (result1 == false || result2 == false) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: failed to verify message!\n")), -2); } } catch (const CORBA::Exception& e) { e._tao_print_exception("Exception caught in main():"); return -1; } return 0; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]){ try { DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); OpenDDS::DCPS::TransportConfig_rch config = OpenDDS::DCPS::TransportRegistry::instance()->get_config("dds4ccm_rtps"); if (config.is_nil()) { config = OpenDDS::DCPS::TransportRegistry::instance()->create_config("dds4ccm_rtps"); } OpenDDS::DCPS::TransportInst_rch inst = OpenDDS::DCPS::TransportRegistry::instance()->get_inst("the_rtps_transport"); if (inst.is_nil()) { inst = OpenDDS::DCPS::TransportRegistry::instance()->create_inst("the_rtps_transport", "rtps_udp"); config->instances_.push_back(inst); OpenDDS::DCPS::TransportRegistry::instance()->global_config(config); } // Create another transport instance for participant2 since RTPS transport instances // cannot be shared by domain participants. OpenDDS::DCPS::TransportConfig_rch config2 = OpenDDS::DCPS::TransportRegistry::instance()->get_config("dds4ccm_rtps_2"); if (config2.is_nil()) { config2 = OpenDDS::DCPS::TransportRegistry::instance()->create_config("dds4ccm_rtps_2"); } OpenDDS::DCPS::TransportInst_rch inst2 = OpenDDS::DCPS::TransportRegistry::instance()->get_inst("the_rtps_transport_2"); if (inst2.is_nil()) { inst2 = OpenDDS::DCPS::TransportRegistry::instance()->create_inst("the_rtps_transport_2", "rtps_udp"); config2->instances_.push_back(inst2); } #ifndef DDS_HAS_MINIMUM_BIT OpenDDS::RTPS::RtpsDiscovery_rch disc = new OpenDDS::RTPS::RtpsDiscovery(OpenDDS::DCPS::Discovery::DEFAULT_RTPS); // The recommended value for the resend period is 2 seconds for // the current implementation of OpenDDS. disc->resend_period(ACE_Time_Value(2)); TheServiceParticipant->add_discovery(OpenDDS::DCPS::static_rchandle_cast<OpenDDS::DCPS::Discovery>(disc)); TheServiceParticipant->set_repo_domain(11, disc->key()); #endif TheServiceParticipant->set_default_discovery (OpenDDS::DCPS::Discovery::DEFAULT_RTPS); DDS::DomainParticipant_var participant = dpf->create_participant(11, PARTICIPANT_QOS_DEFAULT, DDS::DomainParticipantListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (participant.in ())) { cerr << "create_participant failed." << endl; return 1; } else { ACE_DEBUG ((LM_DEBUG, "Created participant 1 with instance handle %d\n", participant->get_instance_handle ())); } OpenDDS::DCPS::TransportRegistry::instance()->bind_config(config, participant.in()); DDS::DomainParticipant_var participant2 = dpf->create_participant(11, PARTICIPANT_QOS_DEFAULT, DDS::DomainParticipantListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (participant2.in ())) { cerr << "create_participant failed." << endl; return 1; } else { ACE_DEBUG ((LM_DEBUG, "Created participant 2 with instance handle %d\n", participant2->get_instance_handle ())); } try { OpenDDS::DCPS::TransportRegistry::instance()->bind_config(config2, participant2.in()); } catch (const OpenDDS::DCPS::Transport::MiscProblem &) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: TransportRegistry::bind_config() throws") ACE_TEXT(" Transport::MiscProblem exception\n")), -1); } catch (const OpenDDS::DCPS::Transport::NotFound &) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: TransportRegistry::bind_config() throws") ACE_TEXT(" Transport::NotFound exception\n")), -1); } // Register TypeSupport (Messenger::Message) Messenger::MessageTypeSupport_var mts = new Messenger::MessageTypeSupportImpl(); if (mts->register_type(participant.in(), "") != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: register_type failed!\n")), -1); } // Create Topic CORBA::String_var type_name = mts->get_type_name(); DDS::Topic_var topic = participant->create_topic("Movie Discussion List", type_name.in(), TOPIC_QOS_DEFAULT, DDS::TopicListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(topic.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: create_topic failed!\n")), -1); } // Create Publisher DDS::Publisher_var pub = participant->create_publisher(PUBLISHER_QOS_DEFAULT, DDS::PublisherListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(pub.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: create_publisher failed!\n")), -1); } // Create DataWriter DDS::DataWriter_var dw = pub->create_datawriter(topic.in(), DATAWRITER_QOS_DEFAULT, DDS::DataWriterListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(dw.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: create_datawriter failed!\n")), -1); } DDS::ReturnCode_t retcode2 = pub->delete_datawriter (dw.in ()); if (retcode2 != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: should be able to delete datawriter\n")), -1); } DDS::ReturnCode_t retcode5 = dpf->delete_participant(participant.in ()); if (retcode5 != DDS::RETCODE_PRECONDITION_NOT_MET) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: should not be able to delete participant\n")), -1); } DDS::ReturnCode_t retcode3 = participant->delete_publisher (pub.in ()); if (retcode3 != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: should be able to delete publisher\n")), -1); } DDS::ReturnCode_t retcode4 = participant->delete_topic (topic.in ()); if (retcode4 != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: should be able to delete topic\n")), -1); } DDS::ReturnCode_t retcode6 = dpf->delete_participant(participant.in ()); if (retcode6 != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: should be able to delete participant\n")), -1); } // DDS::ReturnCode_t retcode7 = dpf->delete_participant(participant2.in ()); // if (retcode7 != DDS::RETCODE_OK) { // ACE_ERROR_RETURN((LM_ERROR, // ACE_TEXT("%N:%l: main()") // ACE_TEXT(" ERROR: should be able to delete participant2\n")), // -1); // } ACE_DEBUG ((LM_DEBUG, "Shutting down the service participant with one participant still registered\n")); TheServiceParticipant->shutdown (); } catch (CORBA::Exception& e) { cerr << "dp: Exception caught in main.cpp:" << endl << e << endl; exit(1); } return 0; }
int main (int argc, ACE_TCHAR *argv[]) { try { DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); DDS::DomainParticipant_var participant = dpf->create_participant(411, PARTICIPANT_QOS_DEFAULT, DDS::DomainParticipantListener::_nil()); if (CORBA::is_nil (participant.in ())) { cerr << "create_participant failed." << endl; return 1; } if (parse_args (argc, argv) == -1) { return -1; } Messenger::MessageTypeSupport_var mts = new Messenger::MessageTypeSupportImpl(); if (DDS::RETCODE_OK != mts->register_type(participant.in (), "")) { cerr << "register_type failed." << endl; exit(1); } CORBA::String_var type_name = mts->get_type_name (); DDS::TopicQos topic_qos; participant->get_default_topic_qos(topic_qos); DDS::Topic_var topic = participant->create_topic ("Movie Discussion List", type_name.in (), topic_qos, DDS::TopicListener::_nil()); if (CORBA::is_nil (topic.in ())) { cerr << "create_topic failed." << endl; exit(1); } OpenDDS::DCPS::TransportImpl_rch tcp_impl = TheTransportFactory->create_transport_impl (transport_impl_id, ::OpenDDS::DCPS::AUTO_CONFIG); DDS::Publisher_var pub = participant->create_publisher(PUBLISHER_QOS_DEFAULT, DDS::PublisherListener::_nil()); if (CORBA::is_nil (pub.in ())) { cerr << "create_publisher failed." << endl; exit(1); } // Attach the publisher to the transport. OpenDDS::DCPS::PublisherImpl* pub_impl = dynamic_cast< OpenDDS::DCPS::PublisherImpl*>(pub.in ()); if (0 == pub_impl) { cerr << "Failed to obtain publisher servant" << endl; exit(1); } OpenDDS::DCPS::AttachStatus status = pub_impl->attach_transport(tcp_impl.in()); if (status != OpenDDS::DCPS::ATTACH_OK) { std::string status_str; switch (status) { case OpenDDS::DCPS::ATTACH_BAD_TRANSPORT: status_str = "ATTACH_BAD_TRANSPORT"; break; case OpenDDS::DCPS::ATTACH_ERROR: status_str = "ATTACH_ERROR"; break; case OpenDDS::DCPS::ATTACH_INCOMPATIBLE_QOS: status_str = "ATTACH_INCOMPATIBLE_QOS"; break; default: status_str = "Unknown Status"; break; } cerr << "Failed to attach to the transport. Status == " << status_str.c_str() << endl; exit(1); } // Create the datawriter DDS::DataWriterQos dw_qos; pub->get_default_datawriter_qos (dw_qos); DDS::DataWriter_var dw = pub->create_datawriter(topic.in (), dw_qos, DDS::DataWriterListener::_nil()); if (CORBA::is_nil (dw.in ())) { cerr << "create_datawriter failed." << endl; exit(1); } Writer* writer = new Writer(dw.in()); writer->start (); while ( !writer->is_finished()) { ACE_Time_Value small(0,250000); ACE_OS::sleep (small); } // Cleanup writer->end (); delete writer; participant->delete_contained_entities(); dpf->delete_participant(participant.in ()); TheTransportFactory->release(); TheServiceParticipant->shutdown (); } catch (CORBA::Exception& e) { cerr << "PUB: Exception caught in main.cpp:" << endl << e << endl; exit(1); } return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { // Initialize DomainParticipantFactory DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); if (parse_args (argc, argv) != 0) { return 1; } TheServiceParticipant->monitor_factory_->initialize(); // Create DomainParticipant DDS::DomainParticipant_var participant = dpf->create_participant(411, PARTICIPANT_QOS_DEFAULT, DDS::DomainParticipantListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(participant.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: create_participant failed!\n")), -1); } // Register TypeSupport (Messenger::Message) Messenger::MessageTypeSupport_var mts = new Messenger::MessageTypeSupportImpl(); if (mts->register_type(participant.in(), "") != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: register_type failed!\n")), -1); } // Create Topic DDS::Topic_var topic = participant->create_topic("Movie Discussion List", mts->get_type_name(), TOPIC_QOS_DEFAULT, DDS::TopicListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(topic.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: create_topic failed!\n")), -1); } // Create Publisher DDS::Publisher_var pub = participant->create_publisher(PUBLISHER_QOS_DEFAULT, DDS::PublisherListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(pub.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: create_publisher failed!\n")), -1); } // Create DataWriter DDS::DataWriter_var dw = pub->create_datawriter(topic.in(), DATAWRITER_QOS_DEFAULT, DDS::DataWriterListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(dw.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: create_datawriter failed!\n")), -1); } // Start writing threads Writer* writer = new Writer(dw.in()); writer->start(); while (!writer->is_finished()) { ACE_Time_Value small_time(0, 250000); ACE_OS::sleep(small_time); } writer->end(); delete writer; // Clean-up! participant->delete_contained_entities(); dpf->delete_participant(participant.in()); TheServiceParticipant->shutdown(); } catch (const CORBA::Exception& e) { e._tao_print_exception("Exception caught in main():"); ACE_OS::exit(-1); } return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { // Initialize DomainParticipantFactory DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); // Create DomainParticipant DDS::DomainParticipant_var participant = dpf->create_participant(42, PARTICIPANT_QOS_DEFAULT, 0, OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (!participant) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: %N:%l: main() -") ACE_TEXT(" create_participant failed!\n")), -1); } // Register Type (Messenger::Message) Messenger::MessageTypeSupport_var ts = new Messenger::MessageTypeSupportImpl; if (ts->register_type(participant, "") != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: %N:%l: main() -") ACE_TEXT(" register_type failed!\n")), -1); } // Create Topic (Movie Discussion List) CORBA::String_var type_name = ts->get_type_name(); DDS::Topic_var topic = participant->create_topic("Movie Discussion List", type_name, TOPIC_QOS_DEFAULT, 0, OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (!topic) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: %N:%l: main() -") ACE_TEXT(" create_topic failed!\n")), -1); } // Create Subscriber DDS::Subscriber_var subscriber = participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT, 0, OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (!subscriber) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: %N:%l: main() -") ACE_TEXT(" create_subscriber failed!\n")), -1); } // Create DataReader DDS::DataReaderListener_var listener(new DataReaderListenerImpl); DDS::DataReader_var reader = subscriber->create_datareader(topic, DATAREADER_QOS_DEFAULT, listener, OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (!reader) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: %N:%l: main() -") ACE_TEXT(" create_datareader failed!\n")), -1); } Messenger::MessageDataReader_var reader_i = Messenger::MessageDataReader::_narrow(reader); if (!reader_i) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: %N:%l: main() -") ACE_TEXT(" _narrow failed!\n")), -1); } // Block until Publisher completes DDS::StatusCondition_var condition = reader->get_statuscondition(); condition->set_enabled_statuses(DDS::SUBSCRIPTION_MATCHED_STATUS); DDS::WaitSet_var ws = new DDS::WaitSet; ws->attach_condition(condition); while (true) { DDS::SubscriptionMatchedStatus matches; if (reader->get_subscription_matched_status(matches) != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: %N:%l: main() -") ACE_TEXT(" get_subscription_matched_status failed!\n")), -1); } if (matches.current_count == 0 && matches.total_count > 0) { break; } DDS::ConditionSeq conditions; DDS::Duration_t timeout = { 60, 0 }; if (ws->wait(conditions, timeout) != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: %N:%l: main() -") ACE_TEXT(" wait failed!\n")), -1); } } ws->detach_condition(condition); // Clean-up! participant->delete_contained_entities(); dpf->delete_participant(participant); TheServiceParticipant->shutdown(); } catch (const CORBA::Exception& e) { e._tao_print_exception("Exception caught in main():"); return -1; } return 0; }
bool Publisher::run (void) { ::DDS::DomainId_t domain_id = 411; try { sync_client_->way_point_reached (1); sync_client_->get_notification (); ACE_High_Res_Timer participant_timer; participant_timer.start(); for (size_t count = 0; count < participant_count_; count++) { participant_[count] = dpf_->create_participant (domain_id, PARTICIPANT_QOS_DEFAULT, DDS::DomainParticipantListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (participant_[count].in ())) { cerr << "create_participant failed." << endl; return false; } } participant_timer.stop(); Messenger::MessageTypeSupport_var mts = new Messenger::MessageTypeSupportImpl(); for (size_t count = 0; count < participant_count_; count++) { if (DDS::RETCODE_OK != mts->register_type(participant_[count].in (), "")) { cerr << "register_type failed." << endl; return false; } } CORBA::String_var type_name = mts->get_type_name (); DDS::TopicQos topic_qos; participant_[0]->get_default_topic_qos(topic_qos); ACE_High_Res_Timer topic_timer; topic_timer.start(); for (size_t count = 0; count < topic_count_; count++) { topic_[count] = participant_[count % participant_count_]->create_topic ("Movie Discussion List", type_name.in (), topic_qos, DDS::TopicListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (topic_[count].in ())) { cerr << "create_topic failed." << endl; return false; } } topic_timer.stop(); // Initialize the transports for( size_t count = 0; count < writer_count_; ++count) { this->transports_[ count] = TheTransportFactory->obtain( this->transport_impl_id_ + count); if( false == this->transports_[ count].is_nil()) { // Only create transports that need to be. continue; } this->transports_[ count] = TheTransportFactory->create_transport_impl( this->transport_impl_id_ + count, ACE_TEXT("SimpleTcp"), ::OpenDDS::DCPS::DONT_AUTO_CONFIG ); OpenDDS::DCPS::TransportConfiguration_rch config = TheTransportFactory->create_configuration( this->transport_impl_id_ + count, ACE_TEXT("SimpleTcp") ); if( this->transports_[ count]->configure( config.in()) != 0) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) %T ERROR: TCP ") ACE_TEXT("failed to configure the transport.\n") )); return false; } } ACE_High_Res_Timer pub_timer; pub_timer.start(); for (size_t count = 0; count < writer_count_; count++) { // Create the publisher and attach to the corresponding // transport. pub_[count] = participant_[count]->create_publisher(PUBLISHER_QOS_DEFAULT, DDS::PublisherListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (pub_[count].in ())) { cerr << "create_publisher failed." << endl; return false; } OpenDDS::DCPS::PublisherImpl* pub_impl = dynamic_cast< OpenDDS::DCPS::PublisherImpl*>(pub_[count].in ()); if (0 == pub_impl) { cerr << "Failed to obtain publisher servant" << endl; return false; } // Attach the publisher to the transport. OpenDDS::DCPS::AttachStatus status = pub_impl->attach_transport( this->transports_[ count].in() ); if (status != OpenDDS::DCPS::ATTACH_OK) { std::string status_str; switch (status) { case OpenDDS::DCPS::ATTACH_BAD_TRANSPORT: status_str = "ATTACH_BAD_TRANSPORT"; break; case OpenDDS::DCPS::ATTACH_ERROR: status_str = "ATTACH_ERROR"; break; case OpenDDS::DCPS::ATTACH_INCOMPATIBLE_QOS: status_str = "ATTACH_INCOMPATIBLE_QOS"; break; default: status_str = "Unknown Status"; break; } cerr << "Failed to attach to the transport. Status == " << status_str.c_str() << endl; return false; } } // Create the datawriter DDS::DataWriterQos dw_qos; pub_[0]->get_default_datawriter_qos (dw_qos); for (size_t count = 0; count < writer_count_; count++) { dw_[count] = pub_[count]->create_datawriter(topic_[count].in (), dw_qos, DDS::DataWriterListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (dw_[count].in ())) { cerr << "create_datawriter failed." << endl; return false; } } // Wait for all expected subscribers while (true) { ::DDS::InstanceHandleSeq handles; dw_[0]->get_matched_subscriptions(handles); //ACE_DEBUG ((LM_DEBUG, "(%P|%t) subs connected: %d\n", handles.length())); if (handles.length() >= subscriber_count_) { break; } ACE_OS::sleep (1); } pub_timer.stop (); // sync up sync_client_->way_point_reached (2); sync_client_->get_notification (); ACE_Time_Value tv; participant_timer.elapsed_time (tv); sync_client_->publish (SyncExt::Topic, topic_count_, tv.msec()); //ACE_DEBUG ((LM_DEBUG, "(%P|%t) Created %d participants in %d secs.\n" //, participant_count_, tv.sec())); topic_timer.elapsed_time (tv); sync_client_->publish (SyncExt::Participant, participant_count_ , tv.msec()); //ACE_DEBUG ((LM_DEBUG, "(%P|%t) Created %d topics in %d secs.\n" //, topic_count_, tv.sec())); pub_timer.elapsed_time (tv); sync_client_->publish (SyncExt::Publisher, writer_count_ , tv.msec()); //ACE_DEBUG ((LM_DEBUG, "(%P|%t) Created %d publishers in %d secs.\n" //, writer_count_, tv.sec())); /* std::auto_ptr<Writer> writer (new Writer(dw_[0].in())); writer->start (); while ( !writer->is_finished()) { ACE_Time_Value small(0,250000); ACE_OS::sleep (small); } // Cleanup writer->end (); //delete writer; */ for (size_t count = 0; count < participant_count_; count++) { participant_[count]->delete_contained_entities (); dpf_->delete_participant (participant_[count].in ()); } TheTransportFactory->release(); TheServiceParticipant->shutdown (); } catch (CORBA::Exception& e) { cerr << "PUB: Exception caught in Publisher::run():\n " << e << endl; return false; } return true; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { // Initialize DomainParticipantFactory DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); int error; if ((error = parse_args(argc, argv)) != 0) { return error; } // Create DomainParticipant DDS::DomainParticipant_var participant = dpf->create_participant(411, PARTICIPANT_QOS_DEFAULT, DDS::DomainParticipantListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(participant.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: create_participant() failed!\n")), -1); } // Register Type (Messenger::Message) Messenger::MessageTypeSupport_var ts = new Messenger::MessageTypeSupportImpl(); if (ts->register_type(participant.in(), "") != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: register_type() failed!\n")), -1); } // Create Topic (Movie Discussion List) DDS::Topic_var topic = participant->create_topic("Movie Discussion List", ts->get_type_name(), TOPIC_QOS_DEFAULT, DDS::TopicListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(topic.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: create_topic() failed!\n")), -1); } ::DDS::SubscriberQos subscriber_qos; participant->get_default_subscriber_qos (subscriber_qos); subscriber_qos.presentation.access_scope = (::DDS::PresentationQosPolicyAccessScopeKind)acess_scope; subscriber_qos.presentation.coherent_access = true; subscriber_qos.presentation.ordered_access = true; SubscriberListenerImpl* subscriber_listener_svt = new SubscriberListenerImpl(); DDS::SubscriberListener_var subscriber_listener(subscriber_listener_svt); // Create Subscriber DDS::Subscriber_var sub = participant->create_subscriber(subscriber_qos, subscriber_listener.in(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(sub.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: create_subscriber() failed!\n")), -1); } // Initialize Transport OpenDDS::DCPS::TransportImpl_rch transport_impl = TheTransportFactory->create_transport_impl(transport_impl_id, OpenDDS::DCPS::AUTO_CONFIG); OpenDDS::DCPS::AttachStatus status = transport_impl->attach(sub.in()); if (status != OpenDDS::DCPS::ATTACH_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: attach() failed!\n")), -1); } // Create DataReader DataReaderListenerImpl* listener_svt1 = new DataReaderListenerImpl("DataReader1"); DataReaderListenerImpl* listener_svt2 = new DataReaderListenerImpl("DataReader2"); DDS::DataReaderListener_var listener1(listener_svt1); DDS::DataReaderListener_var listener2(listener_svt2); ::DDS::DataReaderQos readerQos; sub->get_default_datareader_qos( readerQos); readerQos.history.kind = ::DDS::KEEP_ALL_HISTORY_QOS; readerQos.resource_limits.max_samples_per_instance = ::DDS::LENGTH_UNLIMITED; DDS::DataReader_var reader1 = sub->create_datareader(topic.in(), readerQos, listener1.in(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(reader1.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: create_datareader() failed!\n")), -1); } DDS::DataReader_var reader2 = sub->create_datareader(topic.in(), readerQos, listener2.in(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(reader2.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: create_datareader() failed!\n")), -1); } // Block until Publisher completes DDS::StatusCondition_var condition1 = reader1->get_statuscondition(); DDS::StatusCondition_var condition2 = reader2->get_statuscondition(); condition1->set_enabled_statuses(DDS::SUBSCRIPTION_MATCHED_STATUS); condition2->set_enabled_statuses(DDS::SUBSCRIPTION_MATCHED_STATUS); DDS::WaitSet_var ws1 = new DDS::WaitSet; DDS::WaitSet_var ws2 = new DDS::WaitSet; ws1->attach_condition(condition1); ws2->attach_condition(condition2); DDS::Duration_t timeout = { DDS::DURATION_INFINITE_SEC, DDS::DURATION_INFINITE_NSEC }; DDS::ConditionSeq conditions1; DDS::ConditionSeq conditions2; DDS::SubscriptionMatchedStatus matches1 = { 0, 0, 0, 0, 0 }; DDS::SubscriptionMatchedStatus matches2 = { 0, 0, 0, 0, 0 }; do { if (matches1.current_count == 0 && ws1->wait(conditions1, timeout) != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: wait() failed!\n")), -1); } if (matches2.current_count == 0 && ws2->wait(conditions2, timeout) != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: wait() failed!\n")), -1); } if (reader1->get_subscription_matched_status(matches1) != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: get_subscription_matched_status() failed!\n")), -1); } if (reader2->get_subscription_matched_status(matches2) != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: get_subscription_matched_status() failed!\n")), -1); } } while (matches1.current_count > 0 && matches2.current_count > 0); if (! subscriber_listener_svt->verify_result () || ! listener_svt1->verify_result() || ! listener_svt2->verify_result()) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: failed to verify message!\n")), -1); } ws1->detach_condition(condition1); ws2->detach_condition(condition2); // Clean-up! participant->delete_contained_entities(); dpf->delete_participant(participant.in()); TheTransportFactory->release(); TheServiceParticipant->shutdown(); } catch (const CORBA::Exception& e) { e._tao_print_exception("Exception caught in main():"); return -1; } return 0; }
bool Subscriber::run (void) { ::DDS::DomainId_t domain_id = 411; try { sync_client_->way_point_reached (1); sync_client_->get_notification (); /* size_t max_wait_time = 10; //(seconds) size_t wait_time = 0; while (true) { if (wait_time > max_wait_time) { std::cerr << "Timed out waiting for external file: " << control_file_.c_str() << std::endl; return -1; } // check for file ACE_stat my_stat; if (ACE_OS::stat (control_file_.c_str(), &my_stat) == 0) { // found the trigger file. break; } ACE_OS::sleep (1); wait_time++; } */ ACE_High_Res_Timer participant_timer; participant_timer.start(); for (size_t count = 0; count < participant_count_; count++) { participant_[count] = dpf_->create_participant (domain_id, PARTICIPANT_QOS_DEFAULT, DDS::DomainParticipantListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (participant_[count].in ())) { cerr << "create_participant failed." << endl; return false; } } participant_timer.stop(); Messenger::MessageTypeSupport_var mts = new Messenger::MessageTypeSupportImpl(); for (size_t count = 0; count < participant_count_; count++) { if (DDS::RETCODE_OK != mts ->register_type(participant_[count].in (), "")) { cerr << "register_type failed." << endl; return false; } } CORBA::String_var type_name = mts->get_type_name (); DDS::TopicQos topic_qos; ACE_High_Res_Timer topic_timer; topic_timer.start(); for (size_t count = 0; count < topic_count_; count++) { size_t part_count = ((count < participant_count_) ? count: 0); participant_[part_count]->get_default_topic_qos(topic_qos); topic_[count] = participant_[part_count]->create_topic ("Movie Discussion List", type_name.in (), topic_qos, DDS::TopicListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (topic_[count].in ())) { cerr << "create_topic failed." << endl; return false; } } topic_timer.stop(); ACE_High_Res_Timer sub_timer; sub_timer.start(); for (size_t count = 0; count < reader_count_; count++) { // Create the subscriber subs_[count] = participant_[count]->create_subscriber(SUBSCRIBER_QOS_DEFAULT, DDS::SubscriberListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (subs_[count].in ())) { cerr << "Failed to create_subscriber." << endl; return false; } } // Create the Datareaders DDS::DataReaderQos dr_qos; subs_[0]->get_default_datareader_qos (dr_qos); for (size_t count = 0; count < reader_count_; count++) { dr_[count] = subs_[count]->create_datareader(topic_[count].in (), dr_qos, DDS::DataReaderListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (dr_[count].in ())) { cerr << "create_datareader failed." << endl; return false; } } // Wait for all expected subscribers while (true) { ::DDS::InstanceHandleSeq handles; dr_[0]->get_matched_publications(handles); //ACE_DEBUG ((LM_DEBUG, "pubs connected: %d\n", handles.length())); if (handles.length() >= publisher_count_) { break; } ACE_OS::sleep (1); } sub_timer.stop (); // sync up sync_client_->way_point_reached (2); sync_client_->get_notification (); ACE_Time_Value tv; participant_timer.elapsed_time (tv); sync_client_->publish (SyncExt::Topic, topic_count_, tv.msec()); //ACE_DEBUG ((LM_DEBUG, "(%P|%t) Created %d participants in %d secs.\n" //, participant_count_, tv.sec())); topic_timer.elapsed_time (tv); sync_client_->publish (SyncExt::Participant, participant_count_ , tv.msec()); //ACE_DEBUG ((LM_DEBUG, "(%P|%t) Created %d topics in %d secs.\n" //, topic_count_, tv.sec())); sub_timer.elapsed_time (tv); sync_client_->publish (SyncExt::Subscriber, reader_count_ , tv.msec()); //ACE_DEBUG ((LM_DEBUG, "(%P|%t) Created %d subscribers in %d secs.\n" //, reader_count_, tv.sec())); for (size_t count = 0; count < participant_count_; count++) { participant_[count]->delete_contained_entities (); dpf_->delete_participant (participant_[count].in ()); } //ACE_OS::sleep(2); TheServiceParticipant->shutdown (); } catch (CORBA::Exception& e) { cerr << "SUB: Exception caught in Subscriber::run():\n " << e << endl; return false; } return true; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { int status = 0; try { // Initialize DomainParticipantFactory DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); bool reliable = true; int num_msgs = 10; int my_pid = ACE_OS::getpid(); parse_args(argc, argv, reliable, num_msgs, my_pid); // Create DomainParticipant DDS::DomainParticipant_var participant = dpf->create_participant(411, PARTICIPANT_QOS_DEFAULT, DDS::DomainParticipantListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(participant.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: create_participant failed!\n")), -1); } // Register TypeSupport (Messenger::Message) Messenger::MessageTypeSupport_var mts = new Messenger::MessageTypeSupportImpl(); if (mts->register_type(participant.in(), "") != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: register_type failed!\n")), -1); } // Create Topic CORBA::String_var type_name = mts->get_type_name(); DDS::Topic_var topic = participant->create_topic("Movie Discussion List", type_name.in(), TOPIC_QOS_DEFAULT, DDS::TopicListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(topic.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: create_topic failed!\n")), -1); } // Create Publisher DDS::Publisher_var pub = participant->create_publisher(PUBLISHER_QOS_DEFAULT, DDS::PublisherListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(pub.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: create_publisher failed!\n")), -1); } DDS::DataWriterQos qos; pub->get_default_datawriter_qos(qos); qos.liveliness.kind = DDS::AUTOMATIC_LIVELINESS_QOS; qos.liveliness.lease_duration.sec = 5; qos.liveliness.lease_duration.nanosec = 0; qos.history.kind = DDS::KEEP_ALL_HISTORY_QOS; qos.durability.kind = DDS::TRANSIENT_LOCAL_DURABILITY_QOS; // Create DataWriter DDS::DataWriter_var dw = pub->create_datawriter(topic.in(), qos, DDS::DataWriterListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(dw.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: create_datawriter failed!\n")), -1); } DDS::DataWriter_var dw2 = pub->create_datawriter(topic.in(), qos, DDS::DataWriterListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(dw2.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: create_datawriter 2 failed!\n")), -1); } { Writer writer(dw, dw2, my_pid); writer.write(reliable, num_msgs); } // Sleep to give subscriber a chance to nak before exiting ACE_OS::sleep(3); ACE_DEBUG((LM_DEBUG, "Publisher delete contained entities\n")); // Clean-up! participant->delete_contained_entities(); ACE_DEBUG((LM_DEBUG, "Publisher delete participant\n")); dpf->delete_participant(participant.in()); ACE_DEBUG((LM_DEBUG, "Publisher shutdown\n")); TheServiceParticipant->shutdown(); ACE_DEBUG((LM_DEBUG, "Publisher vars going out of scope\n")); } catch (const CORBA::Exception& e) { e._tao_print_exception("Exception caught in main():"); status = -1; } ACE_DEBUG((LM_DEBUG, "Publisher exiting with status=%d\n", status)); return status; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { // Initialize DomainParticipantFactory DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); int error; if ((error = parse_args(argc, argv)) != 0) { return error; } // Create DomainParticipant DDS::DomainParticipant_var participant = dpf->create_participant(4, PARTICIPANT_QOS_DEFAULT, DDS::DomainParticipantListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(participant.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: create_participant() failed!\n")), -1); } // Register Type (Messenger::Message) Messenger::MessageTypeSupport_var ts = new Messenger::MessageTypeSupportImpl(); if (ts->register_type(participant.in(), "") != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: register_type() failed!\n")), -1); } // Create Topic (Movie Discussion List) DDS::Topic_var topic = participant->create_topic("Movie Discussion List", ts->get_type_name(), TOPIC_QOS_DEFAULT, DDS::TopicListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(topic.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: create_topic() failed!\n")), -1); } // Create Subscriber DDS::Subscriber_var sub = participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT, DDS::SubscriberListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(sub.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: create_subscriber() failed!\n")), -1); } // Create DataReader DataReaderListenerImpl listener; DDS::DataReader_var reader = sub->create_datareader(topic.in(), DATAREADER_QOS_DEFAULT, &listener, OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(reader.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: create_datareader() failed!\n")), -1); } // Block until Publisher completes DDS::StatusCondition_var condition = reader->get_statuscondition(); condition->set_enabled_statuses(DDS::SUBSCRIPTION_MATCHED_STATUS); DDS::WaitSet_var ws = new DDS::WaitSet; ws->attach_condition(condition); DDS::Duration_t timeout = { DDS::DURATION_INFINITE_SEC, DDS::DURATION_INFINITE_NSEC }; DDS::ConditionSeq conditions; DDS::SubscriptionMatchedStatus matches = { 0, 0, 0, 0, 0 }; do { if (ws->wait(conditions, timeout) != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: wait() failed!\n")), -1); } if (reader->get_subscription_matched_status(matches) != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: get_subscription_matched_status() failed!\n")), -1); } } while (matches.current_count > 0); ws->detach_condition(condition); // Clean-up! participant->delete_contained_entities(); dpf->delete_participant(participant.in()); TheServiceParticipant->shutdown(); } catch (const CORBA::Exception& e) { e._tao_print_exception("Exception caught in main():"); return -1; } return 0; }