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
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() ;
  }
}