コード例 #1
0
ファイル: Factory.cpp プロジェクト: FlavioFalcao/DDS-1
DDS::DomainParticipant_var
Factory::participant(const DDS::DomainParticipantFactory_var& dpf) const
{
  DDS::DomainParticipant_var dp =
          dpf->create_participant(MY_DOMAIN,
                                  PARTICIPANT_QOS_DEFAULT,
                                  DDS::DomainParticipantListener::_nil(),
                                  OpenDDS::DCPS::DEFAULT_STATUS_MASK);
  TEST_CHECK(!CORBA::is_nil(dp.in()));

  // If there is a ini file-based configuration name initialize
  // the transport configuration for the corresponding Entity
  if (opts_.configuration_str != "none" && opts_.entity_str == "participant")
    {
      OpenDDS::DCPS::TransportRegistry::instance()->bind_config(opts_.configuration_str, dp.in());
    }


  // Register TypeSupport (Messenger::Message)
  CORBA::String_var tn = typsup_->get_type_name();
  TEST_CHECK(DDS::RETCODE_OK == typsup_->register_type(dp.in(), tn)); // Use the default name for the type

  return dp;

}
コード例 #2
0
void
SubscriberMonitorImpl::report() {
  if (!CORBA::is_nil(this->sub_writer_.in())) {
    SubscriberReport report;
    report.handle = sub_->get_instance_handle();
    DDS::DomainParticipant_var dp = sub_->get_participant();
    OpenDDS::DCPS::DomainParticipantImpl* dpi = dynamic_cast<DomainParticipantImpl*>(dp.in());
    if (!dpi) {
      ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) SubscriberMonitorImpl::report():")
        ACE_TEXT(" failed to obtain DomainParticipantImpl.\n")));
      return;
    }
    report.dp_id   = dpi->get_id();
    TransportImpl_rch ti; //TODO: transport    = sub_->get_transport_impl();
    // TODO: remove transport_id and replace with name
    report.transport_id = 0;
    SubscriberImpl::SubscriptionIdVec readers;
    sub_->get_subscription_ids(readers);
    CORBA::ULong length = 0;
    report.readers.length(static_cast<CORBA::ULong>(readers.size()));
    for (SubscriberImpl::SubscriptionIdVec::iterator iter = readers.begin();
         iter != readers.end();
         ++iter) {
      report.readers[length++] = *iter;
    }
    this->sub_writer_->write(report, DDS::HANDLE_NIL);
  }
}
コード例 #3
0
ファイル: Factory.cpp プロジェクト: FlavioFalcao/DDS-1
DDS::Subscriber_var
Factory::subscriber(const DDS::DomainParticipant_var& dp) const
{

  DDS::SubscriberQos sub_qos;
  dp->get_default_subscriber_qos(sub_qos);
  if (opts_.entity_str == "rw")
    {
      sub_qos.entity_factory.autoenable_created_entities = opts_.entity_autoenable;
    }

  // Create the subscriber
  DDS::Subscriber_var sub =
          dp->create_subscriber(sub_qos,
                                DDS::SubscriberListener::_nil(),
                                OpenDDS::DCPS::DEFAULT_STATUS_MASK);
  TEST_ASSERT(!CORBA::is_nil(sub.in()));

  // If there is a ini file-based configuration name initialize
  // the transport configuration for the corresponding Entity
  if (opts_.configuration_str != "none" && opts_.entity_str == "pubsub")
    {
      OpenDDS::DCPS::TransportRegistry::instance()->bind_config(opts_.configuration_str, sub.in());
    }

  return sub;
}
コード例 #4
0
ファイル: DDSApp.cpp プロジェクト: AndroidDev77/OpenDDS
// either cleans up the specified participant, or all participants and the domain participant factory
void
DDSApp::cleanup(DDS::DomainParticipant_var participant)
{
  determine_participant(participant);
  participant->delete_contained_entities();
  dpf_->delete_participant(participant.in());

  remove(participant);
}
コード例 #5
0
void
TopicMonitorImpl::report() {
  if (!CORBA::is_nil(this->topic_writer_.in())) {
    TopicReport report;
    DDS::DomainParticipant_var dp = this->topic_->get_participant();
    DomainParticipantImpl* dp_impl =
      dynamic_cast<DomainParticipantImpl*>(dp.in());
    report.dp_id      = dp_impl->get_id();
    report.topic_id   = this->topic_->get_id();
    report.topic_name = this->topic_->get_name();
    report.type_name  = this->topic_->get_type_name();
    this->topic_writer_->write(report, DDS::HANDLE_NIL);
  }
}
コード例 #6
0
ファイル: DDSApp.cpp プロジェクト: AndroidDev77/OpenDDS
void
DDSApp::remove(const DDS::DomainParticipant_var& participant)
{
  participants_.erase(participant.in());
  if (participant.in() == default_participant_.in()) {
    if (participants_.empty()) {
      default_participant_ = DDS::DomainParticipant_var();
    }
    else {
      ACE_DEBUG((LM_DEBUG,
                 "NOTE: removed default participant and assigning new "
                 "default\n"));
      default_participant_ = participants_.begin()->second;
    }
  }
}
コード例 #7
0
ファイル: Boilerplate.cpp プロジェクト: yanbodiaoweng/DDS
DDS::Topic_var
createTopic(DDS::DomainParticipant_var participant)
{
  // Register TypeSupport (Messenger::Message)
  Reliability::MessageTypeSupport_var ts =
    new Reliability::MessageTypeSupportImpl;

  if (ts->register_type(participant, "") != DDS::RETCODE_OK) {
    throw std::string("failed to register type support");
  }

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

  DDS::Topic_var topic =
    participant->create_topic("transaction_test",
                              type_name,
                              TOPIC_QOS_DEFAULT,
                              0,
                              OpenDDS::DCPS::DEFAULT_STATUS_MASK);

  // Check for failure
  if (!topic) {
    throw std::string("failed to create topic");
  }
  return topic;
}
コード例 #8
0
ファイル: DDSApp.cpp プロジェクト: AndroidDev77/OpenDDS
void
DDSApp::add(const DDS::DomainParticipant_var& participant)
{
  participants_.insert(std::make_pair(participant.in(), participant));
  if (!default_participant_.in())
    default_participant_ = participant;
}
コード例 #9
0
jstring JNICALL Java_OpenDDS_DCPS_TheServiceParticipant_get_1unique_1id
(JNIEnv * jni, jclass, jobject participant)
{
  DDS::DomainParticipant_var part;
  copyToCxx(jni, part, participant);
  OpenDDS::DCPS::DomainParticipantImpl* impl = dynamic_cast<OpenDDS::DCPS::DomainParticipantImpl*>(part.in());
  jstring retStr = jni->NewStringUTF(impl->get_unique_id().c_str());
  return retStr;
}
コード例 #10
0
ファイル: subscriber.cpp プロジェクト: Fantasticer/OpenDDS
DDS::DataReader_var
create_reader(const DDS::Subscriber_var& sub, const char* topicName,
  const DDS::DataReaderQos& qos = DATAREADER_QOS_DEFAULT,
  const DDS::DataReaderListener_var& listener = 0,
  const DDS::StatusMask& mask = OpenDDS::DCPS::DEFAULT_STATUS_MASK)
{
  const DDS::TypeSupport_var ts = new ::OpenDDS::DCPS::TypeSupportImpl_T<MessageType>();
  const DDS::DomainParticipant_var dp = sub->get_participant();
  const CORBA::String_var typeName = ts->get_type_name();
  (void) ts->register_type(dp, typeName); // may have been registered before

  const DDS::Topic_var topic =
    dp->create_topic(topicName, typeName, TOPIC_QOS_DEFAULT, 0, 0);
  if (!topic) return 0;

  const DDS::DataReader_var dr =
    sub->create_datareader(topic, qos, listener, mask);
  return OpenDDS::DCPS::DDSTraits<MessageType>::DataReaderType::_narrow(dr);
}
コード例 #11
0
ファイル: DDSApp.cpp プロジェクト: AndroidDev77/OpenDDS
DDS::Publisher_var
DDSApp::create_pub(DDS::DomainParticipant_var participant,
                   const DDS::PublisherQos&   qos,
                   DDS::PublisherListener_var a_listener,
                   DDS::StatusMask            mask)
{
  determine_participant(participant);
  return participant->create_publisher(qos,
                                       a_listener.in(),
                                       mask);
}
コード例 #12
0
ファイル: Writer.cpp プロジェクト: Fantasticer/OpenDDS
void
Writer_Base::start()
{
  DDS::DomainParticipant_var part = DDS::Publisher_var(writer_->get_publisher())->get_participant();
  id_ = OPENDDS_STRING(OpenDDS::DCPS::GuidConverter(dynamic_cast<OpenDDS::DCPS::DomainParticipantImpl*>(part.in())->get_repoid(writer_->get_instance_handle())));

  ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) Writer_Base::start %C\n"), get_id()));
  if (activate(THR_NEW_LWP | THR_JOINABLE, 1) == -1) {
    cerr << "Writer_Base::start(): activate failed" << endl;
    exit(1);
  }
}
コード例 #13
0
bool ExampleSubscriber::teardown()
{
  /* Shutdown */
  if (participant != NULL)
  {
    if (subscriber.in() != NULL) {
      status = participant->delete_subscriber(subscriber.in());
      checkStatus(status, "DDS::DomainParticipant::delete_subscriber");
    }

    status = participant->delete_topic(large_message_topic.in());
    checkStatus(status, "DDS::DomainParticipant::delete_topic (large_message_topic)");

    status = dpf->delete_participant(participant.in());
    checkStatus(status, "DDS::DomainParticipantFactory::delete_participant");
  }

  DDS::string_free(large_message_type_name);

  return true;
}
コード例 #14
0
ファイル: Factory.cpp プロジェクト: FlavioFalcao/DDS-1
DDS::Topic_var
Factory::topic(const DDS::DomainParticipant_var& dp) const
{

  // When collocation doesn't matter we choose a topic name that will not match
  // the publisher's topic name
  std::string topicname((opts_.collocation_str == "none") ? MY_OTHER_TOPIC : MY_SAME_TOPIC);

  DDS::TopicQos topic_qos;
  TEST_CHECK(DDS::RETCODE_OK == dp->get_default_topic_qos(topic_qos));

  CORBA::String_var tn = typsup_->get_type_name();
  ACE_DEBUG((LM_ERROR, ACE_TEXT("(%P|%t) Topic name: %C\n"), tn.in()));
  DDS::Topic_var p(dp->create_topic(topicname.c_str(),
                                    tn,
                                    TOPIC_QOS_DEFAULT,
                                    DDS::TopicListener::_nil(),
                                    OpenDDS::DCPS::DEFAULT_STATUS_MASK));
  TEST_CHECK(!CORBA::is_nil(p.in()));
  return p;
}
コード例 #15
0
ファイル: DDSApp.cpp プロジェクト: AndroidDev77/OpenDDS
void
DDSApp::determine_participant(DDS::DomainParticipant_var& part)
{
  if (part.in())
    return;

  if (!default_participant_.in()) {
    // this will create a participant and assign the default participant
    participant();
  }

  part = default_participant_;
}
コード例 #16
0
ファイル: PublisherMonitorImpl.cpp プロジェクト: binary42/OCI
void
PublisherMonitorImpl::report() {
  if (!CORBA::is_nil(this->pub_writer_.in())) {
    PublisherReport report;
    report.handle = pub_->get_instance_handle();
    DDS::DomainParticipant_var dp = pub_->get_participant();
    report.dp_id   = dynamic_cast<DomainParticipantImpl*>(dp.in())->get_id();
    TransportImpl_rch ti; //TODO: transport    = pub_->get_transport_impl();
    // TODO: remove/replace
    report.transport_id = 0;
    PublisherImpl::PublicationIdVec writers;
    pub_->get_publication_ids(writers);
    CORBA::ULong length = 0;
    report.writers.length(static_cast<CORBA::ULong>(writers.size()));
    for (PublisherImpl::PublicationIdVec::iterator iter = writers.begin();
         iter != writers.end();
         ++iter) {
      report.writers[length++] = *iter;
    }
    this->pub_writer_->write(report, DDS::HANDLE_NIL);
  }
}
コード例 #17
0
ファイル: TestFramework.cpp プロジェクト: CapXilinx/OpenDDS
DDS::DomainParticipant_var
TestBase::create_participant()
{
  DDS::DomainId_t domain = DEFAULT_DOMAIN;

  DDS::DomainParticipantQos qos;
  DDS::DomainParticipantFactory_var dpf = TheParticipantFactory;
  if (dpf->get_default_participant_qos(qos) != DDS::RETCODE_OK) {
    ACE_ERROR((LM_ERROR,
               ACE_TEXT("ERROR: %N:%l: create_participant() -")
               ACE_TEXT(" get_default_participant_qos failed!\n")));
    ACE_OS::exit(-1);
  }

  DDS::DomainParticipantListener_ptr listener =
    DDS::DomainParticipantListener::_nil();

  DDS::StatusMask status = OpenDDS::DCPS::DEFAULT_STATUS_MASK;

  if (init_participant(domain, qos, listener, status) != DDS::RETCODE_OK) {
    ACE_ERROR((LM_ERROR,
               ACE_TEXT("ERROR: %N:%l: create_participant() -")
               ACE_TEXT(" init_participant failed!\n")));
    ACE_OS::exit(-1);
  }

  DDS::DomainParticipant_var participant =
    dpf->create_participant(domain, qos, listener, status);

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

  return participant;
}
コード例 #18
0
DDS::Streams::StreamDataWriter_impl::~StreamDataWriter_impl() {
    DDS::DomainParticipant_var tmp;

    os_mutexLock(&classLock.lfMutex);

    if (topic.in()) {
        tmp = topic->get_participant();
        /* participant may have been deleted */
        if (tmp != NULL) {
            tmp->delete_topic(topic);
        }
    }

    if (publisher.in()) {
        DDS::ReturnCode_t result;
        participant->delete_publisher(publisher);
        if (--nrParticipantUsers == 0) {
            (void)DDS::DomainParticipantFactory::get_instance()->delete_participant(participant.in());
        }
    }

    os_mutexUnlock(&classLock.lfMutex);
}
コード例 #19
0
ファイル: Factory.cpp プロジェクト: FlavioFalcao/DDS-1
DDS::DataReader_var
Factory::reader(const DDS::Subscriber_var& sub, const DDS::Topic_var& topic, const DDS::DataReaderListener_var& drl) const
{
  // Create the data readers
  DDS::DataReaderQos dr_qos;
  sub->get_default_datareader_qos(dr_qos);

  dr_qos.durability.kind = opts_.durability_kind;
  dr_qos.liveliness.kind = opts_.liveliness_kind;
  dr_qos.liveliness.lease_duration = opts_.LEASE_DURATION;
  dr_qos.reliability.kind = opts_.reliability_kind;

  DDS::DomainParticipant_var dp = sub->get_participant();
  CORBA::String_var tn = topic->get_name();
  DDS::TopicDescription_var description = dp->lookup_topicdescription(tn);
  TEST_ASSERT(!CORBA::is_nil(description.in()));

  DDS::DataReader_var rd(sub->create_datareader(description.in(),
                                                dr_qos,
                                                drl.in(),
                                                ::OpenDDS::DCPS::DEFAULT_STATUS_MASK));

  // Initialize the transport configuration for the appropriate entity
  TEST_ASSERT(!opts_.configuration_str.empty());
  if (opts_.configuration_str != "none" && opts_.entity_str == "rw")
    {

      OpenDDS::DCPS::TransportRegistry::instance()->bind_config(opts_.configuration_str,
                                                                rd.in());
      if (!opts_.entity_autoenable)
        {
          TEST_ASSERT(DDS::RETCODE_OK == rd->enable());
        }
    }

  return rd;
}
コード例 #20
0
ファイル: Boilerplate.cpp プロジェクト: yanbodiaoweng/DDS
DDS::Publisher_var
createPublisher(DDS::DomainParticipant_var participant)
{
  // Create Publisher
  DDS::Publisher_var publisher =
    participant->create_publisher(
        PUBLISHER_QOS_DEFAULT,
        0,
        OpenDDS::DCPS::DEFAULT_STATUS_MASK);

  // Check for failure
  if (!publisher) {
    throw std::string("failed to create publisher");
  }
  return publisher;
}
コード例 #21
0
ファイル: Boilerplate.cpp プロジェクト: yanbodiaoweng/DDS
void
cleanup(
  DDS::DomainParticipant_var participant,
  DDS::DomainParticipantFactory_var dpf)
{
  std::cout << "delete_contained_entities"<< std::endl;
  // Delete any topics, publishers and subscribers owned by participant
  participant->delete_contained_entities();
  std::cout << "delete_participant"<< std::endl;
  // Delete participant itself
  dpf->delete_participant(participant);
  std::cout << "shutdown"<< std::endl;
  // Shut down info repo connection
  TheServiceParticipant->shutdown();
  std::cout << "shutdown complete"<< std::endl;
}
コード例 #22
0
ファイル: Boilerplate.cpp プロジェクト: yanbodiaoweng/DDS
DDS::Subscriber_var
createSubscriber(DDS::DomainParticipant_var participant)
{
  // Create Subscriber
  DDS::Subscriber_var subscriber =
      participant->create_subscriber(
          SUBSCRIBER_QOS_DEFAULT,
          0,
          OpenDDS::DCPS::DEFAULT_STATUS_MASK);

  // Check for failure
  if (!subscriber) {
    throw std::string("failed to create subscriber");
  }

  return subscriber;
}
コード例 #23
0
ファイル: publisher.cpp プロジェクト: svn2github/OpenDDS
void init ()
{
  participant
    = dpf->create_participant(domain_id,
                              PARTICIPANT_QOS_DEFAULT,
                              ::DDS::DomainParticipantListener::_nil(),
                              ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
  if (CORBA::is_nil (participant.in ()))
    {
      ACE_ERROR ((LM_ERROR,
                ACE_TEXT("(%P|%t) create_participant failed.\n")));
      throw TestException ();
    }

  ::Xyz::FooTypeSupportImpl* fts_servant
    = new ::Xyz::FooTypeSupportImpl();

  if (::DDS::RETCODE_OK != fts_servant->register_type(participant.in (), type_name))
    {
      ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) register_type failed.\n")));
      throw TestException ();
    }

  ::DDS::TopicQos topic_qos;
  participant->get_default_topic_qos(topic_qos);

  topic[0]
    = participant->create_topic (topic_name[0],
                                  type_name,
                                  topic_qos,
                                  ::DDS::TopicListener::_nil(),
                                  ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
  if (CORBA::is_nil (topic[0].in ()))
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT("(%P|%t) create_topic failed.\n")));
      throw TestException ();
    }

  topic[1]
    = participant->create_topic (topic_name[1],
                                  type_name,
                                  topic_qos,
                                  ::DDS::TopicListener::_nil(),
                                  ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
  if (CORBA::is_nil (topic[1].in ()))
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT("(%P|%t) create_topic failed.\n")));
      throw TestException ();
    }

  writer_impl
    = TheTransportFactory->create_transport_impl (PUB_TRAFFIC_TCP,
                                                  ACE_TEXT("SimpleTcp"),
                                                  OpenDDS::DCPS::DONT_AUTO_CONFIG);

  OpenDDS::DCPS::TransportConfiguration_rch writer_config
    = TheTransportFactory->create_configuration (PUB_TRAFFIC_TCP, ACE_TEXT("SimpleTcp"));

  OpenDDS::DCPS::SimpleTcpConfiguration* writer_tcp_config
    = static_cast <OpenDDS::DCPS::SimpleTcpConfiguration*> (writer_config.in ());

  if (writer_address_given)
    {
      ACE_INET_Addr writer_address (writer_address_str.c_str ());
      writer_tcp_config->local_address_ = writer_address;
      writer_tcp_config->local_address_str_ = writer_address_str.c_str ();
    }
    // else use default address - OS assigned.

  if (writer_impl->configure(writer_config.in()) != 0)
    {
      ACE_ERROR((LM_ERROR,
                ACE_TEXT("(%P|%t) init_writer_tranport: pub TCP")
                ACE_TEXT(" Failed to configure the transport.\n")));
      throw TestException ();
    }

  // Create the default publisher
  publisher = participant->create_publisher(PUBLISHER_QOS_DEFAULT,
                                ::DDS::PublisherListener::_nil(),
                                ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
  if (CORBA::is_nil (publisher.in ()))
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT("(%P|%t) create_publisher failed.\n")));
      throw TestException ();
    }

  // Attach the publisher to the transport.
  OpenDDS::DCPS::PublisherImpl* pub_impl
    = dynamic_cast<OpenDDS::DCPS::PublisherImpl*>
    (publisher.in ());

  if (0 == pub_impl)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT("(%P|%t) Failed to obtain publisher servant \n")));
      throw TestException ();
    }

  ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) attach to tcp \n")));
  OpenDDS::DCPS::AttachStatus attach_status
    = pub_impl->attach_transport(writer_impl.in());

  if (attach_status != OpenDDS::DCPS::ATTACH_OK)
    {
      // We failed to attach to the transport for some reason.
      ACE_TString status_str;

      switch (attach_status)
        {
          case OpenDDS::DCPS::ATTACH_BAD_TRANSPORT:
            status_str = ACE_TEXT("ATTACH_BAD_TRANSPORT");
            break;
          case OpenDDS::DCPS::ATTACH_ERROR:
            status_str = ACE_TEXT("ATTACH_ERROR");
            break;
          case OpenDDS::DCPS::ATTACH_INCOMPATIBLE_QOS:
            status_str = ACE_TEXT("ATTACH_INCOMPATIBLE_QOS");
            break;
          default:
            status_str = ACE_TEXT("Unknown Status");
            break;
        }

      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT("(%P|%t) Failed to attach to the transport. ")
                  ACE_TEXT("AttachStatus == %s\n"),
                  status_str.c_str()));
      throw TestException ();
    }

  // Create the datawriters
  ::DDS::DataWriterQos dw_qos;
  publisher->get_default_datawriter_qos (dw_qos);

  // Make it KEEP_ALL history so we can verify the received
  // data without dropping.
  dw_qos.history.kind = ::DDS::KEEP_ALL_HISTORY_QOS;
  dw_qos.reliability.kind = ::DDS::RELIABLE_RELIABILITY_QOS;
  dw_qos.resource_limits.max_samples_per_instance = ::DDS::LENGTH_UNLIMITED;
  dw_qos.reliability.max_blocking_time.sec = 0;
  dw_qos.reliability.max_blocking_time.nanosec = 0;

  for (int i = 0; i < 2; ++i)
    {
      datawriter[i] = publisher->create_datawriter(topic[i].in (),
                                          dw_qos,
                                          ::DDS::DataWriterListener::_nil(),
                                          ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);

      if (CORBA::is_nil (datawriter[i].in ()))
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT("(%P|%t) create_datawriter failed.\n")));
          throw TestException ();
        }

      writers[i] = new Writer (datawriter[i].in (), i);
    }
}
コード例 #24
0
ファイル: publisher.cpp プロジェクト: svn2github/OpenDDS
int ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  int status = 0;

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

      dpf = TheParticipantFactoryWithArgs(argc, argv);

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

      init ();

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

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

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

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

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

      int timeout_writes = 0;
      bool writers_finished = false;

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

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

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

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

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


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

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

  shutdown ();
  return status;
}
コード例 #25
0
ファイル: subscriber.cpp プロジェクト: FlavioFalcao/DDS-1
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;
}
コード例 #26
0
ファイル: publisher.cpp プロジェクト: Fantasticer/OpenDDS
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) {
  int status = 0;
  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;
      }
      DDS::DomainParticipant_var participant2 =
        dpf->create_participant(411,
                                PARTICIPANT_QOS_DEFAULT,
                                DDS::DomainParticipantListener::_nil(),
                                ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (participant2.in ())) {
        cerr << "create_participant failed." << endl;
        return 1;
      }

      OpenDDS::DCPS::TransportConfig_rch cfg = TheTransportRegistry->get_config("part1");
      if (!cfg.is_nil()) {
        TheTransportRegistry->bind_config(cfg, participant);
      }
      cfg = TheTransportRegistry->get_config("part2");
      if (!cfg.is_nil()) {
        TheTransportRegistry->bind_config(cfg, participant2);
      }

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

      MessageTypeSupport_var mts = new MessageTypeSupportImpl();
      MessageTypeSupport_var mts2 = new MessageTypeSupportImpl();

      if (DDS::RETCODE_OK != mts->register_type(participant.in (), "")) {
        cerr << "register_type failed." << endl;
        exit(1);
      }
      if (DDS::RETCODE_OK != mts2->register_type(participant2.in (), "")) {
        cerr << "register_type failed." << endl;
        exit(1);
      }

      CORBA::String_var type_name = mts->get_type_name ();
      CORBA::String_var type_name2 = mts2->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 << "create_topic failed." << endl;
        exit(1);
      }
      DDS::Topic_var topic2 =
        participant2->create_topic ("Movie Discussion List",
                                   type_name2.in (),
                                   TOPIC_QOS_DEFAULT,
                                   DDS::TopicListener::_nil(),
                                   ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (topic2.in ())) {
        cerr << "create_topic failed." << endl;
        exit(1);
      }

      DDS::Publisher_var pub =
        participant->create_publisher(PUBLISHER_QOS_DEFAULT,
        DDS::PublisherListener::_nil(),
        ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (pub.in ())) {
        cerr << "create_publisher failed." << endl;
        exit(1);
      }
      DDS::Publisher_var pub2 =
        participant2->create_publisher(PUBLISHER_QOS_DEFAULT,
        DDS::PublisherListener::_nil(),
        ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (pub2.in ())) {
        cerr << "create_publisher failed." << endl;
        exit(1);
      }

      DataWriterListenerImpl * dwl1_servant = new DataWriterListenerImpl;
      ::DDS::DataWriterListener_var dwl1 (dwl1_servant);
      DataWriterListenerImpl * dwl2_servant = new DataWriterListenerImpl;
      ::DDS::DataWriterListener_var dwl2 (dwl2_servant);
      DataWriterListenerImpl * dwl3_servant = new DataWriterListenerImpl;
      ::DDS::DataWriterListener_var dwl3 (dwl3_servant);
      DataWriterListenerImpl * dwl4_servant = new DataWriterListenerImpl;
      ::DDS::DataWriterListener_var dwl4 (dwl4_servant);

      // Create the datawriters
      ::DDS::DataWriterQos dw_qos;
      pub->get_default_datawriter_qos (dw_qos);
      ::DDS::DataWriterQos dw2_qos;
      pub2->get_default_datawriter_qos (dw2_qos);

      dw_qos.liveliness.kind = ::DDS::MANUAL_BY_PARTICIPANT_LIVELINESS_QOS;
      dw_qos.liveliness.lease_duration.sec = LEASE_DURATION_SEC;
      dw_qos.liveliness.lease_duration.nanosec = 0;
      dw2_qos.liveliness.kind = ::DDS::MANUAL_BY_PARTICIPANT_LIVELINESS_QOS;
      dw2_qos.liveliness.lease_duration.sec = LEASE_DURATION_SEC;
      dw2_qos.liveliness.lease_duration.nanosec = 0;

      // Create the datawriter
      DDS::DataWriter_var dw1 =
        pub->create_datawriter(topic.in (),
                               dw_qos,
                               dwl1.in(),
                               ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (dw1.in ())) {
        cerr << "create_datawriter failed." << endl;
        exit(1);
      }
      // Create the datawriter
      DDS::DataWriter_var dw2 =
        pub2->create_datawriter(topic2.in (),
                               dw2_qos,
                               dwl2.in(),
                               ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (dw2.in ())) {
        cerr << "create_datawriter failed." << endl;
        exit(1);
      }

      dw_qos.liveliness.kind = ::DDS::MANUAL_BY_TOPIC_LIVELINESS_QOS;
      // Create the datawriter
      DDS::DataWriter_var dw3 =
        pub->create_datawriter(topic.in (),
                               dw_qos,
                               dwl3.in(),
                               ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (dw3.in ())) {
        cerr << "create_datawriter failed." << endl;
        exit(1);
      }
      // Create the datawriter
      DDS::DataWriter_var dw4 =
        pub->create_datawriter(topic.in (),
                               dw_qos,
                               dwl4.in(),
                               ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (dw4.in ())) {
        cerr << "create_datawriter failed." << endl;
        exit(1);
      }

      {
        Write_Samples writer1(dw1, "Manual_By_Participant_Writer_1");
        Assert_Participant_Liveliness writer2(dw2, "Manual_By_Participant_Writer_2");
        Write_Samples writer3(dw3, "Manual_By_Topic_Writer_1");
        Assert_Writer_Liveliness writer4(dw4, "Manual_By_Topic_Writer_2");

        writer1.start();
        writer2.start();
        writer3.start();
        writer4.start();

        writer1.end();
        writer2.end();
        writer3.end();
        writer4.end();
      }

      const unsigned long actual = dwl1_servant->num_liveliness_lost_callbacks() +
        dwl2_servant->num_liveliness_lost_callbacks() +
        dwl3_servant->num_liveliness_lost_callbacks() +
        dwl4_servant->num_liveliness_lost_callbacks();

      if (liveliness_lost_test
          && static_cast<int>(actual) != num_liveliness_lost_callbacks)
      {
        cerr << "ERROR: did not receive expected liveliness lost callbacks. "
          << actual << "/" <<
          num_liveliness_lost_callbacks << endl;
        status = 1;
      }

      ACE_OS::sleep(1);
      ACE_DEBUG((LM_INFO, "publisher deleting entities\n"));
      participant->delete_contained_entities();
      dpf->delete_participant(participant.in ());
      participant2->delete_contained_entities();
      dpf->delete_participant(participant2.in ());
      TheServiceParticipant->shutdown ();
  }
  catch (CORBA::Exception& e)
    {
      cerr << "PUB: Exception caught in main.cpp:" << endl
         << e << endl;
      exit(1);
    }

  return status;
}
コード例 #27
0
ファイル: subscriber.cpp プロジェクト: stonejiang208/OpenDDS
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;
}
コード例 #28
0
ファイル: monitor.cpp プロジェクト: svn2github/OpenDDS
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;
}
コード例 #29
0
ファイル: subscriber.cpp プロジェクト: shaominghaoo/OpenDDS
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
    {
      DDS::DomainParticipantFactory_var dpf;
      DDS::DomainParticipant_var participant;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  return 0;
}
コード例 #30
0
ファイル: publisher.cpp プロジェクト: shaominghaoo/OpenDDS
int ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  int status = 0;

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

    bool reliable = true;
    int num_msgs = 10;
    int my_pid = ACE_OS::getpid();

    parse_args(argc, argv, reliable, num_msgs, my_pid);

    // 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 TypeSupport (Messenger::Message)
    Messenger::MessageTypeSupport_var mts =
      new Messenger::MessageTypeSupportImpl();

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

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

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

    DDS::DataWriterQos qos;
    pub->get_default_datawriter_qos(qos);
    qos.liveliness.kind = DDS::AUTOMATIC_LIVELINESS_QOS;
    qos.liveliness.lease_duration.sec = 5;
    qos.liveliness.lease_duration.nanosec = 0;
    qos.history.kind = DDS::KEEP_ALL_HISTORY_QOS;
    qos.durability.kind = DDS::TRANSIENT_LOCAL_DURABILITY_QOS;

    // Create DataWriter
    DDS::DataWriter_var dw =
      pub->create_datawriter(topic.in(),
                             qos,
                             DDS::DataWriterListener::_nil(),
                             OpenDDS::DCPS::DEFAULT_STATUS_MASK);

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

    DDS::DataWriter_var dw2 =
      pub->create_datawriter(topic.in(),
                             qos,
                             DDS::DataWriterListener::_nil(),
                             OpenDDS::DCPS::DEFAULT_STATUS_MASK);

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

    {
      Writer writer(dw, dw2, my_pid);
      writer.write(reliable, num_msgs);
    }

    // Sleep to give subscriber a chance to nak before exiting
    ACE_OS::sleep(3);

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

    ACE_DEBUG((LM_DEBUG, "Publisher shutdown\n"));
    TheServiceParticipant->shutdown();

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

  ACE_DEBUG((LM_DEBUG, "Publisher exiting with status=%d\n", status));
  return status;
}