Beispiel #1
0
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;
}
Beispiel #3
0
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();
}
Beispiel #4
0
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;
  }
}
/**
 * UDPGenerator::gloveDgramWrite
 *
 * @param remotehost
 * @param remoteport
 * @param glovedata
 *
 * @return
 */
int UDPGenerator::gloveDgramWrite(
    const ACE_TCHAR * remotehost,
    u_short remoteport,
    const DataGloveData &glovedata)
{
    ACE_DEBUG ((LM_DEBUG, "Sender::initiate_write called\n"));
    const size_t max_payload_size =
        4 //boolean alignment flag
        + 4 //payload length
        + glovedata.length // Data Glove data length
        + ACE_CDR::MAX_ALIGNMENT; //pading

    // Rescuer header
    u_short myid = htons(5);
    u_short mysize = htons(max_payload_size);

    ACE_Message_Block* rescuerheader= 0;
    ACE_NEW_RETURN(rescuerheader, ACE_Message_Block(4), -1);
    rescuerheader->copy((const char *)&myid, 2);
    rescuerheader->copy((const char *)&mysize, 2);

    // My DGS stuff (header and payload)
    ACE_OutputCDR header (ACE_CDR::MAX_ALIGNMENT + 8);
    header << ACE_OutputCDR::from_boolean (ACE_CDR_BYTE_ORDER);
    header << ACE_CDR::ULong(length);

    // DGS Payload
    ACE_OutputCDR payload (max_payload_size);
    payload << glovedata;
    ACE_CDR::ULong length = payload.total_length();

    iovec iov[3];
    iov[0].iov_base = rescuerheader->rd_ptr();
    iov[0].iov_len  = 4;
    iov[1].iov_base = header.begin()->rd_ptr();
    iov[1].iov_len  = HEADER_SIZE;
    iov[2].iov_base = payload.begin()->rd_ptr();
    iov[2].iov_len  = length;

    ACE_INET_Addr serverAddr(remoteport, remotehost);
    return sockDgram_.send(iov,3,  serverAddr );
}
Beispiel #6
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;
}
Beispiel #7
0
  //FUZZ: disable check_for_lack_ACE_OS
  int send (const ACE_Log_Record &log_record) {
  //FUZZ: enable check_for_lack_ACE_OS

    // Serialize the log record using a CDR stream, allocate
    // enough space for the complete <ACE_Log_Record>.
    const size_t max_payload_size =
     4 // type()
     + 8 // timestamp
     + 4 // process id
     + 4 // data length
     + ACE_Log_Record::MAXLOGMSGLEN // data
     + ACE_CDR::MAX_ALIGNMENT; // padding;

    // Insert contents of <log_record> into payload stream.
    ACE_OutputCDR payload (max_payload_size);
    payload << log_record;

    // Get the number of bytes used by the CDR stream.
    ACE_CDR::ULong length = payload.total_length ();

    // Send a header so the receiver can determine the byte
    // order and size of the incoming CDR stream.
    ACE_OutputCDR header (ACE_CDR::MAX_ALIGNMENT + 8);
    header << ACE_OutputCDR::from_boolean (ACE_CDR_BYTE_ORDER);

    // Store the size of the payload that follows
    header << ACE_CDR::ULong (length);
    // Use an iovec to send both buffer and payload simultaneously.
    iovec iov[2];
    iov[0].iov_base = header.begin ()->rd_ptr ();
    iov[0].iov_len  = 8;
    iov[1].iov_base = payload.begin ()->rd_ptr ();
    iov[1].iov_len  = length;

    // Send header and payload efficiently using "gather-write".
    return logging_peer_.sendv_n (iov, 2);
  }
