RTI Connext Traditional C++ API  Version 5.2.0
 All Classes Functions Variables Typedefs Enumerations Enumerator Groups Pages
connext::Replier< TReq, TRep > Class Template Reference

Allows receiving requests and sending replies. More...

Public Types

typedef TReq Request
 The request type.
 
typedef TRep Reply
 The reply type.
 
typedef dds_type_traits< TRep >
::DataWriter 
ReplyDataWriter
 The typed DataWriter for type TRep.
 
typedef dds_type_traits< TReq >
::DataReader 
RequestDataReader
 The typed DataReader for type TReq.
 

Public Member Functions

 Replier (DDSDomainParticipant *participant, const std::string &service_name)
 Creates a Replier with the minimum set of parameters.
 
 Replier (const ReplierParams< TReq, TRep > &params)
 Creates a Replier with parameters.
 
virtual ~Replier ()
 Releases the internal entities created by this Replier.
 
template<typename URep >
void send_reply (const URep &reply, const SampleIdentity_t &related_request_id)
 Sends a reply for a previous request.
 
template<typename URep >
void send_reply (WriteSample< URep > &reply, const SampleIdentity_t &related_request_id)
 Sends a reply for a previous request.
 
template<typename URep >
void send_reply (WriteSampleRef< URep > &reply, const SampleIdentity_t &related_request_id)
 Sends a reply for a previous request using a SampleRef.
 
bool receive_request (connext::Sample< TReq > &request, const DDS_Duration_t &max_wait)
 Waits for a request and copies its contents into a Sample.
 
bool receive_request (connext::SampleRef< TReq > request, const DDS_Duration_t &max_wait)
 Waits for a request and copies its contents into a SampleRef.
 
LoanedSamplesType receive_requests (const DDS_Duration_t &max_wait)
 Waits for multiple requests and provides a loaned container to access them.
 
LoanedSamplesType receive_requests (int min_request_count, int max_request_count, const DDS_Duration_t &max_wait)
 Waits for multiple requests and provides a loaned container to access them.
 
bool wait_for_requests (const DDS_Duration_t &max_wait)
 Waits for requests.
 
bool wait_for_requests (int min_count, const DDS_Duration_t &max_wait)
 Waits for requests.
 
bool take_request (connext::Sample< TReq > &request)
 Copies the contents of a request into a Sample.
 
bool take_request (connext::SampleRef< TReq > request)
 Copies the contents of a request into a SampleRef.
 
LoanedSamplesType take_requests (int max_samples=DDS_LENGTH_UNLIMITED)
 Provides a loaned container to access the existing requests.
 
bool read_request (connext::Sample< TReq > &request)
 Copies the contents of a request into a Sample.
 
bool read_request (connext::SampleRef< TReq > request)
 Copies the contents of a request into a SampleRef.
 
LoanedSamplesType read_requests (int max_samples=DDS_LENGTH_UNLIMITED)
 Provides a loaned container to access the existing requests.
 
RequestDataReaderget_request_datareader () const
 Retrieves the underlying DDSDataReader.
 
ReplyDataWriterget_reply_datawriter () const
 Retrieves the underlying DDSDataWriter.
 

Detailed Description

template<typename TReq, typename TRep>
class connext::Replier< TReq, TRep >

Allows receiving requests and sending replies.

A Replier is an entity with two associated topics: a request topic and a reply topic. It can receive requests by subscribing to the request topic and can send replies to those requests by publishing the reply topic.

Valid types for these topics (TReq and TRep) are: those generated by the rtiddsgen code generator, the DDS built-in types, and DynamicData. See Creating a Replier.

A Replier has four main types of operations:

  • Waiting for requests to be received from the middleware
  • Getting those requests
  • Receiving requests (a convenience operation that is a combination of waiting and getting in a single operation)
  • Sending a reply for a previously received request (i.e., publishing a reply sample on the reply topic with special meta-data so that the orignal Requester can identify it)

For multi-reply scenarios in which a connext::Replier generates more than one reply for a request, the connext::Replier should mark all the intermediate replies (all but the last) using the DDS_INTERMEDIATE_REPLY_SEQUENCE_SAMPLE flag in DDS_WriteParams_t::flag.

Much like a Requester, a Replier has an associated DDSDomainParticipant, which can be shared with other Repliers or RTI Connext routines. All the other entities required for the request-reply interaction, including a DDSDataWriter for writing replies and a DDSDataReader for reading requests, are automatically created when the Replier is constructed.

