RTI Connext Modern C++ API  Version 6.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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.
 
template<typename Functor >
 SimpleReplier (const ReplierParams &params, Functor request_handler)
 Creates a SimpleReplier with additional parameters.
 

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

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
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

RTI Connext Modern C++ API Version 6.0.1 Copyright © Sat Nov 23 2019 Real-Time Innovations, Inc