示例#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
    void
    CCM_DDS_ContentFilterSetting_i::delete_contentfilteredtopic (
      ::DDS::Subscriber_ptr subscriber)
    {
      DDS4CCM_TRACE ("CCM_DDS_ContentFilterSetting_i::delete_contentfilteredtopic");

      if (! ::CORBA::is_nil (subscriber))
        {
          ::DDS::DomainParticipant_var dp = subscriber->get_participant ();
          ::DDS::ContentFilteredTopic_var cft = this->cft_._retn ();
          if (! ::CORBA::is_nil (dp.in ()) && (! ::CORBA::is_nil (cft.in ())))
            {
              ::CORBA::String_var name = cft->get_name ();
              ::DDS::ReturnCode_t const retcode =
                dp->delete_contentfilteredtopic (cft.in ());

              if (retcode == ::DDS::RETCODE_OK)
                {
                  DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION, (LM_DEBUG, DDS4CCM_INFO
                                "CCM_DDS_ContentFilterSetting_i::delete_contentfilteredtopic: "
                                "successfully deleted ContentFilteredTopic <%C>\n",
                                name.in ()));
                }
              else
                {
                  DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
                                "CCM_DDS_ContentFilterSetting_i::delete_contentfilteredtopic: "
                                "Error deleting ContentFilteredTopic <%C>: <%C>\n",
                                name.in (),
                                translate_retcode (retcode)));
                  throw ::CCM_DDS::InternalError (retcode, 0);
                }
            }
        }
    }