Quality of Service for the underlying DataWriter and DataReader can be configured (see connext::RequesterParams::qos_profile). By default, they are created with reliable quality of service. The exact default configuration is described here: Configuring Request-Reply QoS profiles

There are several ways to use a Replier:

Template Parameters
TReqThe data type for the request topic
TRepThe data type for the reply topic
See Also
connext::Requester
Request-Reply Examples
Basic Replier example

Member Typedef Documentation

template<typename TReq, typename TRep>
typedef TReq connext::Replier< TReq, TRep >::Request

The request type.

template<typename TReq, typename TRep>
typedef TRep connext::Replier< TReq, TRep >::Reply

The reply type.

template<typename TReq, typename TRep>
typedef dds_type_traits<TRep>::DataWriter connext::Replier< TReq, TRep >::ReplyDataWriter

The typed DataWriter for type TRep.

template<typename TReq, typename TRep>
typedef dds_type_traits<TReq>::DataReader connext::Replier< TReq, TRep >::RequestDataReader

The typed DataReader for type TReq.

Constructor & Destructor Documentation

template<typename TReq , typename TRep >
Replier< TReq, TRep >::Replier ( DDSDomainParticipant participant,
const std::string &  service_name 
)

Creates a Replier with the minimum set of parameters.

Parameters
participantThe DomainParticipant that this Replier uses to join a domain.
service_nameThe service name. See connext::ReplierParams::service_name
Exceptions
Oneof the RTI Connext Exceptions
template<typename TReq, typename TRep>
Replier< TReq, TRep >::Replier ( const ReplierParams< TReq, TRep > &  params)
explicit

Creates a Replier with parameters.

Parameters
paramsAll the parameters that configure this Replier
Exceptions
Oneof the RTI Connext Exceptions
See Also
connext::ReplierParams
Creating a Replier
template<typename TReq , typename TRep >
Replier< TReq, TRep >::~Replier ( )
virtual

Releases the internal entities created by this Replier.

Among other internal resources, it deletes the Replier's underlying DataReader and DataWriter.

See Also
DDSSubscriber::delete_datareader
DDSPublisher::delete_datawriter

Member Function Documentation

template<typename TReq , typename TRep >
template<typename URep >
void Replier< TReq, TRep >::send_reply ( const URep &  reply,
const SampleIdentity_t related_request_id 
)

Sends a reply for a previous request.

The related request identity can be retrieved from an existing request sample (connext::Sample).

Parameters
replyThe reply to be sent.
related_request_idThe identity of a previously received request
Exceptions
Oneof the RTI Connext Exceptions
See Also
connext::Sample::identity()
receive_request(Sample<TReq>&, const Duration_t&)
receive_requests(int, int, const Duration_t&)
take_request(Sample<TReq>&)
take_requests(int)
Basic Replier example
template<typename TReq , typename TRep >
template<typename URep >
void Replier< TReq, TRep >::send_reply ( WriteSample< URep > &  reply,
const SampleIdentity_t related_request_id 
)

Sends a reply for a previous request.

Allows you to set custom parameters for writing a reply.

Contrary to the connext::Requester, where retrieving the sample identity for correlation is common, on the Replier side using a WriteSample is only necessary when the default write parameters need to be overridden, and send_reply(const URep&, const SampleIdentity_t&) may be used if that is not necessary.

One reason to override the default write parameters is a multi-reply scenario in which a connext::Replier generates more than one reply for a request. In this case, all the intermediate replies (all but the last) should be marked with the DDS_INTERMEDIATE_REPLY_SEQUENCE_SAMPLE flag in DDS_WriteParams_t::flag within connext::WriteSample::info().

A connext::Requester can detect if a reply is the last reply of a sequence of replies by checking that the flag DDS_INTERMEDIATE_REPLY_SEQUENCE_SAMPLE is not set in DDS_SampleInfo::flag within connext::Sample::info().

See Also
send_reply(const URep&, const SampleIdentity_t&)
connext::WriteSample
template<typename TReq , typename TRep >
template<typename URep >
void Replier< TReq, TRep >::send_reply ( WriteSampleRef< URep > &  reply,
const SampleIdentity_t related_request_id 
)
template<typename TReq, typename TRep >
bool Replier< TReq, TRep >::receive_request ( connext::Sample< TReq > &  request,
const DDS_Duration_t max_wait 
)
template<typename TReq, typename TRep >
bool Replier< TReq, TRep >::receive_request ( connext::SampleRef< TReq >  request,
const DDS_Duration_t max_wait 
)

