Ejemplo n.º 1
0
Reader::Reader(::DDS::DomainParticipant_ptr dp,
               int history_depth,
               int max_samples_per_instance)
    : max_samples_per_instance_(max_samples_per_instance),
    dp_(::DDS::DomainParticipant::_duplicate (dp))
{
  sub_ = dp->create_subscriber(SUBSCRIBER_QOS_DEFAULT,
                             ::DDS::SubscriberListener::_nil(),
                             ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
  if (CORBA::is_nil (sub_.in ()))
  {
    ACE_ERROR ((LM_ERROR,
               ACE_TEXT("(%P|%t) create_subscriber failed.\n")));
    throw TestException() ;
  }


  ::DDS::TopicDescription_var description =
      dp->lookup_topicdescription(MY_TOPIC);
  if (CORBA::is_nil (description.in ()))
  {
    ACE_ERROR ((LM_ERROR,
               ACE_TEXT("(%P|%t) lookup_topicdescription failed.\n")));
    throw TestException() ;
  }

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

  dr_qos.history.depth = history_depth  ;
  dr_qos.resource_limits.max_samples_per_instance =
            max_samples_per_instance ;

  dr_qos.liveliness.lease_duration.sec =
          static_cast<CORBA::Long> (max_blocking_time.sec ());
  dr_qos.liveliness.lease_duration.nanosec = 0 ;

  ::DDS::DataReaderListener_var drl (new DataReaderListenerImpl);

  ::DDS::DataReader_var dr = sub_->create_datareader(description.in (),
                                dr_qos,
//                                ::DDS::DataReaderListener::_nil()
                                drl.in (),
                                ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);

  if (CORBA::is_nil (dr.in ()))
  {
    ACE_ERROR ((LM_ERROR,
               ACE_TEXT("(%P|%t) create_datareader failed.\n")));
    throw TestException() ;
  }
}
Ejemplo n.º 2
0
void
DDS_Base_Connector_T<CCM_TYPE>::init_subscriber (
  ::DDS::DomainParticipant_ptr participant,
  ::DDS::Subscriber_ptr & subscriber)
{
  DDS4CCM_TRACE ("DDS_Base_Connector_T::init_subscriber");

  if (::CORBA::is_nil (subscriber))
    {
#if (CIAO_DDS4CCM_NDDS==1)
      if (this->qos_profile_.in () != 0)
        {
          subscriber = participant->create_subscriber_with_profile (
                                              this->qos_profile_.in (),
                                              ::DDS::SubscriberListener::_nil (),
                                              0);
        }
      else
#endif
        {
          ::DDS::SubscriberQos sqos;
          DDS::ReturnCode_t const retcode =
            participant->get_default_subscriber_qos (sqos);

          if (retcode != DDS::RETCODE_OK)
            {
              DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
                  "DDS_Base_Connector_T::init_subscriber - "
                  "Error: Unable to retrieve get_default_subscriber_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_sub_qos =
                this->qos_xml_->get_subscriber_qos (
                  sqos,
                  this->qos_profile_.in ());

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

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

          subscriber = participant->create_subscriber (sqos,
                                              ::DDS::SubscriberListener::_nil (),
                                              0);
        }
      if (!::CORBA::is_nil (subscriber))
        {
          DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION, (LM_TRACE, DDS4CCM_INFO
                      "DDS_Base_Connector_T::init_subscriber - "
                      "Created subscriber "
                      DDS_ENTITY_FORMAT_SPECIFIER
                      " using participant "
                      DDS_ENTITY_FORMAT_SPECIFIER
                      "\n",
                      DDS_ENTITY_LOG (subscriber),
                      DDS_ENTITY_LOG (participant)));
        }
      else
        {
          DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_DDS_NIL_RETURN, (LM_ERROR, DDS4CCM_INFO
                        "DDS_Base_Connector_T::init_subscriber - "
                        "Error: DDS returned a nil subscriber.\n"));
          throw ::CCM_DDS::InternalError (::DDS::RETCODE_ERROR, 0);
        }
    }
}
Ejemplo n.º 3
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;
}
Ejemplo n.º 4
0
Reader::Reader(::DDS::DomainParticipant_ptr dp,
               int history_depth,
               int max_samples_per_instance)
    : max_samples_per_instance_(max_samples_per_instance),
    dp_(::DDS::DomainParticipant::_duplicate (dp))
{
  sub_ = dp->create_subscriber(SUBSCRIBER_QOS_DEFAULT,
                             ::DDS::SubscriberListener::_nil());
  if (CORBA::is_nil (sub_.in ()))
  {
    ACE_ERROR ((LM_ERROR,
               ACE_TEXT("(%P|%t) create_subscriber failed.\n")));
    throw TestException() ;
  }

  // Initialize the transport
  if (0 != init_transport() )
  {
    ACE_ERROR ((LM_ERROR,
                 ACE_TEXT("(%P|%t) init_transport failed!\n")));
    throw TestException() ;
  }

  // Attach the subscriber to the transport.
  TAO::DCPS::SubscriberImpl* sub_impl
    = TAO::DCPS::reference_to_servant<TAO::DCPS::SubscriberImpl> (sub_.in ());

  if (0 == sub_impl)
  {
    ACE_ERROR ((LM_ERROR,
               ACE_TEXT("(%P|%t) Failed to obtain servant ::TAO::DCPS::SubscriberImpl\n")));
    throw TestException() ;
  }
  sub_impl->attach_transport(reader_transport_impl.in());

  ::DDS::TopicDescription_var description =
      dp->lookup_topicdescription(MY_TOPIC);
  if (CORBA::is_nil (description.in ()))
  {
    ACE_ERROR ((LM_ERROR,
               ACE_TEXT("(%P|%t) lookup_topicdescription failed.\n")));
    throw TestException() ;
  }

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

  dr_qos.history.depth = history_depth  ;
  dr_qos.resource_limits.max_samples_per_instance =
            max_samples_per_instance ;

  dr_qos.liveliness.lease_duration.sec =
	  static_cast<CORBA::Long> (max_blocking_time.sec ());
  dr_qos.liveliness.lease_duration.nanosec = 0 ;

  ::DDS::DataReaderListener_var drl
    = ::TAO::DCPS::servant_to_reference(&drl_servant_);

  ::DDS::DataReader_var dr = sub_->create_datareader(description.in (),
                                dr_qos,
//                                ::DDS::DataReaderListener::_nil()
                                drl.in ());

  if (CORBA::is_nil (dr.in ()))
  {
    ACE_ERROR ((LM_ERROR,
               ACE_TEXT("(%P|%t) create_datareader failed.\n")));
    throw TestException() ;
  }
}
Ejemplo n.º 5
0
::DDS::Subscriber_ptr
create_subscriber (::DDS::DomainParticipant_ptr participant,
                   int                          attach_to_udp,
                   int                          attach_to_multicast,
                   int                          attach_to_rtps,
                   int                          attach_to_shmem)
{

  // Create the subscriber
  ::DDS::Subscriber_var sub;

  try
    {
      sub = participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT,
                             ::DDS::SubscriberListener::_nil(),
                             ::OpenDDS::DCPS::DEFAULT_STATUS_MASK);
      if (CORBA::is_nil (sub.in ()))
        {
          ACE_ERROR ((LM_ERROR,
            ACE_TEXT ("Failed to create_subscriber.")));
          return ::DDS::Subscriber::_nil ();
        }

      // Attach the subscriber to the transport.
      if (attach_to_udp)
        {
          ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) attach to udp \n")));
          TheTransportRegistry->bind_config("udp", sub.in());
        }
      else if (attach_to_multicast)
        {
          ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) attach to multicast \n")));
          TheTransportRegistry->bind_config("multicast", sub.in());
        }
      else if (attach_to_rtps)
        {
          ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) attach to RTPS\n")));
          TheTransportRegistry->bind_config("rtps", sub);
        }
      else if (attach_to_shmem)
        {
          ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) attach to shmem\n")));
          TheTransportRegistry->bind_config("shmem", sub);
        }
      else
        {
          ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) attach to tcp \n")));
          TheTransportRegistry->bind_config("tcp", sub.in());
        }

    }
  catch (const TestException&)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT("(%P|%t) TestException caught in create_subscriber. ")));
      return ::DDS::Subscriber::_nil ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Exception caught in create_subscriber.");
      return ::DDS::Subscriber::_nil ();
    }

  return sub._retn ();
}
Ejemplo n.º 6
0
::DDS::Subscriber_ptr
create_subscriber (::DDS::DomainParticipant_ptr participant,
                   int                          attach_to_udp,
                   int                          attach_to_mcast,
                   int                          attach_to_reliable_multicast)
{

  // Create the subscriber
  ::DDS::Subscriber_var sub;

  try
    {
      sub = participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT,
                             ::DDS::SubscriberListener::_nil());
      if (CORBA::is_nil (sub.in ()))
        {
          ACE_ERROR ((LM_ERROR,
            ACE_TEXT ("Failed to create_subscriber.")));
          return ::DDS::Subscriber::_nil ();
        }

      // Attach the subscriber to the transport.
      ::TAO::DCPS::SubscriberImpl* sub_impl
        = ::TAO::DCPS::reference_to_servant< ::TAO::DCPS::SubscriberImpl,
                                             ::DDS::Subscriber_ptr>
                              (sub.in ());

      if (0 == sub_impl)
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT("(%P|%t) Failed to obtain subscriber servant\n")));
          return ::DDS::Subscriber::_nil ();
        }

      TAO::DCPS::AttachStatus attach_status;

      if (attach_to_udp)
        {
          ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) attach to udp \n")));
          attach_status = sub_impl->attach_transport(reader_udp_impl.in());
        }
      else if (attach_to_mcast)
        {
          ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) attach to mcast \n")));
          attach_status = sub_impl->attach_transport(reader_mcast_impl.in());
        }
      else if (attach_to_reliable_multicast)
        {
          ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) attach to reliable multicast \n")));
          attach_status = sub_impl->attach_transport(reader_reliable_multicast_impl.in());
        }
      else
        {
          ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) attach to tcp \n")));
          attach_status = sub_impl->attach_transport(reader_tcp_impl.in());
        }

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

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

          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT("(%P|%t) Failed to attach to the transport. ")
                      ACE_TEXT("AttachStatus == %s\n"),
                      status_str.c_str()));
          return ::DDS::Subscriber::_nil ();
        }
    }
  catch (const TestException&)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT("(%P|%t) TestException caught in create_subscriber. ")));
      return ::DDS::Subscriber::_nil ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Exception caught in create_subscriber.");
      return ::DDS::Subscriber::_nil ();
    }

  return sub._retn ();
}