示例#3
0
void
DDS_Base_Connector_T<CCM_TYPE>::passivate_subscriber (
  ::DDS::Subscriber_ptr subscriber,
  ::DDS::SubscriberListener_ptr subscriber_listener)
{
  DDS4CCM_TRACE ("DDS_Base_Connector_T::passivate_subscriber");

  if (!::CORBA::is_nil (subscriber_listener))
    {
      DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION, (LM_DEBUG, DDS4CCM_INFO
                    "DDS_Base_Connector_T::passivate_subscriber - "
                    "Setting the listener on the subscriber to nil\n"));

      DDS::ReturnCode_t const retcode =
        subscriber->set_listener (::DDS::SubscriberListener::_nil (), 0);
      if (retcode != ::DDS::RETCODE_OK)
        {
          DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
                        "DDS_Base_Connector_T::passivate_subscriber - "
                        "Error while setting the listener on the subscriber - <%C>\n",
                        ::CIAO::DDS4CCM::translate_retcode (retcode)));
          throw ::CORBA::INTERNAL ();
        }
    }
}
示例#4
0
void SubscriberDelegate::init_builtin(DDS::Subscriber_ptr ddssub)
{
    if(ddssub == 0) throw dds::core::NullReferenceError(org::opensplice::core::exception_helper(
                    OSPL_CONTEXT_LITERAL(
                        "dds::core::NullReferenceError : Unable to get builtin Subscriber. "
                        "Nil return from ::get_builtin_subscriber")));

    DDS::SubscriberQos qos;
    DDS::ReturnCode_t result = ddssub->get_qos(qos);
    org::opensplice::core::check_and_throw(result, OSPL_CONTEXT_LITERAL("Calling ::get_qos"));
    qos_ = org::opensplice::sub::qos::convertQos(qos);

    sub_.reset(ddssub, ::org::opensplice::core::SubDeleter(dp_->dp_));

    DDS::DataReaderQos oldqos;
    result = sub_->get_default_datareader_qos(oldqos);
    org::opensplice::core::check_and_throw(result, OSPL_CONTEXT_LITERAL("Calling ::get_default_datareader_qos"));

    default_dr_qos_ = org::opensplice::sub::qos::convertQos(oldqos);
    entity_ = DDS::Entity::_narrow(ddssub);

    org::opensplice::core::SubDeleter* d = OSPL_CXX11_STD_MODULE::get_deleter<org::opensplice::core::SubDeleter>(sub_);
    if(d)
    {
        d->set_builtin();
    }
}
示例#5
0
void
DDS_Subscriber_Base_T<CCM_TYPE, TYPED_DDS_READER, VALUE_TYPE, SEQ_VALUE_TYPE>::remove (
  ::DDS::Subscriber_ptr subscriber)
{
  DDS4CCM_TRACE ("DDS_Subscriber_Base_T<CCM_TYPE, TYPED_DDS_READER, VALUE_TYPE, SEQ_VALUE_TYPE>::remove");

  ::DDS::DataReader_var dr = this->dds_read_->get_dds_reader ();

  this->condition_manager_.set_dds_entity (::DDS::DataReader::_nil ());
  this->dds_read_->set_dds_reader (::DDS::DataReader::_nil (), 0);
  this->ccm_data_reader_->set_dds_entity (::DDS::DataReader::_nil ());

  if (!::CORBA::is_nil (dr.in ()))
    {
      DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION_STARTING, (LM_TRACE, DDS4CCM_INFO
                  "DDS_Subscriber_Base_T::remove - "
                  "Going to delete DataReader "
                  DDS_ENTITY_FORMAT_SPECIFIER
                  " from subscriber "
                  DDS_ENTITY_FORMAT_SPECIFIER
                  "\n",
                  DDS_ENTITY_LOG (dr.in ()),
                  DDS_ENTITY_LOG (subscriber)));

      DDS::ReturnCode_t const retval =
        subscriber->delete_datareader (dr.in ());

      if (retval != ::DDS::RETCODE_OK)
        {
          DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
                        ACE_TEXT ("DDS_Subscriber_Base_T::remove - ")
                        ACE_TEXT ("Unable to delete DataReader: <%C>\n"),
                        ::CIAO::DDS4CCM::translate_retcode (retval)));
          throw ::CORBA::INTERNAL ();
        }
      else
        {
          DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_DDS_STATUS, (LM_INFO, DDS4CCM_INFO
              "DDS_Subscriber_Base_T::remove - "
              "Deleted DataReader\n"));
        }
    }

  dr = ::DDS::DataReader::_nil ();
  this->cft_setting_->delete_contentfilteredtopic (subscriber);
}
示例#6
0
    ::DDS::ContentFilteredTopic_ptr
    CCM_DDS_ContentFilterSetting_i::create_contentfilteredtopic (
      ::DDS::Topic_ptr topic,
      ::DDS::Subscriber_ptr subscriber)
    {
      DDS4CCM_TRACE ("CCM_DDS_ContentFilterSetting_i::create_contentfilteredtopic");

      ::DDS::DomainParticipant_var dp = subscriber->get_participant ();
      if (::CORBA::is_nil (dp.in ()))
        {
          DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
                        "CCM_DDS_ContentFilterSetting_i::create_contentfilteredtopic: "
                        "Unable to get DomainParticipant.\n"));
          throw ::CORBA::INTERNAL ();
        }

      ACE_Auto_Array_Ptr <char> name;
      {
        char *name_bootstrap = 0;
        ACE_NEW_THROW_EX (name_bootstrap,
                          char[32],
                          ::CORBA::NO_MEMORY ());
        name.reset(name_bootstrap);
      }
      ACE_OS::sprintf (name.get (),
                       "DDS4CCM_CFT_%ld",
                       reinterpret_cast <unsigned long> (this));

      this->cft_ = dp->create_contentfilteredtopic (name.get (),
                                                    topic,
                                                    this->filter_.expression,
                                                    this->filter_.parameters);
      if (::CORBA::is_nil (this->cft_.in ()))
        {
          DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
                        "CCM_DDS_ContentFilterSetting_i::create_contentfilteredtopic: "
                        "Error creating ContentFilteredTopic <%C>.\n",
                        name.get ()));
          throw ::CORBA::INTERNAL ();
        }
      DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION, (LM_DEBUG, DDS4CCM_INFO
                    "CCM_DDS_ContentFilterSetting_i::create_contentfilteredtopic: "
                    "successfully created ContentFilteredTopic <%C>\n",
                    name.get ()));
      return ::DDS::ContentFilteredTopic::_duplicate (this->cft_);
    }
