OpenDDS_Domain_Manager::~OpenDDS_Domain_Manager ()
{
  // delete the participant's contained entities
  if (!CORBA::is_nil (dp_.in ()))
    dp_->delete_contained_entities ();

  DDS::DomainParticipantFactory_var dpf =
    OpenDDS::DCPS::Service_Participant::instance()->
    get_domain_participant_factory ();

  if (!CORBA::is_nil (dpf.in ()))
    dpf->delete_participant(dp_.in ());

  // shut down the service participant
  OpenDDS::DCPS::Service_Participant::instance ()->shutdown ();
}
Ejemplo n.º 2
0
dds::domain::DomainParticipant find(uint32_t id)
{
    DDS::DomainParticipantFactory_var dpf = DDS::DomainParticipantFactory::get_instance();
    if(dpf.in() == 0)
    {
        throw dds::core::PreconditionNotMetError(org::opensplice::core::exception_helper(
                    OSPL_CONTEXT_LITERAL(
                        "dds::core::PreconditionNotMetError: Unable to resolve the DomainParticipant Factory.")));
    }
    DDS::DomainParticipant_ptr ddsdp = dpf->lookup_participant(id);
    if(ddsdp)
    {
        dds::domain::DomainParticipant dp =
            org::opensplice::core::EntityRegistry<DDS::DomainParticipant_ptr, dds::domain::DomainParticipant>::get(ddsdp);
        if(dp != dds::core::null)
        {
            return dp;
        }
    }
    return dds::domain::DomainParticipant(dds::core::null);
}
Ejemplo n.º 3
0
void
SPMonitorImpl::report()
{
  if (CORBA::is_nil(this->sp_writer_.in())) {
    this->sp_writer_ = this->monitor_factory_->get_sp_writer();
  }

  // If the SP writer is not available, it is too soon to report
  if (!CORBA::is_nil(this->sp_writer_.in())) {
    ServiceParticipantReport report;
    report.host = this->hostname_.c_str();
    report.pid  = this->pid_;
    DDS::DomainParticipantFactory_var pf = TheParticipantFactory;
    const DomainParticipantFactoryImpl::DPMap& participants =
      dynamic_cast<DomainParticipantFactoryImpl*>(pf.in())->participants();
    CORBA::ULong length = 0;
    for (DomainParticipantFactoryImpl::DPMap::const_iterator mapIter = participants.begin();
         mapIter != participants.end();
         ++mapIter) {
      for (DomainParticipantFactoryImpl::DPSet::const_iterator iter = mapIter->second.begin();
           iter != mapIter->second.end();
           ++iter) {
        report.domain_participants.length(length+1);
        report.domain_participants[length] = iter->svt_->get_id();
        length++;
      }
    }
    length = 0;
    // TODO: Redo the transport-related monitor publishing here...
    //const TransportFactory::ImplMap& transports =
    //  TransportFactory::instance()->get_transport_impl_map();
    //report.transports.length(static_cast<CORBA::ULong>(transports.size()));
    //for (TransportFactory::ImplMap::const_iterator mapIter = transports.begin();
    //     mapIter != transports.end();
    //     ++mapIter) {
    //  report.transports[length++] = mapIter->first;
    //}
    this->sp_writer_->write(report, DDS::HANDLE_NIL);
  }
}
Ejemplo n.º 4
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) {

  DDS::DomainParticipantFactory_var dpf = DDS::DomainParticipantFactory::_nil();
  DDS::DomainParticipant_var participant = DDS::DomainParticipant::_nil();

  try {

    // Initialize, and create a DomainParticipant
    // (same as publishe

    dpf = TheParticipantFactoryWithArgs(argc, argv);

    participant = dpf->create_participant(
      QUOTER_DOMAIN_ID,
      PARTICIPANT_QOS_DEFAULT,
      DDS::DomainParticipantListener::_nil(),
      ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
    if (CORBA::is_nil (participant.in ())) {
      cerr << "create_participant failed." << endl;
      ACE_OS::exit(1);
    }

    // Create a subscriber for the two topics
    // (SUBSCRIBER_QOS_DEFAULT is defined in Marked_Default_Qos.h)
    DDS::Subscriber_var sub =
      participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT,
                                     DDS::SubscriberListener::_nil(),
                                     ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
    if (CORBA::is_nil (sub.in ())) {
      cerr << "create_subscriber failed." << endl;
      ACE_OS::exit(1);
    }

    // Initialize the transport; the TRANSPORT_IMPL_ID must match the
    // value in the configuration file.
    OpenDDS::DCPS::TransportImpl_rch trans_impl =
      TheTransportFactory->create_transport_impl (TRANSPORT_IMPL_ID,
                                                  OpenDDS::DCPS::AUTO_CONFIG);

    // Attach the subscriber to the TCP transport.
    // (almost identical to the publisher)
    OpenDDS::DCPS::SubscriberImpl* sub_impl =
      dynamic_cast< OpenDDS::DCPS::SubscriberImpl* >(sub.in ());
    if (0 == sub_impl) {
      cerr << "Failed to obtain subscriber servant" << endl;
      ACE_OS::exit(1);
    }
    OpenDDS::DCPS::AttachStatus status = sub_impl->attach_transport(trans_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;
      ACE_OS::exit(1);
    }

    // Register the Quote type
    // (same as publisher)
    StockQuoter::QuoteTypeSupport_var quote_servant
      = new StockQuoter::QuoteTypeSupportImpl();

    if (DDS::RETCODE_OK != quote_servant->register_type(participant.in (),
                                                        QUOTER_QUOTE_TYPE)) {
      cerr << "register_type for " << QUOTER_QUOTE_TYPE << " failed." << endl;
      ACE_OS::exit(1);
    }

    // Register the ExchangeEvent type
    // (same as publisher)
    StockQuoter::ExchangeEventTypeSupport_var exchange_evt_servant
      = new StockQuoter::ExchangeEventTypeSupportImpl();

    if (DDS::RETCODE_OK != exchange_evt_servant->register_type(participant.in (),
                                                               QUOTER_EXCHANGE_EVENT_TYPE)) {
      cerr << "register_type for " << QUOTER_EXCHANGE_EVENT_TYPE
           << " failed." << endl;
      ACE_OS::exit(1);
    }

    // Get QoS to use for our two topics
    // (same as publisher)
    DDS::TopicQos default_topic_qos;
    participant->get_default_topic_qos(default_topic_qos);

    // Create a topic for the Quote type...
    // Could also use TOPIC_QOS_DEFAULT instead
    // (same as publisher)
    DDS::Topic_var quote_topic =
      participant->create_topic (QUOTER_QUOTE_TOPIC,
                                 QUOTER_QUOTE_TYPE,
                                 default_topic_qos,
                                 DDS::TopicListener::_nil(),
                                 ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
    if (CORBA::is_nil (quote_topic.in ())) {
      cerr << "create_topic for " << QUOTER_QUOTE_TOPIC << " failed." << endl;
      ACE_OS::exit(1);
    }

    // .. and another topic for the Exchange Event type
    // (same as publisher)
    DDS::Topic_var exchange_evt_topic =
      participant->create_topic (QUOTER_EXCHANGE_EVENT_TOPIC,
                                 QUOTER_EXCHANGE_EVENT_TYPE,
                                 default_topic_qos,
                                 DDS::TopicListener::_nil(),
                                 ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
    if (CORBA::is_nil (exchange_evt_topic.in ())) {
      cerr << "create_topic for " << QUOTER_EXCHANGE_EVENT_TOPIC << " failed." << endl;
      ACE_OS::exit(1);
    }

    // Create DataReaders and DataReaderListeners for the
    // Quote and ExchangeEvent
    DDS::DataReaderListener_var quote_listener (new QuoteDataReaderListenerImpl);

    if (CORBA::is_nil (quote_listener.in ())) {
      cerr << "Quote listener is nil." << endl;
      ACE_OS::exit(1);
    }

    DDS::DataReaderListener_var exchange_evt_listener (new ExchangeEventDataReaderListenerImpl);
    ExchangeEventDataReaderListenerImpl* listener_servant =
      dynamic_cast<ExchangeEventDataReaderListenerImpl*>(exchange_evt_listener.in());

    if (CORBA::is_nil (exchange_evt_listener.in ())) {
      cerr << "ExchangeEvent listener is nil." << endl;
      ACE_OS::exit(1);
    }

    // Create the Quote and ExchangeEvent DataReaders

    // Get the default QoS for our Data Readers
    // Could also use DATAREADER_QOS_DEFAULT
    DDS::DataReaderQos dr_default_qos;
    sub->get_default_datareader_qos (dr_default_qos);

    DDS::DataReader_var quote_dr =
      sub->create_datareader(quote_topic.in (),
                             dr_default_qos,
                             quote_listener.in (),
                             ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);

    DDS::DataReader_var exchange_evt_dr =
      sub->create_datareader(exchange_evt_topic.in (),
                             dr_default_qos,
                             exchange_evt_listener.in (),
                             ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);

    // Wait for events from the Publisher; shut down when "close" received
    cout << "Subscriber: waiting for events" << endl;
    while ( ! listener_servant->is_exchange_closed_received() ) {
      ACE_OS::sleep(1);
    }

    cout << "Received CLOSED event from publisher; exiting..." << endl;

  } catch (CORBA::Exception& e) {
    cerr << "Exception caught in main.cpp:" << endl
         << e << endl;
    ACE_OS::exit(1);
  }

  // Cleanup
  try {
    if (!CORBA::is_nil (participant.in ())) {
      participant->delete_contained_entities();
    }
    if (!CORBA::is_nil (dpf.in ())) {
      dpf->delete_participant(participant.in ());
    }
  } catch (CORBA::Exception& e) {
    cerr << "Exception caught in cleanup." << endl << e << endl;
    ACE_OS::exit(1);
  }
  TheTransportFactory->release();
  TheServiceParticipant->shutdown ();
  return 0;
}
Ejemplo n.º 5
0
int ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  int status = 0;

  try
    {
      ACE_DEBUG((LM_INFO,"(%P|%t) %T publisher main\n"));

      dpf = TheParticipantFactoryWithArgs(argc, argv);

      // let the Service_Participant (in above line) strip out -DCPSxxx parameters
      // and then get application specific parameters.
      parse_args (argc, argv);

      init ();

      // Indicate that the publisher is ready
      FILE* writers_ready = ACE_OS::fopen (pub_ready_filename.c_str (), ACE_TEXT("w"));
      if (writers_ready == 0)
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT("(%P|%t) ERROR: Unable to create publisher ready file\n")));
        }

      // Wait for the subscriber to be ready.
      FILE* readers_ready = 0;
      do
        {
          ACE_Time_Value small_time(0,250000);
          ACE_OS::sleep (small_time);
          readers_ready = ACE_OS::fopen (sub_ready_filename.c_str (), ACE_TEXT("r"));
        } while (0 == readers_ready);

      ACE_OS::fclose(writers_ready);
      ACE_OS::fclose(readers_ready);

      // ensure the associations are fully established before writing.
      ACE_OS::sleep(3);

      {  // Extra scope for VC6
        for (int i = 0; i < num_datawriters; i ++)
          {
            writers[i]->start ();
          }
      }

      int timeout_writes = 0;
      bool writers_finished = false;

      while ( !writers_finished )
        {
          writers_finished = true;
          for (int i = 0; i < num_datawriters; i ++)
            {
              writers_finished = writers_finished && writers[i]->is_finished();
            }
        }

      {  // Extra scope for VC6
        for (int i = 0; i < num_datawriters; i ++)
          {
            timeout_writes += writers[i]->get_timeout_writes();
          }
      }
      // Indicate that the publisher is done
      FILE* writers_completed = ACE_OS::fopen (pub_finished_filename.c_str (), ACE_TEXT("w"));
      if (writers_completed == 0)
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT("(%P|%t) ERROR: Unable to i publisher completed file\n")));
        }
      else
        {
          ACE_OS::fprintf (writers_completed, "%d\n", timeout_writes);
        }

      // Wait for the subscriber to finish.
      FILE* readers_completed = 0;
      do
        {
          ACE_Time_Value small_time(0,250000);
          ACE_OS::sleep (small_time);
          readers_completed = ACE_OS::fopen (sub_finished_filename.c_str (), ACE_TEXT("r"));
        } while (0 == readers_completed);

      ACE_OS::fclose(writers_completed);
      ACE_OS::fclose(readers_completed);

      {  // Extra scope for VC6
        for (int i = 0; i < num_datawriters; i ++)
          {
            writers[i]->end ();
            delete writers[i];
          }
      }
    }
  catch (const TestException&)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT("(%P|%t) TestException caught in main (). ")));
      status = 1;
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Exception caught in main ():");
      status = 1;
    }


  try
    {
      if (! CORBA::is_nil (participant.in ()))
        {
          participant->delete_contained_entities();
        }

      if (! CORBA::is_nil (dpf.in ()))
        {
          dpf->delete_participant(participant.in ());
        }
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Exception caught in cleanup.");
      status = 1;
    }

  shutdown ();
  return status;
}
Ejemplo n.º 6
0
int ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  int status = 0;

  try
    {
      ACE_DEBUG((LM_INFO,"(%P|%t) %T subscriber main\n"));

      dpf = TheParticipantFactoryWithArgs(argc, argv);

      // let the Service_Participant (in above line) strip out -DCPSxxx parameters
      // and then get application specific parameters.
      parse_args (argc, argv);

      init_listener ();
      init_dcps_objects (0);
      init_dcps_objects (1);

      // Indicate that the subscriber is ready
      FILE* readers_ready = ACE_OS::fopen (sub_ready_filename.c_str (), ACE_TEXT("w"));
      if (readers_ready == 0)
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT("(%P|%t) ERROR: Unable to create subscriber completed file\n")));
        }

      // Wait for the publisher to be ready
      FILE* writers_ready = 0;
      do
        {
          ACE_Time_Value small_time(0,250000);
          ACE_OS::sleep (small_time);
          writers_ready = ACE_OS::fopen (pub_ready_filename.c_str (), ACE_TEXT("r"));
        } while (0 == writers_ready);

      ACE_OS::fclose(readers_ready);
      ACE_OS::fclose(writers_ready);

      int expected
        = num_datawriters * num_instances_per_writer * num_samples_per_instance;

      FILE* writers_completed = 0;
      int timeout_writes = 0;

      while ( num_reads < expected)
        {
          // Get the number of the timed out writes from publisher so we
          // can re-calculate the number of expected messages. Otherwise,
          // the blocking timeout test will never exit from this loop.
          if (writers_completed == 0)
            {
              writers_completed = ACE_OS::fopen (pub_finished_filename.c_str (), ACE_TEXT("r"));
              if (writers_completed != 0)
                {
                  //writers_completed = ACE_OS::fopen (pub_finished_filename.c_str (), ACE_TEXT("r"));
                  fscanf (writers_completed, "%d\n", &timeout_writes);
                  expected -= timeout_writes;
                  ACE_DEBUG((LM_DEBUG,
                             ACE_TEXT ("(%P|%t) timed out writes %d, we expect %d\n"),
                             timeout_writes, expected));
                }

            }
          ACE_OS::sleep (1);
        }

      // Indicate that the subscriber is done
      FILE* readers_completed = ACE_OS::fopen (sub_finished_filename.c_str (), ACE_TEXT("w"));
      if (readers_completed == 0)
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT("(%P|%t) ERROR: Unable to create subscriber completed file\n")));
        }

      // Wait for the publisher to finish
      while (writers_completed == 0)
        {
          ACE_Time_Value small_time(0,250000);
          ACE_OS::sleep (small_time);
          writers_completed = ACE_OS::fopen (pub_finished_filename.c_str (), ACE_TEXT("r"));
        }

      ACE_OS::fclose(readers_completed);
      ACE_OS::fclose(writers_completed);
    }
  catch (const TestException&)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT("(%P|%t) TestException caught in main (). ")));
      status = 1;
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Exception caught in main ():");
      status = 1;
    }

  try
    {
      for (int i = 0; i < 2; ++i)
      {
        if (! CORBA::is_nil (participant[i].in ()))
          {
            participant[i]->delete_contained_entities();
          }
        if (! CORBA::is_nil (dpf.in ()))
          {
            dpf->delete_participant(participant[i].in ());
          }
      }
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Exception caught in cleanup.");
      status = 1;
    }

  shutdown ();

  return status;
}
Ejemplo n.º 7
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
    {
      DDS::DomainParticipantFactory_var dpf;
      DDS::DomainParticipant_var participant;

      dpf = TheParticipantFactoryWithArgs(argc, argv);
      participant =
        dpf->create_participant(11,
                                PARTICIPANT_QOS_DEFAULT,
                                DDS::DomainParticipantListener::_nil(),
                                ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (participant.in ())) {
        cerr << "create_participant failed." << endl;
        return 1 ;
      }

      Messenger::MessageTypeSupportImpl* mts_servant =
        new Messenger::MessageTypeSupportImpl;

      if (DDS::RETCODE_OK != mts_servant->register_type(participant.in (),
                                                        ""))
      {
        cerr << "Failed to register the MessageTypeTypeSupport." << endl;
        exit(1);
      }

      CORBA::String_var type_name = mts_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 << "Failed to create_topic." << endl;
        exit(1);
      }

      // Create the subscriber and attach to the corresponding
      // transport.
      DDS::Subscriber_var sub =
        participant->create_subscriber (SUBSCRIBER_QOS_DEFAULT,
                                        DDS::SubscriberListener::_nil(),
                                        ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (sub.in ())) {
        cerr << "Failed to create_subscriber." << endl;
        exit(1);
      }


      // ----------------------------------------------
      {
        // Attempt to create a DataReader with intentionally
        // incompatible QoS.
        DDS::DataReaderQos bogus_qos;
        sub->get_default_datareader_qos (bogus_qos);

        // Set up a 2 second recurring deadline.  DataReader creation
        // should fail with this QoS since the requested deadline period
        // will be less than the test configured offered deadline
        // period.
        bogus_qos.deadline.period.sec = 2;
        bogus_qos.deadline.period.nanosec = 0;

        DDS::DataReader_var tmp_dr =
          sub->create_datareader (topic.in (),
                                  bogus_qos,
                                  DDS::DataReaderListener::_nil (),
                                  ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);

        if (CORBA::is_nil (tmp_dr.in ()))
        {
          cerr << "ERROR: DataReader creation with bogus QoS failed."
               << endl;
          exit (1);
        }

        DDS::StatusCondition_var cond = tmp_dr->get_statuscondition();
        cond->set_enabled_statuses(DDS::REQUESTED_INCOMPATIBLE_QOS_STATUS);
        DDS::WaitSet_var ws = new DDS::WaitSet;
        ws->attach_condition(cond);
        DDS::Duration_t four_sec = {4, 0};
        DDS::ConditionSeq active;
        ws->wait(active, four_sec);

        // Check if the incompatible deadline was correctly flagged.
        if ((active.length() == 0) || (active[0] != cond)) {
          cerr << "ERROR: Failed to get requested incompatible qos status" << endl;
          exit (1);
        }

        DDS::RequestedIncompatibleQosStatus incompatible_status;
        if (tmp_dr->get_requested_incompatible_qos_status (incompatible_status) != ::DDS::RETCODE_OK)
        {
          cerr << "ERROR: Failed to get requested incompatible qos status" << endl;
          exit (1);
        }

        DDS::QosPolicyCountSeq const & policies =
          incompatible_status.policies;

        bool incompatible_deadline = false;
        CORBA::ULong const len = policies.length ();
        for (CORBA::ULong i = 0; i < len; ++i)
        {
          if (policies[i].policy_id == DDS::DEADLINE_QOS_POLICY_ID)
          {
            incompatible_deadline = true;
            break;
          }
        }

        if (!incompatible_deadline)
        {
          cerr << "ERROR: A DataReader/Writer association was created " << endl
               << "       despite use of deliberately incompatible deadline "
               << "QoS." << endl;
          exit (1);
        }
      }


      // ----------------------------------------------

      // Create the listener.
      DDS::DataReaderListener_var listener (new DataReaderListenerImpl);
      DataReaderListenerImpl* listener_servant =
        dynamic_cast<DataReaderListenerImpl*>(listener.in());

      if (CORBA::is_nil (listener.in ()))
      {
        cerr << "ERROR: listener is nil." << endl;
        exit(1);
      }

      DDS::DataReaderQos dr_qos; // Good QoS.
      sub->get_default_datareader_qos (dr_qos);

      assert (DEADLINE_PERIOD.sec > 1); // Requirement for the test.

      // First data reader will have a listener to test listener
      // callback on deadline expiration.
      DDS::DataReader_var dr1 =
        sub->create_datareader (topic.in (),
                                dr_qos,
                                listener.in (),
                                ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);

      // Second data reader will not have a listener to test proper
      // handling of a nil listener in the deadline handling code.
      DDS::DataReader_var dr2 =
        sub->create_datareader (topic.in (),
                                dr_qos,
                                DDS::DataReaderListener::_nil (),
                                ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);

      if (CORBA::is_nil (dr1.in ()) || CORBA::is_nil (dr2.in ()))
      {
        cerr << "ERROR: create_datareader failed." << endl;
        exit(1);
      }

      dr_qos.deadline.period.sec     = DEADLINE_PERIOD.sec;
      dr_qos.deadline.period.nanosec = DEADLINE_PERIOD.nanosec;

      // Reset qos to have deadline. The watch dog now starts.
      if (dr1->set_qos (dr_qos) != ::DDS::RETCODE_OK
        || dr2->set_qos (dr_qos) != ::DDS::RETCODE_OK)
      {
        cerr << "ERROR: set deadline qos failed." << endl;
        exit(1);
      }

      Messenger::MessageDataReader_var message_dr1 =
        Messenger::MessageDataReader::_narrow(dr1.in());

      Messenger::MessageDataReader_var message_dr2 =
        Messenger::MessageDataReader::_narrow(dr2.in());

      int max_attempts = 10;
      int attempts = 0;

      // Synchronize with publisher. Wait until both associate with DataWriter.
      while (attempts < max_attempts)
      {
        ::DDS::SubscriptionMatchedStatus status1;
        ::DDS::SubscriptionMatchedStatus status2;
        if (dr1->get_subscription_matched_status (status1) == ::DDS::RETCODE_OK
          && dr2->get_subscription_matched_status (status2) == ::DDS::RETCODE_OK)
        {
          if (status1.total_count == 1 && status2.total_count == 1)
            break;
          ++ attempts;
          ACE_OS::sleep (1);
        }
        else
        {
          cerr << "ERROR: Failed to get subscription matched status" << endl;
          exit (1);
        }
      }

      if (attempts >= max_attempts)
      {
        cerr << "ERROR: failed to make associations. " << endl;
        exit (1);
      }
      // ----------------------------------------------

      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Subscriber: sleep for %d milliseconds\n"),
                            SLEEP_DURATION.msec()));

      // Wait for deadline periods to expire.
      ACE_OS::sleep (SLEEP_DURATION);

      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Subscriber: now verify missed ")
                            ACE_TEXT ("deadline status \n")));

      DDS::RequestedDeadlineMissedStatus deadline_status1;
      if (dr1->get_requested_deadline_missed_status(deadline_status1) != ::DDS::RETCODE_OK)
      {
        cerr << "ERROR: Failed to get requested deadline missed status" << endl;
        exit (1);
      }

      DDS::RequestedDeadlineMissedStatus deadline_status2;
      if (dr2->get_requested_deadline_missed_status(deadline_status2) != ::DDS::RETCODE_OK)
      {
        cerr << "ERROR: Failed to get requested deadline missed status" << endl;
        exit (1);
      }

      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Subscriber: got missed")
                            ACE_TEXT ("deadline status \n")));

      Messenger::Message message;
      message.subject_id = 99;
      ::DDS::InstanceHandle_t dr1_hd1 = message_dr1->lookup_instance (message);
      ::DDS::InstanceHandle_t dr2_hd1 = message_dr2->lookup_instance (message);
      message.subject_id = 100;
      ::DDS::InstanceHandle_t dr1_hd2 = message_dr1->lookup_instance (message);
      ::DDS::InstanceHandle_t dr2_hd2 = message_dr2->lookup_instance (message);

      if (deadline_status1.last_instance_handle != dr1_hd1
        && deadline_status1.last_instance_handle != dr1_hd2)
      {
        cerr << "ERROR: Expected DR1 last instance handle ("
             << dr1_hd1 << " or " << dr1_hd2 << ") did not occur ("
             << deadline_status1.last_instance_handle << ")" << endl;

        exit (1);
      }

      if (deadline_status2.last_instance_handle != dr2_hd1
        && deadline_status2.last_instance_handle != dr2_hd2)
      {
        cerr << "ERROR: Expected DR2 last instance handle ("
             << dr2_hd1 << " or " << dr2_hd2 << ") did not occur ("
             << deadline_status2.last_instance_handle << endl;

        exit (1);
      }

      //The reader deadline period is 5 seconds and writer writes
      //each instance every 9 seconds, so after SLEEP_DURATION(11secs),
      //the deadline missed should be 1 per instance
      if (deadline_status1.total_count != NUM_INSTANCE
          || deadline_status2.total_count != NUM_INSTANCE)
      {
        cerr << "ERROR: Expected number of missed requested "
             << "deadlines (" << NUM_INSTANCE << ") " << "did " << endl
             << "       not occur ("
             << deadline_status1.total_count << " and/or "
             << deadline_status2.total_count << ")." << endl;

        exit (1);
      }

      if (deadline_status1.total_count_change != NUM_INSTANCE
          || deadline_status2.total_count_change != NUM_INSTANCE)
      {
        cerr << "ERROR: Incorrect missed requested "
             << "deadline count change" << endl
             << "       ("
             << deadline_status1.total_count_change
             << " and/or "
             << deadline_status2.total_count_change
             << " instead of " << NUM_EXPIRATIONS * NUM_INSTANCE << ")."
             << endl;

        exit (1);
      }

      // Here the writers should continue writes all samples with
      // .5 second interval.
      ACE_Time_Value no_miss_period = num_messages * write_interval;

      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Subscriber: sleep for %d msec\n"),
                            (SLEEP_DURATION + no_miss_period).msec()));

      // Wait for another set of deadline periods(5 + 11 secs).
      // During this period, the writers continue write all samples with
      // .5 second interval.
      ACE_OS::sleep (SLEEP_DURATION + no_miss_period);

      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Subscriber: now verify missed ")
                            ACE_TEXT ("deadline status \n")));

      if ((dr1->get_requested_deadline_missed_status(deadline_status1) != ::DDS::RETCODE_OK)
        || (dr2->get_requested_deadline_missed_status(deadline_status2) != ::DDS::RETCODE_OK))
      {
        cerr << "ERROR: failed to get requested deadline missed status" << endl;
        exit (1);
      }

      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Subscriber: got missed")
                            ACE_TEXT ("deadline status \n")));

      if (deadline_status1.last_instance_handle != dr1_hd1
        && deadline_status1.last_instance_handle != dr1_hd2)
      {
        cerr << "ERROR: Expected DR1 last instance handle ("
             << dr1_hd1 << " or " << dr1_hd2 << ") did not occur ("
             << deadline_status1.last_instance_handle << ")" << endl;

        exit (1);
      }

      if (deadline_status2.last_instance_handle != dr2_hd1
        && deadline_status2.last_instance_handle != dr2_hd2)
      {
        cerr << "ERROR: Expected DR2 last instance handle ("
             << dr2_hd1 << " or " << dr2_hd2 << ") did not occur ("
             << deadline_status2.last_instance_handle << endl;

        exit (1);
      }

      if (deadline_status1.total_count != 3 * NUM_INSTANCE
          || deadline_status2.total_count != 3 * NUM_INSTANCE)
      {
        cerr << "ERROR: Another expected number of missed requested "
             << "deadlines (" << NUM_INSTANCE << ")" << endl
             << "       did not occur ("
             << deadline_status1.total_count << " and/or "
             << deadline_status2.total_count << ")." << endl;

        exit (1);
      }

      if (deadline_status1.total_count_change != 2 * NUM_INSTANCE
          || deadline_status2.total_count_change != 2 * NUM_INSTANCE)
      {
        cerr << "ERROR: Incorrect missed requested "
             << "deadline count" << endl
             << "       change ("
             << deadline_status1.total_count_change
             << "and/or "
             << deadline_status2.total_count_change
             << " instead of " << NUM_EXPIRATIONS << ")." << endl;

        exit (1);
      }


      int expected = 10;
      while ( listener_servant->num_arrived() < expected) {
        ACE_OS::sleep (1);
      }

      if (!CORBA::is_nil (participant.in ())) {
        participant->delete_contained_entities();
      }
      if (!CORBA::is_nil (dpf.in ())) {
        dpf->delete_participant(participant.in ());
      }

      ACE_OS::sleep(2);

      TheServiceParticipant->shutdown ();
    }
  catch (CORBA::Exception& e)
    {
      cerr << "SUB: Exception caught in main ():" << endl << e << endl;
      return 1;
    }

  return 0;
}
Ejemplo n.º 8
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
    {
      DDS::DomainParticipantFactory_var dpf;
      DDS::DomainParticipant_var participant;

      dpf = TheParticipantFactoryWithArgs(argc, argv);
      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* mts_servant =
        new Messenger::MessageTypeSupportImpl;

      if (DDS::RETCODE_OK != mts_servant->register_type(participant.in (),
                                                        ""))
      {
        cerr << "Failed to register the MessageTypeTypeSupport." << endl;
        exit(1);
      }

      CORBA::String_var type_name = mts_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 << "Failed to create_topic." << endl;
        exit(1);
      }

      // Initialize the transport
      OpenDDS::DCPS::TransportImpl_rch tcp_impl = 
        TheTransportFactory->create_transport_impl (
          transport_impl_id, 
          ::OpenDDS::DCPS::AUTO_CONFIG);

      // Create the first subscriber belongs to PARTITION A 
      DDS::SubscriberQos sub_qos1;
      participant->get_default_subscriber_qos (sub_qos1);      

      sub_qos1.partition.name.length (1);
      sub_qos1.partition.name[0] = PARTITION_A;

      DDS::Subscriber_var sub1 =
        participant->create_subscriber (sub_qos1,
                                        DDS::SubscriberListener::_nil());
      if (CORBA::is_nil (sub1.in ())) {
        cerr << "Failed to create_subscriber." << endl;
        exit(1);
      }

      // Create the second subscriber belongs to PARTITION B
      DDS::SubscriberQos sub_qos2;
      participant->get_default_subscriber_qos (sub_qos2);
      
      sub_qos2.partition.name.length (1);
      sub_qos2.partition.name[0] = PARTITION_B;

      DDS::Subscriber_var sub2 =
        participant->create_subscriber (sub_qos2,
                                        DDS::SubscriberListener::_nil());
      if (CORBA::is_nil (sub2.in ())) {
        cerr << "Failed to create_subscriber." << endl;
        exit(1);
      }

      // Attach the subscribers to the transport.
      OpenDDS::DCPS::SubscriberImpl* sub_impl1 =
        dynamic_cast<OpenDDS::DCPS::SubscriberImpl*> (sub1.in ());
      if (0 == sub_impl1) {
        cerr << "Failed to obtain subscriber1 servant \n" << endl;
        exit(1);
      }

      OpenDDS::DCPS::SubscriberImpl* sub_impl2 =
        dynamic_cast<OpenDDS::DCPS::SubscriberImpl*> (sub2.in ());
      if (0 == sub_impl2) {
        cerr << "Failed to obtain subscriber2 servant \n" << endl;
        exit(1);
      }

      OpenDDS::DCPS::AttachStatus status =
        sub_impl1->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);
      }
     
      status = sub_impl2->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);
      }

      DDS::DataReaderQos dr_qos; 
      sub1->get_default_datareader_qos (dr_qos);

      // Create first DataReader with listener.
      DDS::DataReaderListener_var listener1 (new DataReaderListenerImpl);
      if (CORBA::is_nil (listener1.in ()))
      {
        cerr << "ERROR: listener1 is nil." << endl;
        exit(1);
      }

      DDS::DataReader_var dr1 =
        sub1->create_datareader (topic.in (),
                                dr_qos,
                                listener1.in ());

      // Create second DataReader with listener.
      DDS::DataReaderListener_var listener2 (new DataReaderListenerImpl);
      if (CORBA::is_nil (listener2.in ()))
      {
        cerr << "ERROR: listener2 is nil." << endl;
        exit(1);
      }

      DDS::DataReader_var dr2 =
        sub2->create_datareader (topic.in (),
                                dr_qos,
                                listener2.in ());

      if (CORBA::is_nil (dr1.in ()) || CORBA::is_nil (dr2.in ()))
      {
        cerr << "ERROR: create_datareader failed." << endl;
        exit(1);
      }

      DataReaderListenerImpl* listener_servant1 =
        dynamic_cast<DataReaderListenerImpl*>(listener1.in());
      DataReaderListenerImpl* listener_servant2 =
        dynamic_cast<DataReaderListenerImpl*>(listener2.in());

      int expected = 10; 
      // Writer of PARTITION A -> Reader of PARTITION A
      while ( listener_servant1->num_reads() < expected) {
        ACE_OS::sleep (1);
      }

      // Writer switch from PARTITION A to B -> Reader of PARTITION B
      while ( listener_servant2->num_reads() < expected) {
        ACE_OS::sleep (1);
      }
      
      // ----------------------------------------------
      // Now switch first reader/subscriber from A to B
      // and it should be connected with DataWriter.
      sub_qos1.partition.name[0] = PARTITION_B;

      if (sub1->set_qos (sub_qos1) != ::DDS::RETCODE_OK)
      {
        cerr << "ERROR: failed to set partition" << endl;
        exit (1);
      }

      // Continue receive 10 more messages each.
      expected = 20;

      while ( listener_servant1->num_reads() < expected) {
        ACE_OS::sleep (1);
      }

      while ( listener_servant2->num_reads() < expected) {
        ACE_OS::sleep (1);
      }
      
      if (listener_servant1->num_reads() > expected 
        || listener_servant2->num_reads() > expected)
      {
        cerr << "ERROR: received more than excepted messages" << endl;
        exit (1);
      }

      // Now shutdown
      if (!CORBA::is_nil (participant.in ())) {
        participant->delete_contained_entities();
      }
      if (!CORBA::is_nil (dpf.in ())) {
        dpf->delete_participant(participant.in ());
      }

      TheTransportFactory->release();
      TheServiceParticipant->shutdown ();
    }
  catch (CORBA::Exception& e)
    {
      cerr << "SUB: Exception caught in main ():" << endl << e << endl;
      return 1;
    }

  return 0;
}
Ejemplo n.º 9
0
int
ACE_TMAIN(int argc, ACE_TCHAR* argv[])
{
  try {
    DDS::DomainParticipantFactory_var dpf;
    DDS::DomainParticipant_var participant;

    dpf = TheParticipantFactoryWithArgs(argc, argv);
    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* mts_servant = new MessageTypeSupportImpl;

    if (DDS::RETCODE_OK != mts_servant->register_type(participant.in (),
                                                      "")) {
      cerr << "Failed to register the MessageTypeTypeSupport." << endl;
      exit(1);
    }

    CORBA::String_var type_name = mts_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 << "Failed to create_topic." << endl;
      exit(1);
    }

    // Create the subscriber and attach to the corresponding
    // transport.
    DDS::Subscriber_var sub =
      participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT,
                                     DDS::SubscriberListener::_nil(),
                                     ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
    if (CORBA::is_nil (sub.in ())) {
      cerr << "Failed to create_subscriber." << endl;
      exit(1);
    }

    // activate the listener
    DDS::DataReaderListener_var listener (new DataReaderListenerImpl);
    if (CORBA::is_nil (listener.in ())) {
      cerr << "listener is nil." << endl;
      exit(1);
    }
    DataReaderListenerImpl* listener_servant =
      dynamic_cast<DataReaderListenerImpl*>(listener.in());

    // Create the Datareaders
    DDS::DataReaderQos dr_qos;
    sub->get_default_datareader_qos (dr_qos);
    DDS::DataReader_var dr
      = sub->create_datareader(topic.in (),
                               dr_qos,
                               listener.in (),
                               ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
    if (CORBA::is_nil (dr.in ())) {
      cerr << "create_datareader failed." << endl;
      exit(1);
    }


    while ( ! listener_servant->received_all ()) {
      ACE_OS::sleep (1);
    }

    if (! listener_servant->passed ()) {
      cerr << "test failed - see errors." << endl;
      return 1;
    }

    if (!CORBA::is_nil (participant.in ())) {
      participant->delete_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);

    TheServiceParticipant->shutdown();

  } catch (CORBA::Exception& e) {
    cerr << "Exception caught in main ():" << endl << e << endl;
    return 1;
  }

  return 0;
}
Ejemplo n.º 10
0
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;
}
Ejemplo n.º 11
0
int main (int argc, char *argv[])
{
  try {
    DDS::DomainParticipantFactory_var dpf;
    DDS::DomainParticipant_var participant;

    dpf = TheParticipantFactoryWithArgs(argc, argv);
    if( parse_args(argc, argv) != 0)
      return 1;

    participant =
      dpf->create_participant(411,
                              PARTICIPANT_QOS_DEFAULT,
                              DDS::DomainParticipantListener::_nil());
    if (CORBA::is_nil (participant.in ())) {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%P|%t) create_participant failed.\n")
                         , -1);
    }

    MessageTypeSupportImpl* mts_servant = new MessageTypeSupportImpl();
    PortableServer::ServantBase_var safe_servant = mts_servant;

    if (DDS::RETCODE_OK != mts_servant->register_type(participant.in (),
                                                      "")) {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%P|%t) Failed to register the MessageTypeTypeSupport.\n")
                         , -1);
    }

    CORBA::String_var type_name = mts_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 ())) {
      ACE_ERROR_RETURN ((LM_ERROR,
       "(%P|%t) Failed to create_topic.\n")
       , -1);
    }

    // Initialize the transport
    TAO::DCPS::TransportImpl_rch tcp_impl =
      TheTransportFactory->create_transport_impl (TCP_IMPL_ID, ::TAO::DCPS::AUTO_CONFIG);

    // Indicate that the subscriber is about to become ready
    FILE* readers_ready = ACE_OS::fopen (sub_ready_filename, "w");
    if (readers_ready == 0) {
      ACE_ERROR_RETURN ((LM_ERROR,
       "(%P|%t) ERROR Unable to create subscriber ready file.\n")
       , -1);
    }
    ACE_OS::fclose(readers_ready);

    // Check if the publisher is up and running
    ACE_stat stats;
    while (ACE_OS::stat (pub_ready_filename, &stats) == -1)
      {
  ACE_Time_Value small(0,250000);
  ACE_OS::sleep (small);
      }

    for (int count = 1; count <= sub_reinit_itr; count++)
      {
  if (verbose) {
    ACE_DEBUG ((LM_DEBUG, "(%P|%t) Reinitializing subscriber.\n"));
  }

  // Create the subscriber and attach to the corresponding
  // transport.
  DDS::Subscriber_var sub =
    participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT,
           DDS::SubscriberListener::_nil());
  if (CORBA::is_nil (sub.in ())) {
    ACE_ERROR_RETURN ((LM_ERROR,
           "(%P|%t) Failed to create_subscriber.\n")
           , -1);
  }

  // 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) {
    ACE_ERROR_RETURN ((LM_ERROR,
           "(%P|%t) Failed to obtain subscriber servant.\n")
           , -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;
        }
      ACE_ERROR_RETURN ((LM_ERROR,
             "(%P|%t) Failed to attach to the transport. "
             "Status == %s.\n"
             , status_str.c_str())
             , -1);
    }

  // Create the Datareaders
  DDS::DataReaderQos dr_qos;
  sub->get_default_datareader_qos (dr_qos);
  DDS::DataReader_var dr = sub->create_datareader(topic.in (),
              dr_qos,
              DDS::DataReaderListener::_nil());
  if (CORBA::is_nil (dr.in ())) {
    ACE_ERROR_RETURN ((LM_ERROR,
           "(%P|%t) create_datareader failed.\n")
           , -1);
  }

  {
    ACE_OS::sleep (2);
    // This is where a speed-bump should be.
  }

  if (verbose) {
    ACE_DEBUG ((LM_DEBUG, "(%P|%t) *** Destroying Subscriber\n"));
  }

  // Delete data reader
  sub->delete_datareader(dr.in());

  // Delete subscriber
  participant->delete_subscriber(sub.in());
  sub = DDS::Subscriber::_nil();
      }

    if (!CORBA::is_nil (participant.in ())) {
      participant->delete_contained_entities();
    }
    if (!CORBA::is_nil (dpf.in ())) {
      dpf->delete_participant(participant.in ());
    }
    TheTransportFactory->release();
    TheServiceParticipant->shutdown ();

    // Indicate that the subscriber is done
    FILE* readers_completed = ACE_OS::fopen (sub_finished_filename, "w");
    if (readers_completed == 0) {
      ACE_ERROR_RETURN ((LM_ERROR,
       "(%P|%t) ERROR Unable to create subscriber completed file.\n")
      , -1);
    }
    ACE_OS::fclose(readers_completed);

  }
  catch (CORBA::Exception& e) {
    ACE_ERROR_RETURN ((LM_ERROR,
           "(%P|%t) Exception caught in main (): %s (%s).\n"
           ,  e._name (), e._rep_id ())
           , -1);
  }

  return 0;
}
Ejemplo n.º 12
0
int ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
    {
      DDS::DomainParticipantFactory_var dpf;
      DDS::DomainParticipant_var participant;

      dpf = TheParticipantFactoryWithArgs(argc, argv);
      participant = dpf->create_participant(111,
                                            PARTICIPANT_QOS_DEFAULT,
                                            DDS::DomainParticipantListener::_nil(),
                                            ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (participant.in ())) {
        cerr << "create_participant failed." << endl;
        return 1 ;
      }

      Messenger::MessageTypeSupport_var mts_servant =
        new Messenger::MessageTypeSupportImpl;

      if (DDS::RETCODE_OK != mts_servant->register_type (participant.in (),
                                                         ""))
      {
        cerr << "Failed to register the MessageTypeTypeSupport." << endl;
        exit(1);
      }

      CORBA::String_var type_name = mts_servant->get_type_name ();

      DDS::TopicQos topic_qos;
      participant->get_default_topic_qos(topic_qos);
      topic_qos.lifespan.duration.sec = 10;
      topic_qos.lifespan.duration.nanosec = 0;
      topic_qos.durability.kind = DDS::TRANSIENT_LOCAL_DURABILITY_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 << "Failed to create_topic." << endl;
        exit(1);
      }

      // Create the subscriber and attach to the corresponding
      // transport.
      DDS::Subscriber_var sub =
        participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT,
                                       DDS::SubscriberListener::_nil(),
                                       ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (sub.in ()))
      {
        cerr << "Failed to create_subscriber." << endl;
        exit(1);
      }

      // activate the listener
      DDS::DataReaderListener_var listener (new DataReaderListenerImpl);
      DataReaderListenerImpl* const listener_servant =
        dynamic_cast<DataReaderListenerImpl*>(listener.in());

      if (CORBA::is_nil (listener.in ())) {
        cerr << "listener is nil." << endl;
        exit(1);
      }
      if (!listener_servant) {
        ACE_ERROR_RETURN((LM_ERROR,
          ACE_TEXT("%N:%l main()")
          ACE_TEXT(" ERROR: listener_servant is nil (dynamic_cast failed)!\n")), -1);
      }

      // Create the Datareaders
      DDS::DataReader_var dr = sub->create_datareader(topic.in (),
                                                      DATAREADER_QOS_USE_TOPIC_QOS,
                                                      listener.in (),
                                                      ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (dr.in ())) {
        cerr << "create_datareader failed." << endl;
        exit(1);
      }

      ACE_OS::sleep (10);
      if (listener_servant->num_reads () != 1)
        {
          cerr << "ERROR: Incorrect number of samples received." << endl
               << "       Expired data was probably read." << endl;
          exit (1);
        }

      if (!CORBA::is_nil (participant.in ())) {
        participant->delete_contained_entities();
      }
      if (!CORBA::is_nil (dpf.in ())) {
        dpf->delete_participant(participant.in ());
      }
      ACE_OS::sleep(2);

      TheServiceParticipant->shutdown ();
    }
  catch (CORBA::Exception& e)
    {
      cerr << "SUB: Exception caught in main ():" << endl << e << endl;
      return 1;
    }

  return 0;
}
Ejemplo n.º 13
0
int ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  long expected_late = 0;
  try
    {
      DDS::DomainParticipantFactory_var dpf;
      DDS::DomainParticipant_var participant;

      dpf = TheParticipantFactoryWithArgs(argc, argv);
      participant = dpf->create_participant(111,
                                            PARTICIPANT_QOS_DEFAULT,
                                            DDS::DomainParticipantListener::_nil(),
                                            ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (participant.in ())) {
        cerr << "create_participant failed." << endl;
        return 1 ;
      }

      ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("l:"));
      int c;

      while ((c = get_opts ()) != -1)
      {
        switch(c)
        {
        case 'l':
          expected_late = ACE_OS::atoi (get_opts.opt_arg ());
          break;
        case '?':
        default:
          ACE_ERROR_RETURN ((LM_ERROR,
            "usage:  %s "
            "-l expected late samples "
            "\n",
            argv [0]),
            -1);
        }
      }

      Messenger::MessageTypeSupportImpl::_var_type mts_servant =
        new Messenger::MessageTypeSupportImpl;

      if (DDS::RETCODE_OK != mts_servant->register_type (participant.in (),
                                                         ""))
      {
        cerr << "Failed to register the MessageTypeTypeSupport." << endl;
        exit(1);
      }

      CORBA::String_var type_name = mts_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 << "Failed to create_topic." << endl;
        exit(1);
      }

      // Create the subscriber
      DDS::Subscriber_var sub =
        participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT,
                                       DDS::SubscriberListener::_nil(),
                                       ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (sub.in ()))
      {
        cerr << "Failed to create_subscriber." << endl;
        exit(1);
      }


      // activate the listener
      DDS::DataReaderListener_var listener (new DataReaderListenerImpl);
      DataReaderListenerImpl* const listener_servant =
        dynamic_cast<DataReaderListenerImpl*>(listener.in());

      if (CORBA::is_nil (listener.in ())) {
        cerr << "listener is nil." << endl;
        exit(1);
      }
      if (!listener_servant) {
        ACE_ERROR_RETURN((LM_ERROR,
          ACE_TEXT("%N:%l main()")
          ACE_TEXT(" ERROR: listener_servant is nil (dynamic_cast failed)!\n")), -1);
      }

      // Create the Datareaders
      DDS::DataReaderQos dr_qos;
      sub->get_default_datareader_qos (dr_qos);
      dr_qos.latency_budget.duration.sec = 1;
      dr_qos.latency_budget.duration.nanosec = 0;
      DDS::DataReader_var dr = sub->create_datareader(topic.in (),
                                                      dr_qos,
                                                      listener.in (),
                                                      ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (dr.in ())) {
        cerr << "create_datareader failed." << endl;
        exit(1);
      }

      dynamic_cast<OpenDDS::DCPS::DataReaderImpl*> (dr.in ())->
        reset_latency_stats ();
      dynamic_cast<OpenDDS::DCPS::DataReaderImpl*> (dr.in ())->
        statistics_enabled (true);

      ACE_OS::sleep (10);
      if (listener_servant->num_reads () != 10)
        {
          cerr << "ERROR: Incorrect number of samples received." << endl
               << "       Expired data was probably read." << endl;
          exit (1);
        }

      if (listener_servant->num_late () != expected_late)
        {
          cerr << "ERROR: Incorrect number of samples received late." << endl;
          exit (1);
        }

      if (!CORBA::is_nil (participant.in ())) {
        participant->delete_contained_entities();
      }
      if (!CORBA::is_nil (dpf.in ())) {
        dpf->delete_participant(participant.in ());
      }
      ACE_OS::sleep(2);

      TheServiceParticipant->shutdown ();
    }
  catch (CORBA::Exception& e)
    {
      cerr << "SUB: Exception caught in main ():" << endl << e << endl;
      return 1;
    }

  return 0;
}
Ejemplo n.º 14
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
    {
      DDS::DomainParticipantFactory_var dpf;
      DDS::DomainParticipant_var participant;

      dpf = TheParticipantFactoryWithArgs(argc, argv);
      if( parse_args(argc, argv) != 0)
        return 1;

      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,
                           "(%P|%t) create_participant failed.\n")
                          , -1);
      }

      MessageTypeSupportImpl* mts_servant = new MessageTypeSupportImpl;

      if (DDS::RETCODE_OK != mts_servant->register_type(participant.in (),
                                                        "")) {
        ACE_ERROR_RETURN ((LM_ERROR,
                           "(%P|%t) Failed to register the MessageTypeTypeSupport.\n")
                          , -1);
      }

      CORBA::String_var type_name = mts_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 ())) {
        ACE_ERROR_RETURN ((LM_ERROR,
                           "(%P|%t) Failed to create_topic.\n")
                          , -1);
      }

      // Indicate that the subscriber is about to become ready
      FILE* readers_ready = ACE_OS::fopen (sub_ready_filename, ACE_TEXT("w"));
      if (readers_ready == 0) {
        ACE_ERROR_RETURN ((LM_ERROR,
                           "(%P|%t) ERROR: Unable to create subscriber ready file.\n")
                          , -1);
      }
      ACE_OS::fclose(readers_ready);

      // Check if the publisher is up and running
      ACE_stat stats;
      while (ACE_OS::stat (pub_ready_filename, &stats) == -1)
        {
          ACE_Time_Value small_time(0,250000);
          ACE_OS::sleep (small_time);
        }

      for (int count = 1; count <= sub_reinit_itr; count++)
        {
          if (verbose) {
            ACE_DEBUG ((LM_DEBUG, "(%P|%t) Reinitializing subscriber.\n"));
          }

          // Create the subscriber and attach to the corresponding
          // transport.
          DDS::Subscriber_var sub =
            participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT,
                                           DDS::SubscriberListener::_nil(),
                                           ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
          if (CORBA::is_nil (sub.in ())) {
            ACE_ERROR_RETURN ((LM_ERROR,
                               "(%P|%t) Failed to create_subscriber.\n")
                              , -1);
          }

          // Create the Datareaders
          DDS::DataReaderQos dr_qos;
          sub->get_default_datareader_qos (dr_qos);
          DDS::DataReader_var dr = sub->create_datareader(topic.in (),
                                                          dr_qos,
                                                          DDS::DataReaderListener::_nil(),
                                                          ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
          if (CORBA::is_nil (dr.in ())) {
            ACE_ERROR_RETURN ((LM_ERROR,
                               "(%P|%t) create_datareader failed.\n")
                              , -1);
          }

          // This is where a speed-bump should be.
          while (true)
            {
              ::DDS::InstanceHandleSeq handles;
              dr->get_matched_publications (handles);
              if (handles.length() > 0) {
                break;
              }
              ACE_Time_Value small_time (0,250000);
              ACE_OS::sleep (small_time);
            }

          // Add sleep to let the fully_associted message arrive datawriter
          // before remove_associations is called upon delete_datareader,
          // otherwise the datawriter will encounter bit lookup timeout upon
          // fully associated.
          ACE_Time_Value small_time (0,250000);
                ACE_OS::sleep (small_time);

          if (verbose) {
            ACE_DEBUG ((LM_DEBUG, "(%P|%t) *** Destroying Subscriber\n"));
          }

          // Delete data reader
          sub->delete_datareader(dr.in());

          // Delete subscriber
          participant->delete_subscriber(sub.in());
          dr = DDS::DataReader::_nil ();
          sub = DDS::Subscriber::_nil();
        }

      if (!CORBA::is_nil (participant.in ())) {
        participant->delete_contained_entities();
      }
      if (!CORBA::is_nil (dpf.in ())) {
        dpf->delete_participant(participant.in ());
      }
      TheServiceParticipant->shutdown ();

      // Indicate that the subscriber is done
      FILE* readers_completed = ACE_OS::fopen (sub_finished_filename, ACE_TEXT("w"));
      if (readers_completed == 0) {
        ACE_ERROR_RETURN ((LM_ERROR,
                           "(%P|%t) ERROR: Unable to create subscriber completed file.\n")
                          , -1);
      }
      ACE_OS::fclose(readers_completed);

    }
  catch (CORBA::Exception& e) {
    ACE_ERROR_RETURN ((LM_ERROR,
                       "(%P|%t) Exception caught in main (): %C (%C).\n"
                       ,  e._name (), e._rep_id ())
                      , -1);
  }

  return 0;
}
Ejemplo n.º 15
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
    {
      DDS::DomainParticipantFactory_var dpf;
      DDS::DomainParticipant_var participant;

      dpf = TheParticipantFactoryWithArgs(argc, argv);

      // Default DomainParticipantFactory qos is to auto enable.
      ::DDS::DomainParticipantFactoryQos fqos;
      if (dpf->get_qos (fqos) != ::DDS::RETCODE_OK)
      {
        cerr << "DomainParticipantFactory get_qos failed." << endl;
        return 1;
      }

      if (fqos.entity_factory.autoenable_created_entities == 0)
      {
        cerr << "The DomainParticipantFactory defaults to autoenable upon entities creation." << endl;
        return 1;
      }

      // Now disable DomainParticipantFactory autoenable
      fqos.entity_factory.autoenable_created_entities = 0;
      if (dpf->set_qos (fqos) != ::DDS::RETCODE_OK)
      {
        cerr << "DomainParticipantFactory set_qos failed." << endl;
        return 1;
      }

      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 (participant->enable () != ::DDS::RETCODE_PRECONDITION_NOT_MET)
      {
        cerr << "DomainParticipant can not be enabled because factory autoenable is off." << endl;
        return 1;
      }

      MessageTypeSupport_var mts = new MessageTypeSupportImpl();

      if (DDS::RETCODE_OK != mts->register_type(participant.in (), "")) {
          cerr << "Failed to register the MessageTypeTypeSupport." << endl;
          exit(1);
        }

      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 ())) {
        cerr << "Failed to create_topic." << endl;
        exit(1);
      }

      if (topic->enable () != ::DDS::RETCODE_PRECONDITION_NOT_MET)
      {
        cerr << "Topic can not be enabled because DomainParticipant is not enabled." << endl;
        return 1;
      }

      // Initialize the transport
      OpenDDS::DCPS::TransportImpl_rch transport_impl =
        TheTransportFactory->create_transport_impl (transport_impl_id,
                                                    ::OpenDDS::DCPS::AUTO_CONFIG);

      // Create the subscriber and attach to the corresponding
      // transport.
      DDS::Subscriber_var sub =
        participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT,
                                       DDS::SubscriberListener::_nil(),
                                       ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (sub.in ())) {
        cerr << "Failed to create_subscriber." << endl;
        exit(1);
      }

      if (sub->enable () != ::DDS::RETCODE_PRECONDITION_NOT_MET)
      {
        cerr << "Publisher can not be enabled because DomainParticipant is not enabled." << endl;
        return 1;
      }

      // Attach the subscriber to the transport.
      OpenDDS::DCPS::SubscriberImpl* sub_impl =
        dynamic_cast<OpenDDS::DCPS::SubscriberImpl*> (sub.in ());
      if (0 == sub_impl) {
        cerr << "Failed to obtain subscriber servant\n" << endl;
        exit(1);
      }

      OpenDDS::DCPS::AttachStatus status = sub_impl->attach_transport(transport_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::DataReaderListener_var listener = new DataReaderListenerImpl;
      DataReaderListenerImpl &listener_servant =
        *dynamic_cast<DataReaderListenerImpl*>(listener.in());

      if (CORBA::is_nil (listener.in ())) {
        cerr << "listener is nil." << endl;
        exit(1);
      }

      // Create the Datareaders
      DDS::DataReader_var dr = sub->create_datareader(topic.in (),
                                                      DATAREADER_QOS_DEFAULT,
                                                      listener.in (),
                                                      ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (dr.in ())) {
        cerr << "create_datareader failed." << endl;
        exit(1);
      }

      if (dr->enable () != ::DDS::RETCODE_PRECONDITION_NOT_MET)
      {
        cerr << "DataReader can not be enabled because Subscriber is not enabled." << endl;
        return 1;
      }

      // Now enable DomainParticipantFactory autoenable
      fqos.entity_factory.autoenable_created_entities = 1;
      if (dpf->set_qos (fqos) != ::DDS::RETCODE_OK)
      {
        cerr << "DomainParticipantFactory set_qos failed." << endl;
        return 1;
      }

      // Enable every entity from factory to it's entities and it should succeed.
      if (participant->enable () != ::DDS::RETCODE_OK
        || topic->enable () != ::DDS::RETCODE_OK
        || sub->enable () != ::DDS::RETCODE_OK)
      {
        cerr << "Failed to enable factory." << endl;
        return 1;
      }

      // The datareader is not enabled so it will not able to
      // communicate with datawriter.
      int i = 0;
      while (i < 5 && listener_servant.num_reads() == 0)
      {
        ACE_OS::sleep (1);
        ++i;
      }

      if (listener_servant.num_reads() > 0)
      {
        cerr << "Should not receive any samples since datareader is not enabled." << endl;
        return 1;
      }

      if (dr->enable () != ::DDS::RETCODE_OK)
      {
        cerr << "Failed to enable DataReader." << endl;
        return 1;
      }

      int expected = 10;

      while ( listener_servant.num_reads() < expected ) {
        ACE_OS::sleep (1);
      }

      if (!CORBA::is_nil (participant.in ())) {
        participant->delete_contained_entities();
      }
      if (!CORBA::is_nil (dpf.in ())) {
        dpf->delete_participant(participant.in ());
      }
      ACE_OS::sleep(2);

      TheTransportFactory->release();
      TheServiceParticipant->shutdown ();
    }
  catch (CORBA::Exception& e)
    {
      cerr << "SUB: Exception caught in main ():" << endl << e << endl;
      return 1;
    }

  return 0;
}
Ejemplo n.º 16
0
int ACE_TMAIN(int argc, ACE_TCHAR* argv[])
{
  try
    {
      DDS::DomainParticipantFactory_var dpf;
      DDS::DomainParticipant_var participant;

      dpf = TheParticipantFactoryWithArgs(argc, argv);
      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 ;
      }

      Test::DataTypeSupportImpl * const dts_servant =
        new Test::DataTypeSupportImpl;

      if (DDS::RETCODE_OK != dts_servant->register_type(participant.in (),
                                                        ""))
        {
          cerr << "Failed to register the DataTypeSupport." << endl;
          exit(1);
        }

      CORBA::String_var type_name = dts_servant->get_type_name ();

      DDS::TopicQos topic_qos;
      participant->get_default_topic_qos(topic_qos);
      DDS::Topic_var topic =
        participant->create_topic("Data",
                                  type_name.in (),
                                  topic_qos,
                                  DDS::TopicListener::_nil(),
                                  ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (topic.in ())) {
        cerr << "Failed to create_topic." << endl;
        exit(1);
      }

      size_t const num_partitions =
        sizeof (Test::Requested::PartitionConfigs)
        / sizeof (Test::Requested::PartitionConfigs[0]);

      Test::PartitionConfig const * const begin =
        Test::Requested::PartitionConfigs;
      Test::PartitionConfig const * const end =
        begin + num_partitions;

      // Keep the readers around long enough for the publications and
      // subscriptions to match.
      std::vector<DDS::DataReader_var> readers (num_partitions);

      for (Test::PartitionConfig const * i = begin; i != end; ++i)
      {
        DDS::SubscriberQos sub_qos;
        participant->get_default_subscriber_qos (sub_qos);

        // Specify partitions we're requesting.
        CORBA::ULong n = 0;
        DDS::StringSeq & names = sub_qos.partition.name;
        for (char const * const * s = (*i).partitions;
             s != 0 && *s != 0;
             ++s, ++n)
        {
          CORBA::ULong const new_len = names.length () + 1;
          names.length (new_len);
          names[n] = *s;
        }

        // Create the subscriber and attach to the corresponding
        // transport.
        DDS::Subscriber_var sub =
          participant->create_subscriber (sub_qos,
                                          DDS::SubscriberListener::_nil (),
                                          ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
        if (CORBA::is_nil (sub.in ()))
        {
          cerr << "Failed to create_subscriber." << endl;
          exit(1);
        }

        DDS::DataReaderListener_var listener (
          new Test::DataReaderListener ((*i).expected_matches));

        // Create the Datareaders
        DDS::DataReaderQos dr_qos;
        sub->get_default_datareader_qos (dr_qos);
        DDS::DataReader_var dr = sub->create_datareader (topic.in (),
                                                         dr_qos,
                                                         listener.in (),
                                                         ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
        if (CORBA::is_nil (dr.in ())) {
          cerr << "create_datareader failed." << endl;
          exit(1);
        }

        readers.push_back (dr);
      }

      ACE_OS::sleep (15);

//       {
//         // Force contents of writers vector to be destroyed now.
//         std::vector<DDS::DataReader_var> tmp;
//         tmp.swap (readers);
//       }

      if (!CORBA::is_nil (participant.in ())) {
        participant->delete_contained_entities();
      }
      if (!CORBA::is_nil (dpf.in ())) {
        dpf->delete_participant(participant.in ());
      }
      ACE_OS::sleep(2);

      TheServiceParticipant->shutdown ();
    }
  catch (CORBA::Exception& e)
    {
      cerr << "SUB: Exception caught in main ():" << endl << e << endl;
      return 1;
    }

  return 0;
}
Ejemplo n.º 17
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  int return_result = 0;
  try
    {
      DDS::DomainParticipantFactory_var dpf;
      DDS::DomainParticipant_var participant;

      dpf = TheParticipantFactoryWithArgs(argc, argv);
      participant =
        dpf->create_participant(11,
                                PARTICIPANT_QOS_DEFAULT,
                                DDS::DomainParticipantListener::_nil(),
                                ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (participant.in ())) {
        cerr << "create_participant failed." << endl;
        return 1 ;
      }

      Messenger::MessageTypeSupportImpl* mts_servant =
        new Messenger::MessageTypeSupportImpl;

      if (DDS::RETCODE_OK != mts_servant->register_type(participant.in (),
                                                        ""))
      {
        cerr << "Failed to register the MessageTypeTypeSupport." << endl;
        exit(1);
      }

      CORBA::String_var type_name = mts_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 << "Failed to create_topic." << endl;
        exit(1);
      }

      // Create the subscriber and attach to the corresponding
      // transport.
      DDS::Subscriber_var sub =
        participant->create_subscriber (SUBSCRIBER_QOS_DEFAULT,
                                        DDS::SubscriberListener::_nil(),
                                        ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (sub.in ())) {
        cerr << "Failed to create_subscriber." << endl;
        exit(1);
      }

      // Create the listener.
      DDS::DataReaderListener_var listener (new DataReaderListenerImpl);
      DataReaderListenerImpl* listener_servant =
        dynamic_cast<DataReaderListenerImpl*>(listener.in());

      if (CORBA::is_nil (listener.in ()))
      {
        cerr << "ERROR: listener is nil." << endl;
        exit(1);
      }

      DDS::DataReaderQos dr_qos; // Good QoS.
      sub->get_default_datareader_qos (dr_qos);

      dr_qos.resource_limits.max_samples_per_instance = MAX_SAMPLES_PER_INSTANCES;
      dr_qos.resource_limits.max_samples = MAX_SAMPLES;
      dr_qos.resource_limits.max_instances = MAX_INSTANCES;
#ifndef OPENDDS_NO_OWNERSHIP_PROFILE
      dr_qos.history.kind = ::DDS::KEEP_ALL_HISTORY_QOS;
      dr_qos.history.depth = MAX_SAMPLES_PER_INSTANCES;
#endif

      DDS::DataReader_var dr1 =
        sub->create_datareader (topic.in (),
                                dr_qos,
                                listener.in (),
                                ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);

      if (CORBA::is_nil (dr1.in ()) )
      {
        cerr << "ERROR: create_datareader failed." << endl;
        exit(1);
      }

      DDS::DataReader_var dr2 =
        sub->create_datareader (topic.in (),
                                dr_qos,
                                DDS::DataReaderListener::_nil (),
                                ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);

      if (CORBA::is_nil (dr2.in ()) )
      {
        cerr << "ERROR: create_datareader failed." << endl;
        exit(1);
      }

      int max_attempts = 10;
      int attempts = 0;

      // Synchronize with publisher. Wait until both associate with DataWriter.
      while (attempts < max_attempts)
      {
        ::DDS::SubscriptionMatchedStatus status1;
        ::DDS::SubscriptionMatchedStatus status2;
        if (dr1->get_subscription_matched_status (status1) == ::DDS::RETCODE_OK
           && dr2->get_subscription_matched_status (status2) == ::DDS::RETCODE_OK)
        {
          if (status1.total_count == 2 && status2.total_count == 2)
            break;
          ++ attempts;
          ACE_OS::sleep (1);
        }
        else
        {
          cerr << "ERROR: Failed to get subscription matched status" << endl;
          exit (1);
        }
      }

      if (attempts >= max_attempts)
      {
        cerr << "ERROR: failed to make associations. " << endl;
        exit (1);
      }
      // ----------------------------------------------

      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Subscriber: sleep for %d milliseconds\n"),
                            SLEEP_DURATION.msec()));

      // Wait for publisher to finish sending
      ACE_OS::sleep (SLEEP_DURATION);

      long rej_max_samples = listener_servant->num_rejected_for_max_samples();
      long rej_max_instances = listener_servant->num_rejected_for_max_instances();
      long rej_max_samp_instance = listener_servant->num_rejected_for_max_samples_per_instance();

      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Subscriber: %d rejected for ")
                            ACE_TEXT ("max_samples\n"),
                            rej_max_samples));
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Subscriber: %d rejected for ")
                            ACE_TEXT ("max_instances\n"),
                            rej_max_instances));
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Subscriber: %d rejected for ")
                            ACE_TEXT ("max_samples_per_instance\n"),
                            rej_max_samp_instance));
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Subscriber: received %d ")
                            ACE_TEXT ("samples\n"),
                            listener_servant->num_arrived() ));

      // 3 instances writing 5 messages each
      // expect 2 rejected for max_samples
      // expect 6 rejected for max_instances (register_instance + 5 messages)
      // expect 1 rejected for max_samples_per_instance

