int Reader::init_transport () { int status = 0; reader_transport_impl = TheTransportFactory->create_transport_impl (SUB_TRAFFIC, "SimpleTcp", TAO::DCPS::DONT_AUTO_CONFIG); TAO::DCPS::TransportConfiguration_rch reader_config = TheTransportFactory->create_configuration (SUB_TRAFFIC, "SimpleTcp"); TAO::DCPS::SimpleTcpConfiguration* reader_tcp_config = static_cast <TAO::DCPS::SimpleTcpConfiguration*> (reader_config.in ()); ACE_INET_Addr reader_address (reader_address_str); reader_tcp_config->local_address_ = reader_address; if (reader_transport_impl->configure(reader_config.in()) != 0) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ::init_reader_tranport: ") ACE_TEXT("Failed to configure the transport.\n"))); status = 1; } return status; }
void init_dcps_objects (int i) { participant[i] = dpf->create_participant(domain_id, PARTICIPANT_QOS_DEFAULT, ::DDS::DomainParticipantListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (participant[i].in ())) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) create_participant failed.\n"))); throw TestException (); } ::Xyz::FooTypeSupportImpl* fts_servant = new ::Xyz::FooTypeSupportImpl(); ::Xyz::FooTypeSupportImpl* another_fts_servant = new ::Xyz::FooTypeSupportImpl(); if (::DDS::RETCODE_OK != fts_servant->register_type(participant[i].in (), type_name)) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Failed to register the FooNoTypeTypeSupport."))); throw TestException (); } // Test if different TypeSupport instances of the same TypeSupport type can register // with the same type name within the same domain participant. if (::DDS::RETCODE_OK != another_fts_servant->register_type(participant[i].in (), type_name)) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Failed to register the FooNoTypeTypeSupport."))); throw TestException (); } ::DDS::TopicQos topic_qos; participant[i]->get_default_topic_qos(topic_qos); topic[i] = participant[i]->create_topic(topic_name[i], type_name, topic_qos, ::DDS::TopicListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (topic[i].in ())) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Failed to create_topic."))); throw TestException (); } reader_impl[i] = TheTransportFactory->create_transport_impl (transport_id[i], ACE_TEXT("SimpleTcp"), OpenDDS::DCPS::DONT_AUTO_CONFIG); OpenDDS::DCPS::TransportConfiguration_rch reader_config = TheTransportFactory->create_configuration (transport_id[i], ACE_TEXT("SimpleTcp")); OpenDDS::DCPS::SimpleTcpConfiguration* reader_tcp_config = static_cast <OpenDDS::DCPS::SimpleTcpConfiguration*> (reader_config.in ()); if (reader_address_str[i] != ACE_TEXT("")) { ACE_INET_Addr reader_address (reader_address_str[i].c_str()); reader_tcp_config->local_address_ = reader_address; reader_tcp_config->local_address_str_ = reader_address_str[i].c_str(); } // else use default address - OS assigned. if (reader_impl[i]->configure(reader_config.in()) != 0) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) init_reader_tranport: subscriber TCP ") ACE_TEXT(" Failed to configure the transport.\n"))); throw TestException (); } subscriber[i] = participant[i]->create_subscriber(SUBSCRIBER_QOS_DEFAULT, ::DDS::SubscriberListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (subscriber[i].in ())) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Failed to create_subscriber."))); throw TestException (); } // Attach the subscriber to the transport. OpenDDS::DCPS::SubscriberImpl* sub_impl = dynamic_cast<OpenDDS::DCPS::SubscriberImpl*>(subscriber[i].in ()); if (0 == sub_impl) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) Failed to obtain subscriber servant\n"))); throw TestException (); } OpenDDS::DCPS::AttachStatus attach_status; ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) attach to tcp \n"))); attach_status = sub_impl->attach_transport(reader_impl[i].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 Datareaders ::DDS::DataReaderQos dr_qos; subscriber[i]->get_default_datareader_qos (dr_qos); ::DDS::TopicDescription_var description = participant[i]->lookup_topicdescription(topic_name[i]); // create the datareader. datareader[i] = subscriber[i]->create_datareader(description.in (), dr_qos, listener[i].in (), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (datareader[i].in ())) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) create_datareader failed.\n"))); throw TestException (); } }
int main (int argc, char *argv[]) { const int domainId = 411; const char *topicName = "Stock Quotes"; try { DDS::DomainParticipantFactory_var dpf; DDS::DomainParticipant_var participant; dpf = TheParticipantFactoryWithArgs(argc, argv); // To Do: Create the participant participant = dpf->create_participant(domainId, PARTICIPANT_QOS_DEFAULT, DDS::DomainParticipantListener::_nil()); if (CORBA::is_nil (participant.in ())) { cerr << "create_participant failed." << endl; return 1 ; } // End: Create the participant QuoterTypeSupportImpl* servant = new QuoterTypeSupportImpl(); PortableServer::ServantBase_var safe_servant = servant; // To Do: Register the type if (DDS::RETCODE_OK != servant->register_type(participant.in (), "")) { cerr << "Failed to register the QuoterTypeTypeSupport." << endl; exit(1); } // End: Register the type CORBA::String_var type_name = servant->get_type_name (); // To Do: Get the (default) topic QoS and create the topic DDS::TopicQos topic_qos; participant->get_default_topic_qos(topic_qos); DDS::Topic_var topic = participant->create_topic(topicName, type_name.in (), topic_qos, DDS::TopicListener::_nil()); if (CORBA::is_nil (topic.in ())) { cerr << "Failed to create_topic." << endl; exit(1); } // End: Get the (default) topic QoS and create the topic // To Do: Create the subscriber DDS::Subscriber_var sub = participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT, DDS::SubscriberListener::_nil()); if (CORBA::is_nil (sub.in ())) { cerr << "Failed to create_subscriber." << endl; exit(1); } // End: Create the subscriber // jhoffert // There seem to be problems using auto configurations with an application // distributed across different nodes. Take this out for now. // Initialize the transport TAO::DCPS::TransportImpl_rch tcp_impl = TheTransportFactory->create_transport_impl (TCP_IMPL_ID, //::TAO::DCPS::AUTO_CONFIG); ::TAO::DCPS::DONT_AUTO_CONFIG); TAO::DCPS::TransportConfiguration_rch reader_config = //TheTransportFactory->get_configuration (SUB_TRAFFIC); TheTransportFactory->get_configuration (TCP_IMPL_ID); TAO::DCPS::SimpleTcpConfiguration* reader_tcp_config = static_cast <TAO::DCPS::SimpleTcpConfiguration*> (reader_config.in ()); if (0 != ACE_OS::strcmp ("default", reader_address_str)) { ACE_INET_Addr reader_address (reader_address_str); reader_tcp_config->local_address_ = reader_address; } if (0 != tcp_impl->configure (reader_config.in ())) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) ::main: ") ACE_TEXT("Failed to configure the transport.\n"))); exit(1); } // jhoffert - End of transport configuration changes // Attach the subscriber to the transport. TAO::DCPS::SubscriberImpl* sub_impl = ::TAO::DCPS::reference_to_servant< TAO::DCPS::SubscriberImpl, DDS::Subscriber_ptr> (sub.in ()); if (0 == sub_impl) { cerr << "Failed to obtain subscriber servant\n" << endl; exit(1); } TAO::DCPS::AttachStatus status = sub_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); } // activate the listener DataReaderListenerImpl listener_servant; PortableServer::POA_var poa = TheServiceParticipant->the_poa (); CORBA::Object_var obj = poa->servant_to_reference(&listener_servant); DDS::DataReaderListener_var listener = DDS::DataReaderListener::_narrow (obj.in ()); if (CORBA::is_nil (listener.in ())) { cerr << "listener is nil." << endl; exit(1); } // To Do: Get default data reader QoS and create the data reader. DDS::DataReaderQos dr_qos; sub->get_default_datareader_qos (dr_qos); DDS::DataReader_var dr = sub->create_datareader(topic.in (), dr_qos, listener.in ()); if (CORBA::is_nil (dr.in ())) { cerr << "create_datareader failed." << endl; exit(1); } // End: Get default data reader QoS and create the data reader. // To Do: Set up the constraints for when the subscriber is done // receiving updates. int expected = 10; while ( listener_servant.num_reads() < expected) { ACE_OS::sleep (1); } // End: Set up the constraints for how long the subscriber should // receive updates. // To Do: Delete the participant's contained entities if (!CORBA::is_nil (participant.in ())) { participant->delete_contained_entities(); } // End: Delete the participant's contained entities if (!CORBA::is_nil (dpf.in ())) { dpf->delete_participant(participant.in ()); } ::DDS::InstanceHandleSeq handles; while (1) { ACE_OS::sleep(1); dr->get_matched_publications(handles); if (handles.length() == 0) break; } ACE_OS::sleep(2); TheTransportFactory->release(); TheServiceParticipant->shutdown (); } catch (CORBA::Exception& e) { cerr << "Exception caught in main ():" << endl << e << endl; return 1; } return 0; }
/** * @brief Construct a test system from the command line. */ Publisher::Publisher( int argc, char** argv, char** envp) : config_( argc, argv, envp) { // Grab a local reference to the factory ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) INFO: initializing the publisher.\n"))); ::DDS::DomainParticipantFactory_var factory = TheParticipantFactoryWithArgs( argc, argv); if( OpenDDS::DCPS::DCPS_debug_level > 0) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) COMMANDLINE: Verbose == %s\n") ACE_TEXT("(%P|%t) COMMANDLINE: Samples == %d\n"), (this->config_.verbose()? "true": "false"), this->config_.samples() )); } // // Establish DomainParticipant // if( OpenDDS::DCPS::DCPS_debug_level > 0) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) INFO: creating publisher participant in domain %d.\n"), this->config_.domain() )); } this->participant_ = factory->create_participant( this->config_.domain(), PARTICIPANT_QOS_DEFAULT, ::DDS::DomainParticipantListener::_nil() ); if( CORBA::is_nil( this->participant_.in())) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: create_participant failed for ") ACE_TEXT("publisher in domain %d.\n"), this->config_.domain() )); throw BadParticipantException (); } // // Grab and install the transport implementation. // // Establish debug level. if( this->config_.verbose()) { TURN_ON_VERBOSE_DEBUG; } if( OpenDDS::DCPS::DCPS_debug_level > 0) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) INFO: creating a SimpleTCP transport.\n"))); } this->transport_ = TheTransportFactory->create_transport_impl( 0, "SimpleTcp", OpenDDS::DCPS::DONT_AUTO_CONFIG ); OpenDDS::DCPS::TransportConfiguration_rch transport_config = TheTransportFactory->create_configuration( 0, ACE_TString("SimpleTcp") ); #if 0 OpenDDS::DCPS::SimpleTcpConfiguration* tcp_config = static_cast <OpenDDS::DCPS::SimpleTcpConfiguration*>( transport_config.in() ); std::string address; if( address.length() > 0) { ACE_INET_Addr reader_address( address.c_str()); tcp_config->local_address_ = reader_address; } #endif if( this->transport_->configure( transport_config.in()) != 0) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: TCP ") ACE_TEXT("failed to configure the transport.\n") )); throw BadTransportException (); } // // Establish the Type Support for the data // if( OpenDDS::DCPS::DCPS_debug_level > 0) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) INFO: Installing type %s support into domain %d.\n"), this->config_.typeName().c_str(), this->config_.domain() )); } ::Xyz::FooNoKeyTypeSupportImpl* publisher_data = new ::Xyz::FooNoKeyTypeSupportImpl(); if(::DDS::RETCODE_OK != publisher_data->register_type( this->participant_.in(), this->config_.typeName().c_str() ) ) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: Unable to install type %s support for domain %d.\n"), this->config_.typeName().c_str(), this->config_.domain() )); throw TestException (); } // // Establish the Topic // this->topic_ = this->participant_->create_topic( this->config_.topicName().c_str(), this->config_.typeName().c_str(), TOPIC_QOS_DEFAULT, ::DDS::TopicListener::_nil() ); if( CORBA::is_nil( this->topic_.in()) ) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) ERROR: Failed to create topic %s for publisher.\n"), this->config_.topicName().c_str() )); throw BadTopicException (); } // // Establish the Publisher // this->publisher_ = this->participant_->create_publisher( PUBLISHER_QOS_DEFAULT, ::DDS::PublisherListener::_nil() ); if( CORBA::is_nil (this->publisher_.in ())) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) ERROR: Failed to create_publisher.\n"))); throw BadPublisherException (); } // Attach the publisher to the transport. OpenDDS::DCPS::PublisherImpl* pub_impl = dynamic_cast<OpenDDS::DCPS::PublisherImpl*>( this->publisher_.in() ); if (0 == pub_impl) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: Failed to obtain publisher servant\n"))); throw BadPublisherException (); } OpenDDS::DCPS::AttachStatus attach_status; if( OpenDDS::DCPS::DCPS_debug_level > 0) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) INFO: attaching publisher to transport \n"))); } attach_status = pub_impl->attach_transport( this->transport_.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 = "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; } ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: Failed to attach to the transport. ") ACE_TEXT("AttachStatus == %s\n"), status_str.c_str())); throw BadTransportException (); } // // Establish and install the DataWriter. // if( OpenDDS::DCPS::DCPS_debug_level > 0) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) INFO: creating datawriter.\n"))); } // // Keep all data samples to allow us to establish connections in an // arbitrary order, with samples being buffered at the first writer // that has not yet had a subscription match. // ::DDS::DataWriterQos writerQos; this->publisher_->get_default_datawriter_qos( writerQos); writerQos.durability.kind = ::DDS::TRANSIENT_LOCAL_DURABILITY_QOS; writerQos.history.kind = ::DDS::KEEP_ALL_HISTORY_QOS; writerQos.resource_limits.max_samples_per_instance = ::DDS::LENGTH_UNLIMITED; writerQos.reliability.kind = ::DDS::RELIABLE_RELIABILITY_QOS; writerQos.reliability.max_blocking_time.sec = 0; writerQos.reliability.max_blocking_time.nanosec = 0; this->dataWriter_ = this->publisher_->create_datawriter( this->topic_.in(), writerQos, ::DDS::DataWriterListener::_nil() ); if( CORBA::is_nil( this->dataWriter_.in()) ) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: create datawriter failed.\n"))); throw BadWriterException (); } }
int init_tranport () { int status = 0; if (sub_using_udp) { reader_transport_impl = TheTransportFactory->create_transport_impl (SUB_TRAFFIC, ACE_TEXT("udp"), OpenDDS::DCPS::DONT_AUTO_CONFIG); OpenDDS::DCPS::TransportConfiguration_rch reader_config = TheTransportFactory->create_configuration (SUB_TRAFFIC, ACE_TEXT("udp")); OpenDDS::DCPS::UdpConfiguration* reader_udp_config = static_cast <OpenDDS::DCPS::UdpConfiguration*> (reader_config.in ()); if (!reader_address_given) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) init_transport: sub UDP") ACE_TEXT(" Must specify an address for UDP.\n"))); return 11; } ACE_INET_Addr reader_address (reader_address_str.c_str ()); reader_udp_config->local_address_ = reader_address; if (reader_transport_impl->configure(reader_config.in()) != 0) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) init_transport: sub UDP") ACE_TEXT(" Failed to configure the transport.\n"))); status = 1; } } else { reader_transport_impl = TheTransportFactory->create_transport_impl (SUB_TRAFFIC, ACE_TEXT("SimpleTcp"), OpenDDS::DCPS::DONT_AUTO_CONFIG); OpenDDS::DCPS::TransportConfiguration_rch reader_config = TheTransportFactory->create_configuration (SUB_TRAFFIC, ACE_TEXT("SimpleTcp")); OpenDDS::DCPS::SimpleTcpConfiguration* reader_tcp_config = static_cast <OpenDDS::DCPS::SimpleTcpConfiguration*> (reader_config.in ()); if (reader_address_given) { ACE_INET_Addr reader_address (reader_address_str.c_str ()); reader_tcp_config->local_address_ = reader_address; reader_tcp_config->local_address_str_ = reader_address_str; } // else use default address - OS assigned. if (reader_transport_impl->configure(reader_config.in()) != 0) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) init_transport: sub TCP ") ACE_TEXT(" Failed to configure the transport.\n"))); status = 1; } } if (pub_using_udp) { writer_transport_impl = TheTransportFactory->create_transport_impl (PUB_TRAFFIC, ACE_TEXT("udp"), OpenDDS::DCPS::DONT_AUTO_CONFIG); OpenDDS::DCPS::TransportConfiguration_rch writer_config = TheTransportFactory->create_configuration (PUB_TRAFFIC, ACE_TEXT("udp")); OpenDDS::DCPS::UdpConfiguration* writer_udp_config = static_cast <OpenDDS::DCPS::UdpConfiguration*> (writer_config.in ()); if (!writer_address_given) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) init_transport: pub UDP") ACE_TEXT(" Must specify an address for UDP.\n"))); return 12; } ACE_INET_Addr writer_address (writer_address_str.c_str ()); writer_udp_config->local_address_ = writer_address; if (writer_transport_impl->configure(writer_config.in()) != 0) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) init_transport: sub UDP") ACE_TEXT(" Failed to configure the transport.\n"))); status = 1; } } else { writer_transport_impl = TheTransportFactory->create_transport_impl (PUB_TRAFFIC, ACE_TEXT("SimpleTcp"), OpenDDS::DCPS::DONT_AUTO_CONFIG); OpenDDS::DCPS::TransportConfiguration_rch writer_config = TheTransportFactory->create_configuration (PUB_TRAFFIC, 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; } // else use default address - OS assigned. if (writer_transport_impl->configure(writer_config.in()) != 0) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) init_transport: sub TCP") ACE_TEXT(" Failed to configure the transport.\n"))); status = 1; } } return status; }