Waits for a request and copies its contents into a SampleRef.

See Also
connext::Requester::receive_reply(SampleRef<TRep>, const Duration_t&)
template<typename TReq , typename TRep >
Replier< TReq, TRep >::LoanedSamplesType Replier< TReq, TRep >::receive_requests ( const DDS_Duration_t max_wait)

Waits for multiple requests and provides a loaned container to access them.

Equivalent to using receive_requests(int, int, const Duration_t&) with min_count=1 and max_count=DDS_LENGTH_UNLIMITED

See Also
connext::LoanedSamples
receive_requests(int, int, const Duration_t&)
template<typename TReq , typename TRep >
Replier< TReq, TRep >::LoanedSamplesType Replier< TReq, TRep >::receive_requests ( int  min_request_count,
int  max_request_count,
const DDS_Duration_t max_wait 
)

Waits for multiple requests and provides a loaned container to access them.

Equivalent to using wait_for_requests(int, const Duration_t&) and take_requests(int)

See Also
connext::LoanedSamples
wait_for_requests(int, const Duration_t&)
take_requests(int)
template<typename TReq , typename TRep >
bool Replier< TReq, TRep >::wait_for_requests ( const DDS_Duration_t max_wait)

Waits for requests.

Equivalent to wait_for_requests(int, const Duration_t&) with min_count=1

See Also
wait_for_requests(int, const Duration_t&)
template<typename TReq , typename TRep >
bool Replier< TReq, TRep >::wait_for_requests ( int  min_count,
const DDS_Duration_t max_wait 
)

Waits for requests.

This operation waits for min_count requests to be available. It will wait up to max_wait .

This operation is similar to connext::Requester::wait_for_replies(int, const Duration_t&).

Parameters
min_countMinimum number of requests that need to be available for this operation to unblock.
max_waitMaximum waiting time after which this operation unblocks regardless of how many requests are available.
Returns
true if at least min_count requests were available before max_wait elapsed, or false otherwise.
See Also
take_requests(int)
connext::Requester::wait_for_replies(int, const Duration_t&)
template<typename TReq, typename TRep >
bool Replier< TReq, TRep >::take_request ( connext::Sample< TReq > &  request)

Copies the contents of a request into a Sample.

See Also
connext::Requester::take_reply(Sample<TRep>&)
template<typename TReq, typename TRep >
bool Replier< TReq, TRep >::take_request ( connext::SampleRef< TReq >  request)

Copies the contents of a request into a SampleRef.

See Also
connext::Requester::take_reply(SampleRef<TRep>)
template<typename TReq , typename TRep >
Replier< TReq, TRep >::LoanedSamplesType Replier< TReq, TRep >::take_requests ( int  max_samples = DDS_LENGTH_UNLIMITED)

Provides a loaned container to access the existing requests.

See Also
connext::Requester::take_replies(int)
template<typename TReq, typename TRep >
bool Replier< TReq, TRep >::read_request ( connext::Sample< TReq > &  request)

Copies the contents of a request into a Sample.

This operation is equivalent to connext::Replier::take_request(Sample<TReq>&) except the request remains in the Replier and can be read or taken again.

template<typename TReq, typename TRep >
bool Replier< TReq, TRep >::read_request ( connext::SampleRef< TReq >  request)

Copies the contents of a request into a SampleRef.

See Also
connext::Requester::read_reply(SampleRef<TRep>)
template<typename TReq , typename TRep >
Replier< TReq, TRep >::LoanedSamplesType Replier< TReq, TRep >::read_requests ( int  max_samples = DDS_LENGTH_UNLIMITED)

Provides a loaned container to access the existing requests.

This operation is equivalent to connext::Replier::take_requests(int) except the requests remain in the Replier and can be read or taken again.

template<typename TReq , typename TRep >
Replier< TReq, TRep >::RequestDataReader * Replier< TReq, TRep >::get_request_datareader ( ) const
inline

Retrieves the underlying DDSDataReader.

See Also
connext::Requester::get_reply_datareader()
template<typename TReq , typename TRep >
Replier< TReq, TRep >::ReplyDataWriter * Replier< TReq, TRep >::get_reply_datawriter ( ) const
inline

RTI Connext Traditional C++ API Version 5.2.0 Copyright © Sun Jun 21 2015 Real-Time Innovations, Inc