Пример #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();
}
Пример #2
0
DDS::DataWriter_ptr
MonitorFactoryImpl::create_data_writer(DDS::DomainParticipant_ptr participant,
                                       DDS::Publisher_ptr publisher,
                                       const char* type_name,
                                       const char* topic_name,
                                       const DDS::DataWriterQos& dw_qos)
{
  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, "MonitorFactoryImpl::create_data_writer(): Failed to create topic, name = %s\n", topic_name));
  }
  DDS::DataWriter_var writer =
    publisher->create_datawriter(topic.in(),
                                 dw_qos,
                                 DDS::DataWriterListener::_nil(),
                                 OpenDDS::DCPS::DEFAULT_STATUS_MASK);
  if (CORBA::is_nil(writer)) {
    ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::create_data_writer(): Failed to create data writer\n"));
  }

  return writer._retn();
}
Пример #3
0
void
DDS_Base_Connector_T<CCM_TYPE>::init_topic (
  ::DDS::DomainParticipant_ptr participant,
  ::DDS::Topic_ptr & topic,
  const char * topic_name,
  const char * type_name)
{
  DDS4CCM_TRACE ("DDS_Base_Connector_T::init_topic");

  ::DDS::Duration_t timeout;
  timeout.sec = 0;
  timeout.nanosec = 0;

  DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION_STARTING, (LM_TRACE, DDS4CCM_INFO
                "DDS_Base_Connector_T::init_topic - "
                "Finding existing topic "
                "name <%C> for profile <%C> in participant "
                DDS_ENTITY_FORMAT_SPECIFIER "\n",
                topic_name, this->qos_profile_.in (),
                DDS_ENTITY_LOG (participant)));

  ::DDS::Topic_var dds_tp =
    participant->find_topic (topic_name, timeout);

  if (!CORBA::is_nil (dds_tp.in ()))
    {
      // Re-use topic.
      DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION_STARTING, (LM_TRACE, DDS4CCM_INFO
                    "DDS_Base_Connector_T::init_topic - "
                    "Re using topic <%C> for profile <%C>\n",
                    topic_name, this->qos_profile_.in ()));

      topic = ::DDS::Topic::_duplicate (dds_tp);
      return;
    }
#if (CIAO_DDS4CCM_NDDS==1)
  if (this->qos_profile_.in () != 0)
    {
      // Create a new topic
      topic = participant->create_topic_with_profile (topic_name,
                                          type_name,
                                          this->qos_profile_.in (),
                                          ::DDS::TopicListener::_nil (),
                                          0);
    }
  else
#endif
    {
      ::DDS::TopicQos tqos;
      DDS::ReturnCode_t const retcode =
        participant->get_default_topic_qos (tqos);

      if (retcode != DDS::RETCODE_OK)
      {
        DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
            "DDS_Base_Connector_T::init_topic - "
            "Error: Unable to retrieve default_topic_qos: <%C>\n",
            ::CIAO::DDS4CCM::translate_retcode (retcode)));
        throw ::CCM_DDS::InternalError (retcode, 0);
      }

      if (this->qos_profile_.in () != 0 && this->qos_xml_)
        {
          DDS::ReturnCode_t const retcode_tp_qos =
            this->qos_xml_->get_topic_qos (
                        tqos,
                        this->qos_profile_.in (),
                        topic_name);

          if (retcode_tp_qos != DDS::RETCODE_OK)
            {
              DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
                  "DDS_Base_Connector_T::init_topic - "
                  "Error: Unable to retrieve topic QOS from XML: <%C>\n",
                  ::CIAO::DDS4CCM::translate_retcode (retcode_tp_qos)));
              throw ::CCM_DDS::InternalError (retcode_tp_qos, 0);
            }
        }

#if defined GEN_OSTREAM_OPS
      if (DDS4CCM_debug_level >= DDS4CCM_LOG_LEVEL_DDS_STATUS)
        {
          std::stringstream output;
          output << tqos;
          std::string message = output.str();
          DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_DDS_STATUS, (LM_INFO, DDS4CCM_INFO
                        ACE_TEXT ("DDS_Base_Connector_T::init_topic - ")
                        ACE_TEXT ("Using topic QOS <%C>\n"), message.c_str()));
        }
