DDS::Publisher_var Factory::publisher(const DDS::DomainParticipant_var& dp) const { DDS::PublisherQos pub_qos; dp->get_default_publisher_qos(pub_qos); if (opts_.entity_str == "rw") { pub_qos.entity_factory.autoenable_created_entities = opts_.entity_autoenable; } // Create the publisher DDS::Publisher_var pub = dp->create_publisher(pub_qos, DDS::PublisherListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); TEST_ASSERT(!CORBA::is_nil(pub.in())); // If there is a ini file-based configuration name initialize // the transport configuration for the corresponding Entity if (opts_.configuration_str != "none" && opts_.entity_str == "pubsub") { OpenDDS::DCPS::TransportRegistry::instance()->bind_config(opts_.configuration_str, pub.in()); } return pub; }
void MonitorFactoryImpl::initialize() { DDS::DomainParticipantFactory_var dpf = TheServiceParticipant->get_domain_participant_factory(); DDS::DomainParticipant_var participant = dpf->create_participant(MONITOR_DOMAIN_ID, PARTICIPANT_QOS_DEFAULT, DDS::DomainParticipantListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(participant.in())) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("ERROR: %N:%l: MonitorFactoryImpl::initialize() -") ACE_TEXT(" create_participant failed!\n"))); } DDS::Publisher_var publisher = participant->create_publisher(PUBLISHER_QOS_DEFAULT, DDS::PublisherListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); static const std::string config_name = TransportRegistry::DEFAULT_INST_PREFIX + std::string("MonitorBITTransportConfig"); OpenDDS::DCPS::TransportConfig_rch config = TheTransportRegistry->get_config (config_name); if (config.is_nil ()) { config = TransportRegistry::instance()->create_config(config_name); std::string inst_name = TransportRegistry::DEFAULT_INST_PREFIX + std::string("FederationBITTCPTransportInst"); TransportInst_rch inst = TransportRegistry::instance()->create_inst(inst_name, "tcp"); config->instances_.push_back(inst); } TransportRegistry::instance()->bind_config(config, publisher.in()); DDS::DataWriter_var writer; DDS::DataWriterQos dw_qos; publisher->get_default_datawriter_qos(dw_qos); dw_qos.durability.kind = DDS::TRANSIENT_LOCAL_DURABILITY_QOS; OpenDDS::DCPS::ServiceParticipantReportTypeSupport_var sp_ts = new OpenDDS::DCPS::ServiceParticipantReportTypeSupportImpl(); ::DDS::ReturnCode_t ret = sp_ts->register_type(participant.in(), ""); if (DDS::RETCODE_OK == ret) { CORBA::String_var sp_type_name = sp_ts->get_type_name(); writer = create_data_writer(participant.in(), publisher.in(), sp_type_name.in(), SERVICE_PARTICIPANT_MONITOR_TOPIC, dw_qos); this->sp_writer_ = OpenDDS::DCPS::ServiceParticipantReportDataWriter::_narrow(writer.in()); if (CORBA::is_nil(this->sp_writer_)) { ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::initialize(): Failed to narrow sp_writer\n")); } } else { ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::initialize(): Failed to register sp_ts\n")); } OpenDDS::DCPS::DomainParticipantReportTypeSupport_var dp_ts = new OpenDDS::DCPS::DomainParticipantReportTypeSupportImpl(); ret = dp_ts->register_type(participant.in(), ""); if (DDS::RETCODE_OK == ret) { CORBA::String_var dp_type_name = dp_ts->get_type_name(); writer = create_data_writer(participant.in(), publisher.in(), dp_type_name.in(), DOMAIN_PARTICIPANT_MONITOR_TOPIC, dw_qos); this->dp_writer_ = OpenDDS::DCPS::DomainParticipantReportDataWriter::_narrow(writer.in()); if (CORBA::is_nil(this->dp_writer_)) { ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::initialize(): Failed to narrow dp_writer\n")); } } else { ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::initialize(): Failed to register dp_ts\n")); } OpenDDS::DCPS::TopicReportTypeSupport_var topic_ts = new OpenDDS::DCPS::TopicReportTypeSupportImpl(); ret = topic_ts->register_type(participant.in(), ""); if (DDS::RETCODE_OK == ret) { CORBA::String_var topic_type_name = topic_ts->get_type_name(); writer = create_data_writer(participant.in(), publisher.in(), topic_type_name.in(), TOPIC_MONITOR_TOPIC, dw_qos); this->topic_writer_ = OpenDDS::DCPS::TopicReportDataWriter::_narrow(writer.in()); if (CORBA::is_nil(this->topic_writer_)) { ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::initialize(): Failed to narrow topic_writer\n")); } } else { ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::initialize(): Failed to register topic_ts\n")); } OpenDDS::DCPS::PublisherReportTypeSupport_var pub_ts = new OpenDDS::DCPS::PublisherReportTypeSupportImpl(); ret = pub_ts->register_type(participant.in(), ""); if (DDS::RETCODE_OK == ret) { CORBA::String_var pub_type_name = pub_ts->get_type_name(); writer = create_data_writer(participant.in(), publisher.in(), pub_type_name.in(), PUBLISHER_MONITOR_TOPIC, dw_qos); this->pub_writer_ = OpenDDS::DCPS::PublisherReportDataWriter::_narrow(writer.in()); if (CORBA::is_nil(this->pub_writer_)) { ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::initialize(): Failed to narrow pub_writer\n")); } } else { ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::initialize(): Failed to register pub_ts\n")); } OpenDDS::DCPS::SubscriberReportTypeSupport_var sub_ts = new OpenDDS::DCPS::SubscriberReportTypeSupportImpl(); ret = sub_ts->register_type(participant.in(), ""); if (DDS::RETCODE_OK == ret) { CORBA::String_var sub_type_name = sub_ts->get_type_name(); writer = create_data_writer(participant.in(), publisher.in(), sub_type_name.in(), SUBSCRIBER_MONITOR_TOPIC, dw_qos); this->sub_writer_ = OpenDDS::DCPS::SubscriberReportDataWriter::_narrow(writer.in()); if (CORBA::is_nil(this->sub_writer_)) { ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::initialize(): Failed to narrow sub_writer\n")); } } else { ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::initialize(): Failed to register sub_ts\n")); } OpenDDS::DCPS::DataWriterReportTypeSupport_var dw_ts = new OpenDDS::DCPS::DataWriterReportTypeSupportImpl(); ret = dw_ts->register_type(participant.in(), ""); if (DDS::RETCODE_OK == ret) { CORBA::String_var dw_type_name = dw_ts->get_type_name(); writer = create_data_writer(participant.in(), publisher.in(), dw_type_name.in(), DATA_WRITER_MONITOR_TOPIC, dw_qos); this->dw_writer_ = OpenDDS::DCPS::DataWriterReportDataWriter::_narrow(writer.in()); if (CORBA::is_nil(this->dw_writer_)) { ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::initialize(): Failed to narrow dw_writer\n")); } } else { ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::initialize(): Failed to register sp_ts\n")); } OpenDDS::DCPS::DataWriterPeriodicReportTypeSupport_var dw_per_ts = new OpenDDS::DCPS::DataWriterPeriodicReportTypeSupportImpl(); ret = dw_per_ts->register_type(participant.in(), ""); if (DDS::RETCODE_OK == ret) { CORBA::String_var dw_per_type_name = dw_per_ts->get_type_name(); writer = create_data_writer(participant.in(), publisher.in(), dw_per_type_name.in(), DATA_WRITER_PERIODIC_MONITOR_TOPIC, dw_qos); this->dw_per_writer_ = OpenDDS::DCPS::DataWriterPeriodicReportDataWriter::_narrow(writer.in()); if (CORBA::is_nil(this->dw_per_writer_)) { ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::initialize(): Failed to narrow dw_per_writer\n")); } } else { ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::initialize(): Failed to register dw_per_ts\n")); } OpenDDS::DCPS::DataReaderReportTypeSupport_var dr_ts = new OpenDDS::DCPS::DataReaderReportTypeSupportImpl(); ret = dr_ts->register_type(participant.in(), ""); if (DDS::RETCODE_OK == ret) { CORBA::String_var dr_type_name = dr_ts->get_type_name(); writer = create_data_writer(participant.in(), publisher.in(), dr_type_name.in(), DATA_READER_MONITOR_TOPIC, dw_qos); this->dr_writer_ = OpenDDS::DCPS::DataReaderReportDataWriter::_narrow(writer.in()); if (CORBA::is_nil(this->dr_writer_)) { ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::initialize(): Failed to narrow dr_writer\n")); } } else { ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::initialize(): Failed to register dr_ts\n")); } OpenDDS::DCPS::DataReaderPeriodicReportTypeSupport_var dr_per_ts = new OpenDDS::DCPS::DataReaderPeriodicReportTypeSupportImpl(); ret = dr_per_ts->register_type(participant.in(), ""); if (DDS::RETCODE_OK == ret) { CORBA::String_var dr_per_type_name = dr_per_ts->get_type_name(); writer = create_data_writer(participant.in(), publisher.in(), dr_per_type_name.in(), DATA_READER_PERIODIC_MONITOR_TOPIC, dw_qos); this->dr_per_writer_ = OpenDDS::DCPS::DataReaderPeriodicReportDataWriter::_narrow(writer.in()); if (CORBA::is_nil(this->dr_per_writer_)) { ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::initialize(): Failed to narrow dr_per_writer\n")); } } else { ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::initialize(): Failed to register dr_per_ts\n")); } OpenDDS::DCPS::TransportReportTypeSupport_var transport_ts = new OpenDDS::DCPS::TransportReportTypeSupportImpl(); ret = transport_ts->register_type(participant.in(), ""); if (DDS::RETCODE_OK == ret) { CORBA::String_var transport_type_name = transport_ts->get_type_name(); writer = create_data_writer(participant.in(), publisher.in(), transport_type_name.in(), TRANSPORT_MONITOR_TOPIC, dw_qos); this->transport_writer_ = OpenDDS::DCPS::TransportReportDataWriter::_narrow(writer.in()); if (CORBA::is_nil(this->transport_writer_)) { ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::initialize(): Failed to narrow transport_writer\n")); } } else { ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::initialize(): Failed to register transport_ts\n")); } }
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(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 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(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[]){ 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 { // 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 (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 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[]){ 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 ACE_TMAIN(int argc, ACE_TCHAR** argv) { try { TheParticipantFactoryWithArgs(argc, argv); // Create Participant DDS::DomainParticipant_var participant = TheParticipantFactory->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: main()") ACE_TEXT(" ERROR: create_participant failed!\n")), 1); // Create Subscriber DDS::Subscriber_var subscriber = participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT, DDS::SubscriberListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(subscriber.in())) ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: create_subscriber failed!\n")), 2); // 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: main()") ACE_TEXT(" ERROR: create_publisher failed!\n")), 1); OpenDDS::DCPS::TransportIdType transportId(0); // Attach Subscriber Transport ++transportId; OpenDDS::DCPS::TransportConfiguration_rch sub_config = TheTransportFactory->get_or_create_configuration(transportId, ACE_TEXT("SimpleTcp")); OpenDDS::DCPS::TransportImpl_rch sub_transport = TheTransportFactory->create_transport_impl(transportId); OpenDDS::DCPS::SubscriberImpl* subscriber_i = dynamic_cast<OpenDDS::DCPS::SubscriberImpl*>(subscriber.in()); if (subscriber_i == 0) ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: dynamic_cast failed!\n")), 1); OpenDDS::DCPS::AttachStatus sub_status = subscriber_i->attach_transport(sub_transport.in()); if (sub_status != OpenDDS::DCPS::ATTACH_OK) ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: attach_transport failed!\n")), 1); // Attach Publisher Transport ++transportId; OpenDDS::DCPS::TransportConfiguration_rch pub_config = TheTransportFactory->get_or_create_configuration(transportId, ACE_TEXT("SimpleTcp")); OpenDDS::DCPS::TransportImpl_rch pub_transport = TheTransportFactory->create_transport_impl(transportId); OpenDDS::DCPS::PublisherImpl* publisher_i = dynamic_cast<OpenDDS::DCPS::PublisherImpl*>(publisher.in()); if (publisher_i == 0) ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: dynamic_cast failed!\n")), 1); OpenDDS::DCPS::AttachStatus pub_status = publisher_i->attach_transport(pub_transport.in()); if (pub_status != OpenDDS::DCPS::ATTACH_OK) ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: attach_transport 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: main()") ACE_TEXT(" ERROR: 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: main()") ACE_TEXT(" ERROR: create_topic failed!\n")), 1); // Create DataReader DDS::DataReaderQos qos; if (subscriber->get_default_datareader_qos(qos) != DDS::RETCODE_OK) ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l main()") ACE_TEXT(" ERROR: create_datareader failed!\n")), -1); qos.history.kind = DDS::KEEP_ALL_HISTORY_QOS; DDS::DataReader_var reader = subscriber->create_datareader(topic.in(), qos, DDS::DataReaderListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(reader.in())) ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: create_datareader failed!\n")), 7); FooDataReader_var reader_i = FooDataReader::_narrow(reader); if (CORBA::is_nil(reader_i)) ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: _narrow failed!\n")), 1); // Create DataWriter DDS::DataWriter_var writer = publisher->create_datawriter(topic.in(), DATAWRITER_QOS_DEFAULT, DDS::DataWriterListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(writer.in())) ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: 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: main()") ACE_TEXT(" ERROR: _narrow failed!\n")), 1); // Block until Subscriber is associated 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: main()") ACE_TEXT(" ERROR: wait failed!\n")), 1); if (writer->get_publication_matched_status(matches) != ::DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: failed to get publication matched status!\n")), 2); } } while (matches.current_count < 1); ws->detach_condition(cond); // // FooDataWriter::dispose should cause an instance to be // deleted after the last sample in the instance has been // taken from the ReceivedDataElementList: // DDS_TEST test(reader_i); if (!test) return 1; Foo foo; DDS::InstanceHandle_t handle; handle = writer_i->register_instance(foo); writer_i->write(foo, handle); writer_i->dispose(foo, handle); ACE_OS::sleep(5); // wait for samples to arrive if (!test.take_all_samples()) ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: unable to take samples!\n")), 2); /// Verify instance has been deleted if (test.has_instance(handle)) ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: instance not removed!\n")), 3); // Clean-up! participant->delete_contained_entities(); TheParticipantFactory->delete_participant(participant); TheTransportFactory->release(); TheServiceParticipant->shutdown(); } catch (const CORBA::Exception& e) { e._tao_print_exception("caught in main()"); return -1; } return 0; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try { DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); // Default DomainParticipantFactory qos is to auto enable. ::DDS::DomainParticipantFactoryQos fqos; if (dpf->get_qos (fqos) != ::DDS::RETCODE_OK) { cerr << "DomainParticipantFactory get_qos failed." << endl; return 1; } if (fqos.entity_factory.autoenable_created_entities == 0) { cerr << "The DomainParticipantFactory defaults to autoenable upon entities creation." << endl; return 1; } // Now disable DomainParticipantFactory autoenable fqos.entity_factory.autoenable_created_entities = 0; if (dpf->set_qos (fqos) != ::DDS::RETCODE_OK) { cerr << "DomainParticipantFactory set_qos failed." << endl; 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; } if (participant->enable () != ::DDS::RETCODE_PRECONDITION_NOT_MET) { cerr << "DomainParticipant can not be enabled because factory autoenable is off." << endl; return 1; } MessageTypeSupport_var mts = new MessageTypeSupportImpl(); if (DDS::RETCODE_OK != mts->register_type(participant.in (), "")) { cerr << "register_type failed." << endl; exit(1); } CORBA::String_var type_name = mts->get_type_name (); DDS::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); } if (topic->enable () != ::DDS::RETCODE_PRECONDITION_NOT_MET) { cerr << "Topic can not be enabled because DomainParticipant is not enabled." << endl; return 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); } if (pub->enable () != ::DDS::RETCODE_PRECONDITION_NOT_MET) { cerr << "Publisher can not be enabled because DomainParticipant is not enabled." << endl; return 1; } // Create the 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 ())) { cerr << "create_datawriter failed." << endl; exit(1); } if (dw->enable () != ::DDS::RETCODE_PRECONDITION_NOT_MET) { cerr << "DataWriter can not be enabled because Publisher is not enabled." << endl; return 1; } // Now enable DomainParticipantFactory autoenable fqos.entity_factory.autoenable_created_entities = 1; if (dpf->set_qos (fqos) != ::DDS::RETCODE_OK) { cerr << "DomainParticipantFactory set_qos failed." << endl; return 1; } // Enable every entity from factory to it's entities and it should succeed. if (participant->enable () != ::DDS::RETCODE_OK || topic->enable () != ::DDS::RETCODE_OK || pub->enable () != ::DDS::RETCODE_OK) { cerr << "Failed to enable factory." << endl; return 1; } Writer* writer = new Writer(dw.in()); writer->start (); writer->wait (); delete writer; 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 { ACE_DEBUG ((LM_DEBUG, "(%P|%t) publisher main\n")); DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); if (parse_args (argc, argv) == -1) { return -1; } DDS::DomainParticipantQos partQos; dpf->get_default_participant_qos(partQos); // set up user data in DP qos CORBA::ULong part_user_data_len = static_cast<CORBA::ULong>(ACE_OS::strlen (PART_USER_DATA)); partQos.user_data.value.length (part_user_data_len); partQos.user_data.value.replace (part_user_data_len, part_user_data_len, reinterpret_cast<CORBA::Octet*>(PART_USER_DATA)); DDS::DomainParticipant_var participant = dpf->create_participant(411, partQos, DDS::DomainParticipantListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (participant.in ())) { cerr << "publisher: create_participant failed." << endl; return 1; } ::Messenger::MessageTypeSupport_var ts = new ::Messenger::MessageTypeSupportImpl(); if (DDS::RETCODE_OK != ts->register_type(participant.in (), "Messenger")) { cerr << "publisher: register_type failed." << endl; exit(1); } CORBA::String_var type_name = ts->get_type_name (); DDS::TopicQos topic_qos; participant->get_default_topic_qos(topic_qos); // set up topic data in topic qos CORBA::ULong topic_data_len = static_cast<CORBA::ULong>(ACE_OS::strlen (TOPIC_DATA)); topic_qos.topic_data.value.length (topic_data_len); topic_qos.topic_data.value.replace (topic_data_len, topic_data_len, reinterpret_cast<CORBA::Octet*>(TOPIC_DATA)); 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 << "publisher: create_topic failed." << endl; exit(1); } DDS::PublisherQos pub_qos; participant->get_default_publisher_qos (pub_qos); // set up group data in group qos CORBA::ULong group_data_len = static_cast<CORBA::ULong> (ACE_OS::strlen (GROUP_DATA)); pub_qos.group_data.value.length (group_data_len); pub_qos.group_data.value.replace (group_data_len, group_data_len, reinterpret_cast<CORBA::Octet*>(GROUP_DATA)); DDS::Publisher_var pub = participant->create_publisher(pub_qos, DDS::PublisherListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (pub.in ())) { cerr << "publisher: create_publisher failed." << endl; exit(1); } // Create the datawriter DDS::DataWriterQos dw_qos; pub->get_default_datawriter_qos (dw_qos); dw_qos.durability.kind = DDS::TRANSIENT_LOCAL_DURABILITY_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; // set up user data in DW qos CORBA::ULong dw_user_data_len = static_cast<CORBA::ULong>(ACE_OS::strlen (DW_USER_DATA)); dw_qos.user_data.value.length (dw_user_data_len); dw_qos.user_data.value.replace (dw_user_data_len, dw_user_data_len, reinterpret_cast<CORBA::Octet*>(DW_USER_DATA)); 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 << "publisher: create_datawriter failed." << endl; exit(1); } // wait for Monitor 1 done 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 monitor1 done ...\n"))); ACE_OS::sleep (1); ++ i; fp = ACE_OS::fopen (synch_fname, ACE_TEXT("r")); } if (fp != 0) ACE_OS::fclose (fp); // Now change the changeable qos. The second monitor should get the updated qos from BIT. part_user_data_len = static_cast<CORBA::ULong>(ACE_OS::strlen (UPDATED_PART_USER_DATA)); partQos.user_data.value.length (part_user_data_len); partQos.user_data.value.replace (part_user_data_len, part_user_data_len, reinterpret_cast<CORBA::Octet*>(UPDATED_PART_USER_DATA)); participant->set_qos (partQos); dw_user_data_len = static_cast<CORBA::ULong>(ACE_OS::strlen (UPDATED_DW_USER_DATA)); dw_qos.user_data.value.length (dw_user_data_len); dw_qos.user_data.value.replace (dw_user_data_len, dw_user_data_len, reinterpret_cast<CORBA::Octet*>(UPDATED_DW_USER_DATA)); dw->set_qos (dw_qos); group_data_len = static_cast<CORBA::ULong> (ACE_OS::strlen (UPDATED_GROUP_DATA)); pub_qos.group_data.value.length (group_data_len); pub_qos.group_data.value.replace (group_data_len, group_data_len, reinterpret_cast<CORBA::Octet*>(UPDATED_GROUP_DATA)); pub->set_qos (pub_qos); topic_data_len = static_cast<CORBA::ULong>(ACE_OS::strlen (UPDATED_TOPIC_DATA)); topic_qos.topic_data.value.length (topic_data_len); topic_qos.topic_data.value.replace (topic_data_len, topic_data_len, reinterpret_cast<CORBA::Octet*>(UPDATED_TOPIC_DATA)); topic->set_qos (topic_qos); 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.in ()); TheServiceParticipant->shutdown (); } catch (CORBA::Exception& e) { cerr << "publisher: 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); OpenDDS::DCPS::TransportConfig_rch config = OpenDDS::DCPS::TransportRegistry::instance()->get_config("dds4ccm_rtps"); if (config.is_nil()) { config = OpenDDS::DCPS::TransportRegistry::instance()->create_config("dds4ccm_rtps"); } OpenDDS::DCPS::TransportInst_rch inst = OpenDDS::DCPS::TransportRegistry::instance()->get_inst("the_rtps_transport"); if (inst.is_nil()) { inst = OpenDDS::DCPS::TransportRegistry::instance()->create_inst("the_rtps_transport", "rtps_udp"); config->instances_.push_back(inst); OpenDDS::DCPS::TransportRegistry::instance()->global_config(config); } // Create another transport instance for participant2 since RTPS transport instances // cannot be shared by domain participants. OpenDDS::DCPS::TransportConfig_rch config2 = OpenDDS::DCPS::TransportRegistry::instance()->get_config("dds4ccm_rtps_2"); if (config2.is_nil()) { config2 = OpenDDS::DCPS::TransportRegistry::instance()->create_config("dds4ccm_rtps_2"); } OpenDDS::DCPS::TransportInst_rch inst2 = OpenDDS::DCPS::TransportRegistry::instance()->get_inst("the_rtps_transport_2"); if (inst2.is_nil()) { inst2 = OpenDDS::DCPS::TransportRegistry::instance()->create_inst("the_rtps_transport_2", "rtps_udp"); config2->instances_.push_back(inst2); } #ifndef DDS_HAS_MINIMUM_BIT OpenDDS::RTPS::RtpsDiscovery_rch disc = new OpenDDS::RTPS::RtpsDiscovery(OpenDDS::DCPS::Discovery::DEFAULT_RTPS); // The recommended value for the resend period is 2 seconds for // the current implementation of OpenDDS. disc->resend_period(ACE_Time_Value(2)); TheServiceParticipant->add_discovery(OpenDDS::DCPS::static_rchandle_cast<OpenDDS::DCPS::Discovery>(disc)); TheServiceParticipant->set_repo_domain(11, disc->key()); #endif TheServiceParticipant->set_default_discovery (OpenDDS::DCPS::Discovery::DEFAULT_RTPS); DDS::DomainParticipant_var participant = dpf->create_participant(11, PARTICIPANT_QOS_DEFAULT, DDS::DomainParticipantListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (participant.in ())) { cerr << "create_participant failed." << endl; return 1; } else { ACE_DEBUG ((LM_DEBUG, "Created participant 1 with instance handle %d\n", participant->get_instance_handle ())); } OpenDDS::DCPS::TransportRegistry::instance()->bind_config(config, participant.in()); DDS::DomainParticipant_var participant2 = dpf->create_participant(11, PARTICIPANT_QOS_DEFAULT, DDS::DomainParticipantListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (participant2.in ())) { cerr << "create_participant failed." << endl; return 1; } else { ACE_DEBUG ((LM_DEBUG, "Created participant 2 with instance handle %d\n", participant2->get_instance_handle ())); } try { OpenDDS::DCPS::TransportRegistry::instance()->bind_config(config2, participant2.in()); } catch (const OpenDDS::DCPS::Transport::MiscProblem &) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: TransportRegistry::bind_config() throws") ACE_TEXT(" Transport::MiscProblem exception\n")), -1); } catch (const OpenDDS::DCPS::Transport::NotFound &) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: TransportRegistry::bind_config() throws") ACE_TEXT(" Transport::NotFound exception\n")), -1); } // Register TypeSupport (Messenger::Message) Messenger::MessageTypeSupport_var mts = new Messenger::MessageTypeSupportImpl(); if (mts->register_type(participant.in(), "") != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: register_type failed!\n")), -1); } // Create Topic CORBA::String_var type_name = mts->get_type_name(); DDS::Topic_var topic = participant->create_topic("Movie Discussion List", type_name.in(), TOPIC_QOS_DEFAULT, DDS::TopicListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(topic.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: create_topic failed!\n")), -1); } // Create Publisher DDS::Publisher_var pub = participant->create_publisher(PUBLISHER_QOS_DEFAULT, DDS::PublisherListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(pub.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: create_publisher failed!\n")), -1); } // Create DataWriter DDS::DataWriter_var dw = pub->create_datawriter(topic.in(), DATAWRITER_QOS_DEFAULT, DDS::DataWriterListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(dw.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: create_datawriter failed!\n")), -1); } DDS::ReturnCode_t retcode2 = pub->delete_datawriter (dw.in ()); if (retcode2 != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: should be able to delete datawriter\n")), -1); } DDS::ReturnCode_t retcode5 = dpf->delete_participant(participant.in ()); if (retcode5 != DDS::RETCODE_PRECONDITION_NOT_MET) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: should not be able to delete participant\n")), -1); } DDS::ReturnCode_t retcode3 = participant->delete_publisher (pub.in ()); if (retcode3 != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: should be able to delete publisher\n")), -1); } DDS::ReturnCode_t retcode4 = participant->delete_topic (topic.in ()); if (retcode4 != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: should be able to delete topic\n")), -1); } DDS::ReturnCode_t retcode6 = dpf->delete_participant(participant.in ()); if (retcode6 != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: should be able to delete participant\n")), -1); } // DDS::ReturnCode_t retcode7 = dpf->delete_participant(participant2.in ()); // if (retcode7 != DDS::RETCODE_OK) { // ACE_ERROR_RETURN((LM_ERROR, // ACE_TEXT("%N:%l: main()") // ACE_TEXT(" ERROR: should be able to delete participant2\n")), // -1); // } ACE_DEBUG ((LM_DEBUG, "Shutting down the service participant with one participant still registered\n")); TheServiceParticipant->shutdown (); } catch (CORBA::Exception& e) { cerr << "dp: Exception caught in main.cpp:" << endl << e << endl; exit(1); } return 0; }
int 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[]){ 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 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[]) { 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; }
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; }
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 ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { // Initialize DomainParticipantFactory DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); // Create DomainParticipant DDS::DomainParticipant_var participant = dpf->create_participant(42, PARTICIPANT_QOS_DEFAULT, DDS::DomainParticipantListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(participant.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: %N:%l: main() -") ACE_TEXT(" create_participant failed!\n")), -1); } // Register TypeSupport (Messenger::Message) Messenger::MessageTypeSupport_var ts = new Messenger::MessageTypeSupportImpl(); if (ts->register_type(participant.in(), "") != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: %N:%l: main() -") ACE_TEXT(" register_type failed!\n")), -1); } // Create Topic (Movie Discussion List) CORBA::String_var type_name = ts->get_type_name(); DDS::Topic_var topic = participant->create_topic("Movie Discussion List", type_name.in(), TOPIC_QOS_DEFAULT, DDS::TopicListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(topic.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: %N:%l: main() -") ACE_TEXT(" create_topic failed!\n")), -1); } // Create Publisher DDS::Publisher_var publisher = participant->create_publisher(PUBLISHER_QOS_DEFAULT, DDS::PublisherListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(publisher.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: %N:%l: main() -") ACE_TEXT(" create_publisher failed!\n")), -1); } // Create DataWriter DDS::DataWriter_var writer = publisher->create_datawriter(topic.in(), DATAWRITER_QOS_DEFAULT, DDS::DataWriterListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(writer.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: %N:%l: main() -") ACE_TEXT(" create_datawriter failed!\n")), -1); } Messenger::MessageDataWriter_var message_writer = Messenger::MessageDataWriter::_narrow(writer.in()); if (CORBA::is_nil(message_writer.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: %N:%l: main() -") ACE_TEXT(" _narrow failed!\n")), -1); } // Block until Subscriber is available DDS::StatusCondition_var condition = writer->get_statuscondition(); condition->set_enabled_statuses(DDS::PUBLICATION_MATCHED_STATUS); DDS::WaitSet_var ws = new DDS::WaitSet; ws->attach_condition(condition); DDS::ConditionSeq conditions; DDS::PublicationMatchedStatus matches = { 0, 0, 0, 0, 0 }; DDS::Duration_t timeout = { 30, 0 }; do { if (ws->wait(conditions, timeout) != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: %N:%l: main() -") ACE_TEXT(" wait failed!\n")), -1); } if (writer->get_publication_matched_status(matches) != ::DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: %N:%l: main() -") ACE_TEXT(" get_publication_matched_status failed!\n")), -1); } } while (matches.current_count < 1); ws->detach_condition(condition); // Write samples Messenger::Message message; message.subject_id = 99; message.from = CORBA::string_dup("Comic Book Guy"); message.subject = CORBA::string_dup("Review"); message.text = CORBA::string_dup("Worst. Movie. Ever."); message.count = 0; for (int i = 0; i < 10; i++) { DDS::ReturnCode_t error = message_writer->write(message, DDS::HANDLE_NIL); if (error != DDS::RETCODE_OK) { ACE_ERROR((LM_ERROR, ACE_TEXT("ERROR: %N:%l: main() -") ACE_TEXT(" write returned %d!\n"), error)); } } // Wait for samples to be acknowledged if (message_writer->wait_for_acknowledgments(timeout) != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: %N:%l: main() -") ACE_TEXT(" wait_for_acknowledgments failed!\n")), -1); } // Clean-up! participant->delete_contained_entities(); dpf->delete_participant(participant.in()); TheServiceParticipant->shutdown(); } catch (const CORBA::Exception& e) { e._tao_print_exception("Exception caught in main():"); return -1; } return 0; }