18 #ifndef __IGN_TRANSPORT_REPHANDLER_HH_INCLUDED__ 19 #define __IGN_TRANSPORT_REPHANDLER_HH_INCLUDED__ 22 #pragma warning(push, 0) 24 #include <google/protobuf/message.h> 48 : hUuid(
Uuid().ToString())
69 public:
virtual void RunCallback(
const std::string &_req,
82 public:
virtual std::string ReqTypeName()
const = 0;
86 public:
virtual std::string RepTypeName()
const = 0;
111 <
void(
const Req &, Rep &,
bool &)> &_cb)
124 auto msgReq = google::protobuf::down_cast<
const Req*>(&_msgReq);
125 auto msgRep = google::protobuf::down_cast<Rep*>(&_msgRep);
127 this->cb(*msgReq, *msgRep, _result);
131 std::cerr <<
"RepHandler::RunLocalCallback() error: " 132 <<
"Callback is NULL" << std::endl;
145 std::cerr <<
"RepHandler::RunCallback() error: " 146 <<
"Callback is NULL" << std::endl;
152 auto msgReq = this->CreateMsg(_req);
160 this->cb(*msgReq, msgRep, _result);
162 if (!msgRep.SerializeToString(&_rep))
164 std::cerr <<
"RepHandler::RunCallback(): Error serializing the " 165 <<
"response" << std::endl;
174 return Req().GetTypeName();
180 return Rep().GetTypeName();
186 private: std::shared_ptr<Req> CreateMsg(
const std::string &_data)
const 189 std::shared_ptr<Req> msgPtr(
new Req());
192 if (!msgPtr->ParseFromString(_data))
194 std::cerr <<
"RepHandler::CreateMsg() error: ParseFromString failed" 202 private: std::function<void(const Req &, Rep &, bool &)> cb;
std::string HandlerUuid() const
Get the unique UUID of this handler.
Definition: RepHandler.hh:75
Interface class used to manage a replier handler.
Definition: RepHandler.hh:44
#define IGNITION_VISIBLE
Use to represent "symbol visible" if supported.
Definition: Helpers.hh:56
std::string hUuid
Unique handler's UUID.
Definition: RepHandler.hh:89
virtual std::string ReqTypeName() const
Get the message type name used in the service request.
Definition: RepHandler.hh:172
IRepHandler()
Constructor.
Definition: RepHandler.hh:47
void RunCallback(const std::string &_req, std::string &_rep, bool &_result)
Executes the callback registered for this handler.
Definition: RepHandler.hh:138
A portable class for representing a Universally Unique Identifier.
Definition: Uuid.hh:41
virtual std::string RepTypeName() const
Get the message type name used in the service response.
Definition: RepHandler.hh:178
google::protobuf::Message ProtoMsg
Definition: TransportTypes.hh:62
void RunLocalCallback(const transport::ProtoMsg &_msgReq, transport::ProtoMsg &_msgRep, bool &_result)
Executes the local callback registered for this handler.
Definition: RepHandler.hh:117
with the service response.
Definition: RepHandler.hh:98
void SetCallback(const std::function< void(const Req &, Rep &, bool &)> &_cb)
Set the callback for this handler.
Definition: RepHandler.hh:110
Definition: AdvertiseOptions.hh:25