DDS::DataWriter_var Factory::writer(const DDS::Publisher_var& pub, const DDS::Topic_var& topic, const DDS::DataWriterListener_var& dwl) const { // Create the data writer DDS::DataWriterQos dw_qos; pub->get_default_datawriter_qos(dw_qos); dw_qos.durability.kind = opts_.durability_kind; dw_qos.liveliness.kind = opts_.liveliness_kind; dw_qos.liveliness.lease_duration = opts_.LEASE_DURATION; dw_qos.reliability.kind = opts_.reliability_kind; DDS::DataWriter_var dw = pub->create_datawriter(topic, dw_qos, dwl.in(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); // Initialize the transport configuration for the appropriate entity if (opts_.configuration_str != "none" && opts_.entity_str == "rw") { OpenDDS::DCPS::TransportRegistry::instance()->bind_config(opts_.configuration_str, dw.in()); if (!opts_.entity_autoenable) { TEST_ASSERT(DDS::RETCODE_OK == dw->enable()); } } return dw; }
typename OpenDDS::DCPS::DDSTraits<MessageType>::DataWriterType::_var_type create_writer(const DDS::Publisher_var& pub, const char* topicName, const DDS::DataWriterQos& qos = DATAWRITER_QOS_DEFAULT, const DDS::DataWriterListener_var& listener = 0, const DDS::StatusMask& mask = OpenDDS::DCPS::DEFAULT_STATUS_MASK) { const DDS::TypeSupport_var ts = new ::OpenDDS::DCPS::TypeSupportImpl_T<MessageType>(); const DDS::DomainParticipant_var dp = pub->get_participant(); const CORBA::String_var typeName = ts->get_type_name(); (void) ts->register_type(dp, typeName); // may have been registered before const DDS::Topic_var topic = dp->create_topic(topicName, typeName, TOPIC_QOS_DEFAULT, 0, 0); if (!topic) return 0; const DDS::DataWriter_var dw = pub->create_datawriter(topic, qos, listener, mask); return OpenDDS::DCPS::DDSTraits<MessageType>::DataWriterType::_narrow(dw); }
DDS::DataWriter_var createDataWriter( DDS::Publisher_var publisher, DDS::Topic_var topic, bool keep_last_one) { // Set qos DDS::DataWriterQos dw_qos; publisher->get_default_datawriter_qos(dw_qos); // RELIABLE/KEEP_ALL/10/10 works dw_qos.reliability.kind = DDS::RELIABLE_RELIABILITY_QOS; dw_qos.reliability.max_blocking_time.sec = 1; dw_qos.reliability.max_blocking_time.nanosec = 0; if (keep_last_one) { dw_qos.history.kind = DDS::KEEP_LAST_HISTORY_QOS; dw_qos.history.depth = 1; dw_qos.resource_limits.max_samples = 1; dw_qos.resource_limits.max_samples_per_instance = 1; std::cout << "Datawriter QOS keep last one" << std::endl; } else { dw_qos.history.kind = DDS::KEEP_ALL_HISTORY_QOS; dw_qos.resource_limits.max_samples = 10; dw_qos.resource_limits.max_samples_per_instance = 10; } // Create DataWriter DDS::DataWriter_var writer = publisher->create_datawriter(topic, dw_qos, 0, OpenDDS::DCPS::DEFAULT_STATUS_MASK); // Check for failure if (!writer) { throw std::string("failed to create data writer"); } return writer; }
int ACE_TMAIN(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(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (participant.in ())) { cerr << "create_participant failed." << endl; return 1; } Test::DataTypeSupportImpl* servant = new Test::DataTypeSupportImpl(); if (DDS::RETCODE_OK != servant->register_type(participant.in (), "")) { cerr << "register_type failed." << endl; exit(1); } CORBA::String_var type_name = servant->get_type_name (); DDS::TopicQos topic_qos; participant->get_default_topic_qos (topic_qos); DDS::Topic_var topic = participant->create_topic ("Data", type_name.in (), topic_qos, DDS::TopicListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (topic.in ())) { cerr << "create_topic failed." << endl; exit(1); } size_t const num_partitions = sizeof (Test::Offered::PartitionConfigs) / sizeof (Test::Offered::PartitionConfigs[0]); Test::PartitionConfig const * const begin = Test::Offered::PartitionConfigs; Test::PartitionConfig const * const end = begin + num_partitions; // Keep the writers around long enough for the publications and // subscriptions to match. typedef std::vector<DDS::DataWriter_var> writers_type; writers_type writers (num_partitions); for (Test::PartitionConfig const * i = begin; i != end; ++i) { DDS::PublisherQos pub_qos; participant->get_default_publisher_qos (pub_qos); // Specify partitions we're offering. CORBA::ULong n = 0; DDS::StringSeq & names = pub_qos.partition.name; for (char const * const * s = (*i).partitions; s != 0 && *s != 0; ++s, ++n) { CORBA::ULong const new_len = names.length () + 1; names.length (new_len); names[n] = *s; } DDS::Publisher_var pub = participant->create_publisher (pub_qos, DDS::PublisherListener::_nil (), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (pub.in ())) { cerr << "create_publisher failed." << endl; exit(1); } DDS::DataWriterListener_var listener ( new Test::DataWriterListener ((*i).expected_matches)); // 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, listener.in (), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (dw.in ())) { cerr << "create_datawriter failed." << endl; exit(1); } writers.push_back (dw); Test::DataDataWriter_var writer = Test::DataDataWriter::_narrow (dw.in()); if (CORBA::is_nil (writer.in ())) { cerr << "Data Writer could not be narrowed"<< endl; exit(1); } Test::Data the_data; the_data.key = 2; the_data.the_data = CORBA::string_dup ("Data Wuz Here!"); ::DDS::InstanceHandle_t const handle = writer->register_instance(the_data); ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) %T PUB starting to write.\n"))); ::DDS::ReturnCode_t const ret = writer->write (the_data, handle);; if (ret != ::DDS::RETCODE_OK) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: PUB ") ACE_TEXT ("write() returned %d.\n"), ret)); } } // // Wait for DataReaders to finish. // writers_type::const_iterator zend (writers.end ()); // for (writers_type::const_iterator z (writers.begin ()); z != zend; ++z) // { // ::DDS::InstanceHandleSeq handles; // while (1) // { // (*z)->get_matched_subscriptions (handles); // if (handles.length () == 0) // break; // else // ACE_OS::sleep (1); // } // } ACE_OS::sleep (20); { // Force contents of writers vector to be destroyed now. writers_type tmp; tmp.swap (writers); } participant->delete_contained_entities(); dpf->delete_participant(participant.in ()); 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); 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[]) { int status = 0; try { DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); 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 ())) { cerr << "create_participant failed." << endl; return 1; } DDS::DomainParticipant_var participant2 = dpf->create_participant(411, PARTICIPANT_QOS_DEFAULT, DDS::DomainParticipantListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (participant2.in ())) { cerr << "create_participant failed." << endl; return 1; } OpenDDS::DCPS::TransportConfig_rch cfg = TheTransportRegistry->get_config("part1"); if (!cfg.is_nil()) { TheTransportRegistry->bind_config(cfg, participant); } cfg = TheTransportRegistry->get_config("part2"); if (!cfg.is_nil()) { TheTransportRegistry->bind_config(cfg, participant2); } if (parse_args (argc, argv) == -1) { return -1; } MessageTypeSupport_var mts = new MessageTypeSupportImpl(); MessageTypeSupport_var mts2 = new MessageTypeSupportImpl(); if (DDS::RETCODE_OK != mts->register_type(participant.in (), "")) { cerr << "register_type failed." << endl; exit(1); } if (DDS::RETCODE_OK != mts2->register_type(participant2.in (), "")) { cerr << "register_type failed." << endl; exit(1); } CORBA::String_var type_name = mts->get_type_name (); CORBA::String_var type_name2 = mts2->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 ())) { cerr << "create_topic failed." << endl; exit(1); } DDS::Topic_var topic2 = participant2->create_topic ("Movie Discussion List", type_name2.in (), TOPIC_QOS_DEFAULT, DDS::TopicListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (topic2.in ())) { cerr << "create_topic failed." << endl; exit(1); } DDS::Publisher_var pub = participant->create_publisher(PUBLISHER_QOS_DEFAULT, DDS::PublisherListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (pub.in ())) { cerr << "create_publisher failed." << endl; exit(1); } DDS::Publisher_var pub2 = participant2->create_publisher(PUBLISHER_QOS_DEFAULT, DDS::PublisherListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (pub2.in ())) { cerr << "create_publisher failed." << endl; exit(1); } DataWriterListenerImpl * dwl1_servant = new DataWriterListenerImpl; ::DDS::DataWriterListener_var dwl1 (dwl1_servant); DataWriterListenerImpl * dwl2_servant = new DataWriterListenerImpl; ::DDS::DataWriterListener_var dwl2 (dwl2_servant); DataWriterListenerImpl * dwl3_servant = new DataWriterListenerImpl; ::DDS::DataWriterListener_var dwl3 (dwl3_servant); DataWriterListenerImpl * dwl4_servant = new DataWriterListenerImpl; ::DDS::DataWriterListener_var dwl4 (dwl4_servant); // Create the datawriters ::DDS::DataWriterQos dw_qos; pub->get_default_datawriter_qos (dw_qos); ::DDS::DataWriterQos dw2_qos; pub2->get_default_datawriter_qos (dw2_qos); dw_qos.liveliness.kind = ::DDS::MANUAL_BY_PARTICIPANT_LIVELINESS_QOS; dw_qos.liveliness.lease_duration.sec = LEASE_DURATION_SEC; dw_qos.liveliness.lease_duration.nanosec = 0; dw2_qos.liveliness.kind = ::DDS::MANUAL_BY_PARTICIPANT_LIVELINESS_QOS; dw2_qos.liveliness.lease_duration.sec = LEASE_DURATION_SEC; dw2_qos.liveliness.lease_duration.nanosec = 0; // Create the datawriter DDS::DataWriter_var dw1 = pub->create_datawriter(topic.in (), dw_qos, dwl1.in(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (dw1.in ())) { cerr << "create_datawriter failed." << endl; exit(1); } // Create the datawriter DDS::DataWriter_var dw2 = pub2->create_datawriter(topic2.in (), dw2_qos, dwl2.in(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (dw2.in ())) { cerr << "create_datawriter failed." << endl; exit(1); } dw_qos.liveliness.kind = ::DDS::MANUAL_BY_TOPIC_LIVELINESS_QOS; // Create the datawriter DDS::DataWriter_var dw3 = pub->create_datawriter(topic.in (), dw_qos, dwl3.in(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (dw3.in ())) { cerr << "create_datawriter failed." << endl; exit(1); } // Create the datawriter DDS::DataWriter_var dw4 = pub->create_datawriter(topic.in (), dw_qos, dwl4.in(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (dw4.in ())) { cerr << "create_datawriter failed." << endl; exit(1); } { Write_Samples writer1(dw1, "Manual_By_Participant_Writer_1"); Assert_Participant_Liveliness writer2(dw2, "Manual_By_Participant_Writer_2"); Write_Samples writer3(dw3, "Manual_By_Topic_Writer_1"); Assert_Writer_Liveliness writer4(dw4, "Manual_By_Topic_Writer_2"); writer1.start(); writer2.start(); writer3.start(); writer4.start(); writer1.end(); writer2.end(); writer3.end(); writer4.end(); } const unsigned long actual = dwl1_servant->num_liveliness_lost_callbacks() + dwl2_servant->num_liveliness_lost_callbacks() + dwl3_servant->num_liveliness_lost_callbacks() + dwl4_servant->num_liveliness_lost_callbacks(); if (liveliness_lost_test && static_cast<int>(actual) != num_liveliness_lost_callbacks) { cerr << "ERROR: did not receive expected liveliness lost callbacks. " << actual << "/" << num_liveliness_lost_callbacks << endl; status = 1; } ACE_OS::sleep(1); ACE_DEBUG((LM_INFO, "publisher deleting entities\n")); participant->delete_contained_entities(); dpf->delete_participant(participant.in ()); participant2->delete_contained_entities(); dpf->delete_participant(participant2.in ()); TheServiceParticipant->shutdown (); } catch (CORBA::Exception& e) { cerr << "PUB: Exception caught in main.cpp:" << endl << e << endl; exit(1); } 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 ParticipantTask::svc() { try { ACE_DEBUG((LM_INFO, ACE_TEXT("(%P|%t) -> PARTICIPANT STARTED\n"))); DDS::DomainParticipantFactory_var dpf = TheParticipantFactory; DDS::DomainParticipant_var participant; DDS::Publisher_var publisher; DDS::DataWriter_var writer; FooDataWriter_var writer_i; DDS::StatusCondition_var cond; DDS::WaitSet_var ws = new DDS::WaitSet; { // Scope for guard to serialize creating Entities. GuardType guard(lock_); // Create Participant participant = dpf->create_participant(42, PARTICIPANT_QOS_DEFAULT, DDS::DomainParticipantListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); #ifdef OPENDDS_SAFETY_PROFILE // RTPS cannot be shared char config_name[64], inst_name[64]; ACE_OS::snprintf(config_name, 64, "cfg_%d", thread_index_); ACE_OS::snprintf(inst_name, 64, "rtps_%d", thread_index_); ++thread_index_; ACE_DEBUG((LM_INFO, "(%P|%t) -> PARTICIPANT creating transport config %C\n", config_name)); OpenDDS::DCPS::TransportConfig_rch config = TheTransportRegistry->create_config(config_name); OpenDDS::DCPS::TransportInst_rch inst = TheTransportRegistry->create_inst(inst_name, "rtps_udp"); config->instances_.push_back(inst); TheTransportRegistry->bind_config(config_name, participant); #endif } // End of lock scope. if (CORBA::is_nil(participant.in())) ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: svc()") ACE_TEXT(" create_participant failed!\n")), 1); { // Create Publisher 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("%N:%l: svc()") ACE_TEXT(" create_publisher failed!\n")), 1); // Register Type (FooType) FooTypeSupport_var ts = new FooTypeSupportImpl; if (ts->register_type(participant.in(), "") != DDS::RETCODE_OK) ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: svc()") ACE_TEXT(" register_type failed!\n")), 1); // Create Topic (FooTopic) DDS::Topic_var topic = participant->create_topic("FooTopic", 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: svc()") ACE_TEXT(" create_topic failed!\n")), 1); // Create DataWriter DDS::DataWriterQos writer_qos; publisher->get_default_datawriter_qos(writer_qos); #ifndef OPENDDS_NO_OWNERSHIP_PROFILE writer_qos.history.depth = samples_per_thread_; #endif writer = publisher->create_datawriter(topic.in(), writer_qos, DDS::DataWriterListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(writer.in())) ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: svc()") ACE_TEXT(" create_datawriter failed!\n")), 1); writer_i = FooDataWriter::_narrow(writer); if (CORBA::is_nil(writer_i)) ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: svc()") ACE_TEXT(" _narrow failed!\n")), 1); // Block until Subscriber is available cond = writer->get_statuscondition(); cond->set_enabled_statuses(DDS::PUBLICATION_MATCHED_STATUS); ws->attach_condition(cond); DDS::Duration_t timeout = { DDS::DURATION_INFINITE_SEC, DDS::DURATION_INFINITE_NSEC }; DDS::ConditionSeq conditions; DDS::PublicationMatchedStatus matches = {0, 0, 0, 0, 0}; do { if (ws->wait(conditions, timeout) != DDS::RETCODE_OK) ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: svc()") ACE_TEXT(" wait failed!\n")), 1); if (writer->get_publication_matched_status(matches) != ::DDS::RETCODE_OK) { ACE_ERROR ((LM_ERROR, "(%P|%t) ERROR: failed to get publication matched status\n")); ACE_OS::exit (1); } } while (matches.current_count < 1); ws->detach_condition(cond); // The following is intentionally inefficient to stress various // pathways related to publication; we should be especially dull // and write only one sample at a time per writer. ProgressIndicator progress("(%P|%t) PARTICIPANT %d%% (%d samples sent)\n", samples_per_thread_); for (std::size_t i = 0; i < samples_per_thread_; ++i) { Foo foo; foo.key = 3; DDS::InstanceHandle_t handle = writer_i->register_instance(foo); if (writer_i->write(foo, handle) != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: svc()") ACE_TEXT(" write failed!\n")), 1); } ++progress; } DDS::Duration_t interval = { 30, 0}; if( DDS::RETCODE_OK != writer->wait_for_acknowledgments( interval)) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("(%P:%t) ERROR: svc() - ") ACE_TEXT("timed out waiting for acks!\n") ), 1); } } // Clean-up! ACE_DEBUG((LM_INFO, ACE_TEXT("(%P|%t) <- PUBLISHER PARTICIPANT DEL CONT ENTITIES\n"))); participant->delete_contained_entities(); ACE_DEBUG((LM_INFO, ACE_TEXT("(%P|%t) <- PUBLISHER DELETE PARTICIPANT\n"))); dpf->delete_participant(participant.in()); ACE_DEBUG((LM_INFO, ACE_TEXT("(%P|%t) <- PUBLISHER PARTICIPANT VARS GOING OUT OF SCOPE\n"))); } catch (const CORBA::Exception& e) { e._tao_print_exception("caught in svc()"); return 1; } ACE_DEBUG((LM_INFO, ACE_TEXT("(%P|%t) <- PARTICIPANT FINISHED\n"))); return 0; }
int ACE_TMAIN (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(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (participant.in ())) { cerr << "create_participant failed." << endl; return 1; } MessageTypeSupportImpl* servant = new MessageTypeSupportImpl; if (DDS::RETCODE_OK != servant->register_type(participant.in (), "")) { cerr << "register_type failed." << endl; exit(1); } CORBA::String_var type_name = servant->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(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (topic.in ())) { cerr << "create_topic failed." << endl; exit(1); } DDS::Publisher_var pub = participant->create_publisher(PUBLISHER_QOS_DEFAULT, DDS::PublisherListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (pub.in ())) { cerr << "create_publisher failed." << 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(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); 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_time(0,250000); ACE_OS::sleep (small_time); } // Cleanup writer->end(); delete writer; participant->delete_contained_entities(); dpf->delete_participant(participant); TheServiceParticipant->shutdown(); } catch (CORBA::Exception& e) { cerr << "Exception caught in main.cpp:" << endl << e << endl; exit(1); } return 0; }
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; } MessageTypeSupportImpl* servant = new MessageTypeSupportImpl(); if (DDS::RETCODE_OK != servant->register_type(participant.in (), "")) { cerr << "register_type failed." << endl; exit(1); } CORBA::String_var type_name = servant->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(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (topic.in ())) { cerr << "create_topic failed." << endl; exit(1); } DDS::Publisher_var pub = participant->create_publisher(PUBLISHER_QOS_DEFAULT, DDS::PublisherListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (pub.in ())) { cerr << "create_publisher failed." << endl; exit(1); } // ---------------------------------------------- // Create the listener. DDS::DataWriterListener_var listener (new DataWriterListenerImpl); if (CORBA::is_nil (listener.in ())) { cerr << "ERROR: listener is nil." << endl; exit(1); } DDS::DataWriterQos dw_qos; // Good QoS. pub->get_default_datawriter_qos (dw_qos); assert (DEADLINE_PERIOD.sec > 1); // Requirement for the test. // First data writer will have a listener to test listener // callback on deadline expiration. DDS::DataWriter_var dw = pub->create_datawriter (topic.in (), dw_qos, listener.in (), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (dw.in ())) { cerr << "ERROR: create_datawriter failed." << endl; exit(1); } dw_qos.deadline.period.sec = DEADLINE_PERIOD.sec; dw_qos.deadline.period.nanosec = DEADLINE_PERIOD.nanosec; // Set qos with deadline. The watch dog starts now. if (dw->set_qos (dw_qos) != ::DDS::RETCODE_OK) { cerr << "ERROR: set deadline qos failed." << endl; exit(1); } { // Two threads use same datawriter to write different instances. std::auto_ptr<Writer> writer1 (new Writer (dw.in (), 99, SLEEP_DURATION)); std::auto_ptr<Writer> writer2 (new Writer (dw.in (), 100, SLEEP_DURATION)); writer1->start (); writer2->start (); // ---------------------------------------------- // Wait for fully associate with DataReaders. if (writer1->wait_for_start () == false || writer2->wait_for_start () == false) { cerr << "ERROR: took too long to associate. " << endl; exit (1); } ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Publisher: sleep for %d milliseconds\n"), SLEEP_DURATION.msec ())); // Wait for a set of deadline periods to expire. ACE_OS::sleep (SLEEP_DURATION); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Publisher: now verify missed ") ACE_TEXT ("deadline status \n"))); ::DDS::InstanceHandle_t handle1 = writer1->get_instance_handle (); ::DDS::InstanceHandle_t handle2 = writer2->get_instance_handle (); DDS::OfferedDeadlineMissedStatus deadline_status; if (dw->get_offered_deadline_missed_status(deadline_status) != ::DDS::RETCODE_OK) { cerr << "ERROR: Failed to get offered deadline missed status" << endl; exit (1); } ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Publisher: got missed") ACE_TEXT ("deadline status \n"))); if (deadline_status.total_count != NUM_EXPIRATIONS * NUM_WRITE_THREADS) { cerr << "ERROR: Unexpected number of missed offered " << "deadlines (" << deadline_status.total_count << " instead of " << NUM_EXPIRATIONS * NUM_WRITE_THREADS << ") " << endl; exit (1); } if (deadline_status.total_count_change != NUM_EXPIRATIONS * NUM_WRITE_THREADS) { cerr << "ERROR: Incorrect missed offered " << "deadline count change (" << deadline_status.total_count_change << ") instead of " << NUM_EXPIRATIONS * NUM_WRITE_THREADS << endl; exit (1); } if (deadline_status.last_instance_handle != handle1 && deadline_status.last_instance_handle != handle2) { cerr << "ERROR: Unexpected last instance handle " << deadline_status.last_instance_handle << " instead of " << handle1 << " or " << handle2 << endl; exit (1); } writer1->wait (); writer2->wait (); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Publisher: sleep for %d milliseconds\n"), SLEEP_DURATION.msec())); // Wait for another set of deadline periods to expire. ACE_OS::sleep (SLEEP_DURATION); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Publisher: now verify missed ") ACE_TEXT ("deadline status \n"))); if (dw->get_offered_deadline_missed_status(deadline_status) != ::DDS::RETCODE_OK) { cerr << "ERROR: Failed to get offered deadline missed status" << endl; exit (1); } ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Publisher: got missed") ACE_TEXT ("deadline status \n"))); if (deadline_status.total_count != (NUM_EXPIRATIONS + 2) * NUM_WRITE_THREADS) { cerr << "ERROR: Unexpected number of missed offered " << "deadlines (" << deadline_status.total_count << " instead of " << (NUM_EXPIRATIONS + 2) * NUM_WRITE_THREADS << ") " << endl; exit (1); } if (deadline_status.total_count_change != NUM_WRITE_THREADS * 2) { cerr << "ERROR: Incorrect missed offered " << "deadline count change (" << deadline_status.total_count_change << ") instead of " << NUM_WRITE_THREADS * 2 << endl; exit (1); } if (deadline_status.last_instance_handle != handle1 && deadline_status.last_instance_handle != handle2) { cerr << "ERROR: Unexpected last instance handle " << deadline_status.last_instance_handle << " instead of " << handle1 << " or " << handle2 << endl; exit (1); } // Wait for datareader finish. while (1) { ::DDS::InstanceHandleSeq handles; dw->get_matched_subscriptions (handles); if (handles.length () == 0) break; else ACE_OS::sleep(1); } } participant->delete_contained_entities(); dpf->delete_participant(participant.in ()); 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 { DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); DDS::DomainParticipant_var participant = dpf->create_participant(311, PARTICIPANT_QOS_DEFAULT, DDS::DomainParticipantListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (participant.in ())) { cerr << "create_participant failed." << endl; return 1; } MessageTypeSupportImpl* servant = new MessageTypeSupportImpl(); if (DDS::RETCODE_OK != servant->register_type(participant.in (), "")) { cerr << "register_type failed." << endl; exit(1); } CORBA::String_var type_name = servant->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(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (topic.in ())) { cerr << "create_topic failed." << endl; exit(1); } DDS::PublisherQos pub_qos; participant->get_default_publisher_qos (pub_qos); pub_qos.partition.name.length (1); pub_qos.partition.name[0] = PARTITION_A; DDS::Publisher_var pub = participant->create_publisher(pub_qos, DDS::PublisherListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (pub.in ())) { cerr << "create_publisher failed." << endl; exit(1); } // ---------------------------------------------- // Create DataWriter which is belongs to PARTITION_A DDS::DataWriter_var dw = pub->create_datawriter (topic.in (), DATAWRITER_QOS_DEFAULT, DDS::DataWriterListener::_nil (), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); int const max_attempts = 15; int attempts = 1; // ---------------------------------------------- // Wait for first DataReader that belongs to PARTITION_A too, // then write samples. // cache handle for first reader. ::DDS::InstanceHandle_t handle = -1; { std::auto_ptr<Writer> writer (new Writer (dw.in ())); cout << "Pub waiting for match on A partition." << std::endl; if (OpenDDS::Model::WriterSync::wait_match(dw)) { cerr << "Error waiting for match on A partition" << std::endl; return 1; } while (attempts != max_attempts) { ::DDS::InstanceHandleSeq handles; dw->get_matched_subscriptions(handles); cout << "Pub matched " << handles.length() << " A subs." << std::endl; if (handles.length() == 1) { handle = handles[0]; break; } else ACE_OS::sleep(1); ++attempts; } if (attempts == max_attempts) { cerr << "ERROR: failed to wait for first DataReader." << endl; exit (1); } writer->start (); writer->end (); } // ---------------------------------------------- // Switch from PARTITION A to B, now the first DataReader belong to // PARTITION A should be disconnected and the second DataReader belong to // PARTITION B should be connected. pub_qos.partition.name[0] = PARTITION_B; if (pub->set_qos (pub_qos)!= ::DDS::RETCODE_OK) { cerr << "ERROR: DataWriter changed partition which should be compatible " << "but should disconnect with DataReaders" << endl; exit (1); } // ---------------------------------------------- // Now DataWriter is in PARTITION B, the second DataReader in PARTITION B // should receive the messages. { std::auto_ptr<Writer> writer (new Writer (dw.in ())); cout << "Pub waiting for match on B partition." << std::endl; if (OpenDDS::Model::WriterSync::wait_match(dw)) { cerr << "Error waiting for match on B partition" << std::endl; return 1; } attempts = 1; while (attempts != max_attempts) { ::DDS::InstanceHandleSeq handles; dw->get_matched_subscriptions(handles); cout << "Pub matched " << handles.length() << " B subs." << std::endl; if (handles.length() == 1 && handles[0] != handle) break; else ACE_OS::sleep(1); ++attempts; } if (attempts == max_attempts) { cerr << "ERROR: subscriptions failed to match." << endl; exit (1); } writer->start (); writer->end (); } // ---------------------------------------------- // Wait for first reader to switch from PARTITION A to B so // both two readers will receive the messages. { std::auto_ptr<Writer> writer (new Writer (dw.in ())); attempts = 1; while (attempts != max_attempts) { ::DDS::InstanceHandleSeq handles; dw->get_matched_subscriptions(handles); if (handles.length() == 2) break; else ACE_OS::sleep(1); ++ attempts; } if (attempts == max_attempts) { cerr << "ERROR: failed to wait for DataReader partition switch." << endl; exit (1); } writer->start (); writer->end (); } // ---------------------------------------------- // Now wait for subscriber exit. { attempts = 1; while (attempts != max_attempts) { ::DDS::InstanceHandleSeq handles; dw->get_matched_subscriptions(handles); if (handles.length() == 0) break; else ACE_OS::sleep(1); ++ attempts; } } participant->delete_contained_entities(); dpf->delete_participant(participant.in ()); } catch (CORBA::Exception& e) { cerr << "PUB: Exception caught in main.cpp:" << endl << e << endl; exit(1); } TheServiceParticipant->shutdown (); 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); 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; }
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 ())) { ACE_DEBUG((LM_DEBUG, "create_participant failed.\n")); return 1; } MessageTypeSupportImpl* servant = new MessageTypeSupportImpl(); if (DDS::RETCODE_OK != servant->register_type(participant.in (), "")) { ACE_DEBUG((LM_DEBUG, "register_type failed.\n")); exit(1); } CORBA::String_var type_name = servant->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(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (topic.in ())) { ACE_DEBUG((LM_DEBUG, "create_topic failed.\n")); exit(1); } 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_DEBUG((LM_DEBUG, "create_publisher failed.\n")); exit(1); } DDS::DataWriterQos dw_qos; pub->get_default_datawriter_qos (dw_qos); dw_qos.deadline.period.sec = 4; dw_qos.deadline.period.nanosec = 0; // Create DataWriter with 4 second deadline period which // should be compatible with first DataReader which has 5 // seconds deadline period and not with second DataReader // which has 3 seconds deadline period. DDS::DataWriter_var dw = pub->create_datawriter(topic, dw_qos, 0, OpenDDS::DCPS::DEFAULT_STATUS_MASK); int const max_attempts = 20000; int attempts = 1; { // Wait for both first DataReader connect and write messages. std::auto_ptr<Writer> writer (new Writer (dw.in ())); while (attempts != max_attempts) { ::DDS::InstanceHandleSeq handles; dw->get_matched_subscriptions(handles); if (handles.length() == 1) break; else ACE_OS::sleep(1); ++attempts; } if (attempts == max_attempts) { ACE_DEBUG((LM_DEBUG, "ERROR: subscriptions failed to match.\n")); exit (1); } writer->start (); writer->end (); ACE_DEBUG((LM_DEBUG, "Writer changing deadline to incompatible value\n")); // Now set DataWriter deadline to be 6 seconds which is not // compatible with the existing DataReader. This QoS change // should be applied and the association broken. dw_qos.deadline.period.sec = 6; if (dw->set_qos (dw_qos) != ::DDS::RETCODE_OK) { ACE_DEBUG((LM_DEBUG, "ERROR: DataWriter could not change deadline period which " "should break DataReader associations\n")); exit (1); } else { DDS::WaitSet_var ws = new DDS::WaitSet; DDS::StatusCondition_var sc = dw->get_statuscondition(); sc->set_enabled_statuses(DDS::PUBLICATION_MATCHED_STATUS); ws->attach_condition(sc); DDS::PublicationMatchedStatus matched; DDS::ConditionSeq active; const DDS::Duration_t timeout = {5, 0}; // seconds while (dw->get_publication_matched_status(matched) == DDS::RETCODE_OK && matched.current_count) { if (ws->wait(active, timeout) == DDS::RETCODE_TIMEOUT) { break; } } ws->detach_condition(sc); if (matched.current_count != 0) { ACE_DEBUG((LM_DEBUG, "ERROR: DataWriter changed deadline period which should " "break association with all existing DataReaders, but did not\n")); exit(1); } } // We know the reader has been disassociated, but the reader itself may // not have been notified yet. Introducing delay here to let the reader // sync up with the disassociated state before re-associating. // Wait for reader to finish unmatching. FILE* fp = ACE_OS::fopen (synch_fname, ACE_TEXT("r")); int i = 0; while (fp == 0 && i < 15) { ACE_DEBUG ((LM_DEBUG, ACE_TEXT("(%P|%t) waiting reader to unmatch...\n"))); ACE_OS::sleep (1); ++i; fp = ACE_OS::fopen (synch_fname, ACE_TEXT("r")); } if (fp != 0) ACE_OS::fclose (fp); ACE_DEBUG((LM_DEBUG, "Writer restoring deadline to compatible value\n")); // change it back dw_qos.deadline.period.sec = 5; if (dw->set_qos (dw_qos) != ::DDS::RETCODE_OK) { ACE_DEBUG((LM_DEBUG, "ERROR: DataWriter could not change deadline period which " "should restore DataReader associations\n")); exit (1); } } { // Wait for both second DataReader connect which changed deadline period // from 3 seconds to 5 seconds. std::auto_ptr<Writer> writer (new Writer (dw.in ())); attempts = 1; while (attempts != max_attempts) { ::DDS::InstanceHandleSeq handles; dw->get_matched_subscriptions(handles); if (handles.length() == 2) break; else ACE_OS::sleep(1); ++attempts; } if (attempts == max_attempts) { ACE_DEBUG((LM_DEBUG, "ERROR: subscriptions failed to match.\n")); exit(1); } writer->start (); writer->end (); } { // Wait for subscriber exit. attempts = 1; while (attempts != max_attempts) { ::DDS::InstanceHandleSeq handles; dw->get_matched_subscriptions(handles); if (handles.length() == 0) break; else ACE_OS::sleep(1); ++ attempts; } if (attempts == max_attempts) { ACE_DEBUG((LM_DEBUG, "ERROR: failed to wait for DataReader exit.\n")); exit (1); } } participant->delete_contained_entities(); dpf->delete_participant(participant.in ()); } catch (CORBA::Exception& e) { cerr << "PUB: Exception caught in main.cpp:" << endl << e << endl; exit(1); } TheServiceParticipant->shutdown (); return 0; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]){ int result = 0; 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; } MessageTypeSupportImpl* servant = new MessageTypeSupportImpl(); if (DDS::RETCODE_OK != servant->register_type(participant.in (), "")) { cerr << "register_type failed." << endl; exit(1); } CORBA::String_var type_name = servant->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(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (topic.in ())) { cerr << "create_topic failed." << endl; exit(1); } DDS::Publisher_var pub = participant->create_publisher(PUBLISHER_QOS_DEFAULT, DDS::PublisherListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (pub.in ())) { cerr << "create_publisher failed." << endl; exit(1); } // ---------------------------------------------- DDS::DataWriterQos dw_qos; // Good QoS. pub->get_default_datawriter_qos (dw_qos); dw_qos.resource_limits.max_samples_per_instance = MAX_SAMPLES_PER_INSTANCES; dw_qos.resource_limits.max_samples = MAX_SAMPLES; dw_qos.resource_limits.max_instances = MAX_INSTANCES; #ifndef OPENDDS_NO_OWNERSHIP_PROFILE dw_qos.history.kind = ::DDS::KEEP_ALL_HISTORY_QOS; dw_qos.history.depth = MAX_SAMPLES_PER_INSTANCES; #endif DDS::DataWriter_var dw = pub->create_datawriter (topic.in (), dw_qos, DDS::DataWriterListener::_nil (), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (dw.in ())) { cerr << "ERROR: create_datawriter failed." << endl; exit(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 ())) { cerr << "ERROR: create_datawriter failed." << endl; exit(1); } { // Two threads use same datawriter to write different instances. std::auto_ptr<Writer> writer1 (new Writer (dw.in (), 99, SLEEP_DURATION)); std::auto_ptr<Writer> writer2 (new Writer (dw.in (), 100, SLEEP_DURATION)); std::auto_ptr<Writer> writer3 (new Writer (dw.in (), 101, SLEEP_DURATION)); std::auto_ptr<Writer> writer4 (new Writer (dw2.in (), 101, SLEEP_DURATION)); writer1->start (); writer2->start (); // ---------------------------------------------- // Wait for first writer threads to register with DataReaders. if (writer1->wait_for_registered () == false || writer2->wait_for_registered () == false) { cerr << "ERROR: first writers took too long to connect. " << endl; exit (1); } writer3->start (); if (writer3->wait_for_registered () == false) { cerr << "ERROR: writer 3 took too long to connect. " << endl; exit (1); } writer4->start (); if (writer4->wait_for_registered () == false) { cerr << "ERROR: writer 4 took too long to connect. " << endl; exit (1); } writer1->start_sending (); writer2->start_sending (); writer3->start_sending (); writer4->start_sending (); writer1->wait (); writer2->wait (); writer3->wait (); writer4->wait (); // Wait for datareader finish. while (1) { ::DDS::InstanceHandleSeq handles; dw->get_matched_subscriptions (handles); if (handles.length () == 0) break; else ACE_OS::sleep(1); } if (writer1->failed_registration() ) { cerr << "ERROR: unexpected failed registration for writer 1. " << endl; result = 1; } if (writer2->failed_registration() ) { cerr << "ERROR: unexpected failed registration for writer 2. " << endl; result = 1; } if (!writer3->failed_registration() ) { cerr << "ERROR: unexpected registration for writer 3. " << endl; result = 1; } if (writer4->failed_registration() ) { cerr << "ERROR: unexpected failed registration for writer 4. " << endl; result = 1; } } participant->delete_contained_entities(); dpf->delete_participant(participant.in ()); TheServiceParticipant->shutdown (); } catch (CORBA::Exception& e) { cerr << "PUB: Exception caught in main.cpp:" << endl << e << endl; exit(1); } return result; }
int do_writer(DDS::DomainParticipant_var participant, DDS::Topic_var topic, bool toggle) { // Create Publisher DDS::Publisher_var publisher = participant->create_publisher(PUBLISHER_QOS_DEFAULT, 0, OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (!publisher) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: %N:%l: do_writer() -") ACE_TEXT(" create_publisher failed!\n")), -1); } DDS::DataWriterQos qos; publisher->get_default_datawriter_qos(qos); qos.user_data.value.length(3); qos.user_data.value[0] = 0; qos.user_data.value[1] = 0; qos.user_data.value[2] = 1; qos.reliability.kind = DDS::RELIABLE_RELIABILITY_QOS; if (toggle) { ACE_DEBUG((LM_DEBUG, "Creating writer\n")); DDS::DataWriter_var writer = publisher->create_datawriter(topic, qos, 0, OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (!writer) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: %N:%l: do_writer() -") ACE_TEXT(" create_datawriter failed!\n")), -1); } ACE_OS::sleep(SLEEP_SHORT); // Go away. ACE_DEBUG((LM_DEBUG, "Deleting writer\n")); publisher->delete_datawriter(writer); ACE_OS::sleep(SLEEP_SHORT); // Come back. ACE_DEBUG((LM_DEBUG, "Creating writer\n")); writer = publisher->create_datawriter(topic, qos, 0, OpenDDS::DCPS::DEFAULT_STATUS_MASK); ACE_OS::sleep(SLEEP_SHORT); return 0; } else { struct Listener : public DDS::DataWriterListener { size_t found, lost; Listener() : found(0), lost(0) { } virtual void on_offered_deadline_missed (::DDS::DataWriter_ptr, const ::DDS::OfferedDeadlineMissedStatus &) { } virtual void on_offered_incompatible_qos (::DDS::DataWriter_ptr, const ::DDS::OfferedIncompatibleQosStatus &) { } virtual void on_liveliness_lost (::DDS::DataWriter_ptr, const ::DDS::LivelinessLostStatus &) { } virtual void on_publication_matched (::DDS::DataWriter_ptr, const ::DDS::PublicationMatchedStatus & status) { if (status.current_count_change > 0) { ACE_DEBUG((LM_DEBUG, "Writer found reader\n")); ++found; } if (status.current_count_change < 0) { ACE_DEBUG((LM_DEBUG, "Writer lost reader\n")); ++lost; } } } listener; // Create DataWriter DDS::DataWriter_var writer = publisher->create_datawriter(topic, qos, &listener, OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (!writer) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: %N:%l: do_writer() -") ACE_TEXT(" create_datawriter failed!\n")), -1); } ACE_OS::sleep(SLEEP_LONG); if (listener.found == 2 && listener.lost == 1) { writer->set_listener(0, OpenDDS::DCPS::DEFAULT_STATUS_MASK); return 0; } return -1; } }
int ACE_TMAIN (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(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (participant.in ())) { cerr << "create_participant failed." << endl; return 1; } if (parse_args (argc, argv) != 0) return -1; if (delete_data) { using OpenDDS::FileSystemStorage::Directory; Directory::create (ACE_TEXT_ALWAYS_CHAR (dir))->remove (); dpf->delete_participant (participant); TheServiceParticipant->shutdown (); return 0; } MessageTypeSupport_var servant = new MessageTypeSupportImpl (); if (DDS::RETCODE_OK != servant->register_type(participant.in (), "")) { cerr << "register_type failed." << endl; exit (1); } CORBA::String_var type_name = servant->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(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (topic.in ())) { cerr << "create_topic failed." << endl; exit (1); } DDS::Publisher_var pub = participant->create_publisher (PUBLISHER_QOS_DEFAULT, DDS::PublisherListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (pub.in ())) { cerr << "create_publisher failed." << endl; exit (1); } // Configure DataWriter QoS policies. DDS::DataWriterQos dw_qos; pub->get_default_datawriter_qos (dw_qos); dw_qos.durability.kind = DDS::PERSISTENT_DURABILITY_QOS; dw_qos.durability_service.history_kind = ::DDS::KEEP_ALL_HISTORY_QOS; dw_qos.reliability.kind = ::DDS::RELIABLE_RELIABILITY_QOS; dw_qos.resource_limits.max_samples_per_instance = 1000; dw_qos.history.kind = ::DDS::KEEP_ALL_HISTORY_QOS; // ------------------------------------------------------- { DataWriterListenerImpl* listener = new DataWriterListenerImpl; DDS::DataWriterListener_var dwl = listener; // Create a DataWriter. // Upon exiting this scope, all unsent data should be // transferred to OpenDDS's data durability cache since the // run_test.pl script should not have started the subscriber // until it detects the "Done writing" log text. DDS::DataWriter_var dw = pub->create_datawriter (topic.in (), dw_qos, dwl.in (), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (dw.in ())) { cerr << "create_datawriter failed." << endl; exit (1); } // Only write samples if configured to do so. The expectation // is to otherwise retrieve the data from the PERSISTENT data // durability cache. if (do_write) { // Write samples. std::auto_ptr<Writer> writer (new Writer (dw.in ())); if (!writer->start () || !writer->end ()) { // Error logging performed in above method call. exit (1); } // Explicitly destroy the DataWriter. if (pub->delete_datawriter (dw.in ()) == ::DDS::RETCODE_PRECONDITION_NOT_MET) { cerr << "Unable to delete DataWriter" << endl; exit (1); } } else { int const max_attempts = 50; int attempts; for (attempts = 1; attempts != max_attempts && listener->publication_matched_.value () == false; ++attempts) { ACE_OS::sleep (5); } if (attempts == max_attempts) { cerr << "ERROR: subscriptions failed to match." << endl; exit (1); } // Wait for DataReader to finish. ::DDS::InstanceHandleSeq handles; for (attempts = 1; attempts != max_attempts; ++attempts) { dw->get_matched_subscriptions (handles); if (handles.length () == 0) break; else ACE_OS::sleep(1); } // The data durability cache should no longer contain samples // for this domain/topic/type. } } // ------------------------------------------------------- { // Write samples that will not be sent. Exercise // service_cleanup_delay. We can either do this through the // durability member or durability_service member in either of // TopicQos or DataWriterQos. This test arbitrarily uses the // DataWriterQos::durability_service member. // Cleanup data after this number of seconds. CORBA::Long const delay_seconds = 5; ::DDS::Duration_t & cleanup_delay = dw_qos.durability_service.service_cleanup_delay; cleanup_delay.sec = delay_seconds; cleanup_delay.nanosec = 0; // Create a dummy topic which will have no subscriptions. DDS::Topic_var dummy_topic = participant->create_topic ("Dummy Topic", type_name.in (), topic_qos, DDS::TopicListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); DDS::DataWriter_var dummy_dw = pub->create_datawriter (dummy_topic.in (), dw_qos, ::DDS::DataWriterListener::_nil (), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (dummy_dw.in ())) { cerr << "create_datawriter for dummy topic failed." << endl; exit (1); } // Write samples using multiple threads. std::auto_ptr<Writer> writer (new Writer (dummy_dw.in ())); // Explicitly destroy the DataWriter. if (pub->delete_datawriter (dummy_dw.in ()) == ::DDS::RETCODE_PRECONDITION_NOT_MET) { cerr << "Unable to delete DataWriter" << endl; exit (1); } // Allow durability cleanup to occur ACE_OS::sleep (delay_seconds + 3); } participant->delete_contained_entities(); dpf->delete_participant(participant.in ()); TheServiceParticipant->shutdown (); } catch (CORBA::Exception& e) { cerr << "PUB: Exception caught in main.cpp:" << endl << e << endl; exit (1); } catch (const std::runtime_error& err) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: main() - %s\n"), err.what()), -1); } return 0; }
int svc() { int thread_id = thread_counter_++; // Create Publisher DDS::Publisher_var publisher = participant_->create_publisher(PUBLISHER_QOS_DEFAULT, 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); } writers_[thread_id].resize(6); ACE_DEBUG((LM_DEBUG, "(%P|%t) Starting DataWriter %C\n", writers_[thread_id].c_str())); DDS::DataWriterQos qos; publisher->get_default_datawriter_qos(qos); qos.user_data.value.length(3); qos.user_data.value[0] = fromhex(writers_[thread_id], 0); qos.user_data.value[1] = fromhex(writers_[thread_id], 1); qos.user_data.value[2] = fromhex(writers_[thread_id], 2); if (reliable_) { qos.reliability.kind = DDS::RELIABLE_RELIABILITY_QOS; qos.reliability.max_blocking_time.sec = DDS::DURATION_INFINITE_SEC; // qos.resource_limits.max_instances = 10; // qos.history.depth = 10; } else { qos.reliability.kind = DDS::BEST_EFFORT_RELIABILITY_QOS; } // Create DataWriter DDS::DataWriter_var writer = publisher->create_datawriter(topic_, qos, 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); } TestMsgDataWriter_var message_writer = TestMsgDataWriter::_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); } ACE_DEBUG((LM_DEBUG, "(%P|%t) DataWriter %C has %d of %d readers\n", writers_[thread_id].c_str(), matches.current_count, total_readers_)); if (matches.current_count >= total_readers_) { 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 TestMsg message; message.value = 0; for (int i = 0; i < MSGS_PER_WRITER; ++i) { DDS::ReturnCode_t error = message_writer->write(message, DDS::HANDLE_NIL); ++message.value; 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) DataWriter %C is waiting for acknowledgements\n", writers_[thread_id].c_str())); DDS::Duration_t timeout = { 30, 0 }; message_writer->wait_for_acknowledgments(timeout); // With static discovery, it's not an error for wait_for_acks to fail // since the peer process may have terminated before sending acks. ACE_DEBUG((LM_DEBUG, "(%P|%t) DataWriter %C is done\n", writers_[thread_id].c_str())); return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { ACE_Time_Value offset; try { DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); 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 ())) { cerr << "create_participant failed." << endl; return 1; } ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:")); int c; while ((c = get_opts ()) != -1) { switch(c) { case 'o': { int off_secs = ACE_OS::atoi (get_opts.opt_arg ()); offset = ACE_Time_Value(off_secs); } break; case '?': default: ACE_ERROR_RETURN ((LM_ERROR, "usage: %s " "-o offset (in seconds) " "\n", argv [0]), -1); } } MessageTypeSupportImpl* servant = new MessageTypeSupportImpl(); if (DDS::RETCODE_OK != servant->register_type(participant.in (), "")) { cerr << "register_type failed." << endl; exit(1); } CORBA::String_var type_name = servant->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(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (topic.in ())) { cerr << "create_topic failed." << endl; exit(1); } DDS::Publisher_var pub = participant->create_publisher (PUBLISHER_QOS_DEFAULT, DDS::PublisherListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (pub.in ())) { cerr << "create_publisher failed." << endl; exit(1); } // Create the datawriter DDS::DataWriterQos dw_qos; pub->get_default_datawriter_qos (dw_qos); dw_qos.latency_budget.duration.sec = 0; dw_qos.latency_budget.duration.nanosec = 0; ::DDS::DataWriterListener_var dwl (new DataWriterListenerImpl); DDS::DataWriter_var dw = pub->create_datawriter (topic.in (), dw_qos, dwl.in(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (dw.in ())) { cerr << "create_datawriter failed." << endl; exit(1); } { std::auto_ptr<Writer> writer (new Writer (dw.in (), offset)); writer->start (); while ( !writer->is_finished()) { ACE_Time_Value small_time(30,0); ACE_OS::sleep (small_time); } // Cleanup writer->end (); } participant->delete_contained_entities(); dpf->delete_participant(participant); 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 { DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); if( parse_args(argc, argv) != 0) return 1; 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 ())) { cerr << "create_participant failed." << endl; return 1; } Messenger::MessageTypeSupportImpl* servant = new Messenger::MessageTypeSupportImpl; if (DDS::RETCODE_OK != servant->register_type(participant.in (), "")) { cerr << "register_type failed." << endl; exit(1); } CORBA::String_var type_name = servant->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(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (topic.in ())) { cerr << "create_topic failed." << endl; exit(1); } DDS::Publisher_var pub = participant->create_publisher(PUBLISHER_QOS_DEFAULT, DDS::PublisherListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (pub.in ())) { cerr << "create_publisher failed." << endl; exit(1); } // Create the datawriter DDS::DataWriterQos dw_qos; pub->get_default_datawriter_qos (dw_qos); // Make it KEEP_ALL history so we can verify the received // data without dropping. // dw_qos.history.kind = ::DDS::KEEP_ALL_HISTORY_QOS; dw_qos.reliability.kind = ::DDS::RELIABLE_RELIABILITY_QOS; //dw_qos.resource_limits.max_samples_per_instance = num_writes; DDS::DataWriter_var dw = pub->create_datawriter(topic.in (), dw_qos, DDS::DataWriterListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (dw.in ())) { cerr << "create_datawriter failed." << endl; exit(1); } Writer writer (dw.in(), sub_finished_filename, verbose, write_delay_ms); // Indicate that the publisher is ready FILE* writers_ready = ACE_OS::fopen (pub_ready_filename, ACE_TEXT("w")); if (writers_ready == 0) { cerr << "ERROR Unable to create publisher ready file" << endl; exit(1); } ACE_OS::fclose(writers_ready); // Wait for the subscriber to be ready. ACE_stat stats; while (ACE_OS::stat (sub_ready_filename, &stats) == -1) { ACE_Time_Value small_time(0,250000); ACE_OS::sleep (small_time); } writer.start (); writer.wait (); participant->delete_contained_entities(); dpf->delete_participant(participant); TheServiceParticipant->shutdown(); } catch (CORBA::Exception& e) { cerr << "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 main (int argc, char *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; } { // At this point we are connected to the Info Repo. // Trigger the driver std::ofstream ior_stream (driver_trigger.c_str()); if (!ior_stream) { std::cerr << "Unable to open internal trigger file: " << driver_trigger << std::endl; return -1; } ior_stream << "junk"; } int max_wait_time = 30; //seconds int count = 0; while (true) { if (count > max_wait_time) { std::cerr << "Timed out waiting for external file: " << publisher_trigger << std::endl; return -1; } // check for file ACE_stat my_stat; if (ACE_OS::stat (publisher_trigger.c_str(), &my_stat) == 0) { // found the trigger file. break; } ACE_OS::sleep (1); } MessageTypeSupportImpl* servant = new MessageTypeSupportImpl(); PortableServer::ServantBase_var safe_servant = servant; if (DDS::RETCODE_OK != servant->register_type(participant.in (), "")) { cerr << "register_type failed." << endl; exit(1); } CORBA::String_var type_name = servant->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); } TAO::DCPS::TransportImpl_rch tcp_impl = TheTransportFactory->create_transport_impl (transport_impl_id, ::TAO::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. TAO::DCPS::PublisherImpl* pub_impl = ::TAO::DCPS::reference_to_servant< TAO::DCPS::PublisherImpl, DDS::Publisher_ptr>(pub.in ()); if (0 == pub_impl) { cerr << "Failed to obtain publisher servant" << endl; exit(1); } TAO::DCPS::AttachStatus status = pub_impl->attach_transport(tcp_impl.in()); if (status != TAO::DCPS::ATTACH_OK) { std::string status_str; switch (status) { case TAO::DCPS::ATTACH_BAD_TRANSPORT: status_str = "ATTACH_BAD_TRANSPORT"; break; case TAO::DCPS::ATTACH_ERROR: status_str = "ATTACH_ERROR"; break; case TAO::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 main(int argc, char** args){ std::cout << "Welcome to userqos stress test" << std::endl; enum {PUBLISHER, SUBSCRIBER} mode; if(argc != 2 || !(*args[1] == 'p' || *args[1] == 's')){ printf("Usage: %s (p|s)\n" " p - Publisher\n" " s - Subscriber\n",args[0]); exit(EXIT_FAILURE); } else if(*args[1] == 'p'){ mode = PUBLISHER; } else if(*args[1] == 's'){ mode = SUBSCRIBER; } else { printf("Should never reach this state.\n"); exit(EXIT_FAILURE); } DDS::ReturnCode_t retval; DDS::InstanceHandle_t handle; DDS::DomainParticipantFactory_ptr dpf = DDS::DomainParticipantFactory::get_instance(); assert( NULL != dpf); DDS::DomainParticipantQos participant_qos; retval = dpf->get_default_participant_qos(participant_qos); assert( DDS::RETCODE_OK == retval ); DDS::DomainId_t domain = NULL; DDS::DomainParticipant_var participant = dpf->create_participant(domain, PARTICIPANT_QOS_DEFAULT, NULL, DDS::STATUS_MASK_NONE); assert( NULL != participant.in() ); /** Magical key definitions. If you want the idlpp to generate TypeSupport you MUST, I repeat, MUST, add #pragma. Why would you ever NOT want the TypeSupport? Who knows. OpenSplice_PreProcessor_usermanual.pdf , Section: 1.5.1 KeyDefinitions **/ // Memory leak: I cannot seem to free pid_ts. Delete is blocked nor can I find _release per the docs PID::PresenceTypeSupport_ptr pid_ts = new PID::PresenceTypeSupport(); assert( NULL != pid_ts ); retval = pid_ts->register_type(participant, pid_ts->get_type_name()); assert ( DDS::RETCODE_OK == retval ); DDS::TopicQos topic_qos; retval = participant->get_default_topic_qos(topic_qos); assert( DDS::RETCODE_OK == retval ); DDS::Topic_var presence_topic = participant->create_topic("presence", pid_ts->get_type_name(), topic_qos, NULL, DDS::STATUS_MASK_NONE); assert( NULL != presence_topic.in() ); /** Publisher code **/ if(mode == PUBLISHER){ DDS::PublisherQos publisher_qos; retval = participant->get_default_publisher_qos(publisher_qos); assert( DDS::RETCODE_OK == retval ); DDS::Publisher_var publisher = participant->create_publisher(publisher_qos, NULL, DDS::STATUS_MASK_NONE); assert( NULL != publisher.in() ); /** PID Data Writer **/ DDS::DataWriterQos dw_qos; retval = publisher->get_default_datawriter_qos(dw_qos); assert( DDS::RETCODE_OK == retval ); const char* msg = "HI THERE COWBOY"; dw_qos.user_data.value = DDS_DCPSUFLSeq<unsigned char, DDS::octSeq_uniq_>(msg); assert( strlen(msg) == dw_qos.user_data.value.length() ); DDS::DataWriter_var writer = publisher->create_datawriter(presence_topic, dw_qos, NULL, DDS::STATUS_MASK_NONE); assert( NULL != writer.in() ); PID::PresenceDataWriter_var presence_writer = PID::PresenceDataWriter::_narrow(writer); assert( NULL != presence_writer.in() ); PID::Presence temp_presence; temp_presence.pid = 100; temp_presence.hostname = "my_machine"; //handle = presence_writer->register_instance(temp_presence); //assert( DDS::HANDLE_NIL != handle ); handle = DDS::HANDLE_NIL; // std::cout << "LOOPING" << std::endl; // while(shutdown_flag == 0){ retval = presence_writer->write(temp_presence,handle); assert( DDS::RETCODE_OK == retval ); // usleep(50); //} } /** Subscriber **/ else if(mode == SUBSCRIBER){ DDS::SubscriberQos subscriber_qos; retval = participant->get_default_subscriber_qos(subscriber_qos); assert( DDS::RETCODE_OK == retval ); DDS::Subscriber_var subscriber = participant->create_subscriber(subscriber_qos, NULL, DDS::STATUS_MASK_NONE); assert( NULL != subscriber.in() ); /** PID Data Reader **/ DDS::DataReaderQos dr_qos; retval = subscriber->get_default_datareader_qos(dr_qos); assert( DDS::RETCODE_OK == retval ); PID::PresenceReaderListener *p_r_listener = new PID::PresenceReaderListener(); assert(p_r_listener != NULL); DDS::DataReader_ptr reader = subscriber->create_datareader(presence_topic, dr_qos, p_r_listener, DDS::DATA_AVAILABLE_STATUS); assert( NULL != reader ); PID::PresenceDataReader *presence_reader = PID::PresenceDataReader::_narrow(reader); assert( NULL != presence_reader ); while(shutdown_flag == 0){ usleep(50); } } //retval = dpf->delete_participant(participant); //assert( DDS::RETCODE_OK == retval ); retval = DDS::RETCODE_PRECONDITION_NOT_MET; while(retval != DDS::RETCODE_OK){ retval = dpf->delete_contained_entities(); /* switch(retval){ case DDS::RETCODE_OK: printf("DDS::RETCODE_OK\n"); break; case DDS::RETCODE_ERROR: printf("DDS::RETCODE_ERROR\n"); break; case DDS::RETCODE_OUT_OF_RESOURCES: printf("DDS::RETCODE_OUT_OF_RESOURCES\n"); break; case DDS::RETCODE_PRECONDITION_NOT_MET: printf("DDS::RETCODE_PRECONDITION_NOT_MET\n"); break; default: printf("Default case?\n"); } */ usleep(10); } assert( DDS::RETCODE_OK == retval ); return 0; }
int main (int argc, char *argv[]) { try { DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); if( parse_args(argc, argv) != 0) return 1; 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; } Messenger::MessageTypeSupportImpl* servant = new Messenger::MessageTypeSupportImpl(); OpenDDS::DCPS::LocalObject_var safe_servant = servant; if (DDS::RETCODE_OK != servant->register_type(participant.in (), "")) { cerr << "register_type failed." << endl; exit(1); } CORBA::String_var type_name = servant->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); } // Initialize the transport OpenDDS::DCPS::TransportImpl_rch tcp_impl = TheTransportFactory->create_transport_impl (TCP_IMPL_ID, "SimpleTcp", OpenDDS::DCPS::DONT_AUTO_CONFIG); OpenDDS::DCPS::TransportConfiguration_rch writer_config = TheTransportFactory->create_configuration (TCP_IMPL_ID, "SimpleTcp"); OpenDDS::DCPS::SimpleTcpConfiguration* writer_tcp_config = static_cast <OpenDDS::DCPS::SimpleTcpConfiguration*> (writer_config.in ()); writer_tcp_config->local_address_ = ACE_INET_Addr (local_address.c_str()); writer_tcp_config->local_address_str_ = local_address; // This is needed for bp_timeout test. writer_tcp_config->max_output_pause_period_ = 2000; // This is needed to get the connection deletion callback. writer_tcp_config->datalink_release_delay_ = 0; if (tcp_impl->configure(writer_config.in()) != 0) { cerr << "Failed to configure the transport." << endl; exit(1); } 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); } // activate the listener DDS::DataWriterListener_var listener (new DataWriterListenerImpl); if (CORBA::is_nil (listener.in ())) { cerr << "listener is nil." << endl; exit(1); } // Create the datawriter DDS::DataWriterQos dw_qos; pub->get_default_datawriter_qos (dw_qos); // Make it KEEP_ALL history so we can verify the received // data without dropping. dw_qos.history.kind = ::DDS::KEEP_ALL_HISTORY_QOS; dw_qos.reliability.kind = ::DDS::RELIABLE_RELIABILITY_QOS; dw_qos.resource_limits.max_samples_per_instance = num_writes; DDS::DataWriter_var dw = pub->create_datawriter(topic.in (), dw_qos, listener.in ()); if (CORBA::is_nil (dw.in ())) { cerr << "create_datawriter failed." << endl; exit(1); } Writer* writer = new Writer(dw.in()); // Indicate that the publisher is ready FILE* writers_ready = ACE_OS::fopen (pub_ready_filename, "w"); if (writers_ready == 0) { cerr << "ERROR Unable to create publisher ready file" << endl; exit(1); } ACE_OS::fclose(writers_ready); // Wait for the subscriber to be ready. FILE* readers_ready = 0; do { ACE_Time_Value small(0,250000); ACE_OS::sleep (small); readers_ready = ACE_OS::fopen (sub_ready_filename, "r"); } while (0 == readers_ready); ACE_OS::fclose(readers_ready); // ensure the associations are fully established before writing. ACE_OS::sleep(3); writer->start (); while ( !writer->is_finished()) { ACE_Time_Value small(0,250000); ACE_OS::sleep (small); } // Indicate that the publisher is done FILE* writers_completed = ACE_OS::fopen (pub_finished_filename, "w"); if (writers_completed == 0) { cerr << "ERROR Unable to i publisher completed file" << endl; } else { ACE_OS::fprintf (writers_completed, "%d\n", writer->get_timeout_writes()); } ACE_OS::fclose (writers_completed); // Wait for the subscriber to finish. FILE* readers_completed = 0; do { ACE_Time_Value small(0,250000); ACE_OS::sleep (small); readers_completed = ACE_OS::fopen (sub_finished_filename, "r"); } while (0 == readers_completed); ACE_OS::fclose(readers_completed); writer->end (); delete writer; // Sleep a while before shutdown to avoid the problem of repository // crashes when it handles both remove_association from subscriber // and publisher at the same time. // Cleanup //ACE_OS::sleep (2); participant->delete_contained_entities(); dpf->delete_participant(participant.in ()); TheTransportFactory->release(); TheServiceParticipant->shutdown (); } catch (CORBA::Exception& e) { cerr << "Exception caught in main.cpp:" << endl << e << endl; exit(1); } if (actual_lost_pub_notification != expected_lost_pub_notification) { ACE_ERROR ((LM_ERROR, "(%P|%t)ERROR: on_publication_lost called %d times " "and expected %d times\n", actual_lost_pub_notification, expected_lost_pub_notification)); return 1; } if (num_deleted_connections != expected_deleted_connections) { ACE_ERROR ((LM_ERROR, "(%P|%t)ERROR: on_connection_deleted called %d times " "and expected %d times\n", num_deleted_connections, expected_deleted_connections)); return 1; } return 0; }
int ACE_TMAIN (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(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (participant.in ())) { cerr << "create_participant failed." << endl; return 1; } if (parse_args (argc, argv) == -1) { return -1; } { // At this point we are connected to the Info Repo. // Trigger the driver std::ofstream ior_stream (driver_trigger.c_str()); if (!ior_stream) { std::cerr << "Unable to open internal trigger file: " << driver_trigger << std::endl; return -1; } ior_stream << "junk"; } int max_wait_time = 30; //seconds int count = 0; while (true) { if (count > max_wait_time) { std::cerr << "Timed out waiting for external file: " << publisher_trigger << std::endl; return -1; } // check for file ACE_stat my_stat; if (ACE_OS::stat (publisher_trigger.c_str(), &my_stat) == 0) { // found the trigger file. break; } ACE_OS::sleep (1); } MessageTypeSupportImpl* servant = new MessageTypeSupportImpl(); OpenDDS::DCPS::LocalObject_var safe_servant = servant; if (DDS::RETCODE_OK != servant->register_type(participant.in (), "")) { cerr << "register_type failed." << endl; exit(1); } CORBA::String_var type_name = servant->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(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (topic.in ())) { cerr << "create_topic failed." << endl; exit(1); } DDS::Publisher_var pub = participant->create_publisher(PUBLISHER_QOS_DEFAULT, DDS::PublisherListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (pub.in ())) { cerr << "create_publisher failed." << 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(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); 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_time(0,250000); ACE_OS::sleep (small_time); } // Cleanup writer->end(); delete writer; participant->delete_contained_entities(); dpf->delete_participant(participant); TheServiceParticipant->shutdown(); } catch (CORBA::Exception& e) { cerr << "PUB: Exception caught in main.cpp:" << endl << e << endl; exit(1); } return 0; }
int ParticipantTask::svc() { try { ACE_DEBUG((LM_INFO, ACE_TEXT("(%P|%t) -> PARTICIPANT STARTED\n"))); ACE_Time_Value delay_between_pubs(0, this->delay_between_pubs_msec_ * 1000); DDS::DomainParticipantFactory_var dpf = TheParticipantFactory; // Create Participant 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("%N:%l: svc()") ACE_TEXT(" create_participant 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("%N:%l: svc()") ACE_TEXT(" create_publisher failed!\n")), 1); // Register Type (FooType) FooTypeSupport_var ts = new FooTypeSupportImpl; if (ts->register_type(participant.in(), "") != DDS::RETCODE_OK) ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: svc()") ACE_TEXT(" register_type failed!\n")), 1); // Create Topic (FooTopic) DDS::Topic_var topic = participant->create_topic("FooTopic", 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: svc()") ACE_TEXT(" create_topic failed!\n")), 1); // Create DataWriter DDS::DataWriterQos writer_qos; publisher->get_default_datawriter_qos(writer_qos); writer_qos.history.depth = samples_per_thread_; if (deadline_.sec > 0 || deadline_.nanosec > 0) { writer_qos.deadline.period.sec = deadline_.sec; writer_qos.deadline.period.nanosec = deadline_.nanosec; } DDS::DataWriter_var writer = publisher->create_datawriter(topic.in(), writer_qos, DDS::DataWriterListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(writer.in())) ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: svc()") ACE_TEXT(" create_datawriter failed!\n")), 1); FooDataWriter_var writer_i = FooDataWriter::_narrow(writer); if (CORBA::is_nil(writer_i)) ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: svc()") ACE_TEXT(" _narrow failed!\n")), 1); // Block until Subscriber is available DDS::StatusCondition_var cond = writer->get_statuscondition(); cond->set_enabled_statuses(DDS::PUBLICATION_MATCHED_STATUS); DDS::WaitSet_var ws = new DDS::WaitSet; ws->attach_condition(cond); DDS::Duration_t timeout = { DDS::DURATION_INFINITE_SEC, DDS::DURATION_INFINITE_NSEC }; DDS::ConditionSeq conditions; DDS::PublicationMatchedStatus matches = {0, 0, 0, 0, 0}; do { if (ws->wait(conditions, timeout) != DDS::RETCODE_OK) ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: svc()") ACE_TEXT(" wait failed!\n")), 1); if (writer->get_publication_matched_status(matches) != ::DDS::RETCODE_OK) { ACE_ERROR ((LM_ERROR, "(%P|%t) ERROR: failed to get publication matched status\n")); ACE_OS::exit (1); } } while (matches.current_count < 1); ws->detach_condition(cond); // The following is intentionally inefficient to stress various // pathways related to publication; we should be especially dull // and write only one sample at a time per writer. ProgressIndicator progress("(%P|%t) PARTICIPANT %d%% (%d samples sent)\n", samples_per_thread_); for (std::size_t i = 0; i < samples_per_thread_; ++i) { Foo foo; foo.key = 3; DDS::InstanceHandle_t handle = writer_i->register_instance(foo); if (writer_i->write(foo, handle) != DDS::RETCODE_OK) ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: svc()") ACE_TEXT(" write failed!\n")), 1); ++progress; ACE_OS::sleep(delay_between_pubs); } DDS::Duration_t interval = { 30, 0}; if( DDS::RETCODE_OK != writer->wait_for_acknowledgments( interval)) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("(%P:%t) ERROR: svc() - ") ACE_TEXT("timed out waiting for acks!\n") ), 1); } publisher->delete_datawriter(writer); // Clean-up! participant->delete_contained_entities(); dpf->delete_participant(participant.in()); } catch (const CORBA::Exception& e) { e._tao_print_exception("caught in svc()"); return 1; } ACE_DEBUG((LM_INFO, ACE_TEXT("(%P|%t) <- PARTICIPANT FINISHED\n"))); return 0; }
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; }
void KVStore::init() { DDS::DomainId_t myDomain = NULL; DDS::DomainParticipantFactory_var dpf; DDS::DomainParticipant_var dp; DDS::Subscriber_var subscriber; DDS::Publisher_var publisher; DDS::DomainParticipantQos dpQos; DDS::TopicQos tQos; DDS::SubscriberQos sQos; DDS::DataReaderQos drQos; DDS::PublisherQos pQos; DDS::DataWriterQos dwQos; DDS::Topic_var topic; DDSKVStore::TransactionTypeSupport_var ts; // Create Participants dpf = DDS::DomainParticipantFactory::get_instance(); dpf->get_default_participant_qos(dpQos); dp = dpf->create_participant(myDomain, dpQos, NULL, DDS::STATUS_MASK_NONE); // Create Subscriber dp->get_default_subscriber_qos(sQos); sQos.partition.name.length(1); sQos.partition.name[0] = partition.c_str(); subscriber = dp->create_subscriber(sQos, NULL, DDS::STATUS_MASK_NONE); // Create Publisher dp->get_default_publisher_qos(pQos); pQos.partition.name.length(1); pQos.partition.name[0] = partition.c_str(); publisher = dp->create_publisher(pQos, NULL, DDS::STATUS_MASK_NONE); // Set DataReader QoS settings subscriber->get_default_datareader_qos(drQos); drQos.reliability.kind = DDS::RELIABLE_RELIABILITY_QOS; drQos.history.kind = DDS::KEEP_LAST_HISTORY_QOS; drQos.history.depth = 30; // Set DataWriter QoS settings publisher->get_default_datawriter_qos(dwQos); dwQos.reliability.kind = DDS::RELIABLE_RELIABILITY_QOS; dwQos.history.kind = DDS::KEEP_LAST_HISTORY_QOS; dwQos.history.depth = 30; // Set Topic Qos settings dp->get_default_topic_qos(tQos); tQos.reliability.kind = DDS::RELIABLE_RELIABILITY_QOS; tQos.history.kind = DDS::KEEP_LAST_HISTORY_QOS; tQos.history.depth = 30; // Create Topic ts = new DDSKVStore::TransactionTypeSupport(); ts->register_type(dp, "DDSKVStore::Transaction"); topic = dp->create_topic("Transaction", "DDSKVStore::Transaction", tQos, NULL, DDS::STATUS_MASK_NONE); // Create Datareader dataReader = subscriber->create_datareader(topic, drQos, NULL, DDS::STATUS_MASK_NONE); transactionDataReader = DDSKVStore::TransactionDataReader::_narrow( dataReader); if (dataReader == NULL) std::cout << "ERROR: DDS Connection failed" << std::endl; // Create Datawriter transactionDataWriter = DDSKVStore::TransactionDataWriter::_narrow( publisher->create_datawriter(topic, dwQos, NULL, DDS::STATUS_MASK_NONE)); if (transactionDataWriter == NULL) std::cout << "ERROR: DDS Connection failed" << std::endl; // Create Readcondition readCondition = dataReader->create_readcondition(DDS::ANY_SAMPLE_STATE, DDS::ANY_VIEW_STATE, DDS::ALIVE_INSTANCE_STATE); }
void init () { participant = dpf->create_participant(domain_id, PARTICIPANT_QOS_DEFAULT, ::DDS::DomainParticipantListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (participant.in ())) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) create_participant failed.\n"))); throw TestException (); } ::Xyz::FooTypeSupportImpl* fts_servant = new ::Xyz::FooTypeSupportImpl(); if (::DDS::RETCODE_OK != fts_servant->register_type(participant.in (), type_name)) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) register_type failed.\n"))); throw TestException (); } ::DDS::TopicQos topic_qos; participant->get_default_topic_qos(topic_qos); topic[0] = participant->create_topic (topic_name[0], type_name, topic_qos, ::DDS::TopicListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (topic[0].in ())) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) create_topic failed.\n"))); throw TestException (); } topic[1] = participant->create_topic (topic_name[1], type_name, topic_qos, ::DDS::TopicListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (topic[1].in ())) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) create_topic failed.\n"))); throw TestException (); } writer_impl = TheTransportFactory->create_transport_impl (PUB_TRAFFIC_TCP, ACE_TEXT("SimpleTcp"), OpenDDS::DCPS::DONT_AUTO_CONFIG); OpenDDS::DCPS::TransportConfiguration_rch writer_config = TheTransportFactory->create_configuration (PUB_TRAFFIC_TCP, ACE_TEXT("SimpleTcp")); OpenDDS::DCPS::SimpleTcpConfiguration* writer_tcp_config = static_cast <OpenDDS::DCPS::SimpleTcpConfiguration*> (writer_config.in ()); if (writer_address_given) { ACE_INET_Addr writer_address (writer_address_str.c_str ()); writer_tcp_config->local_address_ = writer_address; writer_tcp_config->local_address_str_ = writer_address_str.c_str (); } // else use default address - OS assigned. if (writer_impl->configure(writer_config.in()) != 0) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) init_writer_tranport: pub TCP") ACE_TEXT(" Failed to configure the transport.\n"))); throw TestException (); } // Create the default publisher publisher = participant->create_publisher(PUBLISHER_QOS_DEFAULT, ::DDS::PublisherListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (publisher.in ())) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) create_publisher failed.\n"))); throw TestException (); } // Attach the publisher to the transport. OpenDDS::DCPS::PublisherImpl* pub_impl = dynamic_cast<OpenDDS::DCPS::PublisherImpl*> (publisher.in ()); if (0 == pub_impl) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) Failed to obtain publisher servant \n"))); throw TestException (); } ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) attach to tcp \n"))); OpenDDS::DCPS::AttachStatus attach_status = pub_impl->attach_transport(writer_impl.in()); if (attach_status != OpenDDS::DCPS::ATTACH_OK) { // We failed to attach to the transport for some reason. ACE_TString status_str; switch (attach_status) { case OpenDDS::DCPS::ATTACH_BAD_TRANSPORT: status_str = ACE_TEXT("ATTACH_BAD_TRANSPORT"); break; case OpenDDS::DCPS::ATTACH_ERROR: status_str = ACE_TEXT("ATTACH_ERROR"); break; case OpenDDS::DCPS::ATTACH_INCOMPATIBLE_QOS: status_str = ACE_TEXT("ATTACH_INCOMPATIBLE_QOS"); break; default: status_str = ACE_TEXT("Unknown Status"); break; } ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) Failed to attach to the transport. ") ACE_TEXT("AttachStatus == %s\n"), status_str.c_str())); throw TestException (); } // Create the datawriters ::DDS::DataWriterQos dw_qos; publisher->get_default_datawriter_qos (dw_qos); // Make it KEEP_ALL history so we can verify the received // data without dropping. dw_qos.history.kind = ::DDS::KEEP_ALL_HISTORY_QOS; dw_qos.reliability.kind = ::DDS::RELIABLE_RELIABILITY_QOS; dw_qos.resource_limits.max_samples_per_instance = ::DDS::LENGTH_UNLIMITED; dw_qos.reliability.max_blocking_time.sec = 0; dw_qos.reliability.max_blocking_time.nanosec = 0; for (int i = 0; i < 2; ++i) { datawriter[i] = publisher->create_datawriter(topic[i].in (), dw_qos, ::DDS::DataWriterListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (datawriter[i].in ())) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) create_datawriter failed.\n"))); throw TestException (); } writers[i] = new Writer (datawriter[i].in (), i); } }
int main (int argc, char *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; } MessageTypeSupportImpl* servant = new MessageTypeSupportImpl; if (DDS::RETCODE_OK != servant->register_type(participant.in (), "")) { cerr << "register_type failed." << endl; exit(1); } CORBA::String_var type_name = servant->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 (TCP_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 << "Exception caught in main.cpp:" << endl << e << endl; exit(1); } return 0; }