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 do_writer(DDS::DomainParticipant_var participant, DDS::Topic_var topic, bool toggle) { // Create Publisher DDS::Publisher_var publisher = participant->create_publisher(PUBLISHER_QOS_DEFAULT, 0, OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (!publisher) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: %N:%l: do_writer() -") ACE_TEXT(" create_publisher failed!\n")), -1); } DDS::DataWriterQos qos; publisher->get_default_datawriter_qos(qos); qos.user_data.value.length(3); qos.user_data.value[0] = 0; qos.user_data.value[1] = 0; qos.user_data.value[2] = 1; qos.reliability.kind = DDS::RELIABLE_RELIABILITY_QOS; if (toggle) { ACE_DEBUG((LM_DEBUG, "Creating writer\n")); DDS::DataWriter_var writer = publisher->create_datawriter(topic, qos, 0, OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (!writer) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: %N:%l: do_writer() -") ACE_TEXT(" create_datawriter failed!\n")), -1); } ACE_OS::sleep(SLEEP_SHORT); // Go away. ACE_DEBUG((LM_DEBUG, "Deleting writer\n")); publisher->delete_datawriter(writer); ACE_OS::sleep(SLEEP_SHORT); // Come back. ACE_DEBUG((LM_DEBUG, "Creating writer\n")); writer = publisher->create_datawriter(topic, qos, 0, OpenDDS::DCPS::DEFAULT_STATUS_MASK); ACE_OS::sleep(SLEEP_SHORT); return 0; } else { struct Listener : public DDS::DataWriterListener { size_t found, lost; Listener() : found(0), lost(0) { } virtual void on_offered_deadline_missed (::DDS::DataWriter_ptr, const ::DDS::OfferedDeadlineMissedStatus &) { } virtual void on_offered_incompatible_qos (::DDS::DataWriter_ptr, const ::DDS::OfferedIncompatibleQosStatus &) { } virtual void on_liveliness_lost (::DDS::DataWriter_ptr, const ::DDS::LivelinessLostStatus &) { } virtual void on_publication_matched (::DDS::DataWriter_ptr, const ::DDS::PublicationMatchedStatus & status) { if (status.current_count_change > 0) { ACE_DEBUG((LM_DEBUG, "Writer found reader\n")); ++found; } if (status.current_count_change < 0) { ACE_DEBUG((LM_DEBUG, "Writer lost reader\n")); ++lost; } } } listener; // Create DataWriter DDS::DataWriter_var writer = publisher->create_datawriter(topic, qos, &listener, OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (!writer) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: %N:%l: do_writer() -") ACE_TEXT(" create_datawriter failed!\n")), -1); } ACE_OS::sleep(SLEEP_LONG); if (listener.found == 2 && listener.lost == 1) { writer->set_listener(0, OpenDDS::DCPS::DEFAULT_STATUS_MASK); return 0; } return -1; } }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]){ try { DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); DDS::DomainParticipant_var participant = dpf->create_participant(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 { 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); 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; }