Beispiel #8
0
ssize_t
ACE_Log_Msg_IPC::log (ACE_Log_Record &log_record)
{
    // Serialize the log record using a CDR stream, allocate enough
    // space for the complete <ACE_Log_Record>.
    size_t const max_payload_size =
        4    // type
        + 4  // pid
        + 12 // timestamp
        + 4  // process id
        + 4  // data length
#if defined (ACE_USES_WCHAR)
        + (log_record.msg_data_len () * ACE_OutputCDR::wchar_maxbytes())  // message
#else
        + log_record.msg_data_len () // message
#endif
        + ACE_CDR::MAX_ALIGNMENT;     // padding;

    // Insert contents of <log_record> into payload stream.
    ACE_OutputCDR payload (max_payload_size);
    payload << log_record;

    // Get the number of bytes used by the CDR stream. If it becomes desireable
    // to support payloads more than 4GB, this field will need to be changed
    // to a 64-bit value.
    ACE_CDR::ULong length =
        ACE_Utils::truncate_cast<ACE_CDR::ULong> (payload.total_length ());

    // Send a header so the receiver can determine the byte order and
    // size of the incoming CDR stream.
    ACE_OutputCDR header (ACE_CDR::MAX_ALIGNMENT + 8);
    header << ACE_OutputCDR::from_boolean (ACE_CDR_BYTE_ORDER);

    // Store the size of the payload that follows
    header << ACE_CDR::ULong (length);

    // Use an iovec to send both buffer and payload simultaneously.
    iovec iov[2];
    iov[0].iov_base = header.begin ()->rd_ptr ();
    iov[0].iov_len  = 8;
    iov[1].iov_base = payload.begin ()->rd_ptr ();
    iov[1].iov_len  = length;

#if defined (ACE_HAS_STREAM_PIPES)
    // Use the <putpmsg> API if supported to ensure correct message
    // queueing according to priority.

    ACE_Str_Buf header_msg (static_cast<void *> (header.begin ()->rd_ptr ()),
                            static_cast<int> (8));

    ACE_Str_Buf payload_msg (static_cast<void *> (payload.begin ()->rd_ptr ()),
                             static_cast<int> (length));

    return this->message_queue_.send (&header_msg,
                                      &payload_msg,
                                      static_cast<int> (log_record.priority ()),
                                      MSG_BAND);
#else
    // We're running over sockets, so send header and payload
    // efficiently using "gather-write".
    return this->message_queue_.sendv_n (iov, 2);
#endif /* ACE_HAS_STREAM_PIPES */
}
Beispiel #9
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  const ACE_TCHAR *logger_host = argc > 1 ? argv[1] : LOGGER_HOST;
  u_short logger_port  = argc > 2 ? ACE_OS::atoi (argv[2]) : LOGGER_PORT;
  int max_iterations = argc > 3 ? ACE_OS::atoi (argv[3]) : MAX_ITERATIONS;

  ACE_SOCK_Stream logger;
  ACE_SOCK_Connector connector;
  ACE_INET_Addr addr (logger_port, logger_host);

  if (connector.connect (logger, addr) == -1)
    ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("open")), -1);

  for (int i = 0; i < max_iterations; i++)
    {
      ACE_Log_Record log_record (LM_DEBUG,
                                 ACE_OS::time ((time_t *) 0),
                                 ACE_OS::getpid ());

      ACE_TCHAR buf[BUFSIZ];
      ACE_OS::sprintf (buf, ACE_TEXT ("message = %d\n"), i + 1);
      log_record.msg_data (buf);

      const size_t max_payload_size =
        4 // type()
        + 8 // timestamp
        + 4 // process id
        + 4 // data length
        + ACE_Log_Record::MAXLOGMSGLEN // data
        + ACE_CDR::MAX_ALIGNMENT; // padding;

      // Insert contents of <log_record> into payload stream.
      ACE_OutputCDR payload (max_payload_size);
      payload << log_record;

      // Get the number of bytes used by the CDR stream.
      ACE_CDR::ULong length =
        ACE_Utils::truncate_cast<ACE_CDR::ULong> (payload.total_length ());

      // Send a header so the receiver can determine the byte order and
      // size of the incoming CDR stream.
      ACE_OutputCDR header (ACE_CDR::MAX_ALIGNMENT + 8);
      header << ACE_OutputCDR::from_boolean (ACE_CDR_BYTE_ORDER);

      // Store the size of the payload that follows
      header << ACE_CDR::ULong (length);

      // Use an iovec to send both buffer and payload simultaneously.
      iovec iov[2];
      iov[0].iov_base = header.begin ()->rd_ptr ();
      iov[0].iov_len  = 8;
      iov[1].iov_base = payload.begin ()->rd_ptr ();
      iov[1].iov_len  = length;

      if (logger.sendv_n (iov, 2) == -1)
        ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "send"), -1);
    }

  if (logger.close () == -1)
    ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("close")), -1);

  return 0;
}
Beispiel #10
0
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"));
}
Beispiel #11
0
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"));
}
Beispiel #12
0
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();
}