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"
43 inline namespace GZ_TRANSPORT_VERSION_NAMESPACE {
53 hUuid(
Uuid().ToString()),
71 const bool _result) = 0;
98 return this->requested;
105 this->requested = _value;
127 public:
template<
typename Lock>
bool WaitUntil(Lock &_lock,
128 const unsigned int _timeout)
131 return this->condition.wait_until(_lock,
135 return this->repAvailable;
150 #pragma warning(push)
151 #pragma warning(disable: 4251)
174 private:
bool requested;
202 auto msgPtr = std::make_shared<Rep>();
205 if (!msgPtr->ParseFromString(_data))
207 std::cerr <<
"ReqHandler::CreateMsg() error: ParseFromString failed"
220 const Rep &_rep,
const bool _result)> &_cb)
236 this->reqMsg.CopyFrom(*_reqMsg);
252 if (!this->reqMsg.SerializeToString(&_buffer))
254 std::cerr <<
"ReqHandler::Serialize(): Error serializing the request"
269 auto msg = this->CreateMsg(_rep);
271 this->cb(*msg, _result);
276 this->result = _result;
279 this->repAvailable =
true;
280 this->condition.notify_one();
303 private:
std::function<void(
const Rep &_rep,
const bool _result)> cb;
310 google::protobuf::Message>
322 public:
void SetMessage(
const google::protobuf::Message *_reqMsg)
330 this->reqMsg = _reqMsg->New();
331 this->reqMsg->CopyFrom(*_reqMsg);
338 public:
void SetResponse(
const google::protobuf::Message *_repMsg)
346 this->repMsg = _repMsg->New();
347 this->repMsg->CopyFrom(*_repMsg);
359 if (!this->reqMsg->SerializeToString(&_buffer))
361 std::cerr <<
"ReqHandler::Serialize(): Error serializing the request"
373 this->result = _result;
375 this->repAvailable =
true;
376 this->condition.notify_one();
386 std::cerr <<
"ReqHandler::ReqTypeName() Warning: Using ReqTypeName() "
387 <<
"without type information" <<
std::endl;
399 std::cerr <<
"ReqHandler::RepTypeName() Warning: Using RepTypeName() "
400 <<
"without type information" <<
std::endl;
406 private: google::protobuf::Message *reqMsg =
nullptr;
409 private: google::protobuf::Message *repMsg =
nullptr;