#endif

      // Create a new topic
      topic = participant->create_topic (topic_name,
                            type_name,
                            tqos,
                            ::DDS::TopicListener::_nil (),
                            0);
    }

  if (!::CORBA::is_nil (topic))
    {
      DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION_STARTING, (LM_TRACE, DDS4CCM_INFO
                    "DDS_Base_Connector_T::init_topic - "
                    "Created new topic "
                    DDS_ENTITY_FORMAT_SPECIFIER
                    " name <%C> type <%C> for profile <%C>\n",
                    DDS_ENTITY_LOG (topic),
                    topic_name, type_name, this->qos_profile_.in ()));
    }
  else
    {
      DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_DDS_NIL_RETURN, (LM_ERROR, DDS4CCM_INFO
                    "DDS_Base_Connector_T::init_topic - "
                    "Error: unable to create new topic <%C> for profile <%C>\n",
                    topic_name, this->qos_profile_.in ()));
      throw ::CCM_DDS::InternalError (::DDS::RETCODE_ERROR, 0);
    }
}
Пример #4
0
int run_test_instance(DDS::DomainParticipant_ptr dp)
{
  using namespace DDS;
  using namespace OpenDDS::DCPS;
  using namespace Messenger;
  WaitSet_var ws = new WaitSet;
  MessageTypeSupport_var ts = new MessageTypeSupportImpl;
  ts->register_type(dp, "");
  CORBA::String_var type_name = ts->get_type_name();
  Topic_var topic = dp->create_topic("MyTopic", type_name,
    TOPIC_QOS_DEFAULT, 0, ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);

  Publisher_var pub = dp->create_publisher(PUBLISHER_QOS_DEFAULT, 0,
    ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
  DataWriter_var dw = pub->create_datawriter(topic, DATAWRITER_QOS_DEFAULT, 0,
    ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);

  Subscriber_var sub = dp->create_subscriber(SUBSCRIBER_QOS_DEFAULT, 0,
    ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
  DataReader_var dr = sub->create_datareader(topic, DATAREADER_QOS_DEFAULT, 0,
    ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);

  StatusCondition_var dw_sc = dw->get_statuscondition();
  dw_sc->set_enabled_statuses(PUBLICATION_MATCHED_STATUS);
  ws->attach_condition(dw_sc);
  Duration_t infinite = {DURATION_INFINITE_SEC, DURATION_INFINITE_NSEC};
  ConditionSeq active;

  ReturnCode_t ret = ws->wait(active, infinite);
  if (ret != RETCODE_OK) return ret;

  ret = ws->detach_condition(dw_sc);
  if (ret != RETCODE_OK) return ret;

  MessageDataWriter_var mdw = MessageDataWriter::_narrow(dw);
  Message msg = {0};
  for (int i(0); i < 12; ++i) {
    ++msg.subject_id;
    ret = mdw->write(msg, HANDLE_NIL);
    if (ret != RETCODE_OK) return ret;
  }

  ReadCondition_var dr_rc = dr->create_readcondition(NOT_READ_SAMPLE_STATE,
    NEW_VIEW_STATE, ALIVE_INSTANCE_STATE);
  ReadCondition_var dr_rc2 = dr->create_readcondition(ANY_SAMPLE_STATE,
    ANY_VIEW_STATE, NOT_ALIVE_DISPOSED_INSTANCE_STATE);
  ws->attach_condition(dr_rc);
  ws->attach_condition(dr_rc2);
  MessageDataReader_var mdr = MessageDataReader::_narrow(dr);
  bool passed = true, done = false;
  while (!done) {
    ret = ws->wait(active, infinite);
    if (ret != RETCODE_OK) {
      passed = false;
      break;
    }
    cout << "wait returned" << endl;
    for (CORBA::ULong i(0); i < active.length(); ++i) {
      if (active[i] == dr_rc) {
        // To test both take_w_condition and
        // take_next_instance_w_condition, we'll limit the "take" to 3
        // samples and then use take_next_instance_w_condition.
        MessageSeq data;
        SampleInfoSeq info;
        ret = mdr->take_w_condition(data, info, 3, dr_rc);
        if (ret == RETCODE_NO_DATA) break;
        if (ret != RETCODE_OK) {
          cout << "ERROR: take_w_condition returned " << ret << endl;
          passed = false;
          done = true;
        }
        InstanceHandle_t handle = HANDLE_NIL;
        received_data(data, mdw, msg);
        handle = info[info.length() - 1].instance_handle;
        if (handle == HANDLE_NIL) {
          cout << "ERROR: instance handle is nil" << endl;
          passed = false;
          done = true;
          break;
        }
        cout << "testing take_instance_w_condition" << endl;
        while (true) {
          ret = mdr->take_instance_w_condition(data, info, 1,
                                               handle, dr_rc);
          if (ret == RETCODE_NO_DATA) break;
          if (ret != RETCODE_OK) {
            cout << "ERROR: take_instance_w_condition returned "
                 << ret << endl;
            passed = false;
            done = true;
            break;
          }
          received_data(data, mdw, msg);
        }
      } else if (active[i] == dr_rc2) {
        cout << "an instance has been disposed, exiting" << endl;
        done = true;
      }
    }
  }
  ws->detach_condition(dr_rc);
  ws->detach_condition(dr_rc2);

  dp->delete_contained_entities();
  return passed ? 0 : 1;
}