18 #ifndef IGN_TRANSPORT_REPHANDLER_HH_ 19 #define IGN_TRANSPORT_REPHANDLER_HH_ 22 #pragma warning(push, 0) 24 #include <google/protobuf/message.h> 29 #if GOOGLE_PROTOBUF_VERSION > 2999999 30 #include <google/protobuf/stubs/casts.h> 52 : hUuid(
Uuid().ToString())
73 public:
virtual void RunCallback(
const std::string &_req,
86 public:
virtual std::string ReqTypeName()
const = 0;
90 public:
virtual std::string RepTypeName()
const = 0;
115 <
void(
const Req &, Rep &,
bool &)> &_cb)
128 #if GOOGLE_PROTOBUF_VERSION > 2999999 129 auto msgReq = google::protobuf::down_cast<
const Req*>(&_msgReq);
130 auto msgRep = google::protobuf::down_cast<Rep*>(&_msgRep);
133 google::protobuf::internal::down_cast<
const Req*>(&_msgReq);
134 auto msgRep = google::protobuf::internal::down_cast<Rep*>(&_msgRep);
137 this->cb(*msgReq, *msgRep, _result);
141 std::cerr <<
"RepHandler::RunLocalCallback() error: " 142 <<
"Callback is NULL" << std::endl;
155 std::cerr <<
"RepHandler::RunCallback() error: " 156 <<
"Callback is NULL" << std::endl;
162 auto msgReq = this->CreateMsg(_req);
170 this->cb(*msgReq, msgRep, _result);
172 if (!msgRep.SerializeToString(&_rep))
174 std::cerr <<
"RepHandler::RunCallback(): Error serializing the " 175 <<
"response" << std::endl;
184 return Req().GetTypeName();
190 return Rep().GetTypeName();
196 private: std::shared_ptr<Req> CreateMsg(
const std::string &_data)
const 199 std::shared_ptr<Req> msgPtr(
new Req());
202 if (!msgPtr->ParseFromString(_data))
204 std::cerr <<
"RepHandler::CreateMsg() error: ParseFromString failed" 212 private: std::function<void(const Req &, Rep &, bool &)> cb;
Interface class used to manage a replier handler.
Definition: RepHandler.hh:48
std::string hUuid
Unique handler's UUID.
Definition: RepHandler.hh:93
IRepHandler()
Constructor.
Definition: RepHandler.hh:51
void RunCallback(const std::string &_req, std::string &_rep, bool &_result)
Executes the callback registered for this handler.
Definition: RepHandler.hh:148
A portable class for representing a Universally Unique Identifier.
Definition: Uuid.hh:41
google::protobuf::Message ProtoMsg
Definition: TransportTypes.hh:65
void RunLocalCallback(const transport::ProtoMsg &_msgReq, transport::ProtoMsg &_msgRep, bool &_result)
Executes the local callback registered for this handler.
Definition: RepHandler.hh:121
with the service response.
Definition: RepHandler.hh:102
#define IGNITION_TRANSPORT_VISIBLE
Use to represent "symbol visible" if supported.
Definition: Helpers.hh:57
virtual std::string ReqTypeName() const
Get the message type name used in the service request.
Definition: RepHandler.hh:182
void SetCallback(const std::function< void(const Req &, Rep &, bool &)> &_cb)
Set the callback for this handler.
Definition: RepHandler.hh:114
Definition: AdvertiseOptions.hh:27
std::string HandlerUuid() const
Get the unique UUID of this handler.
Definition: RepHandler.hh:79
virtual std::string RepTypeName() const
Get the message type name used in the service response.
Definition: RepHandler.hh:188