Publisher::Publisher( const Options& options) : status_( 0), options_( options), participant_(0), publisher_(0), waiter_( new DDS::WaitSet) { DDS::DomainParticipantFactory_var dpf = TheParticipantFactory; // Create the DomainParticipant this->participant_ = dpf->create_participant( this->options_.domain(), PARTICIPANT_QOS_DEFAULT, DDS::DomainParticipantListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK ); if( CORBA::is_nil( this->participant_.in())) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: Publisher::Publisher() - ") ACE_TEXT("failed to create a participant.\n") )); throw BadParticipantException(); } else if( this->options_.verbose()) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) Publisher::Publisher() - ") ACE_TEXT("created participant in domain %d.\n"), this->options_.domain() )); } // Create and register the type support. DataTypeSupportImpl* testData = new DataTypeSupportImpl(); CORBA::String_var type_name = testData->get_type_name(); if( ::DDS::RETCODE_OK != testData->register_type( this->participant_.in(), 0)) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: Publisher::Publisher() - ") ACE_TEXT("unable to install type %C support.\n"), type_name.in() )); throw BadTypeSupportException (); } else if( this->options_.verbose()) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) Publisher::Publisher() - ") ACE_TEXT("created type %C support.\n"), type_name.in() )); } // Create the topic. DDS::Topic_var topic = this->participant_->create_topic( this->options_.topicName().c_str(), type_name, TOPIC_QOS_DEFAULT, ::DDS::TopicListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK ); if( CORBA::is_nil( topic.in())) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: Publisher::Publisher() - ") ACE_TEXT("failed to create topic %C.\n"), this->options_.topicName().c_str() )); throw BadTopicException(); } else if( this->options_.verbose()) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) Publisher::Publisher() - ") ACE_TEXT("created topic %C.\n"), this->options_.topicName().c_str() )); } // Create the publisher. this->publisher_ = this->participant_->create_publisher( PUBLISHER_QOS_DEFAULT, ::DDS::PublisherListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK ); if( CORBA::is_nil(this->publisher_.in())) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: Publisher::Publisher() - ") ACE_TEXT("failed to create publisher.\n") )); throw BadPublisherException(); } else if( this->options_.verbose()) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) Publisher::Publisher() - ") ACE_TEXT("created publisher.\n") )); } // Writer Qos policy values. ::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; if( this->options_.verbose()) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) Publisher::Publisher() - ") ACE_TEXT("starting to create %d publications.\n"), this->options_.publications() )); } // Build as many publications as are specified. for( int index = 0; index < this->options_.publications(); ++index) { // Create the writer. DDS::DataWriter_var writer = this->publisher_->create_datawriter( topic.in(), writerQos, DDS::DataWriterListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK ); if( CORBA::is_nil( writer.in())) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: Publisher::Publisher() - ") ACE_TEXT("failed to create writer.\n") )); throw BadWriterException(); } else if( this->options_.verbose()) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) Publisher::Publisher() - ") ACE_TEXT("created publication %d.\n"), (1+index) )); } // Create a publication and store it. this->publications_.push_back( new Writer( writer.in(), index, this->options_.verbose()) ); // // Grab, enable and attach the status condition for test // synchronization of the current publication. // DDS::StatusCondition_var status = writer->get_statuscondition(); status->set_enabled_statuses( DDS::PUBLICATION_MATCHED_STATUS); this->waiter_->attach_condition( status.in()); if( this->options_.verbose()) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) Publisher::Publisher() - ") ACE_TEXT("created StatusCondition for publication %d.\n"), (1+index) )); } } }
Publisher::Publisher( const Options& options) : options_( options), waiter_( new DDS::WaitSet) { DDS::DomainParticipantFactory_var dpf = TheParticipantFactory; // Create the DomainParticipant this->participant_ = dpf->create_participant( this->options_.domain(), PARTICIPANT_QOS_DEFAULT, DDS::DomainParticipantListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK ); if( CORBA::is_nil( this->participant_.in())) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: Publisher::Publisher() - ") ACE_TEXT("failed to create a participant.\n") )); throw BadParticipantException(); } else if( this->options_.verbose()) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) Publisher::Publisher() - ") ACE_TEXT("created participant in domain %d.\n"), this->options_.domain() )); } // Create the transport. OpenDDS::DCPS::TransportConfig_rch transport = TheTransportRegistry->get_config(this->options_.transportKey()); if (transport.is_nil()) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: Subscriber::Subscriber() - ") ACE_TEXT("failed to get %C transport.\n"), this->options_.transportKey().c_str() )); throw BadTransportException(); } else if( this->options_.verbose()) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) Subscriber::Subscriber() - ") ACE_TEXT("created %C transport.\n"), this->options_.transportKey().c_str() )); } // Create and register the type support. DataTypeSupportImpl* testData = new DataTypeSupportImpl(); if( ::DDS::RETCODE_OK != testData->register_type( this->participant_.in(), 0)) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: Publisher::Publisher() - ") ACE_TEXT("unable to install type %C support.\n"), testData->get_type_name() )); throw BadTypeSupportException (); } else if( this->options_.verbose()) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) Publisher::Publisher() - ") ACE_TEXT("created type %C support.\n"), testData->get_type_name() )); } // Create the topic. this->topic_ = this->participant_->create_topic( this->options_.topicName().c_str(), testData->get_type_name(), TOPIC_QOS_DEFAULT, ::DDS::TopicListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK ); if( CORBA::is_nil( this->topic_.in())) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: Publisher::Publisher() - ") ACE_TEXT("failed to create topic %C.\n"), this->options_.topicName().c_str() )); throw BadTopicException(); } else if( this->options_.verbose()) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) Publisher::Publisher() - ") ACE_TEXT("created topic %C.\n"), this->options_.topicName().c_str() )); } // Create the publisher. this->publisher_ = this->participant_->create_publisher( PUBLISHER_QOS_DEFAULT, ::DDS::PublisherListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK ); if( CORBA::is_nil( this->publisher_.in())) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: Publisher::Publisher() - ") ACE_TEXT("failed to create publisher.\n") )); throw BadPublisherException(); } else if( this->options_.verbose()) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) Publisher::Publisher() - ") ACE_TEXT("created publisher.\n") )); } TheTransportRegistry->bind_config(transport, this->publisher_); if( this->options_.verbose()) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) Publisher::Publisher() - ") ACE_TEXT("attached transport to publisher.\n") )); } // Writer Qos policy values. ::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; // Reliability varies with the transport implementation. switch( this->options_.transportType()) { case Options::TCP: case Options::MC: writerQos.reliability.kind = ::DDS::RELIABLE_RELIABILITY_QOS; break; case Options::UDP: writerQos.reliability.kind = ::DDS::BEST_EFFORT_RELIABILITY_QOS; break; case Options::TRANSPORT_NONE: default: ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: Publisher::Publisher() - ") ACE_TEXT("unrecognized transport when setting up Qos policies.\n") )); throw BadQosException(); } if( this->options_.verbose()) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) Publisher::Publisher() - ") ACE_TEXT("starting to create %d publications.\n"), this->options_.profiles().size() )); } // Build as many publications as are specified. for( unsigned int index = 0; index < this->options_.profiles().size(); ++index) { // This publications priority is needed when creating the writer. writerQos.transport_priority.value = this->options_.profiles()[ index]->priority(); // Create the writer. DDS::DataWriter_var writer = this->publisher_->create_datawriter( this->topic_.in(), writerQos, DDS::DataWriterListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK ); if( CORBA::is_nil( writer.in())) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: Publisher::Publisher() - ") ACE_TEXT("failed to create writer.\n") )); throw BadWriterException(); } else if( this->options_.verbose()) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) Publisher::Publisher() - ") ACE_TEXT("created writer for publication %C ") ACE_TEXT("with priority %d.\n"), this->options_.profiles()[ index]->name().c_str(), writerQos.transport_priority.value )); } // Create a publication and store it. this->publications_[ this->options_.profiles()[ index]->name()] = new Writer( writer.in(), *this->options_.profiles()[ index], this->options_.verbose() ); // // Grab, enable and attach the status condition for test // synchronization of the current publication. // DDS::StatusCondition_var status = writer->get_statuscondition(); status->set_enabled_statuses( DDS::PUBLICATION_MATCHED_STATUS); this->waiter_->attach_condition( status.in()); if( this->options_.verbose()) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) Publisher::Publisher() - ") ACE_TEXT("created StatusCondition for publication %C.\n"), this->options_.profiles()[ index]->name().c_str() )); } } }