BeeeOn Gateway  v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
GWRequest.h
1 #pragma once
2 
3 #include <functional>
4 
5 #include <Poco/SharedPtr.h>
6 #include <Poco/JSON/Object.h>
7 
8 #include "gwmessage/GWMessage.h"
9 #include "gwmessage/GWMessageType.h"
10 #include "gwmessage/GWResponse.h"
11 
12 namespace BeeeOn {
13 
25 class GWRequest : public GWMessage {
26 protected:
27  GWRequest(const GWMessageType::Raw &type);
28  GWRequest(const Poco::JSON::Object::Ptr object);
29 
30 public:
31  typedef Poco::SharedPtr<GWRequest> Ptr;
32 
37  template <typename T>
38  Poco::SharedPtr<T> derive(
39  std::function<void(Poco::SharedPtr<T>)> f = [](Poco::SharedPtr<T>){}) const
40  {
41  Poco::SharedPtr<T> response = deriveResponse().cast<T>();
42  f(response);
43  return response;
44  }
45 
50  GWResponse::Ptr derive(
51  std::function<void(GWResponse::Ptr)> f = [](GWResponse::Ptr){}) const
52  {
53  GWResponse::Ptr response = deriveResponse();
54  f(response);
55  return response;
56  }
57 
58 protected:
59  virtual GWResponse::Ptr deriveResponse() const;
60  GWResponse::Ptr deriveGenericResponse(GWResponse::Ptr response) const;
61 };
62 
63 }
The GWMessage is abstract class representing messages (including their contents), that are being sent...
Definition: GWMessage.h:21
Abstract class representing a request message. The GWRequest can not be used alone, but it must be inherited by a specific request object.
Definition: GWRequest.h:25
GWResponse::Ptr derive(std::function< void(GWResponse::Ptr)> f=[](GWResponse::Ptr){}) const
Derive the appropriate response and apply the given function to construct it.
Definition: GWRequest.h:50
GWMessageType type() const
Returns the type of the message.
Definition: GWMessage.cpp:55
Poco::SharedPtr< T > derive(std::function< void(Poco::SharedPtr< T >)> f=[](Poco::SharedPtr< T >){}) const
Derive the appropriate response and apply the given function to construct it.
Definition: GWRequest.h:38