18 #ifndef GZ_TRANSPORT_REQHANDLER_HH_
19 #define GZ_TRANSPORT_REQHANDLER_HH_
23 #pragma warning(disable: 4251)
25 #include <google/protobuf/message.h>
30 #include <condition_variable>
35 #include "gz/transport/config.hh"
36 #include "gz/transport/Export.hh"
45 inline namespace GZ_TRANSPORT_VERSION_NAMESPACE {
55 hUuid(
Uuid().ToString()),
72 public:
virtual void NotifyResult(
const std::string &_rep,
73 const bool _result) = 0;
100 return this->requested;
107 this->requested = _value;
113 public:
virtual bool Serialize(
std::string &_buffer)
const = 0;
129 public:
template<
typename Lock>
bool WaitUntil(Lock &_lock,
130 const unsigned int _timeout)
133 return this->condition.wait_until(_lock,
137 return this->repAvailable;
143 public:
virtual std::string ReqTypeName()
const = 0;
147 public:
virtual std::string RepTypeName()
const = 0;
152 #pragma warning(push)
153 #pragma warning(disable: 4251)
176 private:
bool requested;
207 if (!msgPtr->ParseFromString(_data))
209 std::cerr <<
"ReqHandler::CreateMsg() error: ParseFromString failed"
222 const Rep &_rep,
const bool _result)> &_cb)
238 this->reqMsg.CopyFrom(*_reqMsg);
254 if (!this->reqMsg.SerializeToString(&_buffer))
256 std::cerr <<
"ReqHandler::Serialize(): Error serializing the request"
271 auto msg = this->CreateMsg(_rep);
273 this->cb(*msg, _result);
278 this->result = _result;
281 this->repAvailable =
true;
282 this->condition.notify_one();
288 return Req().GetTypeName();
294 return Rep().GetTypeName();
305 private:
std::function<void(
const Rep &_rep,
const bool _result)> cb;
312 google::protobuf::Message>
324 public:
void SetMessage(
const google::protobuf::Message *_reqMsg)
332 this->reqMsg = _reqMsg->New();
333 this->reqMsg->CopyFrom(*_reqMsg);
340 public:
void SetResponse(
const google::protobuf::Message *_repMsg)
348 this->repMsg = _repMsg->New();
349 this->repMsg->CopyFrom(*_repMsg);
361 if (!this->reqMsg->SerializeToString(&_buffer))
363 std::cerr <<
"ReqHandler::Serialize(): Error serializing the request"
375 this->result = _result;
377 this->repAvailable =
true;
378 this->condition.notify_one();
385 return this->reqMsg->GetTypeName();
388 std::cerr <<
"ReqHandler::ReqTypeName() Warning: Using ReqTypeName() "
389 <<
"without type information" <<
std::endl;
398 return this->repMsg->GetTypeName();
401 std::cerr <<
"ReqHandler::RepTypeName() Warning: Using RepTypeName() "
402 <<
"without type information" <<
std::endl;
408 private: google::protobuf::Message *reqMsg =
nullptr;
411 private: google::protobuf::Message *repMsg =
nullptr;