示例#7
0
int wait_for_data (::DDS::Subscriber_ptr sub,
                   int timeout_sec)
{
  const int factor = 10;
  ACE_Time_Value small_time(0,1000000/factor);
  int timeout_loops = timeout_sec * factor;

  ::DDS::DataReaderSeq_var discard = new ::DDS::DataReaderSeq(10);
  while (timeout_loops-- > 0)
    {
      sub->get_datareaders (
                    discard.inout (),
                    ::DDS::NOT_READ_SAMPLE_STATE,
                    ::DDS::ANY_VIEW_STATE,
                    ::DDS::ANY_INSTANCE_STATE );
      if (discard->length () > 0)
        return 1;

      ACE_OS::sleep (small_time);
    }
  return 0;
}
示例#8
0
void
DDS_Base_Connector_T<CCM_TYPE>::activate_subscriber (
  ACE_Reactor* reactor,
  ::DDS::Subscriber_ptr subscriber,
  ::DDS::SubscriberListener_ptr & subscriber_listener)
{
  DDS4CCM_TRACE ("DDS_Base_Connector_T::activate_subscriber");

  ::CCM_DDS::ConnectorStatusListener_var error_listener =
    this->context_->get_connection_error_listener ();

  ::DDS::StatusMask const mask =
    ::CIAO::DDS4CCM::SubscriberListener::get_mask (error_listener.in ());

  if (mask != 0)
    {
      if (::CORBA::is_nil (subscriber_listener))
        {
          ACE_NEW_THROW_EX (subscriber_listener,
                            ::CIAO::DDS4CCM::SubscriberListener (
                              error_listener.in (),
                              reactor),
                            ::CORBA::NO_MEMORY ());
        }

      DDS::ReturnCode_t const retcode = subscriber->set_listener (subscriber_listener,
                                                                    mask);

      if (retcode != ::DDS::RETCODE_OK)
        {
          DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
                        "DDS_Base_Connector_T::activate_subscriber - "
                        "Error while setting the listener on the subscriber - <%C>\n",
                        ::CIAO::DDS4CCM::translate_retcode (retcode)));
          throw ::CORBA::INTERNAL ();
        }
    }
}
void
SubscriberListenerImpl::on_data_on_readers(
  DDS::Subscriber_ptr subs)
{
  ::DDS::ReturnCode_t ret = subs->begin_access ();
  if (ret != ::DDS::RETCODE_OK) {
    ACE_ERROR((LM_ERROR,
                  ACE_TEXT("%N:%l: SubscriberListenerImpl::on_data_on_readers()")
                  ACE_TEXT(" ERROR: begin_access failed!\n")));
    ACE_OS::exit(-1);
  }

  DDS::SubscriberQos qos;
  ret = subs->get_qos (qos);
  if (ret != ::DDS::RETCODE_OK) {
    ACE_ERROR((LM_ERROR,
                  ACE_TEXT("%N:%l: SubscriberListenerImpl::on_data_on_readers()")
                  ACE_TEXT(" ERROR: get_qos failed!\n")));
    ACE_OS::exit(-1);
  }

  ::DDS::DataReaderSeq_var readers = new ::DDS::DataReaderSeq(100);

  ret = subs->get_datareaders(readers.inout(),
                              ::DDS::NOT_READ_SAMPLE_STATE,
                              ::DDS::ANY_VIEW_STATE,
                              ::DDS::ANY_INSTANCE_STATE) ;
  if (ret != ::DDS::RETCODE_OK) {
    ACE_ERROR((LM_ERROR,
                  ACE_TEXT("%N:%l: SubscriberListenerImpl::on_data_on_readers()")
                  ACE_TEXT(" ERROR: get_datareaders failed!\n")));
    ACE_OS::exit(-1);
  }

  CORBA::ULong len = readers->length ();

  if (qos.presentation.access_scope == ::DDS::GROUP_PRESENTATION_QOS) {
    // redirect datareader listener to receive DISPOSE and UNREGISTER notifications.
    if (len == 0) {
      if (subs->notify_datareaders () != ::DDS::RETCODE_OK) {
        ACE_ERROR((LM_ERROR,
                    ACE_TEXT("%N:%l: SubscriberListenerImpl::on_data_on_readers()")
                    ACE_TEXT(" ERROR: notify_datareaders failed!\n")));
        this->verify_result_ = false;
      }

      return;
    }

    if (len != num_messages * 4) {
      ACE_ERROR((LM_ERROR,
                    ACE_TEXT("%N:%l: SubscriberListenerImpl::on_data_on_readers()")
                    ACE_TEXT(" ERROR: get_datareaders returned %d readers!\n"),
                    len));
      this->verify_result_ = false;
    }

    for (CORBA::ULong i = 0; i < len; ++i) {
      Messenger::MessageDataReader_var message_dr =
        Messenger::MessageDataReader::_narrow(readers[i]);

      Messenger::MessageSeq msg;
      ::DDS::SampleInfoSeq si;
      ret = message_dr->take(msg, si,
              DDS::LENGTH_UNLIMITED,
              ::DDS::NOT_READ_SAMPLE_STATE,
              ::DDS::ANY_VIEW_STATE,
              ::DDS::ANY_INSTANCE_STATE) ;
      if (msg.length() != 1 || si.length() != 1) {
        ACE_ERROR((LM_ERROR,
                    ACE_TEXT("%N:%l: SubscriberListenerImpl::on_data_on_readers()")
                    ACE_TEXT(" ERROR: MessageSeq %d SampleInfoSeq %d!\n"),
                    msg.length(), si.length()));
        this->verify_result_ = false;
      }

      if (ret != DDS::RETCODE_OK) {
        ACE_ERROR((LM_ERROR,
                    ACE_TEXT("%N:%l: SubscriberListenerImpl::on_data_on_readers()")
                    ACE_TEXT(" ERROR: read failed!\n")));
        ACE_OS::exit(-1);
      }

      this->verify (msg[0], si[0], qos, false);
    }
  }
  else if (qos.presentation.access_scope == ::DDS::TOPIC_PRESENTATION_QOS) {
    // redirect datareader listener to receive DISPOSE and UNREGISTER notifications.
    if (len != 2) {
      if (subs->notify_datareaders () != ::DDS::RETCODE_OK) {
        ACE_ERROR((LM_ERROR,
                    ACE_TEXT("%N:%l: SubscriberListenerImpl::on_data_on_readers()")
                    ACE_TEXT(" ERROR: notify_datareaders failed!\n")));
        this->verify_result_ = false;
      }

      return;
    }


    for (CORBA::ULong i = 0; i < len; ++i) {
      Messenger::MessageDataReader_var message_dr =
        Messenger::MessageDataReader::_narrow(readers[i]);

      Messenger::MessageSeq msg;
      ::DDS::SampleInfoSeq si;
      ret = message_dr->take(msg, si,
              DDS::LENGTH_UNLIMITED,
              ::DDS::NOT_READ_SAMPLE_STATE,
              ::DDS::ANY_VIEW_STATE,
              ::DDS::ANY_INSTANCE_STATE) ;

      if (si[0].instance_state == DDS::NOT_ALIVE_DISPOSED_INSTANCE_STATE
         || si[0].instance_state == DDS::NOT_ALIVE_NO_WRITERS_INSTANCE_STATE)

      if (msg.length() != num_messages || si.length() != num_messages) {
        ACE_ERROR((LM_ERROR,
                    ACE_TEXT("%N:%l: SubscriberListenerImpl::on_data_on_readers()")
                    ACE_TEXT(" ERROR: MessageSeq %d SampleInfoSeq %d !\n"),
                    msg.length(), si.length()));
        this->verify_result_ = false;
      }

      if (ret != DDS::RETCODE_OK) {
        ACE_ERROR((LM_ERROR,
                    ACE_TEXT("%N:%l: SubscriberListenerImpl::on_data_on_readers()")
                    ACE_TEXT(" ERROR: read failed!\n")));
        ACE_OS::exit(-1);
      }

      CORBA::ULong num_samples = si.length();
      for (CORBA::ULong i = 0; i < num_samples; ++i) {
        this->verify (msg[i], si[i], qos, i == num_samples - 1 ? true : false);
      }
    }
  }
  else { //::DDS::INSTANCE_PRESENTATION_QOS
    subs->notify_datareaders ();
  }

  ret = subs->end_access ();
  if (ret != ::DDS::RETCODE_OK) {
    ACE_ERROR((LM_ERROR,
                  ACE_TEXT("%N:%l: SubscriberListenerImpl::on_data_on_readers()")
                  ACE_TEXT(" ERROR: end_access failed!\n")));
    ACE_OS::exit(-1);
  }

}
示例#10
0
void
DDS_Subscriber_Base_T<CCM_TYPE, TYPED_DDS_READER, VALUE_TYPE, SEQ_VALUE_TYPE>::configuration_complete (
  ::DDS::Topic_ptr topic,
  ::DDS::Subscriber_ptr subscriber,
  const char * qos_profile,
  DDS_XML_QOS_PARSER_TYPE* qos_xml)
{
  DDS4CCM_TRACE ("DDS_Subscriber_Base_T<CCM_TYPE, TYPED_DDS_READER, VALUE_TYPE, SEQ_VALUE_TYPE>::configuration_complete");

  this->configuration_complete_ = true;

  ::DDS::DataReader_var dr = this->dds_read_->get_dds_reader ();
  if (::CORBA::is_nil (dr.in ()))
    {
      ::DDS::TopicDescription_var td;

      ::CCM_DDS::QueryFilter_var filter = this->cft_setting_->filter ();
      if (ACE_OS::strlen (filter->expression.in ()) > 0)
        {
          ::DDS::ContentFilteredTopic_var cft =
            this->cft_setting_->create_contentfilteredtopic (topic, subscriber);
          if (CORBA::is_nil (cft.in ()))
            {
              DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR,
                            "DDS_Subscriber_Base_T::configuration_complete: "
                            "Error creating ContentFilteredTopic.\n"));
              throw ::CORBA::INTERNAL ();
            }
          td = ::DDS::TopicDescription::_narrow (cft.in ());
        }
      else
        {
          td = ::DDS::TopicDescription::_narrow (topic);
        }