#ifndef OPENDDS_NO_OWNERSHIP_PROFILE
      if (rej_max_samples != 2) {
        cerr << "ERROR: Failed to reject expected for max_samples" << endl;
        return_result = 1;
      }
#endif
      if (rej_max_instances != 6) {
        cerr << "ERROR: Failed to reject expected for max_instances" << endl;
        return_result = 1;
      }
#ifndef OPENDDS_NO_OWNERSHIP_PROFILE
      if (rej_max_samp_instance != 1) {
        cerr << "ERROR: Failed to reject expected for max_samples_per_instance" << endl;
        return_result = 1;
      }
#endif

      Messenger::MessageDataReader_var message_dr1 =
        Messenger::MessageDataReader::_narrow(dr1.in());
      Messenger::MessageDataReader_var message_dr2 =
        Messenger::MessageDataReader::_narrow(dr2.in());
      message_dr1->set_listener(DDS::DataReaderListener::_nil (),
                                ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      message_dr2->set_listener(DDS::DataReaderListener::_nil (),
                                ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      listener = DDS::DataReaderListener::_nil ();
      ACE_OS::sleep (2);

      if (!CORBA::is_nil (participant.in ())) {
        participant->delete_contained_entities();
      }
      if (!CORBA::is_nil (dpf.in ())) {
        dpf->delete_participant(participant.in ());
      }

      ACE_OS::sleep(2);

      TheServiceParticipant->shutdown ();
    }
  catch (CORBA::Exception& e)
    {
      cerr << "SUB: Exception caught in main ():" << endl << e << endl;
      return_result = 1;
    }

  return return_result;
}
Ejemplo n.º 18
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
    {
      DDS::DomainParticipantFactory_var dpf;
      DDS::DomainParticipant_var participant;

      dpf = TheParticipantFactoryWithArgs(argc, argv);
      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* mts_servant =
        new Messenger::MessageTypeSupportImpl;

      if (DDS::RETCODE_OK != mts_servant->register_type(participant.in (),
                                                        ""))
      {
        cerr << "Failed to register the MessageTypeTypeSupport." << endl;
        exit(1);
      }

      CORBA::String_var type_name = mts_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 << "Failed to create_topic." << endl;
        exit(1);
      }

      // Initialize the transport
      OpenDDS::DCPS::TransportImpl_rch tcp_impl = 
        TheTransportFactory->create_transport_impl (
          transport_impl_id, 
          ::OpenDDS::DCPS::AUTO_CONFIG);

      // Create the subscriber and attach to the corresponding
      // transport.
      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);
      }

      // Attach the subscriber to the transport.
      OpenDDS::DCPS::SubscriberImpl* sub_impl =
        dynamic_cast<OpenDDS::DCPS::SubscriberImpl*> (sub.in ());
      if (0 == sub_impl) {
        cerr << "Failed to obtain subscriber servant\n" << endl;
        exit(1);
      }

      OpenDDS::DCPS::AttachStatus const status =
        sub_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);
      }



      // ----------------------------------------------
      {
        // Attempt to create a DataReader with intentionally
        // incompatible QoS.
        DDS::DataReaderQos bogus_qos;
        sub->get_default_datareader_qos (bogus_qos);
      
        // Set up a 1 second recurring deadline.  DataReader creation
        // should fail with this QoS since the requested deadline period
        // will be less than the test configured offered deadline
        // period.
        bogus_qos.deadline.period.sec = 2;
        bogus_qos.deadline.period.nanosec = 0;

        DDS::DataReader_var tmp_dr =
          sub->create_datareader (topic.in (),
                                  bogus_qos,
                                  DDS::DataReaderListener::_nil ());

        if (CORBA::is_nil (tmp_dr.in ()))
        {
          cerr << "ERROR: DataReader creation with bogus QoS failed."
               << endl;
          exit (1);
        }

        ACE_OS::sleep (2);

        // Check if the incompatible deadline was correctly flagged.
        DDS::RequestedIncompatibleQosStatus_var incompatible_status =
          tmp_dr->get_requested_incompatible_qos_status ();

        DDS::QosPolicyCountSeq const & policies =
          incompatible_status->policies;

        bool incompatible_deadline = false;
        CORBA::ULong const len = policies.length ();
        for (CORBA::ULong i = 0; i < len; ++i)
        {
          if (policies[i].policy_id == DDS::DEADLINE_QOS_POLICY_ID)
          {
            incompatible_deadline = true;
            break;
          }
        }

        if (!incompatible_deadline)
        {
          cerr << "ERROR: A DataReader/Writer association was created " << endl
               << "       despite use of deliberately incompatible deadline "
               << "QoS." << endl;
          exit (1);
        }
      }


      // ----------------------------------------------

      // Create the listener.
      DDS::DataReaderListener_var listener (new DataReaderListenerImpl);
      if (CORBA::is_nil (listener.in ()))
      {
        cerr << "ERROR: listener is nil." << endl;
        exit(1);
      }


      DDS::DataReaderQos dr_qos; // Good QoS.
      sub->get_default_datareader_qos (dr_qos);

      // Set up a 5 second recurring deadline.
      static DDS::Duration_t const DEADLINE_PERIOD =
        {
          5,  // seconds
          0   // nanoseconds
        };

      assert (DEADLINE_PERIOD.sec > 1); // Requirement for the test.

      // Time to sleep waiting for deadline periods to expire
      long const NUM_EXPIRATIONS = 2;
      ACE_Time_Value const SLEEP_DURATION (
        OpenDDS::DCPS::duration_to_time_value (DEADLINE_PERIOD)
        * 2
        + ACE_Time_Value (1));

      dr_qos.deadline.period.sec     = DEADLINE_PERIOD.sec;
      dr_qos.deadline.period.nanosec = DEADLINE_PERIOD.nanosec;

      // First data reader will have a listener to test listener
      // callback on deadline expiration.
      DDS::DataReader_var dr1 =
        sub->create_datareader (topic.in (),
                                dr_qos,
                                listener.in ());

      // Second data reader will not have a listener to test proper
      // handling of a nil listener in the deadline handling code.
      DDS::DataReader_var dr2 =
        sub->create_datareader (topic.in (),
                                dr_qos,
                                DDS::DataReaderListener::_nil ());

      if (CORBA::is_nil (dr1.in ()) || CORBA::is_nil (dr2.in ()))
      {
        cerr << "ERROR: create_datareader failed." << endl;
        exit(1);
      }

      // ----------------------------------------------

      // Wait for deadline periods to expire.
      ACE_OS::sleep (SLEEP_DURATION);

      DDS::RequestedDeadlineMissedStatus deadline_status1 =
        dr1->get_requested_deadline_missed_status();

      DDS::RequestedDeadlineMissedStatus deadline_status2 =
        dr2->get_requested_deadline_missed_status();

      if (deadline_status1.total_count != NUM_EXPIRATIONS
          || deadline_status2.total_count != NUM_EXPIRATIONS)
      {
        cerr << "ERROR: Expected number of missed requested "
             << "deadlines (" << NUM_EXPIRATIONS << ") " << "did " << endl
             << "       not occur ("
             << deadline_status1.total_count << " and/or "
             << deadline_status2.total_count << ")." << endl;

        exit (1);
      }

      if (deadline_status1.total_count_change != NUM_EXPIRATIONS
          || deadline_status2.total_count_change != NUM_EXPIRATIONS)
      {
        cerr << "ERROR: Incorrect missed requested "
             << "deadline count change" << endl
             << "       ("
             << deadline_status1.total_count_change
             << " and/or "
             << deadline_status2.total_count_change
             << " instead of " << NUM_EXPIRATIONS << ")."
             << endl;

        exit (1);
      }

      // Wait for another set of deadline periods to expire.
      ACE_OS::sleep (SLEEP_DURATION);

      deadline_status1 = dr1->get_requested_deadline_missed_status();
      deadline_status2 = dr2->get_requested_deadline_missed_status();

      if (deadline_status1.total_count != NUM_EXPIRATIONS * 2
          || deadline_status2.total_count != NUM_EXPIRATIONS * 2)
      {
        cerr << "ERROR: Another expected number of missed requested "
             << "deadlines (" << NUM_EXPIRATIONS * 2 << ")" << endl
             << "       did not occur ("
             << deadline_status1.total_count << " and/or "
             << deadline_status2.total_count << ")." << endl;

        exit (1);
      }

      if (deadline_status1.total_count_change != NUM_EXPIRATIONS
          || deadline_status2.total_count_change != NUM_EXPIRATIONS)
      {
        cerr << "ERROR: Incorrect missed requested "
             << "deadline count" << endl
             << "       change ("
             << deadline_status1.total_count_change
             << "and/or "
             << deadline_status2.total_count_change
             << " instead of " << NUM_EXPIRATIONS << ")." << endl;

        exit (1);
      }


      // Create 3rd data reader to trigger the data writers to write.
      DDS::DataReader_var dr3 =
      sub->create_datareader (topic.in (),
                              dr_qos,
                              DDS::DataReaderListener::_nil ());

      DataReaderListenerImpl* listener_servant =
        dynamic_cast<DataReaderListenerImpl*>(listener.in());
      int expected = 10;
      while ( listener_servant->num_reads() < expected) {
        ACE_OS::sleep (1);
      }



      // @todo We still need a check proper updating of the
      //       @c DDS::RequestedDeadlineMissedStatus::last_instance_handle
      //       field.

      if (!CORBA::is_nil (participant.in ())) {
        participant->delete_contained_entities();
      }
      if (!CORBA::is_nil (dpf.in ())) {
        dpf->delete_participant(participant.in ());
      }

      ACE_OS::sleep(2);

      TheTransportFactory->release();
      TheServiceParticipant->shutdown ();
    }
  catch (CORBA::Exception& e)
    {
      cerr << "SUB: Exception caught in main ():" << endl << e << endl;
      return 1;
    }

  return 0;
}
Ejemplo n.º 19
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 ;
      }

      Messenger::MessageTypeSupport_var mts_servant =
        new Messenger::MessageTypeSupportImpl;

      if (DDS::RETCODE_OK != mts_servant->register_type(participant.in (),
                                                        ""))
      {
        cerr << "Failed to register the MessageTypeTypeSupport." << endl;
        exit(1);
      }

      CORBA::String_var type_name = mts_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 << "Failed to create_topic." << endl;
        exit(1);
      }

      // Create the subscriber and attach to the corresponding
      // transport.
      DDS::Subscriber_var sub =
        participant->create_subscriber (SUBSCRIBER_QOS_DEFAULT,
                                        DDS::SubscriberListener::_nil(),
                                        ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (sub.in ()))
      {
        cerr << "Failed to create_subscriber." << endl;
        exit(1);
      }

      // activate the listener
      DDS::DataReaderListener_var listener (new DataReaderListenerImpl);
      DataReaderListenerImpl* const listener_servant =
        dynamic_cast<DataReaderListenerImpl*>(listener.in());

      if (CORBA::is_nil (listener.in ()))
      {
        cerr << "listener is nil." << endl;
        exit(1);
      }

      // Create the Datareader
      DDS::DataReaderQos dr_qos;
      sub->get_default_datareader_qos(dr_qos);
      dr_qos.durability.kind = DDS::PERSISTENT_DURABILITY_QOS;

      DDS::DataReader_var dr =
        sub->create_datareader(topic, dr_qos, listener,
                               OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (dr.in ())) {
        cerr << "create_datareader failed." << endl;
        exit(1);
      }

      int const expected = 10;
      while (listener_servant->num_reads() < expected)
      {
        ACE_OS::sleep (1);
      }

      if (!CORBA::is_nil (participant.in ())) {
        participant->delete_contained_entities();
      }
      if (!CORBA::is_nil (dpf.in ())) {
        dpf->delete_participant(participant.in ());
      }
      ACE_OS::sleep(2);

      TheServiceParticipant->shutdown ();
    }
  catch (CORBA::Exception& e)
    {
      cerr << "SUB: Exception caught in main ():" << endl << e << endl;
      return 1;
    }

  return 0;
}
Ejemplo n.º 20
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
    {
      DDS::DomainParticipantFactory_var dpf;
      DDS::DomainParticipant_var participant;

      if( OpenDDS::DCPS::DCPS_debug_level > 0) {
        ACE_DEBUG((LM_DEBUG,
          ACE_TEXT("(%P|%t) subscriber: ")
          ACE_TEXT("initialization starting.\n")
        ));
      }

      dpf = TheParticipantFactoryWithArgs(argc, argv);
      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( OpenDDS::DCPS::DCPS_debug_level > 0) {
        ACE_DEBUG((LM_DEBUG,
          ACE_TEXT("(%P|%t) subscriber: ")
          ACE_TEXT("participant created.\n")
        ));
      }

      if (parse_args (argc, argv) == -1) {
        return -1;
      }

      if( OpenDDS::DCPS::DCPS_debug_level > 0) {
        ACE_DEBUG((LM_DEBUG,
          ACE_TEXT("(%P|%t) subscriber: ")
          ACE_TEXT("command line parsed.\n")
        ));
      }

      MessageTypeSupportImpl* mts_servant = new MessageTypeSupportImpl();

      if (DDS::RETCODE_OK != mts_servant->register_type(participant.in (), "")) {
          cerr << "Failed to register the MessageTypeTypeSupport." << endl;
          exit(1);
        }

      CORBA::String_var type_name = mts_servant->get_type_name ();

      if( OpenDDS::DCPS::DCPS_debug_level > 0) {
        ACE_DEBUG((LM_DEBUG,
          ACE_TEXT("(%P|%t) subscriber: ")
          ACE_TEXT("type support installed.\n")
        ));
      }

      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 << "Failed to create_topic." << endl;
        exit(1);
      }

      if( OpenDDS::DCPS::DCPS_debug_level > 0) {
        ACE_DEBUG((LM_DEBUG,
          ACE_TEXT("(%P|%t) subscriber: ")
          ACE_TEXT("topic created.\n")
        ));
      }

      // Initialize the transport
      OpenDDS::DCPS::TransportImpl_rch tcp_impl =
        TheTransportFactory->create_transport_impl (transport_impl_id,
                                                    ::OpenDDS::DCPS::AUTO_CONFIG);

      if( OpenDDS::DCPS::DCPS_debug_level > 0) {
        ACE_DEBUG((LM_DEBUG,
          ACE_TEXT("(%P|%t) subscriber: ")
          ACE_TEXT("transport created.\n")
        ));
      }

      // Create the subscriber and attach to the corresponding
      // transport.
      DDS::Subscriber_var sub =
        participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT,
                                       DDS::SubscriberListener::_nil(),
                                       ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (sub.in ())) {
        cerr << "Failed to create_subscriber." << endl;
        exit(1);
      }

      if( OpenDDS::DCPS::DCPS_debug_level > 0) {
        ACE_DEBUG((LM_DEBUG,
          ACE_TEXT("(%P|%t) subscriber: ")
          ACE_TEXT("subscriber created.\n")
        ));
      }

      // Attach the subscriber to the transport.
      OpenDDS::DCPS::SubscriberImpl* sub_impl =
        dynamic_cast<OpenDDS::DCPS::SubscriberImpl*> (sub.in ());
      if (0 == sub_impl) {
        cerr << "Failed to obtain subscriber servant\n" << endl;
        exit(1);
      }

      if( OpenDDS::DCPS::DCPS_debug_level > 0) {
        ACE_DEBUG((LM_DEBUG,
          ACE_TEXT("(%P|%t) subscriber: ")
          ACE_TEXT("servant extracted.\n")
        ));
      }

      OpenDDS::DCPS::AttachStatus status = sub_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);
      }

      if( OpenDDS::DCPS::DCPS_debug_level > 0) {
        ACE_DEBUG((LM_DEBUG,
          ACE_TEXT("(%P|%t) subscriber: ")
          ACE_TEXT("transport attached.\n")
        ));
      }

      // activate the listener
      DDS::DataReaderListener_var listener (new DataReaderListenerImpl);
      DataReaderListenerImpl* listener_servant =
        dynamic_cast<DataReaderListenerImpl*>(listener.in());

      if (CORBA::is_nil (listener.in ())) {
        cerr << "listener is nil." << endl;
        exit(1);
      }

      if( OpenDDS::DCPS::DCPS_debug_level > 0) {
        ACE_DEBUG((LM_DEBUG,
          ACE_TEXT("(%P|%t) subscriber: ")
          ACE_TEXT("listener created.\n")
        ));
      }

      // Create the Datareaders
      DDS::DataReaderQos dr_qos;
      sub->get_default_datareader_qos (dr_qos);
      DDS::DataReader_var dr = sub->create_datareader(topic.in (),
                                                      dr_qos,
                                                      listener.in (),
                                                      ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (dr.in ())) {
        cerr << "create_datareader failed." << endl;
        exit(1);
      }

      if( OpenDDS::DCPS::DCPS_debug_level > 0) {
        ACE_DEBUG((LM_DEBUG,
          ACE_TEXT("(%P|%t) subscriber: ")
          ACE_TEXT("processing starting.\n")
        ));
      }

      int expected = 5;
      while ( listener_servant->num_reads() < expected) {
        ACE_OS::sleep (1);
      }

      if (!CORBA::is_nil (participant.in ())) {
        participant->delete_contained_entities();
      }
      if (!CORBA::is_nil (dpf.in ())) {
        dpf->delete_participant(participant.in ());
      }
      ACE_OS::sleep(2);

      TheTransportFactory->release();
      TheServiceParticipant->shutdown ();

    }
  catch (CORBA::Exception& e)
    {
      cerr << "SUB: Exception caught in main ():" << endl << e << endl;
      return 1;
    }

  return 0;
}
Ejemplo n.º 21
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
    {
      DDS::DomainParticipantFactory_var dpf;
      DDS::DomainParticipant_var participant;

      dpf = TheParticipantFactoryWithArgs(argc, argv);
      participant =
        dpf->create_participant(11,
                                PARTICIPANT_QOS_DEFAULT,
                                DDS::DomainParticipantListener::_nil(),
                                ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (participant.in ())) {
        cerr << "create_participant failed." << endl;
        return 1 ;
      }

      Messenger::MessageTypeSupportImpl* mts_servant =
        new Messenger::MessageTypeSupportImpl;

      if (DDS::RETCODE_OK != mts_servant->register_type(participant.in (),
                                                        ""))
      {
        cerr << "Failed to register the MessageTypeTypeSupport." << endl;
        exit(1);
      }

      CORBA::String_var type_name = mts_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 << "Failed to create_topic." << endl;
        exit(1);
      }

      // Create the subscriber and attach to the corresponding
      // transport.
      DDS::Subscriber_var sub =
        participant->create_subscriber (SUBSCRIBER_QOS_DEFAULT,
                                        DDS::SubscriberListener::_nil(),
                                        ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (sub.in ())) {
        cerr << "Failed to create_subscriber." << endl;
        exit(1);
      }

     DDS::DataReaderQos dr_qos;
      sub->get_default_datareader_qos (dr_qos);

      // Make reliable
      dr_qos.reliability.kind = DDS::RELIABLE_RELIABILITY_QOS;

      // Set up a 5 second recurring deadline.
      dr_qos.deadline.period.sec     = 5;
      dr_qos.deadline.period.nanosec = 0;

      // Create two listeners. One for each DataReader.
      DDS::DataReaderListener_var listener1 (new DataReaderListenerImpl);
      if (CORBA::is_nil (listener1.in ()))
      {
        cerr << "ERROR: listener1 is nil." << endl;
        exit(1);
      }

      DDS::DataReaderListener_var listener2 (new DataReaderListenerImpl);
      if (CORBA::is_nil (listener2.in ()))
      {
        cerr << "ERROR: listener2 is nil." << endl;
        exit(1);
      }


      // First data reader has 5 second deadline period.
      DDS::DataReader_var dr1 =
        sub->create_datareader (topic.in (),
                                dr_qos,
                                listener1.in (),
                                ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);

      // Set up a 3 second recurring deadline.
      dr_qos.deadline.period.sec     = 3;
      dr_qos.deadline.period.nanosec = 0;

      // Second data reader has 3 second deadline period which
      // is not compatible with DataWriter.
      DDS::DataReader_var dr2 =
        sub->create_datareader (topic.in (),
                                dr_qos,
                                listener2.in (),
                                ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);

      if (CORBA::is_nil (dr1.in ()) || CORBA::is_nil (dr2.in ()))
      {
        cerr << "ERROR: create_datareader failed." << endl;
        exit(1);
      }

      DataReaderListenerImpl* listener_servant1 =
        dynamic_cast<DataReaderListenerImpl*>(listener1.in());
      DataReaderListenerImpl* listener_servant2 =
        dynamic_cast<DataReaderListenerImpl*>(listener2.in());

      int expected = 10;
      // Writer of deadline 4 -> Reader of deadline 5
      while ( listener_servant1->num_reads() < expected) {
        //cout << "subscriber listener1 waiting for " << expected
             //<< " reads, got " << listener_servant1->num_reads() << std::endl;
        ACE_OS::sleep (1);
      }

      // Writer of deadline 4 and Reader of deadline 3 is not
      // compatible so second DataReader should not receive
      // any message from DataWriter.
      if (listener_servant2->num_reads() > 0)
      {
        cerr << "ERROR: second DataReader should not receive message from "
          << "datawriter as their deadline QoS is not compatible" << endl;
        exit (1);
      }

      // Wait for dr1 to be unmatched from the writer (due to writer set_qos).
      ACE_DEBUG((LM_DEBUG, "(%P|%t) check for dr1 unmatch\n"));
      DDS::WaitSet_var ws = new DDS::WaitSet;
      DDS::StatusCondition_var sc = dr1->get_statuscondition();
      sc->set_enabled_statuses(DDS::SUBSCRIPTION_MATCHED_STATUS);
      ws->attach_condition(sc);
      DDS::SubscriptionMatchedStatus matched;
      const DDS::Duration_t timeout = {5, 0}; // seconds
      while (dr1->get_subscription_matched_status(matched) == DDS::RETCODE_OK
             && matched.current_count == matched.total_count)
      {
        DDS::ConditionSeq active;
        ACE_DEBUG((LM_DEBUG, "(%P|%t) wait for dr1 unmatch\n"));
        if (ws->wait(active, timeout) == DDS::RETCODE_TIMEOUT)
        {
          cerr << "ERROR: timeout expired while waiting for dr1 to be "
            "unmatched from the writer which now has a 6 second deadline\n";
          exit (1);
        }
      }
      ws->detach_condition(sc);
      ACE_DEBUG((LM_DEBUG, "(%P|%t) done dr1 unmatch\n"));

      // Now change second DataReader to have deadline period to be 5 seconds. This
      // value is compatible with DataWriter so it will be matched.
      dr_qos.deadline.period.sec = 5;

      if (dr2->set_qos (dr_qos) != ::DDS::RETCODE_OK)
      {
        cerr << "ERROR: DataReader changed deadline period to make it compatible "
          << "with datawriter" << endl;
        exit (1);
      }

      // second DataReader should receive 20 messages so far.
      while ( listener_servant1->num_reads() < 2 * expected) {
        //cout << "subscriber listener1 waiting for " << 2 * expected
             //<< " reads, got " << listener_servant1->num_reads() << std::endl;
        ACE_OS::sleep (1);
      }

      // second DataReader should receive 10 messages.
      while ( listener_servant2->num_reads() < expected) {
        //cout << "subscriber listener2 waiting for " << expected
             //<< " reads, got " << listener_servant2->num_reads() << std::endl;
        ACE_OS::sleep (1);
      }

      // During this period, the 5 second should have at most 1 missed
      // deadline, but with 3 seconds, it should have at least 2 missed
      // deadline.
      ACE_OS::sleep (9);

      if (listener_servant2->num_deadline_missed () > 1)
      {
        cerr << "ERROR: failed to verify deadline missed count " << endl;
        exit (1);
      }

      if (!CORBA::is_nil (participant.in ())) {
        participant->delete_contained_entities();
      }
      if (!CORBA::is_nil (dpf.in ())) {
        dpf->delete_participant(participant.in ());
      }

      TheServiceParticipant->shutdown ();
    }
  catch (CORBA::Exception& e)
    {
      cerr << "SUB: Exception caught in main ():" << endl << e << endl;
      return 1;
    }
  TheServiceParticipant->shutdown ();

  return 0;
}
Ejemplo n.º 22
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
    {
      DDS::DomainParticipantFactory_var dpf;
      DDS::DomainParticipant_var participant;

      dpf = TheParticipantFactoryWithArgs(argc, argv);
      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;
      }

      MessageTypeSupport_var mts = new MessageTypeSupportImpl();

      if (DDS::RETCODE_OK != mts->register_type(participant.in (), "")) {
          cerr << "Failed to register the MessageTypeTypeSupport." << endl;
          exit(1);
        }

      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 ())) {
        cerr << "ERROR Failed to create_topic." << endl;
        exit(1);
      }

      // Create the subscriber and attach to the corresponding
      // transport.
      DDS::Subscriber_var sub =
        participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT,
                                       DDS::SubscriberListener::_nil(),
                                       ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (sub.in ())) {
        cerr << "ERROR Failed to create_subscriber." << endl;
        exit(1);
      }

      // activate the listener
      DDS::DataReaderListener_var listener = new DataReaderListenerImpl;
      DataReaderListenerImpl &listener_servant =
        *dynamic_cast<DataReaderListenerImpl*>(listener.in());

      if (CORBA::is_nil (listener.in ())) {
        cerr << "ERROR listener is nil." << endl;
        exit(1);
      }

      ::DDS::DataReaderQos dr_qos;
      sub->get_default_datareader_qos (dr_qos);

      dr_qos.liveliness.lease_duration.sec = LEASE_DURATION_SEC ;
      dr_qos.liveliness.lease_duration.nanosec = 0 ;

      // Create the Datareaders
      DDS::DataReader_var dr = sub->create_datareader(topic.in (),
                                                      dr_qos,
                                                      listener.in (),
                                                      ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (dr.in ())) {
        cerr << "ERROR create_datareader failed." << endl;
        exit(1);
      }

      int count = 0;
      while ((++count < 60) && ((listener_servant.num_reads() < total_num_messages)))
      {
        ACE_OS::sleep (1);
      }

      ACE_OS::sleep(2);

      ACE_DEBUG((LM_INFO,
                 "Subscriber got %d of %d messages, "
                 "and %d of %d callbacks, deleting entities\n",
                 (int) listener_servant.num_reads(), total_num_messages,
                 listener_servant.num_liveliness_change_callbacks(), num_liveliness_change_callbacks));

      if (!CORBA::is_nil (participant.in ())) {
        participant->delete_contained_entities();
      }
      if (!CORBA::is_nil (dpf.in ())) {
        dpf->delete_participant(participant.in ());
      }
      ACE_OS::sleep(2);

      TheServiceParticipant->shutdown ();

      if (listener_servant.num_liveliness_change_callbacks () != num_liveliness_change_callbacks)
      {
         cerr
         << "ERROR: did not receive liveliness change callbacks as expected.("
         << listener_servant.num_liveliness_change_callbacks () << "/"
         << num_liveliness_change_callbacks << ")" << endl;
         return 1;
      }
    }
  catch (CORBA::Exception& e)
    {
      cerr << "ERROR: subscriber Exception caught in main ():" << endl << e << endl;
      return 1;
    }

  return 0;
}
Ejemplo n.º 23
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try {
    DDS::DomainParticipantFactory_var dpf;
    DDS::DomainParticipant_var participant;

    dpf = TheParticipantFactoryWithArgs(argc, argv);
    if( parse_args(argc, argv) != 0)
      return 1;

    ACE_DEBUG((LM_DEBUG, "(%P|%t) subscriber.cpp main()\n"));

    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 ;
    }

    Messenger::MessageTypeSupportImpl* mts_servant = new Messenger::MessageTypeSupportImpl();
    OpenDDS::DCPS::LocalObject_var safe_servant = mts_servant;

    if (DDS::RETCODE_OK != mts_servant->register_type(participant.in (),
                                                      "")) {
      cerr << "Failed to register the MessageTypeTypeSupport." << endl;
      exit(1);
    }

    CORBA::String_var type_name = mts_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 << "Failed to create_topic." << endl;
      exit(1);
    }

    // Create the subscriber and attach to the corresponding
    // transport.
    DDS::Subscriber_var sub =
      participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT,
                                     DDS::SubscriberListener::_nil(),
                                     ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
    if (CORBA::is_nil (sub.in ())) {
      cerr << "Failed to create_subscriber." << endl;
      exit(1);
    }

    // activate the listener
    DDS::DataReaderListener_var listener (new DataReaderListenerImpl);
    if (CORBA::is_nil (listener.in ())) {
      cerr << "listener is nil." << endl;
      exit(1);
    }
    DataReaderListenerImpl* listener_servant =
      dynamic_cast<DataReaderListenerImpl*>(listener.in());

    // Create the Datareaders
    DDS::DataReaderQos dr_qos;
    sub->get_default_datareader_qos (dr_qos);
    DDS::DataReader_var dr = sub->create_datareader(topic.in (),
                                                    dr_qos,
                                                    listener.in (),
                                                    ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
    if (CORBA::is_nil (dr.in ())) {
      cerr << "create_datareader failed." << endl;
      exit(1);
    }

    // Indicate that the subscriber is ready
    FILE* readers_ready = ACE_OS::fopen (sub_ready_filename, ACE_TEXT ("w"));
    if (readers_ready == 0) {
      cerr << "ERROR Unable to create subscriber ready file." << endl;
      exit(1);
    }
    ACE_OS::fclose(readers_ready);

    // Wait for the publisher to be ready
    FILE* writers_ready = 0;
    do {
      ACE_Time_Value small_time(0,250000);
      ACE_OS::sleep (small_time);
      writers_ready = ACE_OS::fopen (pub_ready_filename, ACE_TEXT ("r"));
    } while (0 == writers_ready);
    ACE_OS::fclose(writers_ready);

    // Since the publisher continue sending while the subscriber crashes,
    // some messages may be lost, we lower the num_expected_reads by 2.
    num_expected_reads -= num_reads_deviation;

    FILE* writers_completed = 0;
    int timeout_writes = 0;
    while ( listener_servant->num_reads() < num_expected_reads) {
      // Get the number of the timed out writes from publisher so we
      // can re-calculate the number of expected messages. Otherwise,
      // the blocking timeout test will never exit from this loop.
      if (writers_completed == 0) {
        writers_completed = ACE_OS::fopen (pub_finished_filename, ACE_TEXT ("r"));
        if (writers_completed != 0) {
          if (end_with_publisher)
          {
            // Since we are in the "bp_timeout" test case that publisher
            // close connection when backpressure last longer than
            // max_output_pause_period, the publisher ends as it finishes
            // sending. As the subscriber sees the publisher is done, it
            // changes the read_delay_ms to 0 so it can read all received
            // messages and them announce it completed.

            int old_read_delay_ms = read_delay_ms;
            read_delay_ms = 0;
            // Give time to finish reading.
            ACE_OS::sleep (old_read_delay_ms/1000 * 2);
            break;
          }

          //writers_completed = ACE_OS::fopen (pub_finished_filename, "r");
          fscanf (writers_completed, "%d\n", &timeout_writes);
          num_expected_reads -= timeout_writes;
          cout << "timed out writes " << timeout_writes << ", we expect "
               << num_expected_reads << endl;
        }
      }
      ACE_OS::sleep (1);
    }

    // Indicate that the subscriber is done
    FILE* readers_completed = ACE_OS::fopen (sub_finished_filename, ACE_TEXT ("w"));
    if (readers_completed == 0) {
      cerr << "ERROR Unable to create subscriber completed file." << endl;
      exit(1);
    }
    ACE_OS::fclose(readers_completed);

    // Wait for 5 seconds to (>passive_reconnect_duration)
    // to give transport time to detect the connection lost due to
    // backpressure timeout before shutdown the datareader.
    if (end_with_publisher)
      ACE_OS::sleep (5);

    if (!CORBA::is_nil (participant.in ())) {
      participant->delete_contained_entities();
    }
    if (!CORBA::is_nil (dpf.in ())) {
      dpf->delete_participant(participant.in ());
    }
    TheServiceParticipant->shutdown ();

  } catch (CORBA::Exception& e) {
    cerr << "Exception caught in main ():" << endl << e << endl;
    return 1;
  }

  if (verify_lost_sub_notification
    && actual_lost_sub_notification != expected_lost_sub_notification)
  {
    ACE_ERROR ((LM_ERROR, "(%P|%t) ERROR: on_subscription_lost called %d times "
      "and expected %d times\n", actual_lost_sub_notification,
      expected_lost_sub_notification));
    return 1;
  }

  return 0;
}
Ejemplo n.º 24
0
int ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  int result = 0;
  ACE_DEBUG ((LM_DEBUG, "(%P|%t) subscriber main\n"));
  try
    {
      DDS::DomainParticipantFactory_var dpf;
      DDS::DomainParticipant_var participant;

      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));

      participant = dpf->create_participant(411,
                                            partQos,
                                            DDS::DomainParticipantListener::_nil(),
                                            ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (participant.in ())) {
        cerr << "subscriber: create_participant failed." << endl;
        return 1 ;
      }

      ::Messenger::MessageTypeSupport_var mts = new ::Messenger::MessageTypeSupportImpl();

      if (DDS::RETCODE_OK != mts->register_type(participant.in (), "Messenger")) {
          cerr << "subscriber: Failed to register the MessageTypeTypeSupport." << endl;
          exit(1);
        }

      CORBA::String_var type_name = mts->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 << "subscriber: Failed to create_topic." << endl;
        exit(1);
      }

      // Create the subscriber

      DDS::SubscriberQos sub_qos;
      participant->get_default_subscriber_qos (sub_qos);

      // set up group data in subscriber qos
      CORBA::ULong group_data_len = static_cast<CORBA::ULong> (ACE_OS::strlen (GROUP_DATA));
      sub_qos.group_data.value.length (group_data_len);
      sub_qos.group_data.value.replace (group_data_len, group_data_len, reinterpret_cast<CORBA::Octet*>(GROUP_DATA));

      DDS::Subscriber_var sub =
        participant->create_subscriber(sub_qos,
                                       DDS::SubscriberListener::_nil(),
                                       ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (sub.in ())) {
        cerr << "subscriber: Failed to create_subscriber." << endl;
        exit(1);
      }

      // activate the listener
      DDS::DataReaderListener_var listener (new DataReaderListenerImpl);
      DataReaderListenerImpl* listener_servant =
        dynamic_cast<DataReaderListenerImpl*>(listener.in());

      DDS::Subscriber_var builtin = participant->get_builtin_subscriber();
      DDS::DataReader_var bitdr =
        builtin->lookup_datareader(OpenDDS::DCPS::BUILT_IN_PUBLICATION_TOPIC);
      listener_servant->set_builtin_datareader(bitdr.in());

      if (CORBA::is_nil (listener.in ())) {
        cerr << "subscriber: listener is nil." << endl;
        exit(1);
      }

      // Create the Datareaders
      DDS::DataReaderQos dr_qos;
      sub->get_default_datareader_qos (dr_qos);

      // set up user data in DR qos
      CORBA::ULong dr_user_data_len = static_cast<CORBA::ULong>(ACE_OS::strlen (DR_USER_DATA));
      dr_qos.user_data.value.length (dr_user_data_len);
      dr_qos.user_data.value.replace (dr_user_data_len,
                                      dr_user_data_len,
                                      reinterpret_cast<CORBA::Octet*>(DR_USER_DATA));

      DDS::DataReader_var dr = sub->create_datareader(topic.in (),
                                                      dr_qos,
                                                      listener.in (),
                                                      ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (dr.in ())) {
        cerr << "subscriber: create_datareader 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);

      dr_user_data_len = static_cast<CORBA::ULong>(ACE_OS::strlen (UPDATED_DR_USER_DATA));
      dr_qos.user_data.value.length (dr_user_data_len);
      dr_qos.user_data.value.replace (dr_user_data_len,
                                      dr_user_data_len,
                                      reinterpret_cast<CORBA::Octet*>(UPDATED_DR_USER_DATA));
      dr->set_qos (dr_qos);

      group_data_len = static_cast<CORBA::ULong> (ACE_OS::strlen (UPDATED_GROUP_DATA));
      sub_qos.group_data.value.length (group_data_len);
      sub_qos.group_data.value.replace (group_data_len,
                                        group_data_len,
                                        reinterpret_cast<CORBA::Octet*>(UPDATED_GROUP_DATA));
      sub->set_qos (sub_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);

      while ( listener_servant->num_reads() < num_messages) {
        ACE_OS::sleep (1);
      }

      if (listener_servant->builtin_read_errors()) {
        cerr << "subscriber: Built in topic read failure." << endl;
        result = 1;
      }

      if (!CORBA::is_nil (participant.in ())) {
        participant->delete_contained_entities();
      }
      if (!CORBA::is_nil (dpf.in ())) {
        dpf->delete_participant(participant.in ());
      }

      TheServiceParticipant->shutdown ();
    }
  catch (CORBA::Exception& e)
    {
      cerr << "subscriber: SUB: Exception caught in main ():" << endl << e << endl;
      return 1;
    }

  return result;
}
Ejemplo n.º 25
0
int main (int argc, char *argv[])
{
  try {
    DDS::DomainParticipantFactory_var dpf;
    DDS::DomainParticipant_var participant;

    dpf = TheParticipantFactoryWithArgs(argc, argv);
    if( parse_args(argc, argv) != 0)
      return 1;

    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* mts_servant = new Messenger::MessageTypeSupportImpl();
    TAO::DCPS::LocalObject_var safe_servant = mts_servant;

    if (DDS::RETCODE_OK != mts_servant->register_type(participant.in (),
                                                      "")) {
      cerr << "Failed to register the MessageTypeTypeSupport." << endl;
      exit(1);
    }

    CORBA::String_var type_name = mts_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 << "Failed to create_topic." << endl;
      exit(1);
    }

    // Initialize the transport
    TAO::DCPS::TransportImpl_rch tcp_impl =
      TheTransportFactory->create_transport_impl (TCP_IMPL_ID, ::TAO::DCPS::AUTO_CONFIG);

    // Create the subscriber and attach to the corresponding
    // transport.
    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);
    }

    // Attach the subscriber to the transport.
    TAO::DCPS::SubscriberImpl* sub_impl =
      TAO::DCPS::reference_to_servant<TAO::DCPS::SubscriberImpl> (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;
    DDS::DataReaderListener_var listener =
      ::TAO::DCPS::servant_to_reference (&listener_servant);
    if (CORBA::is_nil (listener.in ())) {
      cerr << "listener is nil." << endl;
      exit(1);
    }

    // Create the Datareaders
    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);
    }

    // Indicate that the subscriber is ready
    FILE* readers_ready = ACE_OS::fopen (sub_ready_filename, "w");
    if (readers_ready == 0) {
      cerr << "ERROR Unable to create subscriber ready file." << endl;
      exit(1);
    }
    ACE_OS::fclose(readers_ready);

    // Wait for the publisher to be ready
    FILE* writers_ready = 0;
    do {
      ACE_Time_Value small(0,250000);
      ACE_OS::sleep (small);
      writers_ready = ACE_OS::fopen (pub_ready_filename, "r");
    } while (0 == writers_ready);
    ACE_OS::fclose(writers_ready);

    // Since the publisher continue sending while the subscriber crashes,
    // some messages may be lost, we lower the num_expected_reads by 2.
    num_expected_reads -= num_reads_deviation;

    FILE* writers_completed = 0;
    int timeout_writes = 0;
    while ( listener_servant.num_reads() < num_expected_reads) {
      // Get the number of the timed out writes from publisher so we
      // can re-calculate the number of expected messages. Otherwise,
      // the blocking timeout test will never exit from this loop.
      if (writers_completed == 0) {
        writers_completed = ACE_OS::fopen (pub_finished_filename, "r");
        if (writers_completed != 0) {
          if (end_with_publisher)
          {
            // Since we are in the "bp_timeout" test case that publisher
            // close connection when backpressure last longer than
            // max_output_pause_period, the publisher ends as it finishes
            // sending. As the subscriber sees the publisher is done, it
            // changes the read_delay_ms to 0 so it can read all received
            // messages and them announce it completed.

            int old_read_delay_ms = read_delay_ms;
            read_delay_ms = 0;
            // Give time to finish reading.
            ACE_OS::sleep (old_read_delay_ms/1000 * 2);
            break;
          }

          //writers_completed = ACE_OS::fopen (pub_finished_filename, "r");
          fscanf (writers_completed, "%d\n", &timeout_writes);
          num_expected_reads -= timeout_writes;
          cout << "timed out writes " << timeout_writes << ", we expect "
               << num_expected_reads << endl;
        }
      }
      ACE_OS::sleep (1);
    }

    // Indicate that the subscriber is done
    FILE* readers_completed = ACE_OS::fopen (sub_finished_filename, "w");
    if (readers_completed == 0) {
      cerr << "ERROR Unable to create subscriber completed file." << endl;
      exit(1);
    }
    ACE_OS::fclose(readers_completed);

    // Wait for 5 seconds to (>passive_reconnect_duration) 
    // to give transport time to detect the connection lost due to 
    // backpressure timeout before shutdown the datareader.
    if (end_with_publisher)
      ACE_OS::sleep (5);

    if (!CORBA::is_nil (participant.in ())) {
      participant->delete_contained_entities();
    }
    if (!CORBA::is_nil (dpf.in ())) {
      dpf->delete_participant(participant.in ());
    }
    TheTransportFactory->release();
    TheServiceParticipant->shutdown ();

  } catch (CORBA::Exception& e) {
    cerr << "Exception caught in main ():" << endl << e << endl;
    return 1;
  }

  if (actual_lost_sub_notification != expected_lost_sub_notification)
  {
    ACE_ERROR ((LM_ERROR, "(%P|%t)ERROR: on_subscription_lost called %d times "
      "and expected %d times\n", actual_lost_sub_notification,
      expected_lost_sub_notification));
    return 1;
  }

  return 0;
}
Ejemplo n.º 26
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
    {
      DDS::DomainParticipantFactory_var dpf;
      DDS::DomainParticipant_var participant;

      dpf = TheParticipantFactoryWithArgs(argc, argv);
      participant =
        dpf->create_participant(311,
                                PARTICIPANT_QOS_DEFAULT,
                                DDS::DomainParticipantListener::_nil(),
                                ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (participant.in ())) {
        cerr << "create_participant failed." << endl;
        return 1 ;
      }

      Messenger::MessageTypeSupportImpl* mts_servant =
        new Messenger::MessageTypeSupportImpl;

      if (DDS::RETCODE_OK != mts_servant->register_type(participant.in (),
                                                        ""))
      {
        cerr << "Failed to register the MessageTypeTypeSupport." << endl;
        exit(1);
      }

      CORBA::String_var type_name = mts_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 << "Failed to create_topic." << endl;
        exit(1);
      }

      // Create the first subscriber belongs to PARTITION A
      DDS::SubscriberQos sub_qos1;
      participant->get_default_subscriber_qos (sub_qos1);

      sub_qos1.partition.name.length (1);
      sub_qos1.partition.name[0] = PARTITION_A;

      DDS::Subscriber_var sub1 =
        participant->create_subscriber (sub_qos1,
                                        DDS::SubscriberListener::_nil(),
                                        ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (sub1.in ())) {
        cerr << "Failed to create_subscriber." << endl;
        exit(1);
      }

      // Create the second subscriber belongs to PARTITION B
      DDS::SubscriberQos sub_qos2;
      participant->get_default_subscriber_qos (sub_qos2);

      sub_qos2.partition.name.length (1);
      sub_qos2.partition.name[0] = PARTITION_B;

      DDS::Subscriber_var sub2 =
        participant->create_subscriber (sub_qos2,
                                        DDS::SubscriberListener::_nil(),
                                        ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (sub2.in ())) {
        cerr << "Failed to create_subscriber." << endl;
        exit(1);
      }

      DDS::DataReaderQos dr_qos;
      sub1->get_default_datareader_qos (dr_qos);

      // Create first DataReader with listener.
      DDS::DataReaderListener_var listener1 (new DataReaderListenerImpl);
      if (CORBA::is_nil (listener1.in ()))
      {
        cerr << "ERROR: listener1 is nil." << endl;
        exit(1);
      }

      DDS::DataReader_var dr1 =
        sub1->create_datareader (topic.in (),
                                dr_qos,
                                listener1.in (),
                                ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);

      // Create second DataReader with listener.
      DDS::DataReaderListener_var listener2 (new DataReaderListenerImpl);
      if (CORBA::is_nil (listener2.in ()))
      {
        cerr << "ERROR: listener2 is nil." << endl;
        exit(1);
      }

      DDS::DataReader_var dr2 =
        sub2->create_datareader (topic.in (),
                                dr_qos,
                                listener2.in (),
                                ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);

      if (CORBA::is_nil (dr1.in ()) || CORBA::is_nil (dr2.in ()))
      {
        cerr << "ERROR: create_datareader failed." << endl;
        exit(1);
      }

      DataReaderListenerImpl* listener_servant1 =
        dynamic_cast<DataReaderListenerImpl*>(listener1.in());
      DataReaderListenerImpl* listener_servant2 =
        dynamic_cast<DataReaderListenerImpl*>(listener2.in());

      int expected = 10;
      cout << "subscriber waiting for partition A completion" << endl;
      // Writer of PARTITION A -> Reader of PARTITION A
      while ( listener_servant1->num_reads() < expected) {
        ACE_OS::sleep (1);
      }

      cout << "subscriber waiting for partition B completion" << endl;
      // Writer switch from PARTITION A to B -> Reader of PARTITION B
      while ( listener_servant2->num_reads() < expected) {
        ACE_OS::sleep (1);
      }

      // ----------------------------------------------
      // Now switch first reader/subscriber from A to B
      // and it should be connected with DataWriter.
      cout << "subscriber switching from A to B partition" << endl;
      sub_qos1.partition.name[0] = PARTITION_B;

      if (sub1->set_qos (sub_qos1) != ::DDS::RETCODE_OK)
      {
        cerr << "ERROR: failed to set partition" << endl;
        exit (1);
      }

      // Continue receive 10 more messages each.
      expected = 20;

      cout << "subscriber waiting for 2nd partition B completion" << endl;
      while ( listener_servant1->num_reads() < expected) {
        ACE_OS::sleep (1);
      }

      while ( listener_servant2->num_reads() < expected) {
        ACE_OS::sleep (1);
      }

      if (listener_servant1->num_reads() > expected
        || listener_servant2->num_reads() > expected)
      {
        cerr << "ERROR: received more than excepted messages" << endl;
        exit (1);
      }

      // Now shutdown
      if (!CORBA::is_nil (participant.in ())) {
        participant->delete_contained_entities();
      }
      if (!CORBA::is_nil (dpf.in ())) {
        dpf->delete_participant(participant.in ());
      }

    }
  catch (CORBA::Exception& e)
    {
      cerr << "SUB: Exception caught in main ():" << endl << e << endl;
      return 1;
    }
  TheServiceParticipant->shutdown ();

  return 0;
}
Ejemplo n.º 27
0
bool ExampleSubscriber::init()
{
  this->msgs_count = 0;
  domain = DDS::DOMAIN_ID_DEFAULT;
  partition_name = "Default";
  topic_name = "big_chatter";

  /* Create Domain Participant Factory */
  this->dpf = DDS::DomainParticipantFactory::get_instance();
  checkHandle(dpf.in(), "DDS::DomainParticipantFactory::get_instance");

  /* Create Domain Participant */
  std::cout << "Creating domain participant in subscriber" << std::endl;
  this->participant = dpf->create_participant(
      domain,
      PARTICIPANT_QOS_DEFAULT,
      NULL,
      DDS::STATUS_MASK_NONE
  );
  checkHandle(participant.in(), "DDS::DomainParticipantFactory::create_participant");


  /* Create a default QoS for Topics */
  status = participant->get_default_topic_qos(default_topic_qos);
  checkStatus(status, "DDS::DomainParticipant::get_default_topic_qos");
  // default_topic_qos.reliability.kind = DDS::RELIABLE_RELIABILITY_QOS;
  default_topic_qos.reliability.kind = DDS::BEST_EFFORT_RELIABILITY_QOS;

  /* Register the LargeMessage Type */
  large_message_ts = new LargeMsg::LargeMessageTypeSupport();
  checkHandle(large_message_ts.in(), "new LargeMessageTypeSupport");
  this->large_message_type_name = large_message_ts->get_type_name();
  status = large_message_ts->register_type(participant.in(), large_message_type_name);
  checkStatus(status, "LargeMsg::LargeMessageTypeSupport::register_type");

  /* Setup the Subscribers's QoS */
  status = participant->get_default_subscriber_qos(sub_qos);
  checkStatus(status, "DDS::DomainParticipant::get_default_subscriber_qos");
  sub_qos.partition.name.length(1);
  sub_qos.partition.name[0] = partition_name;

  /* Create the subscriber */
  this->subscriber = participant->create_subscriber(
      sub_qos,
      NULL,
      DDS::STATUS_MASK_NONE
  );
  checkHandle(subscriber.in(), "DDS::DomainParticipant::create_subscriber");

  /* Create the Topic */
  this->large_message_topic = participant->create_topic(
      topic_name,
      large_message_type_name,
      default_topic_qos,
      NULL,
      DDS::STATUS_MASK_NONE
  );
  checkHandle(large_message_topic.in(), "DDS::DomainParticipant::create_topic(LargeMessage)");

  /* Create Topic specific DataReader */
  topic_reader = subscriber->create_datareader(
        large_message_topic.in(),
        DATAREADER_QOS_USE_TOPIC_QOS,
        NULL,
        DDS::STATUS_MASK_NONE
  );
  checkHandle(topic_reader.in(), "DDS::Subscriber::create_datareader");

  /* Narrow topic_reader down to LargeMessage specific DataReader */
  this->data_reader = LargeMsg::LargeMessageDataReader::_narrow(topic_reader.in());
  checkHandle(data_reader.in(), "LargeMsg::LargeMessageDataReader::_narrow");

  this->large_msg_seq = new LargeMsg::LargeMessageSeq();
  this->sample_info_seq = new DDS::SampleInfoSeq();

  std::cout << "Polling DataReader..." << std::endl;
  return true;
}