BeeeOn Gateway  v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
GWSCommandHandler.h
1 #pragma once
2 
3 #include <map>
4 
5 #include <Poco/Mutex.h>
6 #include <Poco/SharedPtr.h>
7 
8 #include "commands/NewDeviceCommand.h"
9 #include "commands/ServerDeviceListCommand.h"
10 #include "commands/ServerLastValueCommand.h"
11 #include "core/CommandHandler.h"
12 #include "gwmessage/GWDeviceListResponse.h"
13 #include "gwmessage/GWLastValueResponse.h"
14 #include "server/GWSConnector.h"
15 #include "server/GWSListener.h"
16 #include "util/Loggable.h"
17 
18 namespace BeeeOn {
19 
31  public CommandHandler,
32  public GWSListener,
33  Loggable {
34 public:
35  typedef Poco::SharedPtr<GWSCommandHandler> Ptr;
36 
38 
39  void setConnector(GWSConnector::Ptr connector);
40 
41  bool accept(const Command::Ptr cmd) override;
42  void handle(Command::Ptr cmd, Answer::Ptr answer) override;
43 
48  void onResponse(const GWResponse::Ptr response) override;
49 
50 protected:
51  void handleNewDevice(NewDeviceCommand::Ptr cmd, Answer::Ptr answer);
52  void handleDeviceList(ServerDeviceListCommand::Ptr cmd, Answer::Ptr answer);
53  void handleLastValue(ServerLastValueCommand::Ptr cmd, Answer::Ptr answer);
54  void sendRequest(GWRequest::Ptr request, Result::Ptr answer);
55  void sendRequestUnsafe(GWRequest::Ptr request, Result::Ptr answer);
56 
57  void onSpecificResponse(const GWResponse::Ptr response, Result::Ptr result);
58  void onDeviceListResponse(const GWDeviceListResponse::Ptr response, Result::Ptr result);
59  void onLastValueResponse(const GWLastValueResponse::Ptr response, Result::Ptr result);
60 
61 private:
62  GWSConnector::Ptr m_connector;
63  std::map<GlobalID, Result::Ptr> m_pending;
64  Poco::FastMutex m_lock;
65 };
66 
67 }
Definition: CommandHandler.h:18
Handle requests to the remote server:
Definition: GWSCommandHandler.h:30
Definition: Loggable.h:19
void onResponse(const GWResponse::Ptr response) override
Check whether the responses associated with a pending command. If it is, update its result according ...
Definition: GWSCommandHandler.cpp:116
GWSListener provides an interface for delivering of events and messages related to communication with...
Definition: GWSListener.h:19