BeeeOn Gateway  v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
GWSCommandSender.h
1 #pragma once
2 
3 #include <Poco/Timespan.h>
4 
5 #include "core/CommandSender.h"
6 #include "gwmessage/GWDeviceAcceptRequest.h"
7 #include "gwmessage/GWListenRequest.h"
8 #include "gwmessage/GWSearchRequest.h"
9 #include "gwmessage/GWSetValueRequest.h"
10 #include "gwmessage/GWUnpairRequest.h"
11 #include "loop/StoppableRunnable.h"
12 #include "loop/StopControl.h"
13 #include "server/GWSConnector.h"
14 #include "server/GWSListener.h"
15 #include "util/Loggable.h"
16 
17 namespace BeeeOn {
18 
32  public StoppableRunnable,
33  public GWSListener,
34  public CommandSender,
35  Loggable {
36 public:
38 
39  void setConnector(GWSConnector::Ptr connector);
40  void setUnpairDuration(const Poco::Timespan &duration);
41 
46  void run() override;
47  void stop() override;
48 
54  void onRequest(GWRequest::Ptr request) override;
55 
56 protected:
57  void handleDeviceAccept(GWDeviceAcceptRequest::Ptr request);
58  void handleListen(GWListenRequest::Ptr request);
59  void handleSearch(GWSearchRequest::Ptr request);
60  void handleSetValue(GWSetValueRequest::Ptr request);
61  void handleUnpair(GWUnpairRequest::Ptr request);
62  void dispatch(Command::Ptr command, GWRequest::Ptr request);
63 
64  class RequestAnswer : public Answer {
65  public:
66  typedef Poco::AutoPtr<RequestAnswer> Ptr;
67 
68  RequestAnswer(AnswerQueue &queue, GWRequest::Ptr request);
69 
70  GWRequest::Ptr request() const;
71 
72  private:
73  GWRequest::Ptr m_request;
74  };
75 
80  void respond(RequestAnswer::Ptr answer, bool failed);
81 
82 private:
83  Poco::Timespan m_unpairDuration;
84  GWSConnector::Ptr m_connector;
85  StopControl m_stopControl;
86 };
87 
88 }
Definition: Answer.h:30
Definition: AnswerQueue.h:22
void onRequest(GWRequest::Ptr request) override
Receive a request from the remote server, convert it to the appropriate Command instance and dispatch...
Definition: GWSCommandSender.cpp:55
Definition: GWSCommandSender.h:64
StopControl implements the stop mechanism generically.
Definition: StopControl.h:12
void respond(RequestAnswer::Ptr answer, bool failed)
When a RequestAnswer instance becomes finished, report its results to the remote server.
Definition: GWSCommandSender.cpp:122
void run() override
A loop that processes answers&#39; updates of commands as created from the remote server requests...
Definition: GWSCommandSender.cpp:81
Definition: CommandSender.h:20
Definition: Loggable.h:19
void stop() override
Definition: GWSCommandSender.cpp:135
Definition: StoppableRunnable.h:8
GWSListener provides an interface for delivering of events and messages related to communication with...
Definition: GWSListener.h:19
Pass requests received from the remote server to the configured CommandDispatcher instance...
Definition: GWSCommandSender.h:31