int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try { DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); DDS::DomainParticipant_var participant = dpf->create_participant(411, PARTICIPANT_QOS_DEFAULT, DDS::DomainParticipantListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (participant.in ())) { cerr << "create_participant failed." << endl; return 1; } MessageTypeSupportImpl* servant = new MessageTypeSupportImpl; if (DDS::RETCODE_OK != servant->register_type(participant.in (), "")) { cerr << "register_type failed." << endl; exit(1); } CORBA::String_var type_name = servant->get_type_name (); DDS::TopicQos topic_qos; participant->get_default_topic_qos(topic_qos); DDS::Topic_var topic = participant->create_topic ("Movie Discussion List", type_name.in (), topic_qos, DDS::TopicListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (topic.in ())) { cerr << "create_topic failed." << endl; exit(1); } DDS::Publisher_var pub = participant->create_publisher(PUBLISHER_QOS_DEFAULT, DDS::PublisherListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (pub.in ())) { cerr << "create_publisher failed." << endl; exit(1); } // Create the datawriter DDS::DataWriterQos dw_qos; pub->get_default_datawriter_qos (dw_qos); DDS::DataWriter_var dw = pub->create_datawriter(topic.in (), dw_qos, DDS::DataWriterListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (dw.in ())) { cerr << "create_datawriter failed." << endl; exit(1); } Writer* writer = new Writer(dw.in()); writer->start (); while ( !writer->is_finished()) { ACE_Time_Value small_time(0,250000); ACE_OS::sleep (small_time); } // Cleanup writer->end(); delete writer; participant->delete_contained_entities(); dpf->delete_participant(participant); TheServiceParticipant->shutdown(); } catch (CORBA::Exception& e) { cerr << "Exception caught in main.cpp:" << endl << e << endl; exit(1); } return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { // Initialize DomainParticipantFactory DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); if (parse_args (argc, argv) != 0) { return 1; } TheServiceParticipant->monitor_factory_->initialize(); // Create DomainParticipant DDS::DomainParticipant_var participant = dpf->create_participant(411, PARTICIPANT_QOS_DEFAULT, DDS::DomainParticipantListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(participant.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: create_participant failed!\n")), -1); } // Register TypeSupport (Messenger::Message) Messenger::MessageTypeSupport_var mts = new Messenger::MessageTypeSupportImpl(); if (mts->register_type(participant.in(), "") != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: register_type failed!\n")), -1); } // Create Topic DDS::Topic_var topic = participant->create_topic("Movie Discussion List", mts->get_type_name(), TOPIC_QOS_DEFAULT, DDS::TopicListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(topic.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: create_topic failed!\n")), -1); } // Create Publisher DDS::Publisher_var pub = participant->create_publisher(PUBLISHER_QOS_DEFAULT, DDS::PublisherListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(pub.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: create_publisher failed!\n")), -1); } // Create DataWriter DDS::DataWriter_var dw = pub->create_datawriter(topic.in(), DATAWRITER_QOS_DEFAULT, DDS::DataWriterListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(dw.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: create_datawriter failed!\n")), -1); } // Start writing threads Writer* writer = new Writer(dw.in()); writer->start(); while (!writer->is_finished()) { ACE_Time_Value small_time(0, 250000); ACE_OS::sleep(small_time); } writer->end(); delete writer; // Clean-up! participant->delete_contained_entities(); dpf->delete_participant(participant.in()); TheServiceParticipant->shutdown(); } catch (const CORBA::Exception& e) { e._tao_print_exception("Exception caught in main():"); ACE_OS::exit(-1); } return 0; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try { 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 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; }
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 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 ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { DDS::DomainParticipantFactory_var dpf; DDS::DomainParticipant_var participant; try { std::cout << "Starting publisher" << std::endl; { // Initialize DomainParticipantFactory dpf = TheParticipantFactoryWithArgs(argc, argv); std::cout << "Starting publisher with " << argc << " args" << std::endl; int error; if ((error = parse_args(argc, argv)) != 0) { return error; } // Create DomainParticipant participant = dpf->create_participant(4, PARTICIPANT_QOS_DEFAULT, DDS::DomainParticipantListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(participant.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: create_participant failed!\n")), -1); } // Register TypeSupport (Messenger::Message) Messenger::MessageTypeSupport_var mts = new Messenger::MessageTypeSupportImpl(); if (mts->register_type(participant.in(), "") != DDS::RETCODE_OK) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: register_type failed!\n")), -1); } // Create Topic CORBA::String_var type_name = mts->get_type_name(); DDS::Topic_var topic = participant->create_topic("Movie Discussion List", type_name.in(), TOPIC_QOS_DEFAULT, DDS::TopicListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(topic.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: create_topic failed!\n")), -1); } // Create Publisher DDS::Publisher_var pub = participant->create_publisher(PUBLISHER_QOS_DEFAULT, DDS::PublisherListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(pub.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: create_publisher failed!\n")), -1); } DDS::DataWriterQos qos; pub->get_default_datawriter_qos(qos); if (dw_reliable()) { std::cout << "Reliable DataWriter" << std::endl; qos.history.kind = DDS::KEEP_ALL_HISTORY_QOS; qos.reliability.kind = DDS::RELIABLE_RELIABILITY_QOS; } // Create DataWriter DDS::DataWriter_var dw = pub->create_datawriter(topic.in(), qos, DDS::DataWriterListener::_nil(), OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil(dw.in())) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: main()") ACE_TEXT(" ERROR: create_datawriter failed!\n")), -1); } // Start writing threads std::cout << "Creating Writer" << std::endl; Writer* writer = new Writer(dw.in()); std::cout << "Starting Writer" << std::endl; writer->start(); while (!writer->is_finished()) { ACE_Time_Value small_time(0, 250000); ACE_OS::sleep(small_time); } std::cout << "Writer finished " << std::endl; writer->end(); if (wait_for_acks) { std::cout << "Writer wait for ACKS" << std::endl; DDS::Duration_t timeout = { DDS::DURATION_INFINITE_SEC, DDS::DURATION_INFINITE_NSEC }; dw->wait_for_acknowledgments(timeout); } else { // let any missed multicast/rtps messages get re-delivered ACE_Time_Value small_time(0, 250000); ACE_OS::sleep(small_time); } std::cout << "deleting DW" << std::endl; delete writer; } // Clean-up! participant->delete_contained_entities(); dpf->delete_participant(participant.in()); TheServiceParticipant->shutdown(); } catch (const CORBA::Exception& e) { e._tao_print_exception("Exception caught in main():"); ACE_OS::exit(-1); } return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { 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; }