BeeeOn Gateway  v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
VPTDeviceManager.h
1 #pragma once
2 
3 #include <map>
4 #include <vector>
5 
6 #include <Poco/Mutex.h>
7 #include <Poco/SharedPtr.h>
8 #include <Poco/Timespan.h>
9 
10 #include "commands/DeviceAcceptCommand.h"
11 #include "commands/DeviceSetValueCommand.h"
12 #include "commands/DeviceUnpairCommand.h"
13 #include "commands/GatewayListenCommand.h"
14 #include "commands/NewDeviceCommand.h"
15 #include "core/AbstractSeeker.h"
16 #include "core/DeviceManager.h"
17 #include "core/PollingKeeper.h"
18 #include "core/GatewayInfo.h"
19 #include "credentials/CredentialsStorage.h"
20 #include "loop/StopControl.h"
21 #include "model/DeviceID.h"
22 #include "model/RefreshTime.h"
23 #include "util/AsyncWork.h"
24 #include "util/CryptoConfig.h"
25 #include "vpt/VPTDevice.h"
26 
27 namespace BeeeOn {
28 
35 public:
40  class VPTSeeker : public AbstractSeeker {
41  public:
42  typedef Poco::SharedPtr<VPTSeeker> Ptr;
43 
44  VPTSeeker(VPTDeviceManager& parent, const Poco::Timespan& duration);
45 
46  protected:
47  void seekLoop(StopControl &control) override;
48 
49  private:
50  VPTDeviceManager& m_parent;
51  };
52 
54 
55  void run() override;
56  void stop() override;
57 
58  void setDevicePoller(DevicePoller::Ptr poller);
59  void setRefresh(const Poco::Timespan &refresh);
60  void setPingTimeout(const Poco::Timespan &timeout);
61  void setHTTPTimeout(const Poco::Timespan &timeout);
62  void setMaxMsgSize(int size);
63  void setBlackList(const std::list<std::string>& list);
64  void setPath(const std::string& path);
65  void setPort(const int port);
66  void setMinNetMask(const std::string& minNetMask);
67  void setGatewayInfo(Poco::SharedPtr<GatewayInfo> gatewayInfo);
68  void setCredentialsStorage(Poco::SharedPtr<CredentialsStorage> storage);
69  void setCryptoConfig(Poco::SharedPtr<CryptoConfig> config);
70 
71 protected:
72  void handleGeneric(const Command::Ptr cmd, Result::Ptr result) override;
73  void handleAccept(const DeviceAcceptCommand::Ptr cmd) override;
74  AsyncWork<>::Ptr startDiscovery(const Poco::Timespan &timeout) override;
76  const DeviceID &id,
77  const Poco::Timespan &timeout) override;
78 
83  void searchPairedDevices();
84 
89  bool isAnySubdevicePaired(VPTDevice::Ptr device);
90 
96  void modifyValue(const DeviceSetValueCommand::Ptr cmd);
97 
102  bool noSubdevicePaired(const DeviceID& id) const;
103 
107  std::vector<VPTDevice::Ptr> seekDevices(const StopControl& stop);
108 
113  void processNewDevice(Poco::SharedPtr<VPTDevice> newDevice);
114 
121  std::string findPassword(const DeviceID& id);
122 
123 private:
124  VPTHTTPScanner m_scanner;
125  uint32_t m_maxMsgSize;
126  Poco::FastMutex m_pairedMutex;
127 
128  PollingKeeper m_pollingKeeper;
129  RefreshTime m_refresh;
130  Poco::Timespan m_httpTimeout;
131  Poco::Timespan m_pingTimeout;
132 
137  std::map<DeviceID, VPTDevice::Ptr> m_devices;
138 
139  Poco::SharedPtr<GatewayInfo> m_gatewayInfo;
140  Poco::SharedPtr<CredentialsStorage> m_credentialsStorage;
141  Poco::SharedPtr<CryptoConfig> m_cryptoConfig;
142 };
143 
144 }
RefreshTime represents time of refreshing values from sensors. E.g. sensors are polled periodically o...
Definition: RefreshTime.h:24
void handleAccept(const DeviceAcceptCommand::Ptr cmd) override
Generic handler of the DeviceAcceptCommand. It might be helpful to override this method in case we ne...
Definition: VPTDeviceManager.cpp:263
bool noSubdevicePaired(const DeviceID &id) const
Returns true if any subdevice is paired.
Definition: VPTDeviceManager.cpp:313
PollingKeeper takes care of devices that are being polled. It cancels all polled devices it manages u...
Definition: PollingKeeper.h:17
std::string findPassword(const DeviceID &id)
Tries to find password credential for VPT by the given DeviceID from the credentials storage...
Definition: VPTDeviceManager.cpp:381
AsyncWork is an interface allowing to wait until an asynchronous operation finishes. It is also possible to force-stop it by calling cancel().
Definition: AsyncWork.h:21
AbstractSeeker represents an asynchronous process that seeks for new devices in a certain network...
Definition: AbstractSeeker.h:25
void stop() override
Definition: VPTDeviceManager.cpp:81
bool isAnySubdevicePaired(VPTDevice::Ptr device)
Examines if any subdevice is paired for the VPT given in the parametr.
Definition: VPTDeviceManager.cpp:206
StopControl implements the stop mechanism generically.
Definition: StopControl.h:12
void handleGeneric(const Command::Ptr cmd, Result::Ptr result) override
Definition: VPTDeviceManager.cpp:219
Definition: VPTHTTPScanner.h:10
Poco::Timespan duration() const
Definition: AbstractSeeker.cpp:17
std::vector< VPTDevice::Ptr > seekDevices(const StopControl &stop)
Searchs the devices on the network.
Definition: VPTDeviceManager.cpp:323
Definition: DeviceManager.h:48
AsyncWork::Ptr startDiscovery(const Poco::Timespan &timeout) override
Starts device discovery process in a technology-specific way. This method is always called inside a c...
Definition: VPTDeviceManager.cpp:229
void processNewDevice(Poco::SharedPtr< VPTDevice > newDevice)
Processes a new device. It means saving the new device and informing the server about it...
Definition: VPTDeviceManager.cpp:353
Provides searching vpt devices on network in own thread. Also takes care of thread where is the liste...
Definition: VPTDeviceManager.h:40
void modifyValue(const DeviceSetValueCommand::Ptr cmd)
Sets the proper device&#39;s module to given value.
Definition: VPTDeviceManager.cpp:292
The class implements the work with Regulators VPT LAN v1.0. Allows us to process and execute the comm...
Definition: VPTDeviceManager.h:34
Definition: DeviceID.h:17
void searchPairedDevices()
Initialized search of paired devices that were obtained by deviceList().
Definition: VPTDeviceManager.cpp:167
AsyncWork< std::set< DeviceID > >::Ptr startUnpair(const DeviceID &id, const Poco::Timespan &timeout) override
Starts device unpair process in a technology-specific way. This method is always called inside a crit...
Definition: VPTDeviceManager.cpp:236