#if (CIAO_DDS4CCM_NDDS==1)
      if (qos_profile)
        {
          dr = subscriber->create_datareader_with_profile (
                                          td.in (),
                                          qos_profile,
                                          ::DDS::DataReaderListener::_nil (),
                                          0);
        }
      else
#endif
        {
          ::DDS::DataReaderQos drqos;
          DDS::ReturnCode_t const retcode =
            subscriber->get_default_datareader_qos (drqos);

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

          if (qos_profile && qos_xml)
            {
              CORBA::String_var name = topic->get_name ();
              DDS::ReturnCode_t const retcode_dr_qos = qos_xml->get_datareader_qos (
                                          drqos,
                                          qos_profile,
                                          name.in ());

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

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

          dr = subscriber->create_datareader (
                                          td.in (),
                                          drqos,
                                          ::DDS::DataReaderListener::_nil (),
                                          0);
        }
      if (!::CORBA::is_nil (dr.in ()))
        {
          DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION, (LM_TRACE, DDS4CCM_INFO
                      "DDS_Subscriber_Base_T::configuration_complete - "
                      "Created DataReader "
                      DDS_ENTITY_FORMAT_SPECIFIER
                      " using subscriber "
                      DDS_ENTITY_FORMAT_SPECIFIER
                      "\n",
                      DDS_ENTITY_LOG (dr.in ()),
                      DDS_ENTITY_LOG (subscriber)));
        }
      else
        {
          DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_DDS_NIL_RETURN, (LM_ERROR, DDS4CCM_INFO
                        "DDS_Subscriber_Base_T::configuration_complete - "
                        "Error: DDS returned a nil datareader.\n"));
          throw ::CORBA::INTERNAL ();
        }

      this->dds_read_->set_dds_reader (dr.in (), &this->condition_manager_);
      this->ccm_data_reader_->set_dds_entity (dr.in ());
      this->condition_manager_.set_dds_entity (dr.in ());
      this->condition_manager_.init_readcondition ();

      DDS::ReturnCode_t const retcode = dr->enable ();
      if (retcode != ::DDS::RETCODE_OK)
        {
          DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
                        "DDS_Subscriber_Base_T::configuration_complete - "
                        "Error: Unable to enable the datareader: <%C>.\n",
                        ::CIAO::DDS4CCM::translate_retcode (retcode)));
          throw ::CORBA::INTERNAL ();
        }
    }
}