Esempio n. 1
0
DDS::DataReader_ptr
create_data_reader(DDS::DomainParticipant_ptr participant,
                   DDS::Subscriber_ptr subscriber,
                   const char* type_name,
                   const char* topic_name,
                   const DDS::DataReaderQos& dr_qos,
                   DDS::DataReaderListener_ptr drl)
{
  DDS::Topic_var topic =
    participant->create_topic(topic_name,
                              type_name,
                              TOPIC_QOS_DEFAULT,
                              DDS::TopicListener::_nil(),
                              OpenDDS::DCPS::DEFAULT_STATUS_MASK);
  if (CORBA::is_nil(topic)) {
    ACE_DEBUG((LM_DEBUG, "create_data_reader(): Failed to create topic, name = %s\n", topic_name));
  }
  DDS::DataReader_var reader =
    subscriber->create_datareader(topic.in(),
                                  dr_qos,
                                  drl,
                                  OpenDDS::DCPS::DEFAULT_STATUS_MASK);
  if (CORBA::is_nil(reader)) {
    ACE_DEBUG((LM_DEBUG, "create_data_reader(): Failed to create data reader\n"));
  }

  return reader._retn();
}
Esempio n. 2
0
DDS::ParticipantBuiltinTopicDataDataReaderImpl*
Spdp::part_bit()
{
  if (!bit_subscriber_.in())
    return 0;

  DDS::DataReader_var d =
    bit_subscriber_->lookup_datareader(DCPS::BUILT_IN_PARTICIPANT_TOPIC);
  return dynamic_cast<DDS::ParticipantBuiltinTopicDataDataReaderImpl*>(d.in());
}
Esempio n. 3
0
int ACE_TMAIN(int argc, ACE_TCHAR** argv)
{
  bool complete = false;
  try {
    OpenDDS::Model::Application application(argc, argv);
    MessengerMC::DefaultMessengerMCType model(application, argc, argv);

    using OpenDDS::Model::MessengerMC::Elements;

    DDS::DataReader_var reader = model.reader( Elements::DataReaders::reader);

    DDS::DataReaderListener_var listener(new ReaderListener(complete));
    reader->set_listener( listener.in(), OpenDDS::DCPS::DEFAULT_STATUS_MASK);

    // START OF EXISTING MESSENGER EXAMPLE CODE

    data1::MessageDataReader_var reader_i =
      data1::MessageDataReader::_narrow(reader);

    if (CORBA::is_nil(reader_i.in())) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("ERROR: %N:%l: main() -")
                        ACE_TEXT(" _narrow failed!\n")),
                       -1);
    }

    ACE_OS::sleep(2);

    std::cout << "sub signaling ready" << std::endl;
    // Signal readiness to publisher
    FileSystemSignal(1).signal();

    // END OF EXISTING MESSENGER EXAMPLE CODE

  } catch (const CORBA::Exception& e) {
    e._tao_print_exception("Exception caught in main():");
    return -1;

  } catch( const std::exception& ex) {
    ACE_ERROR_RETURN((LM_ERROR,
                      ACE_TEXT("(%P|%t) ERROR: %N:%l: main() -")
                      ACE_TEXT(" Exception caught: %C\n"),
                      ex.what()),
                     -1);
  }

  ACE_OS::sleep(5);

  std::cout << "sub exiting" << std::endl;
  return 0;
}
Esempio n. 4
0
int ACE_TMAIN(int argc, ACE_TCHAR** argv)
{
  try {
    OpenDDS::Model::Application application(argc, argv);
    data1::PolicyLib::DefaultPolicyLibType model(application, argc, argv);

    using OpenDDS::Model::data1::PolicyLib::Elements;

    DDS::DataReader_var reader = model.reader( Elements::DataReaders::reader);

    ACE_SYNCH_MUTEX lock;
    ACE_Condition<ACE_SYNCH_MUTEX> condition(lock);
    OpenDDS::Model::ReaderCondSync rcs(reader, condition);
    DDS::DataReaderListener_var listener(new ReaderListener(rcs));
    reader->set_listener( listener.in(), OpenDDS::DCPS::DEFAULT_STATUS_MASK);

    // Call on_data_available in case there are samples which are waiting
    listener->on_data_available(reader);

    // START OF EXISTING MESSENGER EXAMPLE CODE

    data1::MessageDataReader_var reader_i =
      data1::MessageDataReader::_narrow(reader);

    if (CORBA::is_nil(reader_i.in())) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("ERROR: %N:%l: main() -")
                        ACE_TEXT(" _narrow failed!\n")),
                       -1);
    }

    // Block until Publisher completes
    OpenDDS::Model::ReaderSync rs(reader);

    // END OF EXISTING MESSENGER EXAMPLE CODE

  } catch (const CORBA::Exception& e) {
    e._tao_print_exception("Exception caught in main():");
    return -1;

  } catch( const std::exception& ex) {
    ACE_ERROR_RETURN((LM_ERROR,
                      ACE_TEXT("(%P|%t) ERROR: %N:%l: main() -")
                      ACE_TEXT(" Exception caught: %C\n"),
                      ex.what()),
                     -1);
  }

  return 0;
}
Esempio n. 5
0
int ACE_TMAIN(int argc, ACE_TCHAR** argv)
{
  bool disposed = false;
  try {
    std::cout << "subscriber running" << std::endl;
    OpenDDS::Model::Application application(argc, argv);
    ExchangeLib::DefaultExchangeType model(application, argc, argv);

    using OpenDDS::Model::ExchangeLib::Elements;

    DDS::TopicDescription_var tdv(model.topic(Elements::Participants::FeedConsumption,
                                             Elements::Topics::ExchangeLib__Trades));
    DDS::TopicDescription_var qdv(model.topic(Elements::Participants::FeedConsumption,
                                             Elements::Topics::ExchangeLib__Quotes));
    DDS::DataReader_var reader = model.reader(Elements::DataReaders::MatchReader);

    DDS::DataReaderListener_var listener(new ReaderListener(disposed));
    reader->set_listener( listener.in(), OpenDDS::DCPS::DEFAULT_STATUS_MASK);

    // START OF EXISTING MESSENGER EXAMPLE CODE

    TMQDataReader_var reader_i = TMQDataReader::_narrow(reader);

    if (CORBA::is_nil(reader_i.in())) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("ERROR: %N:%l: main() -")
                        ACE_TEXT(" _narrow failed!\n")),
                       -1);
    }

    while (!disposed) {
      ACE_OS::sleep(1);
    }
    // END OF EXISTING MESSENGER EXAMPLE CODE

  } catch (const CORBA::Exception& e) {
    e._tao_print_exception("Exception caught in main():");
    return -1;

  } catch( const std::exception& ex) {
    ACE_ERROR_RETURN((LM_ERROR,
                      ACE_TEXT("(%P|%t) ERROR: %N:%l: main() -")
                      ACE_TEXT(" Exception caught: %C\n"),
                      ex.what()),
                     -1);
  }

  std::cout << "subscriber exiting" << std::endl;
  return 0;
}
Esempio n. 6
0
int
OpenDDS::Model::ReaderSync::wait_unmatch(const DDS::DataReader_var& reader,
                                         unsigned int num_writers)
{
  DDS::ReturnCode_t stat;
  DDS::StatusCondition_var condition = reader->get_statuscondition();
  condition->set_enabled_statuses(DDS::SUBSCRIPTION_MATCHED_STATUS);
  DDS::WaitSet_var ws = new DDS::WaitSet;
  ws->attach_condition(condition);
  DDS::ConditionSeq conditions;
  DDS::SubscriptionMatchedStatus ms = { 0, 0, 0, 0, 0 };
  DDS::Duration_t timeout = { 1, 0 };
  do {
    if (DCPS_debug_level > 4) {
      ACE_DEBUG((LM_NOTICE, ACE_TEXT("ReaderSync: sub checking unmatched\n")));
    }
    stat = reader->get_subscription_matched_status(ms);
    if (stat != DDS::RETCODE_OK) {
      ACE_ERROR_RETURN((
                  LM_ERROR,
                  ACE_TEXT("(%P|%t) ERROR: %N:%l: wait_unmatch() -")
                  ACE_TEXT(" get_subscription_matched_status failed!\n")),
                 -1);
    } else if (ms.current_count == 0 && (unsigned int)ms.total_count >= num_writers) {
      if (DCPS_debug_level > 4) {
        ACE_DEBUG((LM_NOTICE, ACE_TEXT("ReaderSync: sub match count %d total count %d\n"),
                                       ms.current_count, ms.total_count));
      }
      break;  // unmatched
    }
    if (DCPS_debug_level > 4) {
      ACE_DEBUG((LM_NOTICE, ACE_TEXT("ReaderSync: sub match count %d total count %d\n"),
                                     ms.current_count, ms.total_count));
    }
    // wait for a change
    stat = ws->wait(conditions, timeout);
    if ((stat != DDS::RETCODE_OK) && (stat != DDS::RETCODE_TIMEOUT)) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("(%P|%t) ERROR: %N:%l: wait_unmatch() -")
                        ACE_TEXT(" wait failed!\n")),
                       -1);
    }
  } while (true);
  ws->detach_condition(condition);
  if (DCPS_debug_level > 4) {
    ACE_DEBUG((LM_NOTICE, ACE_TEXT("ReaderSync: sub unmatched\n")));
  }
  return 0;
}
void
OpenDDS_Subscription_Manager::remove_topic (const Topic_Manager & topic)
{
  // Create a modifiable copy of the Topic_Manager
  Topic_Manager tm (topic);

  // first find and remove associated data writer
  DDS::DataReader_var dr =
    sub_->lookup_datareader (tm.name ().c_str ());

  sub_->delete_datareader (dr.in ());

  // use topic manager to create the topic
  tm.delete_topic (dm_);
}
Esempio n. 8
0
int ACE_TMAIN(int argc, ACE_TCHAR** argv)
{
  try {
    OpenDDS::Model::Application application(argc, argv);
    CfTopicLib::DefaultCfTopicType model(application, argc, argv);

    using OpenDDS::Model::CfTopicLib::Elements;

    DDS::DataReader_var reader = model.reader( Elements::DataReaders::reader);

    DDS::DataReaderListener_var listener(new ReaderListener);
    reader->set_listener( listener.in(), OpenDDS::DCPS::DEFAULT_STATUS_MASK);

    // START OF EXISTING MESSENGER EXAMPLE CODE

    data1::MessageDataReader_var reader_i =
      data1::MessageDataReader::_narrow(reader);

    if (CORBA::is_nil(reader_i.in())) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("ERROR: %N:%l: main() -")
                        ACE_TEXT(" _narrow failed!\n")),
                       -1);
    }

    OpenDDS::Model::ReaderSync rs(reader);

    // END OF EXISTING MESSENGER EXAMPLE CODE

  } catch (const CORBA::Exception& e) {
    e._tao_print_exception("Exception caught in main():");
    return -1;

  } catch( const std::exception& ex) {
    ACE_ERROR_RETURN((LM_ERROR,
                      ACE_TEXT("(%P|%t) ERROR: %N:%l: main() -")
                      ACE_TEXT(" Exception caught: %C\n"),
                      ex.what()),
                     -1);
  }

  return 0;
}
Esempio 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(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;
}
Esempio n. 10
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;
}
Esempio n. 11
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try {
    // Initialize DomainParticipantFactory
    DDS::DomainParticipantFactory_var dpf =
      TheParticipantFactoryWithArgs(argc, argv);

    // Create DomainParticipant
    DDS::DomainParticipant_var participant =
      dpf->create_participant(42,
                              PARTICIPANT_QOS_DEFAULT,
                              0,
                              OpenDDS::DCPS::DEFAULT_STATUS_MASK);

    if (!participant) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("ERROR: %N:%l: main() -")
                        ACE_TEXT(" create_participant failed!\n")), -1);
    }

    // Register Type (Messenger::Message)
    Messenger::MessageTypeSupport_var ts =
      new Messenger::MessageTypeSupportImpl;

    if (ts->register_type(participant, "") != DDS::RETCODE_OK) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("ERROR: %N:%l: main() -")
                        ACE_TEXT(" register_type failed!\n")), -1);
    }

    // Create Topic (Movie Discussion List)
    CORBA::String_var type_name = ts->get_type_name();
    DDS::Topic_var topic =
      participant->create_topic("Movie Discussion List",
                                type_name,
                                TOPIC_QOS_DEFAULT,
                                0,
                                OpenDDS::DCPS::DEFAULT_STATUS_MASK);

    if (!topic) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("ERROR: %N:%l: main() -")
                        ACE_TEXT(" create_topic failed!\n")), -1);
    }

    // Create Subscriber
    DDS::Subscriber_var subscriber =
      participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT,
                                     0,
                                     OpenDDS::DCPS::DEFAULT_STATUS_MASK);

    if (!subscriber) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("ERROR: %N:%l: main() -")
                        ACE_TEXT(" create_subscriber failed!\n")), -1);
    }

    // Create DataReader
    DDS::DataReaderListener_var listener(new DataReaderListenerImpl);

    DDS::DataReader_var reader =
      subscriber->create_datareader(topic,
                             DATAREADER_QOS_DEFAULT,
                             listener,
                             OpenDDS::DCPS::DEFAULT_STATUS_MASK);

    if (!reader) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("ERROR: %N:%l: main() -")
                        ACE_TEXT(" create_datareader failed!\n")), -1);
    }

    Messenger::MessageDataReader_var reader_i =
      Messenger::MessageDataReader::_narrow(reader);

    if (!reader_i) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("ERROR: %N:%l: main() -")
                        ACE_TEXT(" _narrow failed!\n")),
                       -1);
    }

    // Block until Publisher completes
    DDS::StatusCondition_var condition = reader->get_statuscondition();
    condition->set_enabled_statuses(DDS::SUBSCRIPTION_MATCHED_STATUS);

    DDS::WaitSet_var ws = new DDS::WaitSet;
    ws->attach_condition(condition);

    while (true) {
      DDS::SubscriptionMatchedStatus matches;
      if (reader->get_subscription_matched_status(matches) != DDS::RETCODE_OK) {
        ACE_ERROR_RETURN((LM_ERROR,
                          ACE_TEXT("ERROR: %N:%l: main() -")
                          ACE_TEXT(" get_subscription_matched_status failed!\n")), -1);
      }

      if (matches.current_count == 0 && matches.total_count > 0) {
        break;
      }

      DDS::ConditionSeq conditions;
      DDS::Duration_t timeout = { 60, 0 };
      if (ws->wait(conditions, timeout) != DDS::RETCODE_OK) {
        ACE_ERROR_RETURN((LM_ERROR,
                          ACE_TEXT("ERROR: %N:%l: main() -")
                          ACE_TEXT(" wait failed!\n")), -1);
      }
    }

    ws->detach_condition(condition);

    // Clean-up!
    participant->delete_contained_entities();
    dpf->delete_participant(participant);

    TheServiceParticipant->shutdown();

  } catch (const CORBA::Exception& e) {
    e._tao_print_exception("Exception caught in main():");
    return -1;
  }

  return 0;
}
Esempio 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(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;
}
Esempio n. 13
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;
}
Esempio n. 14
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  DDS::DomainParticipantFactory_var dpf = DDS::DomainParticipantFactory::_nil();
  DDS::DomainParticipant_var participant = DDS::DomainParticipant::_nil();

  try 
  {
     QuantLibAddinCpp::initializeAddin();

     boost::gregorian::date date ( boost::gregorian::from_undelimited_string( "20111019" ) );

     long evaluationDate = QuantLib::Date( date.day(), QuantLib::Month(date.month().as_number()), date.year() ).serialNumber(); 

     QuantLibAddinCpp::qlSettingsSetEvaluationDate(evaluationDate, OH_NULL);

     std::string ticker;

     // Initialize, and create a DomainParticipant
     dpf = TheParticipantFactoryWithArgs(argc, argv);
     
     qldds_utils::BasicDomainParticipant participant( dpf, EQUITY_OPTIONS_DOMAIN_ID );
     participant.createPublisher();
     participant.createSubscriber();
     DDS::DomainParticipant_var dp = participant.getDomainParticipant();  

 
     ACE_Get_Opt cmd_opts( argc, argv, ":s:" );
  
     int option;
  
     while ( (option = cmd_opts()) != EOF )
     {
       switch( option )
       {
         case 's' :
           ticker = cmd_opts.opt_arg();
           break;
       }
     }


     // Topics
     // setting up qlBlackConstantVols Topic
     DDS::Topic_var ql_black_constant_vols_topic = participant.createTopicAndRegisterType
        < qlBlackConstantVolsTypeSupport_var, qlBlackConstantVolsTypeSupportImpl >
         ( QL_BLACK_CONSTANT_VOLS_TOPIC_NAME );

     // setting up qlGeneralizedBlackScholesProcesses Topic
     DDS::Topic_var ql_generalized_black_scholes_processes_topic = participant.createTopicAndRegisterType
        < qlGeneralizedBlackScholesProcessesTypeSupport_var, qlGeneralizedBlackScholesProcessesTypeSupportImpl >
         ( QL_GENERALIZED_BLACK_SCHOLES_PROCESSES_TOPIC_NAME );

     // setting up qlStrikedTypePayoff Topic
     DDS::Topic_var ql_striked_type_payoffs_topic = participant.createTopicAndRegisterType
       < qlStrikedTypePayoffsTypeSupport_var, qlStrikedTypePayoffsTypeSupportImpl >
         ( QL_STRIKED_TYPE_PAYOFFS_TOPIC_NAME );

     // setting up qlEuropeanExercises Topic
     DDS::Topic_var ql_european_exercises_topic = participant.createTopicAndRegisterType
        < qlEuropeanExercisesTypeSupport_var, qlEuropeanExercisesTypeSupportImpl >
         ( QL_EUROPEAN_EXERCISES_TOPIC_NAME ); 

     StraddleSetupTypeSupport_var ts_res = new StraddleSetupTypeSupportImpl;
     if ( ts_res->register_type(dp, "") != DDS::RETCODE_OK )
     {
       std::cout << "Registration of the Topic FAILED!!!!" << std::endl;
     }

     CORBA::String_var type_name = ts_res->get_type_name();
     std::cout << "Type Name : " << type_name << std::endl; 

     std::stringstream multi_topic_select;

     multi_topic_select << "SELECT ticker, putVols, callVols, putPayoffs, callPayoffs, process, exercises FROM "<<
                          QL_BLACK_CONSTANT_VOLS_TOPIC_NAME << " NATURAL JOIN " << 
                          QL_GENERALIZED_BLACK_SCHOLES_PROCESSES_TOPIC_NAME << " NATURAL JOIN " <<
                          QL_STRIKED_TYPE_PAYOFFS_TOPIC_NAME << " NATURAL JOIN " << 
                          QL_EUROPEAN_EXERCISES_TOPIC_NAME << " WHERE ticker = '" << ticker << "'";

     std::cout << multi_topic_select.str() << std::endl; 

     DDS::MultiTopic_var mt = dp->create_multitopic("MyMultiTopic", type_name, multi_topic_select.str().c_str(), DDS::StringSeq()); 

     if ( CORBA::is_nil( mt ) ) 
       std::cout << "MultiTopic Subscribtion failed.!!!!" << mt << std::endl;

     DDS::Subscriber_var sub = participant.getSubscriber();
     std::cout << "Creating Data Reader"<< std::endl;
     DDS::DataReader_var dr = sub->create_datareader(mt, DATAREADER_QOS_DEFAULT, 0, ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
     std::cout << "Done..."<< std::endl;

     DDS::WaitSet_var ws = new DDS::WaitSet;
     DDS::ReadCondition_var rc = dr->create_readcondition( DDS::ANY_SAMPLE_STATE, DDS::ANY_VIEW_STATE, DDS::ANY_INSTANCE_STATE);
     ws->attach_condition(rc);
     DDS::Duration_t infinite = { DDS::DURATION_INFINITE_SEC, DDS::DURATION_INFINITE_NSEC};
     DDS::ConditionSeq active;
     int ret = ws->wait(active, infinite);
     if (ret != DDS::RETCODE_OK) return false;
     ws->detach_condition(rc);

     // setting up topic for Straddles 
     DDS::Topic_var straddles_topic = participant.createTopicAndRegisterType
        < StraddlesTypeSupport_var, StraddlesTypeSupportImpl >
         ( STRADDLES_TOPIC_NAME );

     StraddlesDataWriter_var straddles_dw = participant.createDataWriter
       < StraddlesDataWriter_var, StraddlesDataWriter >
         ( straddles_topic );

     
      int calculation_performed = 0;

      do {
       StraddleSetupDataReader_var res_dr = StraddleSetupDataReader::_narrow(dr);
       StraddleSetupSeq data;
       DDS::SampleInfoSeq info;

       int ret = res_dr->take_w_condition(data, info, DDS::LENGTH_UNLIMITED, rc);

       if (ret == DDS::RETCODE_OK) 
       {
         qlBlackConstantVolMatrix& putVols = data[0].putVols;
         qlStrikedTypePayoffSeq& putPayoffs = data[0].putPayoffs;

         qlBlackConstantVolMatrix& callVols = data[0].callVols;
         qlStrikedTypePayoffSeq& callPayoffs = data[0].callPayoffs;

         processes::qlGeneralizedBlackScholesProcess& process = data[0].process;
         qlEuropeanExerciseSeq& exercises = data[0].exercises;

         Straddles straddles;
         straddles.ticker = CORBA::string_dup( ticker.c_str() );
         straddles.underlying = data[0].process.Underlying; 

         int strike_count = putPayoffs.length() + callPayoffs.length();
         int exercises_count = exercises.length();

         straddles.options.length( strike_count * exercises_count );

         int priced_options = 0;

         price( ticker, putVols, putPayoffs, process, exercises, straddles, priced_options );
         price( ticker, callVols, callPayoffs, process, exercises, straddles, priced_options );

         ACE_DEBUG( (LM_INFO, "(%T|%P|%t) Publishing Straddles for ticker : %s trading @%f\n", ticker.c_str(), data[0].process.Underlying )  );

         int ret = straddles_dw->write( straddles, DDS::HANDLE_NIL );
         if (ret != DDS::RETCODE_OK) {
             ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: Publishing Straddles for ticker : %s failed %d.\n"), ticker.c_str(), ret));
         }

         calculation_performed++;
       } 
     } while ( calculation_performed < 30 );

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

  TheServiceParticipant->shutdown(); 
    
  return 0;
}
Esempio n. 15
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;
}
Esempio n. 16
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;
}
Esempio n. 17
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;
}
Esempio n. 18
0
int
ACE_TMAIN(int argc, ACE_TCHAR** argv)
{
  parse_args(argc, argv);

  ACE_DEBUG((LM_INFO, ACE_TEXT("(%P|%t) -> SUBSCRIBER STARTED\n")));

  ::CORBA::Long sec = deadline_msec / 1000;
  ::CORBA::ULong remainder_msec = (deadline_msec - 1000*sec);
  ::CORBA::ULong nanosec = remainder_msec * 1000000;

  DDS::Duration_t const DEADLINE_PERIOD =
    {
      sec,
      nanosec
    };

  bool deadline_used = DEADLINE_PERIOD.sec > 0 || DEADLINE_PERIOD.nanosec > 0;

  try
  {
    DDS::DomainParticipantFactory_var dpf =
      TheParticipantFactoryWithArgs(argc, argv);

    SubscriberListenerImpl * subscriberListener =
      new SubscriberListenerImpl(received_samples, missed_samples);

    DDS::SubscriberListener_var subscriberListener_var = subscriberListener;

    // Create Participant
    DDS::DomainParticipant_var participant =
      dpf->create_participant(42,
                              PARTICIPANT_QOS_DEFAULT,
                              DDS::DomainParticipantListener::_nil(),
                              ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);

    if (CORBA::is_nil(participant.in()))
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l: main()")
                        ACE_TEXT(" create_participant failed!\n")), 1);

    ACE_Time_Value delay_between_cycles(0, delay_between_cycles_msec * 1000);

    bool expected_samples_received = false;
    int i = 0;

    do
      {
        ++i;

        ACE_DEBUG((LM_INFO, ACE_TEXT("(%P|%t) -> Subscriber cycle %d\n"), i));

        // Create Subscriber
        DDS::Subscriber_var subscriber =
          participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT,
                                         subscriberListener,
                                         ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);

        if (CORBA::is_nil(subscriber.in()))
          ACE_ERROR_RETURN((LM_ERROR,
                            ACE_TEXT("%N:%l: main()")
                            ACE_TEXT(" create_subscriber failed!\n")), 2);

        // Register Type (FooType)
        FooTypeSupport_var ts = new FooTypeSupportImpl;
        if (ts->register_type(participant.in(), "") != DDS::RETCODE_OK)
          ACE_ERROR_RETURN((LM_ERROR,
                            ACE_TEXT("%N:%l: main()")
                            ACE_TEXT(" register_type failed!\n")), 5);

        // Create Topic (FooTopic)
        DDS::Topic_var topic =
          participant->create_topic("FooTopic",
                                    ts->get_type_name(),
                                    TOPIC_QOS_DEFAULT,
                                    DDS::TopicListener::_nil(),
                                    ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);

        DDS::TopicDescription_ptr topic_used = topic.in();
        DDS::ContentFilteredTopic_ptr cft = 0;

        if (use_cft)
          {
            // Topic name must be unique.
            ACE_CString topic_name = "FooTopic-Filtered-" + toStr(i);
            cft =
              participant->create_contentfilteredtopic(topic_name.c_str(),
                                                       topic,
                                                       "key > 0",
                                                       DDS::StringSeq());
            if (CORBA::is_nil(cft))
              ACE_ERROR_RETURN((LM_ERROR,
                                ACE_TEXT("%N:%l: main()")
                                ACE_TEXT(" create_contentfilteredtopic failed!\n")), 8);

            topic_used = cft;
          }

        if (CORBA::is_nil(topic.in()))
          ACE_ERROR_RETURN((LM_ERROR,
                            ACE_TEXT("%N:%l: main()")
                            ACE_TEXT(" create_topic failed!\n")), 6);

        // Create DataReader

        DDS::DataReaderQos reader_qos;
        subscriber->get_default_datareader_qos(reader_qos);

        reader_qos.history.kind = DDS::KEEP_ALL_HISTORY_QOS;
        if (deadline_used)
          {
            reader_qos.deadline.period.sec     = DEADLINE_PERIOD.sec;
            reader_qos.deadline.period.nanosec = DEADLINE_PERIOD.nanosec;
          }

        DDS::DataReader_var reader =
          subscriber->create_datareader(topic_used,
                                        reader_qos,
                                        DDS::DataReaderListener::_nil(),
                                        ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);

        if (CORBA::is_nil(reader.in()))
          ACE_ERROR_RETURN((LM_ERROR,
                            ACE_TEXT("%N:%l: main()")
                            ACE_TEXT(" create_datareader failed!\n")), 7);


        ACE_Time_Value sample_count_sleep(0, sample_count_sleep_msec * 1000);
        std::size_t sample_count;
        std::size_t sample_count_start = subscriberListener->samples_processed();
        do
          {
            ACE_OS::sleep(sample_count_sleep);
            sample_count =
              subscriberListener->samples_processed();
            expected_samples_received = sample_count >= expected_samples;
            // ACE_DEBUG((LM_DEBUG, "(%P|%t) sample_count = %d\n", sample_count));
          }
        while (!expected_samples_received &&
               (sample_count - sample_count_start) < samples_per_cycle);

        subscriber->delete_datareader(reader.in());

        if (use_cft)
          CORBA::release(cft);

        participant->delete_subscriber(subscriber.in());

        ACE_OS::sleep(delay_between_cycles);
      }
    while (!expected_samples_received);

    participant->delete_contained_entities();
    dpf->delete_participant(participant.in());

    TheServiceParticipant->shutdown();

    ACE_DEBUG ((LM_INFO,
                ACE_TEXT("INFO: %d samples received\n"),
                subscriberListener->received_samples()));
    if (deadline_used)
      ACE_DEBUG ((LM_INFO,
                  ACE_TEXT("INFO: deadline missed %d times\n"),
                  subscriberListener->missed_samples()));

  }
  catch (const CORBA::Exception& e)
  {
    e._tao_print_exception("caught in main()");
    return 9;
  }

  ACE_DEBUG((LM_INFO, ACE_TEXT("(%P|%t) <- SUBSCRIBER FINISHED\n")));

  return 0;
}
Esempio n. 19
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  int status = EXIT_SUCCESS;
  try {
    // Initialize DomainParticipantFactory
    DDS::DomainParticipantFactory_var dpf =
      TheParticipantFactoryWithArgs(argc, argv);

    bool reliable = true;
    int num_messages_expected = 40;
    parse_args(argc, argv, reliable, num_messages_expected);

    // handle test performance issue on one platform
#if defined (sun)
    const char* udpTransName = "udp";
    OpenDDS::DCPS::TransportInst_rch inst = OpenDDS::DCPS::TransportRegistry::instance()->get_inst(udpTransName);
    if (inst != 0) {
      OpenDDS::DCPS::UdpInst_rch udp_inst = OpenDDS::DCPS::dynamic_rchandle_cast<OpenDDS::DCPS::UdpInst>(inst);
      if (udp_inst == 0) {
        ACE_ERROR_RETURN((LM_ERROR,
                          ACE_TEXT("%N:%l main()")
                          ACE_TEXT(" ERROR: retrieving transport config for: %C failed!\n"),
                          udpTransName), -1);
      }
      udp_inst->rcv_buffer_size_ = 0x40000;
    }
#endif

    // Create DomainParticipant
    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())) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l main()")
                        ACE_TEXT(" ERROR: create_participant() failed!\n")), -1);
    }

    // Register Type (Messenger::Message)
    Messenger::MessageTypeSupport_var ts =
      new Messenger::MessageTypeSupportImpl();

    if (ts->register_type(participant.in(), "") != DDS::RETCODE_OK) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l main()")
                        ACE_TEXT(" ERROR: register_type() failed!\n")), -1);
    }

    // Create Topic (Movie Discussion List)
    CORBA::String_var type_name = ts->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())) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l main()")
                        ACE_TEXT(" ERROR: create_topic() failed!\n")), -1);
    }

    // Create 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())) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l main()")
                        ACE_TEXT(" ERROR: create_subscriber() failed!\n")), -1);
    }

    // Create DataReader
    DataReaderListenerImpl* listener_svt = new DataReaderListenerImpl;
    DDS::DataReaderListener_var listener(listener_svt);

    DDS::DataReaderQos qos;
    sub->get_default_datareader_qos(qos);
    qos.liveliness.kind = DDS::AUTOMATIC_LIVELINESS_QOS;
    qos.liveliness.lease_duration.sec = 10;
    qos.liveliness.lease_duration.nanosec = 0;
    qos.history.kind = DDS::KEEP_ALL_HISTORY_QOS;
    qos.durability.kind = DDS::TRANSIENT_LOCAL_DURABILITY_QOS;

    if (reliable) {
      qos.reliability.kind = DDS::RELIABLE_RELIABILITY_QOS;
    }

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

    if (CORBA::is_nil(reader.in())) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l main()")
                        ACE_TEXT(" ERROR: create_datareader() failed!\n")), -1);
    }

    for (int delay = 0; listener_svt->num_samples() != num_messages_expected
         && delay < 60; ++delay) {
      ACE_OS::sleep(1);
    }

    const long received = listener_svt->num_samples();
    const bool data_consistent = reliable ? listener_svt->data_consistent() : true;
    std::string error = "";
    bool show_data_loss = true;

    if (reliable && data_consistent && received < num_messages_expected) {
      error = "ERROR: ";
      status = EXIT_FAILURE;
    }
    else if (!data_consistent) {
      status = EXIT_FAILURE;
      show_data_loss = false;
    }

    if (show_data_loss && num_messages_expected) {
      const unsigned int missed_msgs = (num_messages_expected - received);
      const unsigned int percent = (missed_msgs * 100) / num_messages_expected;

      std::cout << error
                << "data loss == " << percent << "% (" << received << "/"
                << num_messages_expected << " received)\n";
    }

    // Clean-up!
    ACE_DEBUG((LM_DEBUG, "Subscriber delete contained entities\n"));
    participant->delete_contained_entities();
    ACE_DEBUG((LM_DEBUG, "Subscriber delete participant\n"));
    dpf->delete_participant(participant);

    ACE_DEBUG((LM_DEBUG, "Subscriber shutdown\n"));
    TheServiceParticipant->shutdown();
    ACE_DEBUG((LM_DEBUG, "Subscriber wait for thread manager\n"));
    ACE_Thread_Manager::instance()->wait();

    ACE_DEBUG((LM_DEBUG, "Subscriber vars going out of scope\n"));
  } catch (const CORBA::Exception& e) {
    e._tao_print_exception("Exception caught in main():");
    status = EXIT_FAILURE;
  }

  ACE_DEBUG((LM_DEBUG, "Subscriber exiting with status=%d\n", status));
  return status;
}
Esempio n. 20
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;
}
Esempio n. 21
0
bool run_multitopic_test(const Publisher_var& pub, const Subscriber_var& sub)
{
  DomainParticipant_var sub_dp = sub->get_participant();

  // Writer-side setup

  Writer<LocationInfo> location(pub, "Location", sub_dp);
  Writer<PlanInfo> flightplan(pub, "FlightPlan", sub_dp);
  Writer<MoreInfo> more(pub, "More", sub_dp);
  Writer<UnrelatedInfo> unrelated(pub, "Unrelated", sub_dp);
  MoreInfoDataWriter_var midw = MoreInfoDataWriter::_narrow(more.dw_);

  // Reader-side setup

  ResultingTypeSupport_var ts_res = new ResultingTypeSupportImpl;
  check(ts_res->register_type(sub_dp, ""));
  CORBA::String_var type_name = ts_res->get_type_name();
  MoreInfo mi;
  DDS::DataReader_var dr;

  for (int i = 0; i < N_ITERATIONS; ++i) {

    MultiTopic_var mt = sub_dp->create_multitopic("MyMultiTopic", type_name,
      "SELECT flight_name, x, y, z AS height, more, misc "
      "FROM Location NATURAL JOIN FlightPlan NATURAL JOIN More NATURAL JOIN "
      "Unrelated WHERE height < 1000 AND x<23", StringSeq());
    if (!mt) return false;
    dr = sub->create_datareader(mt, DATAREADER_QOS_DEFAULT,
                                0, DEFAULT_STATUS_MASK);

    // Write samples (Location)

    waitForMatch(location.dw_);
    LocationInfoDataWriter_var locdw =
      LocationInfoDataWriter::_narrow(location.dw_);
    LocationInfo sample = {100, 97, 23, 2, 3}; // filtered out (x < 23)
    ReturnCode_t ret = locdw->write(sample, HANDLE_NIL);
    if (ret != RETCODE_OK) return false;
    LocationInfo sample2 = {100, 96, 1, 2, 3000}; // filtered out (height < 1000)
    ret = locdw->write(sample2, HANDLE_NIL);
    if (ret != RETCODE_OK) return false;
    LocationInfo sample3 = {100, 99, 1, 2, 3};
    ret = locdw->write(sample3, HANDLE_NIL);
    if (ret != RETCODE_OK) return false;
    LocationInfo sample3_5 = {100, 98, 4, 5, 6};
    ret = locdw->write(sample3_5, HANDLE_NIL);
    if (ret != RETCODE_OK) return false;

    // Write samples (FlightPlan)

    waitForMatch(flightplan.dw_);
    PlanInfoDataWriter_var pidw = PlanInfoDataWriter::_narrow(flightplan.dw_);
    PlanInfo sample4;
    sample4.flight_id1 = 100;
    sample4.flight_id2 = 99;
    sample4.flight_name = "Flight 100-99";
    sample4.tailno = "N12345";
    ret = pidw->write(sample4, HANDLE_NIL);
    if (ret != RETCODE_OK) return false;
    PlanInfo sample4_1(sample4);
    sample4_1.flight_id2 = 97;
    sample4_1.flight_name = "Flight 100-97";
    ret = pidw->write(sample4_1, HANDLE_NIL);
    if (ret != RETCODE_OK) return false;
    PlanInfo sample4_2(sample4);
    sample4_2.flight_id2 = 96;
    sample4_2.flight_name = "Flight 100-96";
    ret = pidw->write(sample4_2, HANDLE_NIL);
    if (ret != RETCODE_OK) return false;

    // Write samples (More)

    waitForMatch(more.dw_);
    mi.flight_id1 = 12345;
    mi.more = "Shouldn't see this";
    ret = midw->write(mi, HANDLE_NIL);
    if (ret != RETCODE_OK) return false;
    mi.flight_id1 = 100;
    mi.more = "Extra info for all flights with id1 == 100";
    ret = midw->write(mi, HANDLE_NIL);
    if (ret != RETCODE_OK) return false;

    // Write samples (Unrelated)

    waitForMatch(unrelated.dw_);
    UnrelatedInfoDataWriter_var uidw =
      UnrelatedInfoDataWriter::_narrow(unrelated.dw_);
    UnrelatedInfo ui;
    ui.misc = "Misc";
    ret = uidw->write(ui, HANDLE_NIL);
    if (ret != RETCODE_OK) return false;

    // Read resulting samples

    WaitSet_var ws = new WaitSet;
    ReadCondition_var rc = dr->create_readcondition(ANY_SAMPLE_STATE,
      ANY_VIEW_STATE, ANY_INSTANCE_STATE);
    ws->attach_condition(rc);
    Duration_t infinite = {DURATION_INFINITE_SEC, DURATION_INFINITE_NSEC};
    ConditionSeq active;
    ret = ws->wait(active, infinite);
    if (ret != RETCODE_OK) return false;
    ws->detach_condition(rc);
    ResultingDataReader_var res_dr = ResultingDataReader::_narrow(dr);
    ResultingSeq data;
    SampleInfoSeq info;
    ret = res_dr->take_w_condition(data, info, LENGTH_UNLIMITED, rc);
    if (ret != RETCODE_OK) return false;
    if (data.length() > 1 || !info[0].valid_data) return false;
    std::cout << "Received: " << data[0].flight_id1 << '-' <<
      data[0].flight_id2 << " \"" << data[0].flight_name << "\" " << data[0].x <<
      " " << data[0].y << " " << data[0].height << " \"" << data[0].more <<
      "\" \"" << data[0].misc << "\"" << std::endl;
    if (data[0].flight_id1 != sample4.flight_id1 || data[0].flight_id2 !=
        sample4.flight_id2 || strcmp(data[0].flight_name, sample4.flight_name) ||
        data[0].x != sample3.x || data[0].y != sample3.y ||
        data[0].height != sample3.z || strcmp(data[0].more, mi.more) ||
        strcmp(data[0].misc, ui.misc)) {
      return false;
    }
    // Check return get_key_value
    Resulting resulting_value;
    ret = res_dr->get_key_value(resulting_value, DDS::HANDLE_NIL);
    if (ret != RETCODE_BAD_PARAMETER) return false;

    data.length(0);
    info.length(0);
    ret = res_dr->read_w_condition(data, info, LENGTH_UNLIMITED, rc);
    dr->delete_readcondition(rc);
    if (ret != RETCODE_NO_DATA) return false;

    // Reader cleanup
    if (i != N_ITERATIONS - 1) {
      sub->delete_datareader(dr);
      waitForMatch(location.dw_, 0);
      waitForMatch(flightplan.dw_, 0);
      waitForMatch(more.dw_, 0);
      waitForMatch(unrelated.dw_, 0);
      sub_dp->delete_multitopic(mt);
    }
  }

  // Dispose

  ReturnCode_t ret = midw->dispose(mi, HANDLE_NIL);
  if (ret != RETCODE_OK) return false;
  ReadCondition_var rc =
    dr->create_readcondition(ANY_SAMPLE_STATE, ANY_VIEW_STATE,
                             NOT_ALIVE_DISPOSED_INSTANCE_STATE);
  WaitSet_var ws = new WaitSet;
  ws->attach_condition(rc);
  const Duration_t infinite = {DURATION_INFINITE_SEC, DURATION_INFINITE_NSEC};
  ConditionSeq active;
  ret = ws->wait(active, infinite);
  if (ret != RETCODE_OK) return false;
  ws->detach_condition(rc);
  ResultingDataReader_var res_dr = ResultingDataReader::_narrow(dr);
  ResultingSeq data;
  SampleInfoSeq info;
  ret = res_dr->read_w_condition(data, info, LENGTH_UNLIMITED, rc);
  dr->delete_readcondition(rc);
  if (ret != RETCODE_OK) return false;
  if (info[0].valid_data ||
      info[0].instance_state != NOT_ALIVE_DISPOSED_INSTANCE_STATE) return false;
  return true;
}
int do_reader(DDS::DomainParticipant_var participant, DDS::Topic_var topic, bool toggle)
{
  // Create Subscriber
  DDS::Subscriber_var subscriber =
    participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT,
                                   0,
                                   OpenDDS::DCPS::DEFAULT_STATUS_MASK);

  if (!subscriber) {
    ACE_ERROR_RETURN((LM_ERROR,
                      ACE_TEXT("ERROR: %N:%l: do_reader() -")
                      ACE_TEXT(" create_subscriber failed!\n")), -1);
  }

  DDS::DataReaderQos qos;
  subscriber->get_default_datareader_qos(qos);
  qos.user_data.value.length(3);
  qos.user_data.value[0] = 0;
  qos.user_data.value[1] = 0;
  qos.user_data.value[2] = 0;
  qos.reliability.kind = DDS::RELIABLE_RELIABILITY_QOS;

  if (toggle) {
    ACE_DEBUG((LM_DEBUG, "Creating reader\n"));
    DDS::DataReader_var reader =
      subscriber->create_datareader(topic,
                                    qos,
                                    0,
                                    OpenDDS::DCPS::DEFAULT_STATUS_MASK);

    if (!reader) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("ERROR: %N:%l: do_reader() -")
                        ACE_TEXT(" create_datareader failed!\n")), -1);
    }

    ACE_OS::sleep(SLEEP_SHORT);
    // Go away.
    ACE_DEBUG((LM_DEBUG, "Deleting reader\n"));
    subscriber->delete_datareader(reader);
    ACE_OS::sleep(SLEEP_SHORT);
    // Come back.
    ACE_DEBUG((LM_DEBUG, "Creating reader\n"));
    reader = subscriber->create_datareader(topic,
                                           qos,
                                           0,
                                           OpenDDS::DCPS::DEFAULT_STATUS_MASK);
    ACE_OS::sleep(SLEEP_SHORT);
    return 0;
  } else {
    struct Listener : public DDS::DataReaderListener {
      size_t found, lost;

      Listener() : found(0), lost(0) { }

      virtual void
      on_requested_deadline_missed (::DDS::DataReader_ptr,
                                    const ::DDS::RequestedDeadlineMissedStatus &) { }

      virtual void
      on_requested_incompatible_qos (::DDS::DataReader_ptr,
                                     const ::DDS::RequestedIncompatibleQosStatus &) { }

      virtual void
      on_sample_rejected (::DDS::DataReader_ptr,
                          const ::DDS::SampleRejectedStatus &) { }

      virtual void
      on_liveliness_changed (::DDS::DataReader_ptr,
                             const ::DDS::LivelinessChangedStatus &) { }

      virtual void
      on_data_available (::DDS::DataReader_ptr) { }

      virtual void
      on_subscription_matched (::DDS::DataReader_ptr,
                               const ::DDS::SubscriptionMatchedStatus & status) {
        if (status.current_count_change > 0) {
          ACE_DEBUG((LM_DEBUG, "Reader found writer\n"));
          ++found;
        }
        if (status.current_count_change < 0) {
          ACE_DEBUG((LM_DEBUG, "Reader lost writer\n"));
          ++lost;
        }
      }

      virtual void
      on_sample_lost (::DDS::DataReader_ptr,
                      const ::DDS::SampleLostStatus &) { }
    } listener;

    // Create DataReader
    DDS::DataReader_var reader =
      subscriber->create_datareader(topic,
                                    qos,
                                    &listener,
                                    OpenDDS::DCPS::DEFAULT_STATUS_MASK);

    if (!reader) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("ERROR: %N:%l: do_reader() -")
                        ACE_TEXT(" create_datareader failed!\n")),
                       -1);
    }

    ACE_OS::sleep(SLEEP_LONG);

    if (listener.found == 2 && listener.lost == 1) {
      reader->set_listener(0, OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      return 0;
    }
    return -1;
  }
}
Esempio n. 23
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;
}
Esempio n. 24
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;
}
Esempio n. 25
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;
}
Esempio n. 26
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;
}
Esempio n. 27
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;
}
Esempio n. 28
0
int ACE_TMAIN(int argc, ACE_TCHAR** argv)
{
  try {
    OpenDDS::Model::Application application(argc, argv);
    SubQos::DefaultSubQosType model(application, argc, argv);

    using OpenDDS::Model::SubQos::Elements;

    DDS::DataReader_var reader = model.reader( Elements::DataReaders::reader);
    DDS::Subscriber_var subscriber = reader->get_subscriber();

    ACE_SYNCH_MUTEX lock;
    ACE_Condition<ACE_SYNCH_MUTEX> condition(lock);
    OpenDDS::Model::ReaderCondSync rcs(reader, condition);
    DDS::DataReaderListener_var listener(new ReaderListener(rcs));
    reader->set_listener( listener.in(), OpenDDS::DCPS::DEFAULT_STATUS_MASK);

    // Call on_data_available in case there are samples which are waiting
    listener->on_data_available(reader);

    // START OF EXISTING MESSENGER EXAMPLE CODE

    MessageDataReader_var reader_i =
      MessageDataReader::_narrow(reader);

    if (CORBA::is_nil(reader_i.in())) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("ERROR: %N:%l: main() -")
                        ACE_TEXT(" _narrow failed!\n")),
                       -1);
    }

    DDS::SubscriberQos sub_qos;

    if (subscriber->get_qos(sub_qos) != 0) {
        ACE_ERROR_RETURN((LM_ERROR,
                          ACE_TEXT("(%P|%t) ERROR: %N:%l: main() -")
                          ACE_TEXT(" get_qos failed!\n")),
                         -1);
    }

    // was set to false for Sub
    if (sub_qos.entity_factory.autoenable_created_entities) {
        ACE_ERROR_RETURN((LM_ERROR,
                          ACE_TEXT("(%P|%t) ERROR: %N:%l: main() -")
                          ACE_TEXT(" subscriber has wrong autoenable value!\n")),
                         -1);
    } else {
      if (subscriber->enable() != DDS::RETCODE_OK) {
        std::cout << "bad return code enabling subscriber" << std::endl;
      }
      if (reader->enable() != DDS::RETCODE_OK) {
        std::cout << "bad return code enabling reader" << std::endl;
      }
    }

    char* buff = reinterpret_cast<char*>(sub_qos.group_data.value.get_buffer());
    std::cout << "Group data is:" << buff << std::endl;
    if (strcmp(buff, "eight is 8") != 0) {
        ACE_ERROR_RETURN((LM_ERROR,
                          ACE_TEXT("(%P|%t) ERROR: %N:%l: main() -")
                          ACE_TEXT(" subscriber has wrong group_data value\n")),
                         -1);
    }

    if (sub_qos.partition.name.length() != 1) {
        ACE_ERROR_RETURN((LM_ERROR,
                          ACE_TEXT("(%P|%t) ERROR: %N:%l: main() -")
                          ACE_TEXT(" subscriber has wrong # of partitions\n")),
                         -1);
    }

    if (strcmp(sub_qos.partition.name[0], "*") != 0) {
        ACE_ERROR_RETURN((LM_ERROR,
                          ACE_TEXT("(%P|%t) ERROR: %N:%l: main() -")
                          ACE_TEXT(" subscriber has wrong partition value\n")),
                         -1);
    }

    if (sub_qos.presentation.access_scope != DDS::TOPIC_PRESENTATION_QOS) {
        ACE_ERROR_RETURN((LM_ERROR,
                          ACE_TEXT("(%P|%t) ERROR: %N:%l: main() -")
                          ACE_TEXT(" subscriber has wrong access scope\n")),
                         -1);
    }
    if (sub_qos.presentation.coherent_access != true) {
        ACE_ERROR_RETURN((LM_ERROR,
                          ACE_TEXT("(%P|%t) ERROR: %N:%l: main() -")
                          ACE_TEXT(" subscriber has wrong choerent access\n")),
                         -1);
    }
    if (sub_qos.presentation.ordered_access != true) {
        ACE_ERROR_RETURN((LM_ERROR,
                          ACE_TEXT("(%P|%t) ERROR: %N:%l: main() -")
                          ACE_TEXT(" subscriber has wrong ordered access\n")),
                         -1);
    }

    OpenDDS::Model::ReaderSync rs(reader);

    // END OF EXISTING MESSENGER EXAMPLE CODE

  } catch (const CORBA::Exception& e) {
    e._tao_print_exception("Exception caught in main():");
    return -1;

  } catch( const std::exception& ex) {
    ACE_ERROR_RETURN((LM_ERROR,
                      ACE_TEXT("(%P|%t) ERROR: %N:%l: main() -")
                      ACE_TEXT(" Exception caught: %C\n"),
                      ex.what()),
                     -1);
  }

  return 0;
}
Esempio n. 29
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try {
    // Initialize DomainParticipantFactory
    DDS::DomainParticipantFactory_var dpf =
      TheParticipantFactoryWithArgs(argc, argv);

    // Create DomainParticipant
    DDS::DomainParticipant_var participant =
      dpf->create_participant(OpenDDS::DCPS::MONITOR_DOMAIN_ID,
                              PARTICIPANT_QOS_DEFAULT,
                              DDS::DomainParticipantListener::_nil(),
                              OpenDDS::DCPS::DEFAULT_STATUS_MASK);

    if (CORBA::is_nil(participant.in())) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l main()")
                        ACE_TEXT(" ERROR: create_participant() failed!\n")), -1);
    }

    // Create 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())) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l main()")
                        ACE_TEXT(" ERROR: create_subscriber() failed!\n")), -1);
    }

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

    OpenDDS::DCPS::AttachStatus status = transport_impl->attach(sub.in());

    if (status != OpenDDS::DCPS::ATTACH_OK) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l main()")
                        ACE_TEXT(" ERROR: attach() failed!\n")), -1);
    }

    DDS::DataReaderQos dr_qos;
    sub->get_default_datareader_qos(dr_qos);
    dr_qos.durability.kind = DDS::TRANSIENT_LOCAL_DURABILITY_QOS;
    DDS::DataReader_var reader;

    // Register for OpenDDS::DCPS::ServiceParticipantReport
    OpenDDS::DCPS::ServiceParticipantReportTypeSupport_var sp_ts =
      new OpenDDS::DCPS::ServiceParticipantReportTypeSupportImpl();
    if (sp_ts->register_type(participant.in(), "") != DDS::RETCODE_OK) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l main()")
                        ACE_TEXT(" ERROR: register_type() failed!\n")), -1);
    }
    CORBA::String_var sp_type_name = sp_ts->get_type_name();
    DDS::DataReaderListener_var sp_drl(new SPMDataReaderListenerImpl);
    reader = create_data_reader(participant.in(),
                                sub.in(),
                                sp_type_name.in(),
                                OpenDDS::DCPS::SERVICE_PARTICIPANT_MONITOR_TOPIC,
                                dr_qos,
                                sp_drl);
    if (CORBA::is_nil(reader.in())) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l main()")
                        ACE_TEXT(" ERROR: create_datareader() failed!\n")), -1);
    }

    // Register for OpenDDS::DCPS::DomainParticipantReport
    OpenDDS::DCPS::DomainParticipantReportTypeSupport_var dp_ts =
      new OpenDDS::DCPS::DomainParticipantReportTypeSupportImpl();
    if (dp_ts->register_type(participant.in(), "") != DDS::RETCODE_OK) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l main()")
                        ACE_TEXT(" ERROR: register_type() failed!\n")), -1);
    }
    CORBA::String_var dp_type_name = dp_ts->get_type_name();
    DDS::DataReaderListener_var dp_drl(new DPMDataReaderListenerImpl);
    reader = create_data_reader(participant.in(),
                                sub.in(),
                                dp_type_name.in(),
                                OpenDDS::DCPS::DOMAIN_PARTICIPANT_MONITOR_TOPIC,
                                dr_qos,
                                dp_drl);
    if (CORBA::is_nil(reader.in())) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l main()")
                        ACE_TEXT(" ERROR: create_datareader() failed!\n")), -1);
    }

    // Register for OpenDDS::DCPS::TopicReport
    OpenDDS::DCPS::TopicReportTypeSupport_var topic_ts =
      new OpenDDS::DCPS::TopicReportTypeSupportImpl();
    if (topic_ts->register_type(participant.in(), "") != DDS::RETCODE_OK) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l main()")
                        ACE_TEXT(" ERROR: register_type() failed!\n")), -1);
    }
    CORBA::String_var topic_type_name = topic_ts->get_type_name();
    DDS::DataReaderListener_var topic_drl(new TopicMDataReaderListenerImpl);
    reader = create_data_reader(participant.in(),
                                sub.in(),
                                topic_type_name.in(),
                                OpenDDS::DCPS::TOPIC_MONITOR_TOPIC,
                                dr_qos,
                                topic_drl);
    if (CORBA::is_nil(reader.in())) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l main()")
                        ACE_TEXT(" ERROR: create_datareader() failed!\n")), -1);
    }

    // Register for OpenDDS::DCPS::PublisherReport
    OpenDDS::DCPS::PublisherReportTypeSupport_var publisher_ts =
      new OpenDDS::DCPS::PublisherReportTypeSupportImpl();
    if (publisher_ts->register_type(participant.in(), "") != DDS::RETCODE_OK) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l main()")
                        ACE_TEXT(" ERROR: register_type() failed!\n")), -1);
    }
    CORBA::String_var publisher_type_name = publisher_ts->get_type_name();
    DDS::DataReaderListener_var publisher_drl(new PublisherMDataReaderListenerImpl);
    reader = create_data_reader(participant.in(),
                                sub.in(),
                                publisher_type_name.in(),
                                OpenDDS::DCPS::PUBLISHER_MONITOR_TOPIC,
                                dr_qos,
                                publisher_drl);
    if (CORBA::is_nil(reader.in())) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l main()")
                        ACE_TEXT(" ERROR: create_datareader() failed!\n")), -1);
    }

    // Register for OpenDDS::DCPS::SubscriberReport
    OpenDDS::DCPS::SubscriberReportTypeSupport_var subscriber_ts =
      new OpenDDS::DCPS::SubscriberReportTypeSupportImpl();
    if (subscriber_ts->register_type(participant.in(), "") != DDS::RETCODE_OK) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l main()")
                        ACE_TEXT(" ERROR: register_type() failed!\n")), -1);
    }
    CORBA::String_var subscriber_type_name = subscriber_ts->get_type_name();
    DDS::DataReaderListener_var subscriber_drl(new SubscriberMDataReaderListenerImpl);
    reader = create_data_reader(participant.in(),
                                sub.in(),
                                subscriber_type_name.in(),
                                OpenDDS::DCPS::SUBSCRIBER_MONITOR_TOPIC,
                                dr_qos,
                                subscriber_drl);
    if (CORBA::is_nil(reader.in())) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l main()")
                        ACE_TEXT(" ERROR: create_datareader() failed!\n")), -1);
    }

    // Register for OpenDDS::DCPS::DataWriterReport
    OpenDDS::DCPS::DataWriterReportTypeSupport_var dw_ts =
      new OpenDDS::DCPS::DataWriterReportTypeSupportImpl();
    if (dw_ts->register_type(participant.in(), "") != DDS::RETCODE_OK) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l main()")
                        ACE_TEXT(" ERROR: register_type() failed!\n")), -1);
    }
    CORBA::String_var dw_type_name = dw_ts->get_type_name();
    DDS::DataReaderListener_var dw_drl(new DWMDataReaderListenerImpl);
    reader = create_data_reader(participant.in(),
                                sub.in(),
                                dw_type_name.in(),
                                OpenDDS::DCPS::DATA_WRITER_MONITOR_TOPIC,
                                dr_qos,
                                dw_drl);
    if (CORBA::is_nil(reader.in())) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l main()")
                        ACE_TEXT(" ERROR: create_datareader() failed!\n")), -1);
    }

    // Register for OpenDDS::DCPS::DataWriterPeriodicReport
    OpenDDS::DCPS::DataWriterPeriodicReportTypeSupport_var dwper_ts =
      new OpenDDS::DCPS::DataWriterPeriodicReportTypeSupportImpl();
    if (dwper_ts->register_type(participant.in(), "") != DDS::RETCODE_OK) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l main()")
                        ACE_TEXT(" ERROR: register_type() failed!\n")), -1);
    }
    CORBA::String_var dwper_type_name = dwper_ts->get_type_name();
    DDS::DataReaderListener_var dwper_drl(new DWPerMDataReaderListenerImpl);
    reader = create_data_reader(participant.in(),
                                sub.in(),
                                dwper_type_name.in(),
                                OpenDDS::DCPS::DATA_WRITER_PERIODIC_MONITOR_TOPIC,
                                dr_qos,
                                dwper_drl);
    if (CORBA::is_nil(reader.in())) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l main()")
                        ACE_TEXT(" ERROR: create_datareader() failed!\n")), -1);
    }

    // Register for OpenDDS::DCPS::DataReaderReport
    OpenDDS::DCPS::DataReaderReportTypeSupport_var dr_ts =
      new OpenDDS::DCPS::DataReaderReportTypeSupportImpl();
    if (dr_ts->register_type(participant.in(), "") != DDS::RETCODE_OK) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l main()")
                        ACE_TEXT(" ERROR: register_type() failed!\n")), -1);
    }
    CORBA::String_var dr_type_name = dr_ts->get_type_name();
    DDS::DataReaderListener_var dr_drl(new DRMDataReaderListenerImpl);
    reader = create_data_reader(participant.in(),
                                sub.in(),
                                dr_type_name.in(),
                                OpenDDS::DCPS::DATA_READER_MONITOR_TOPIC,
                                dr_qos,
                                dr_drl);
    if (CORBA::is_nil(reader.in())) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l main()")
                        ACE_TEXT(" ERROR: create_datareader() failed!\n")), -1);
    }

    // Register for OpenDDS::DCPS::DataReaderPeriodicReport
    OpenDDS::DCPS::DataReaderPeriodicReportTypeSupport_var drper_ts =
      new OpenDDS::DCPS::DataReaderPeriodicReportTypeSupportImpl();
    if (drper_ts->register_type(participant.in(), "") != DDS::RETCODE_OK) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l main()")
                        ACE_TEXT(" ERROR: register_type() failed!\n")), -1);
    }
    CORBA::String_var drper_type_name = drper_ts->get_type_name();
    DDS::DataReaderListener_var drper_drl(new DRPerMDataReaderListenerImpl);
    reader = create_data_reader(participant.in(),
                                sub.in(),
                                drper_type_name.in(),
                                OpenDDS::DCPS::DATA_READER_PERIODIC_MONITOR_TOPIC,
                                dr_qos,
                                drper_drl);
    if (CORBA::is_nil(reader.in())) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l main()")
                        ACE_TEXT(" ERROR: create_datareader() failed!\n")), -1);
    }

    // Register for OpenDDS::DCPS::TransportReport
    OpenDDS::DCPS::TransportReportTypeSupport_var transport_ts =
      new OpenDDS::DCPS::TransportReportTypeSupportImpl();
    if (transport_ts->register_type(participant.in(), "") != DDS::RETCODE_OK) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l main()")
                        ACE_TEXT(" ERROR: register_type() failed!\n")), -1);
    }
    CORBA::String_var transport_type_name = transport_ts->get_type_name();
    DDS::DataReaderListener_var transport_drl(new TransportMDataReaderListenerImpl);
    reader = create_data_reader(participant.in(),
                                sub.in(),
                                transport_type_name.in(),
                                OpenDDS::DCPS::TRANSPORT_MONITOR_TOPIC,
                                dr_qos,
                                transport_drl);
    if (CORBA::is_nil(reader.in())) {
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l main()")
                        ACE_TEXT(" ERROR: create_datareader() failed!\n")), -1);
    }

    while (1) {
      ACE_OS::sleep(1);
    }
    // Clean-up!
    participant->delete_contained_entities();
    dpf->delete_participant(participant.in());

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

  } catch (const CORBA::Exception& e) {
    e._tao_print_exception("Exception caught in main():");
    return -1;
  }

  return 0;
}
Esempio n. 30
0
int
ACE_TMAIN(int argc, ACE_TCHAR** argv)
{
  try
  {
    TheParticipantFactoryWithArgs(argc, argv);

    // Create Participant
    DDS::DomainParticipant_var participant =
      TheParticipantFactory->create_participant(42,
                                                PARTICIPANT_QOS_DEFAULT,
                                                DDS::DomainParticipantListener::_nil(),
                                                OpenDDS::DCPS::DEFAULT_STATUS_MASK);

    if (CORBA::is_nil(participant.in()))
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l: main()")
                        ACE_TEXT(" ERROR: create_participant failed!\n")), 1);

    // Create Subscriber
    DDS::Subscriber_var subscriber =
      participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT,
                                     DDS::SubscriberListener::_nil(),
                                     OpenDDS::DCPS::DEFAULT_STATUS_MASK);

    if (CORBA::is_nil(subscriber.in()))
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l: main()")
                        ACE_TEXT(" ERROR: create_subscriber failed!\n")), 2);

    // Create Publisher
    DDS::Publisher_var publisher =
      participant->create_publisher(PUBLISHER_QOS_DEFAULT,
                                    DDS::PublisherListener::_nil(),
                                    OpenDDS::DCPS::DEFAULT_STATUS_MASK);

    if (CORBA::is_nil(publisher.in()))
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l: main()")
                        ACE_TEXT(" ERROR: create_publisher failed!\n")), 1);

    OpenDDS::DCPS::TransportIdType transportId(0);

    // Attach Subscriber Transport
    ++transportId;

    OpenDDS::DCPS::TransportConfiguration_rch sub_config =
      TheTransportFactory->get_or_create_configuration(transportId, ACE_TEXT("SimpleTcp"));

    OpenDDS::DCPS::TransportImpl_rch sub_transport =
      TheTransportFactory->create_transport_impl(transportId);

    OpenDDS::DCPS::SubscriberImpl* subscriber_i =
      dynamic_cast<OpenDDS::DCPS::SubscriberImpl*>(subscriber.in());

    if (subscriber_i == 0)
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l: main()")
                        ACE_TEXT(" ERROR: dynamic_cast failed!\n")), 1);

    OpenDDS::DCPS::AttachStatus sub_status =
      subscriber_i->attach_transport(sub_transport.in());

    if (sub_status != OpenDDS::DCPS::ATTACH_OK)
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l: main()")
                        ACE_TEXT(" ERROR: attach_transport failed!\n")), 1);

    // Attach Publisher Transport
    ++transportId;

    OpenDDS::DCPS::TransportConfiguration_rch pub_config =
      TheTransportFactory->get_or_create_configuration(transportId, ACE_TEXT("SimpleTcp"));

    OpenDDS::DCPS::TransportImpl_rch pub_transport =
      TheTransportFactory->create_transport_impl(transportId);

    OpenDDS::DCPS::PublisherImpl* publisher_i =
      dynamic_cast<OpenDDS::DCPS::PublisherImpl*>(publisher.in());

    if (publisher_i == 0)
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l: main()")
                        ACE_TEXT(" ERROR: dynamic_cast failed!\n")), 1);

    OpenDDS::DCPS::AttachStatus pub_status =
      publisher_i->attach_transport(pub_transport.in());

    if (pub_status != OpenDDS::DCPS::ATTACH_OK)
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l: main()")
                        ACE_TEXT(" ERROR: attach_transport failed!\n")), 1);

    // Register Type (FooType)
    FooTypeSupport_var ts = new FooTypeSupportImpl;
    if (ts->register_type(participant.in(), "") != DDS::RETCODE_OK)
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l: main()")
                        ACE_TEXT(" ERROR: register_type failed!\n")), 1);

    // Create Topic (FooTopic)
    DDS::Topic_var topic =
      participant->create_topic("FooTopic",
                                ts->get_type_name(),
                                TOPIC_QOS_DEFAULT,
                                DDS::TopicListener::_nil(),
                                OpenDDS::DCPS::DEFAULT_STATUS_MASK);

    if (CORBA::is_nil(topic.in()))
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l: main()")
                        ACE_TEXT(" ERROR: create_topic failed!\n")), 1);

    // Create DataReader
    DDS::DataReaderQos qos;

    if (subscriber->get_default_datareader_qos(qos) != DDS::RETCODE_OK)
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l main()")
                        ACE_TEXT(" ERROR: create_datareader failed!\n")), -1);

    qos.history.kind = DDS::KEEP_ALL_HISTORY_QOS;

    DDS::DataReader_var reader =
      subscriber->create_datareader(topic.in(),
                                    qos,
                                    DDS::DataReaderListener::_nil(),
                                    OpenDDS::DCPS::DEFAULT_STATUS_MASK);

    if (CORBA::is_nil(reader.in()))
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l: main()")
                        ACE_TEXT(" ERROR: create_datareader failed!\n")), 7);

    FooDataReader_var reader_i = FooDataReader::_narrow(reader);
    if (CORBA::is_nil(reader_i))
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l: main()")
                        ACE_TEXT(" ERROR: _narrow failed!\n")), 1);

    // Create DataWriter
    DDS::DataWriter_var writer =
      publisher->create_datawriter(topic.in(),
                                   DATAWRITER_QOS_DEFAULT,
                                   DDS::DataWriterListener::_nil(),
                                   OpenDDS::DCPS::DEFAULT_STATUS_MASK);

    if (CORBA::is_nil(writer.in()))
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l: main()")
                        ACE_TEXT(" ERROR: create_datawriter failed!\n")), 1);

    FooDataWriter_var writer_i = FooDataWriter::_narrow(writer);
    if (CORBA::is_nil(writer_i))
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT("%N:%l: main()")
                        ACE_TEXT(" ERROR: _narrow failed!\n")), 1);

    // Block until Subscriber is associated
    DDS::StatusCondition_var cond = writer->get_statuscondition();
    cond->set_enabled_statuses(DDS::PUBLICATION_MATCHED_STATUS);

    DDS::WaitSet_var ws = new DDS::WaitSet;
    ws->attach_condition(cond);

    DDS::Duration_t timeout =
      { DDS::DURATION_INFINITE_SEC, DDS::DURATION_INFINITE_NSEC };

    DDS::ConditionSeq conditions;
    DDS::PublicationMatchedStatus matches = { 0, 0, 0, 0, 0 };
    do
    {
      if (ws->wait(conditions, timeout) != DDS::RETCODE_OK)
        ACE_ERROR_RETURN((LM_ERROR,
                          ACE_TEXT("%N:%l: main()")
                          ACE_TEXT(" ERROR: wait failed!\n")), 1);

      if (writer->get_publication_matched_status(matches) != ::DDS::RETCODE_OK)
      {
        ACE_ERROR_RETURN((LM_ERROR,
                          ACE_TEXT("%N:%l: main()")
                          ACE_TEXT(" ERROR: failed to get publication matched status!\n")),
                          2);
      }
    }
    while (matches.current_count < 1);

    ws->detach_condition(cond);

    //
    // FooDataWriter::dispose should cause an instance to be
    // deleted after the last sample in the instance has been
    // taken from the ReceivedDataElementList:
    //
    DDS_TEST test(reader_i);
    if (!test) return 1;

    Foo foo;
    DDS::InstanceHandle_t handle;

    handle = writer_i->register_instance(foo);

    writer_i->write(foo, handle);
    writer_i->dispose(foo, handle);

    ACE_OS::sleep(5); // wait for samples to arrive

    if (!test.take_all_samples())
        ACE_ERROR_RETURN((LM_ERROR,
                          ACE_TEXT("%N:%l: main()")
                          ACE_TEXT(" ERROR: unable to take samples!\n")), 2);
    /// Verify instance has been deleted
    if (test.has_instance(handle))
        ACE_ERROR_RETURN((LM_ERROR,
                          ACE_TEXT("%N:%l: main()")
                          ACE_TEXT(" ERROR: instance not removed!\n")), 3);

    // Clean-up!
    participant->delete_contained_entities();
    TheParticipantFactory->delete_participant(participant);

    TheTransportFactory->release();
    TheServiceParticipant->shutdown();
  }
  catch (const CORBA::Exception& e)
  {
    e._tao_print_exception("caught in main()");
    return -1;
  }

  return 0;
}