RTI Connext Modern C++ API  Version 6.1.0
rti::request::SimpleReplier< RequestType, ReplyType > Class Template Reference

<<reference-type>> A callback-based replier More...

#include <rti/request/SimpleReplier.hpp>

Inheritance diagram for rti::request::SimpleReplier< RequestType, ReplyType >:
dds::core::Reference< detail::ReplierImpl< RequestType, ReplyType > >

Public Member Functions

template<typename Functor >
 SimpleReplier (dds::domain::DomainParticipant participant, const std::string &service_name, Functor request_handler)
 Creates a SimpleReplier. More...
 
template<typename Functor >
 SimpleReplier (const ReplierParams &params, Functor request_handler)
 Creates a SimpleReplier with additional parameters. More...
 

Detailed Description

template<typename RequestType, typename ReplyType>
class rti::request::SimpleReplier< RequestType, ReplyType >

<<reference-type>> A callback-based replier

Note
A SimpleReplier provides all the functions of a <<reference-type>> except close() and retain().

A SimpleReplier is based on a callback functor. Requests are passed to the callback, which returns a reply. The reply is directed only to the Requester that sent the request.

SimpleRepliers are useful for simple use cases where a single reply for a request can be generated quickly, for example, looking up a table.

When more than one reply for a request can be generated or the processing is complex or needs to happen asynchronously, use a rti::request::Replier instead.

See also
rti::request::Replier
SimpleReplier example

In the following example, the SimpleReplier responds to requests consisting of the built-in type dds::core::StringTopicType with another string that prepends "Hello" to the request.

SimpleReplier<StringTopicType, StringTopicType> simple_replier(
participant,
"Test",
[](const StringTopicType& request) {
// If a Requester sends "World", this SimpleReplier will
// reply with "Hello World"
return StringTopicType("Hello " + request.data());
}
);

Constructor & Destructor Documentation

◆ SimpleReplier() [1/2]

template<typename RequestType , typename ReplyType >
template<typename Functor >
rti::request::SimpleReplier< RequestType, ReplyType >::SimpleReplier ( dds::domain::DomainParticipant  participant,
const std::string &  service_name,
Functor  request_handler 
)
inline

Creates a SimpleReplier.

Template Parameters
FunctorA function or function object that can receive a single parameter const RequestType& and returns a ReplyType instance by value.
Parameters
participantThe DomainParticipant that the Replier uses to join a domain.
service_nameThe service name. See ReplierParams::service_name
request_handlerA functor that receives a request and returns a reply

◆ SimpleReplier() [2/2]

template<typename RequestType , typename ReplyType >
template<typename Functor >
rti::request::SimpleReplier< RequestType, ReplyType >::SimpleReplier ( const ReplierParams params,
Functor  request_handler 
)
inline

Creates a SimpleReplier with additional parameters.

Template Parameters
FunctorA function or function object that can receive a single parameter const RequestType& and returns a ReplyType instance by value.
Parameters
paramsThe parameters used to configure the replier
request_handlerA functor that receives a request and returns a reply

References dds::sub::DataReader< T >::take().