void PubDriver::add_subscription ( CORBA::Long reader_id, const char * sub_addr ) { ::OpenDDS::DCPS::ReaderAssociationSeq associations; associations.length (1); associations[0].readerTransInfo.transport_id = 1; // TBD - not right OpenDDS::DCPS::NetworkAddress network_order_address(sub_addr); ACE_OutputCDR cdr; cdr << network_order_address; size_t len = cdr.total_length (); associations[0].readerTransInfo.data = OpenDDS::DCPS::TransportInterfaceBLOB (len, len, (CORBA::Octet*)(cdr.buffer ())); associations[0].readerId = reader_id; associations[0].subQos = TheServiceParticipant->initial_SubscriberQos (); associations[0].readerQos = TheServiceParticipant->initial_DataReaderQos (); OpenDDS::DCPS::RepoId pub_id = foo_datawriter_servant_->get_publication_id(); datawriter_servant_->add_associations (pub_id, associations); }
bool MulticastTransport::connection_info_i(TransportLocator& info) const { NetworkAddress network_address(this->config_i_->group_address_); ACE_OutputCDR cdr; cdr << network_address; const CORBA::ULong len = static_cast<CORBA::ULong>(cdr.total_length()); char* buffer = const_cast<char*>(cdr.buffer()); // safe info.transport_type = "multicast"; info.data = TransportBLOB(len, len, reinterpret_cast<CORBA::Octet*>(buffer)); return true; }
void SubDriver::run() { // Set up the publications. OpenDDS::DCPS::AssociationData publications[1]; publications[0].remote_id_ = this->pub_id_; publications[0].remote_data_.transport_id = 2; // TBD later - wrong OpenDDS::DCPS::NetworkAddress network_order_address(this->pub_addr_str_); ACE_OutputCDR cdr; cdr << network_order_address; size_t len = cdr.total_length (); publications[0].remote_data_.data = OpenDDS::DCPS::TransportInterfaceBLOB (len, len, (CORBA::Octet*)(cdr.buffer ())); // Write a file so that test script knows we're ready FILE * file = ACE_OS::fopen ("subready.txt", "w"); ACE_OS::fprintf (file, "Ready\n"); ACE_OS::fclose (file); this->subscriber_.init(ALL_TRAFFIC, this->sub_id_, 1, /* size of publications array */ publications, this->num_msgs_); // Wait until we receive our expected message from the remote // publisher. For this test, we should wait until we receive the // "Hello World!" message that we expect. Then this program // can just shutdown. while (this->subscriber_.received_test_message() == 0) { ACE_OS::sleep(1); } // Tear-down the entire Transport Framework. TheTransportFactory->release(); TheServiceParticipant->shutdown(); }
size_t UdpInst::populate_locator(OpenDDS::DCPS::TransportLocator& info) const { if (this->local_address_ != ACE_INET_Addr()) { NetworkAddress network_address(this->local_address_, this->local_address_.is_any()); ACE_OutputCDR cdr; cdr << network_address; const CORBA::ULong len = static_cast<CORBA::ULong>(cdr.total_length()); char* buffer = const_cast<char*>(cdr.buffer()); // safe info.transport_type = "udp"; info.data = TransportBLOB(len, len, reinterpret_cast<CORBA::Octet*>(buffer)); return 1; } else { return 0; } }
bool TcpTransport::connection_info_i(TransportLocator& local_info) const { DBG_ENTRY_LVL("TcpTransport", "connection_info_i", 6); VDBG_LVL((LM_DEBUG, "(%P|%t) TcpTransport public address str %C\n", this->tcp_config_->get_public_address().c_str()), 2); // Get the public address string from the inst (usually the local address) NetworkAddress network_order_address(this->tcp_config_->get_public_address()); ACE_OutputCDR cdr; cdr << network_order_address; const CORBA::ULong len = static_cast<CORBA::ULong>(cdr.total_length()); char* buffer = const_cast<char*>(cdr.buffer()); // safe local_info.transport_type = "tcp"; local_info.data = TransportBLOB(len, len, reinterpret_cast<CORBA::Octet*>(buffer)); return true; }
void SubDriver::run() { DBG_ENTRY_LVL("SubDriver", "run", 6); VDBG((LM_DEBUG, "(%P|%t) DBG: " "Initialize our SimpleSubscriber object.\n")); this->reader_.enable_transport(false /*reliable*/, false /*durable*/); // Write a file so that test script knows we're ready FILE * file = ACE_OS::fopen ("subready.txt", ACE_TEXT("w")); ACE_OS::fprintf (file, "Ready\n"); ACE_OS::fclose (file); VDBG((LM_DEBUG, "(%P|%t) DBG: Create the 'publications'.\n")); // Set up the publication. OpenDDS::DCPS::AssociationData publication; publication.remote_id_ = this->pub_id_; publication.remote_reliable_ = true; publication.remote_data_.length(1); if (shmem_) { publication.remote_data_[0].transport_type = "shmem"; std::ofstream ofs("sub-pid.txt"); ofs << ACE_OS::getpid() << std::endl; ofs.close(); for (ACE_stat filestat; -1 == ACE_OS::stat("pub-pid.txt", &filestat); ACE_OS::sleep(1)) {/*empty loop*/} std::ifstream ifs("pub-pid.txt"); std::string pid; getline(ifs, pid); std::string str = OpenDDS::DCPS::get_fully_qualified_hostname() + '\0' + "OpenDDS-" + pid + "-shmem1"; publication.remote_data_[0].data.length(static_cast<CORBA::ULong>(str.size())); std::memcpy(publication.remote_data_[0].data.get_buffer(), str.c_str(), str.size()); } else { // tcp publication.remote_data_[0].transport_type = "tcp"; OpenDDS::DCPS::NetworkAddress network_order_address( ACE_TEXT_ALWAYS_CHAR(this->pub_addr_str_.c_str())); ACE_OutputCDR cdr; cdr << network_order_address; CORBA::ULong len = static_cast<CORBA::ULong>(cdr.total_length()); publication.remote_data_[0].data = OpenDDS::DCPS::TransportBLOB(len, len, (CORBA::Octet*)(cdr.buffer())); } this->reader_.init(publication, this->num_msgs_); VDBG((LM_DEBUG, "(%P|%t) DBG: " "Ask the SimpleSubscriber object if it has received what, " "it expected. If not, sleep for 1 second, and ask again.\n")); // Wait until we receive our expected message from the remote // publisher. For this test, we should wait until we receive the // "Hello World!" message that we expect. Then this program // can just shutdown. while (this->reader_.received_test_message() == 0) { ACE_OS::sleep(1); } this->reader_.print_time(); if (shmem_) { ACE_OS::unlink("sub-pid.txt"); } VDBG((LM_DEBUG, "(%P|%t) DBG: " "The SimpleSubscriber object has received what it expected. " "Release TheTransportFactory - causing all TransportImpl " "objects to be shutdown().\n")); this->reader_.disassociate(this->pub_id_); TheServiceParticipant->shutdown(); VDBG((LM_DEBUG, "(%P|%t) DBG: " "TheTransportFactory has finished releasing.\n")); }
void PubDriver::run() { DBG_ENTRY_LVL("PubDriver","run",6); VDBG((LM_DEBUG, "(%P|%t) DBG: " "Initialize our SimplePublisher object.\n")); this->writer_.enable_transport(false /*reliable*/, false /*durable*/); VDBG((LM_DEBUG, "(%P|%t) DBG: Create the 'subscriptions'.\n")); // Set up the subscription. OpenDDS::DCPS::AssociationData subscription; subscription.remote_id_ = this->sub_id_; subscription.remote_reliable_ = true; subscription.remote_data_.length(1); if (shmem_) { subscription.remote_data_[0].transport_type = "shmem"; std::ofstream ofs("pub-pid.txt"); ofs << ACE_OS::getpid() << std::endl; ofs.close(); for (ACE_stat filestat; -1 == ACE_OS::stat("sub-pid.txt", &filestat); ACE_OS::sleep(1)) {/*empty loop*/} std::ifstream ifs("sub-pid.txt"); std::string pid; getline(ifs, pid); std::string str = OpenDDS::DCPS::get_fully_qualified_hostname() + '\0' + "OpenDDS-" + pid + "-shmem1"; subscription.remote_data_[0].data.length(static_cast<CORBA::ULong>(str.size())); std::memcpy(subscription.remote_data_[0].data.get_buffer(), str.c_str(), str.size()); } else { // tcp subscription.remote_data_[0].transport_type = "tcp"; OpenDDS::DCPS::NetworkAddress network_order_address( ACE_TEXT_ALWAYS_CHAR(this->sub_addr_str_.c_str())); ACE_OutputCDR cdr; cdr << network_order_address; CORBA::ULong len = static_cast<CORBA::ULong>(cdr.total_length()); subscription.remote_data_[0].data = OpenDDS::DCPS::TransportBLOB(len, len, (CORBA::Octet*)(cdr.buffer())); } this->writer_.init(subscription); // Wait for a fully association establishment and then start sending samples. ACE_OS::sleep(2); VDBG((LM_DEBUG, "(%P|%t) DBG: " "Run our SimplePublisher object.\n")); this->writer_.run(this->num_msgs_, this->msg_size_); VDBG((LM_DEBUG, "(%P|%t) DBG: " "Ask the SimplePublisher object if it is done running. " "If not, sleep for 1 second, and ask again.\n")); while (this->writer_.delivered_test_message() == 0) { ACE_OS::sleep(1); } if (shmem_) { for (ACE_stat filestat; 0 == ACE_OS::stat("sub-pid.txt", &filestat); ACE_OS::sleep(1)) {/*empty loop*/} } VDBG((LM_DEBUG, "(%P|%t) DBG: " "The SimplePublisher object is done running. " "Release TheTransportFactory - causing all TransportImpl " "objects to be shutdown().\n")); this->writer_.disassociate(this->sub_id_); TheServiceParticipant->shutdown(); VDBG((LM_DEBUG, "(%P|%t) DBG: " "TheTransportFactory has finished releasing.\n")); }
void SubDriver::run() { ACE_DEBUG ((LM_DEBUG, ACE_TEXT("(%P|%t) SubDriver::run, ") ACE_TEXT(" Wait for %s. \n"), pub_id_fname_.c_str ())); PublicationIds ids; // Wait for the publication id file created by the publisher. while (1) { FILE* fp = ACE_OS::fopen (pub_id_fname_.c_str (), ACE_TEXT("r")); if (fp == 0) { ACE_OS::sleep (1); } else { // This could be made cleaner by losing the old C-style I/O. ::OpenDDS::DCPS::PublicationId pub_id = OpenDDS::DCPS::GUID_UNKNOWN; char charBuffer[64]; while (fscanf (fp, "%s\n", &charBuffer[0]) != EOF) { std::stringstream buffer( charBuffer); buffer >> pub_id; ids.push_back (pub_id); std::stringstream idBuffer; idBuffer << pub_id; ACE_DEBUG ((LM_DEBUG, ACE_TEXT("(%P|%t) SubDriver::run, ") ACE_TEXT(" Got from %s: pub_id=%C. \n"), pub_id_fname_.c_str (), buffer.str().c_str())); } ACE_OS::fclose (fp); break; } } CORBA::Object_var object = orb_->string_to_object (pub_driver_ior_.c_str ()); pub_driver_ = ::Test::TestPubDriver::_narrow (object.in ()); TEST_CHECK (!CORBA::is_nil (pub_driver_.in ())); size_t num_publications = ids.size (); // Set up the publications. OpenDDS::DCPS::AssociationData* publications = new OpenDDS::DCPS::AssociationData[num_publications]; for (size_t i = 0; i < num_publications; i ++) { publications[i].remote_id_ = ids[i]; publications[i].remote_data_.transport_id = ALL_TRAFFIC; // TBD later - wrong publications[i].remote_data_.publication_transport_priority = 0; OpenDDS::DCPS::NetworkAddress network_order_address(this->pub_addr_str_); ACE_OutputCDR cdr; cdr << network_order_address; size_t len = cdr.total_length (); publications[i].remote_data_.data = OpenDDS::DCPS::TransportInterfaceBLOB (len, len, (CORBA::Octet*)(cdr.buffer ())); } this->subscriber_.init(ALL_TRAFFIC, this->sub_id_, num_publications, publications, receive_delay_msec_); delete [] publications; while (this->subscriber_.received_test_message() != num_writes_) { ACE_OS::sleep(1); } pub_driver_->shutdown (); // Sleep before release transport so the connection will not go away. // This would avoid the problem of publisher sendv failure due to lost // connection during the shutdown period. ACE_OS::sleep (5); OpenDDS::DCPS::WriterIdSeq writers; writers.length(num_publications); for (size_t i = 0; i < num_publications; ++i) { writers[i] = ids[i]; } this->subscriber_.remove_associations(num_publications, writers.get_buffer(), this->sub_id_); // Tear-down the entire Transport Framework. TheTransportFactory->release(); TheServiceParticipant->shutdown(); }