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> 38 #include "ignition/transport/config.hh" 39 #include "ignition/transport/Export.hh" 48 inline namespace IGNITION_TRANSPORT_VERSION_NAMESPACE {
56 : hUuid(
Uuid().ToString())
76 public:
virtual bool RunCallback(
const std::string &_req,
88 public:
virtual std::string ReqTypeName()
const = 0;
92 public:
virtual std::string RepTypeName()
const = 0;
98 #pragma warning(disable: 4251) 138 std::cerr <<
"RepHandler::RunLocalCallback() error: " 143 #if GOOGLE_PROTOBUF_VERSION > 2999999 144 auto msgReq = google::protobuf::down_cast<
const Req*>(&_msgReq);
145 auto msgRep = google::protobuf::down_cast<Rep*>(&_msgRep);
148 google::protobuf::internal::down_cast<
const Req*>(&_msgReq);
149 auto msgRep = google::protobuf::internal::down_cast<Rep*>(&_msgRep);
152 return this->cb(*msgReq, *msgRep);
162 std::cerr <<
"RepHandler::RunCallback() error: " 168 auto msgReq = this->CreateMsg(_req);
175 if (!this->cb(*msgReq, msgRep))
178 if (!msgRep.SerializeToString(&_rep))
180 std::cerr <<
"RepHandler::RunCallback(): Error serializing the " 191 return Req().GetTypeName();
197 return Rep().GetTypeName();
209 if (!msgPtr->ParseFromString(_data))
211 std::cerr <<
"RepHandler::CreateMsg() error: ParseFromString failed" Interface class used to manage a replier handler.
Definition: RepHandler.hh:52
std::string HandlerUuid() const
Get the unique UUID of this handler.
Definition: RepHandler.hh:81
IRepHandler()
Constructor.
Definition: RepHandler.hh:55
A portable class for representing a Universally Unique Identifier.
Definition: Uuid.hh:45
virtual std::string ReqTypeName() const
Get the message type name used in the service request.
Definition: RepHandler.hh:189
void SetCallback(const std::function< bool(const Req &, Rep &)> &_cb)
Set the callback for this handler.
Definition: RepHandler.hh:125
virtual std::string RepTypeName() const
Get the message type name used in the service response.
Definition: RepHandler.hh:195
bool RunCallback(const std::string &_req, std::string &_rep)
Executes the callback registered for this handler.
Definition: RepHandler.hh:156
with the service response.
Definition: RepHandler.hh:113
bool RunLocalCallback(const transport::ProtoMsg &_msgReq, transport::ProtoMsg &_msgRep)
Executes the local callback registered for this handler.
Definition: RepHandler.hh:132
google::protobuf::Message ProtoMsg
Definition: TransportTypes.hh:70
Definition: AdvertiseOptions.hh:28