Go to the documentation of this file.
18 #ifndef GZ_TRANSPORT_REPHANDLER_HH_
19 #define GZ_TRANSPORT_REPHANDLER_HH_
22 #pragma warning(push, 0)
24 #include <google/protobuf/message.h>
29 #if GOOGLE_PROTOBUF_VERSION > 2999999 && GOOGLE_PROTOBUF_VERSION < 4022000
30 #include <google/protobuf/stubs/casts.h>
38 #include "gz/transport/config.hh"
39 #include "gz/transport/Export.hh"
46 inline namespace IGNITION_TRANSPORT_VERSION_NAMESPACE {
54 : hUuid(
Uuid().ToString())
74 public:
virtual bool RunCallback(
const std::string &_req,
86 public:
virtual std::string ReqTypeName()
const = 0;
90 public:
virtual std::string RepTypeName()
const = 0;
96 #pragma warning(disable: 4251)
136 std::cerr <<
"RepHandler::RunLocalCallback() error: "
142 #if GOOGLE_PROTOBUF_VERSION >= 5028000
144 google::protobuf::DynamicCastMessage<Req>(&_msgReq);
146 google::protobuf::DynamicCastMessage<Rep>(&_msgRep);
147 #elif GOOGLE_PROTOBUF_VERSION >= 4022000
149 google::protobuf::internal::DownCast<const Req*>(&_msgReq);
150 auto msgRep = google::protobuf::internal::DownCast<Rep*>(&_msgRep);
151 #elif GOOGLE_PROTOBUF_VERSION > 2999999
152 auto msgReq = google::protobuf::down_cast<const Req*>(&_msgReq);
153 auto msgRep = google::protobuf::down_cast<Rep*>(&_msgRep);
156 google::protobuf::internal::down_cast<const Req*>(&_msgReq);
157 auto msgRep = google::protobuf::internal::down_cast<Rep*>(&_msgRep);
161 if (msgReq ==
nullptr || msgRep ==
nullptr)
163 if (msgReq ==
nullptr)
165 if (_msgReq.GetDescriptor() !=
nullptr)
167 std::cerr <<
"RepHandler::RunLocalCallback() error: "
168 <<
"Failed to cast the request of the type "
169 << _msgReq.GetDescriptor()->full_name()
170 <<
" to the specified type" <<
'\n';
174 std::cerr <<
"RepHandler::RunLocalCallback() error: "
175 <<
"Failed to cast the request of an unknown type"
176 <<
" to the specified type" <<
'\n';
179 if (msgRep ==
nullptr)
181 if (_msgRep.GetDescriptor() !=
nullptr)
183 std::cerr <<
"RepHandler::RunLocalCallback() error: "
184 <<
"Failed to cast the response of the type "
185 << _msgRep.GetDescriptor()->full_name()
186 <<
" to the specified type" <<
'\n';
190 std::cerr <<
"RepHandler::RunLocalCallback() error: "
191 <<
"Failed to cast the response of an unknown type"
192 <<
" to the specified type" <<
'\n';
199 return this->cb(*msgReq, *msgRep);
209 std::cerr <<
"RepHandler::RunCallback() error: "
215 auto msgReq = this->CreateMsg(_req);
222 if (!this->cb(*msgReq, msgRep))
225 if (!msgRep.SerializeToString(&_rep))
227 std::cerr <<
"RepHandler::RunCallback(): Error serializing the "
256 if (!msgPtr->ParseFromString(_data))
258 std::cerr <<
"RepHandler::CreateMsg() error: ParseFromString failed"
bool RunLocalCallback(const transport::ProtoMsg &_msgReq, transport::ProtoMsg &_msgRep)
Executes the local callback registered for this handler.
Definition: gz/transport/RepHandler.hh:130
google::protobuf::Message ProtoMsg
Definition: gz/transport/TransportTypes.hh:68
virtual std::string RepTypeName() const =0
Get the message type name used in the service response.
std::string HandlerUuid() const
Get the unique UUID of this handler.
Definition: gz/transport/RepHandler.hh:79
virtual bool RunCallback(const std::string &_req, std::string &_rep)=0
Executes the callback registered for this handler.
A portable class for representing a Universally Unique Identifier.
Definition: gz/transport/Uuid.hh:43
void SetCallback(const std::function< bool(const Req &, Rep &)> &_cb)
Set the callback for this handler.
Definition: gz/transport/RepHandler.hh:123
virtual ~IRepHandler()=default
Destructor.
virtual std::string ReqTypeName() const
Get the message type name used in the service request.
Definition: gz/transport/RepHandler.hh:236
virtual std::string RepTypeName() const
Get the message type name used in the service response.
Definition: gz/transport/RepHandler.hh:242
virtual bool RunLocalCallback(const transport::ProtoMsg &_msgReq, transport::ProtoMsg &_msgRep)=0
Executes the local callback registered for this handler.
with the service response.
Definition: gz/transport/RepHandler.hh:111
std::string hUuid
Unique handler's UUID.
Definition: gz/transport/RepHandler.hh:99
Definition: gz/transport/AdvertiseOptions.hh:28
IRepHandler()
Constructor.
Definition: gz/transport/RepHandler.hh:53
Interface class used to manage a replier handler.
Definition: gz/transport/RepHandler.hh:50
virtual std::string ReqTypeName() const =0
Get the message type name used in the service request.
bool RunCallback(const std::string &_req, std::string &_rep)
Executes the callback registered for this handler.
Definition: gz/transport/RepHandler.hh:203