RTC Toolkit  1.0.0
request.hpp
Go to the documentation of this file.
1 
12 #ifndef RTCTK_DATATASK_REQUEST_HPP
13 #define RTCTK_DATATASK_REQUEST_HPP
14 
15 #include <future>
16 
17 namespace rtctk::dataTask {
22 //TODO: reply code by std::error_code
23 template <typename REQ_TYPE>
24 class Request {
25  public:
26  explicit Request(const REQ_TYPE& req_payload)
27  : m_req_payload(req_payload),
28  m_rep_promise(std::make_shared<std::promise<void>>()) {
29  }
30 
31  Request(const Request& r) = default;
32 
33  Request& operator=(const Request& r) = default;
34 
35  const REQ_TYPE& GetPayload() const {
36  return m_req_payload;
37  }
38 
39  std::future<void> GetReplyFuture() const {
40  return m_rep_promise->get_future();
41  }
42 
43  void SetReply() const {
44  m_rep_promise->set_value();
45  }
46 
47  //template <class T>
48  //void SetException(const T& e) const {
49  // m_rep_promise->set_exception(boost::copy_exception(e));
50  //}
51 
52  private:
53  REQ_TYPE m_req_payload; // Payload associated to the request.
54  std::shared_ptr<std::promise<void>> m_rep_promise; // Pointer to the promise associated to the reply.
55 };
56 
57 } // namespace
58 
59 #endif
rtctk::dataTask::Request::GetPayload
const REQ_TYPE & GetPayload() const
Definition: request.hpp:35
rtctk::dataTask::Request::SetReply
void SetReply() const
Definition: request.hpp:43
rtctk::dataTask::Request::GetReplyFuture
std::future< void > GetReplyFuture() const
Definition: request.hpp:39
rtctk::dataTask::Request::Request
Request(const Request &r)=default
rtctk::dataTask
Definition: messageQueue.hpp:20
rtctk::dataTask::Request
Definition: request.hpp:24
rtctk::dataTask::Request::operator=
Request & operator=(const Request &r)=default
rtctk::dataTask::Request::Request
Request(const REQ_TYPE &req_payload)
Definition: request.hpp:26
std
Definition: mudpiProcessingError.hpp:119