Interface class used to manage a request handler. More...
#include <gz/transport/ReqHandler.hh>
Public Member Functions | |
IReqHandler (const std::string &_nUuid) | |
Constructor. | |
virtual | ~IReqHandler ()=default |
Destructor. | |
std::string | HandlerUuid () const |
Returns the unique handler UUID. | |
std::string | NodeUuid () const |
Get the node UUID. | |
virtual void | NotifyResult (const std::string &_rep, const bool _result)=0 |
Executes the callback registered for this handler and notify a potential requester waiting on a blocking call. | |
virtual std::string | RepTypeName () const =0 |
Get the message type name used in the service response. | |
virtual std::string | ReqTypeName () const =0 |
Get the message type name used in the service request. | |
bool | Requested () const |
Returns if this service call request has already been requested. | |
void | Requested (const bool _value) |
Mark the service call as requested (or not). | |
std::string | Response () const |
Get the service response as raw bytes. | |
bool | Result () const |
Get the result of the service response. | |
virtual bool | Serialize (std::string &_buffer) const =0 |
Serialize the Req protobuf message stored. | |
template<typename Lock > | |
bool | WaitUntil (Lock &_lock, const unsigned int _timeout) |
Block the current thread until the response to the service request is available or until the timeout expires. This method uses a condition variable to notify when the response is available. | |
Public Attributes | |
bool | repAvailable |
When there is a blocking service call request, the call can be unlocked when a service call REP is available. This variable captures if we have found a node that can satisty our request. | |
Protected Attributes | |
std::condition_variable_any | condition |
Condition variable used to wait until a service call REP is available. | |
std::string | hUuid |
Unique handler's UUID. | |
std::string | rep |
Stores the service response as raw bytes. | |
bool | result |
Stores the result of the service call. | |
Detailed Description
Interface class used to manage a request handler.
Constructor & Destructor Documentation
◆ IReqHandler()
|
inlineexplicit |
Constructor.
- Parameters
-
[in] _nUuid UUID of the node registering the request handler.
◆ ~IReqHandler()
|
virtualdefault |
Destructor.
Member Function Documentation
◆ HandlerUuid()
|
inline |
◆ NodeUuid()
|
inline |
Get the node UUID.
- Returns
- The string representation of the node UUID.
◆ NotifyResult()
|
pure virtual |
Executes the callback registered for this handler and notify a potential requester waiting on a blocking call.
- Parameters
-
[in] _rep Serialized data containing the response coming from the service call responser. [in] _result Contains the result of the service call coming from the service call responser.
Implemented in ReqHandler< Req, Rep >, and ReqHandler< google::protobuf::Message, google::protobuf::Message >.
◆ RepTypeName()
|
pure virtual |
Get the message type name used in the service response.
- Returns
- Message type name.
Implemented in ReqHandler< Req, Rep >, and ReqHandler< google::protobuf::Message, google::protobuf::Message >.
◆ ReqTypeName()
|
pure virtual |
Get the message type name used in the service request.
- Returns
- Message type name.
Implemented in ReqHandler< Req, Rep >, and ReqHandler< google::protobuf::Message, google::protobuf::Message >.
◆ Requested() [1/2]
|
inline |
Returns if this service call request has already been requested.
- Returns
- True when the service call has been requested.
◆ Requested() [2/2]
|
inline |
Mark the service call as requested (or not).
- Parameters
-
[in] _value true when you want to flag this REQ as requested.
◆ Response()
|
inline |
Get the service response as raw bytes.
- Returns
- The string containing the service response.
References IReqHandler::rep.
◆ Result()
|
inline |
◆ Serialize()
|
pure virtual |
Serialize the Req protobuf message stored.
- Parameters
-
[out] _buffer The serialized data.
- Returns
- True if the serialization succeed or false otherwise.
Implemented in ReqHandler< Req, Rep >, and ReqHandler< google::protobuf::Message, google::protobuf::Message >.
◆ WaitUntil()
|
inline |
Block the current thread until the response to the service request is available or until the timeout expires. This method uses a condition variable to notify when the response is available.
- Parameters
-
[in] _lock Lock used to protect the condition variable. [in] _timeout Maximum waiting time in milliseconds.
- Returns
- True if the service call was executed or false otherwise.
References IReqHandler::condition, steady_clock::now(), IReqHandler::repAvailable, and condition_variable_any::wait_until().
Member Data Documentation
◆ condition
|
protected |
Condition variable used to wait until a service call REP is available.
Referenced by ReqHandler< Req, Rep >::NotifyResult(), ReqHandler< google::protobuf::Message, google::protobuf::Message >::NotifyResult(), and IReqHandler::WaitUntil().
◆ hUuid
|
protected |
Unique handler's UUID.
Referenced by IReqHandler::HandlerUuid().
◆ rep
|
protected |
Stores the service response as raw bytes.
Referenced by ReqHandler< Req, Rep >::NotifyResult(), ReqHandler< google::protobuf::Message, google::protobuf::Message >::NotifyResult(), and IReqHandler::Response().
◆ repAvailable
bool repAvailable |
When there is a blocking service call request, the call can be unlocked when a service call REP is available. This variable captures if we have found a node that can satisty our request.
Referenced by ReqHandler< Req, Rep >::NotifyResult(), ReqHandler< google::protobuf::Message, google::protobuf::Message >::NotifyResult(), and IReqHandler::WaitUntil().
◆ result
|
protected |
Stores the result of the service call.
Referenced by ReqHandler< Req, Rep >::NotifyResult(), ReqHandler< google::protobuf::Message, google::protobuf::Message >::NotifyResult(), and IReqHandler::Result().
The documentation for this class was generated from the following file: