BeeeOn Gateway  v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
BelkinWemoDeviceManager.h
1 #pragma once
2 
3 #include <map>
4 #include <vector>
5 
6 #include <Poco/Mutex.h>
7 #include <Poco/Timespan.h>
8 
9 #include "belkin/BelkinWemoBulb.h"
10 #include "belkin/BelkinWemoDevice.h"
11 #include "belkin/BelkinWemoDimmer.h"
12 #include "belkin/BelkinWemoLink.h"
13 #include "belkin/BelkinWemoSwitch.h"
14 #include "core/AbstractSeeker.h"
15 #include "core/DeviceManager.h"
16 #include "core/PollingKeeper.h"
17 #include "loop/StopControl.h"
18 #include "model/DeviceID.h"
19 #include "model/RefreshTime.h"
20 #include "net/MACAddress.h"
21 #include "util/AsyncWork.h"
22 
23 namespace BeeeOn {
24 
26 public:
32  public:
33  typedef Poco::SharedPtr<BelkinWemoSeeker> Ptr;
34 
35  BelkinWemoSeeker(BelkinWemoDeviceManager& parent, const Poco::Timespan& duration);
36 
37  protected:
38  void seekLoop(StopControl &control) override;
39 
40  private:
41  BelkinWemoDeviceManager& m_parent;
42  };
43 
45 
46  void setDevicePoller(DevicePoller::Ptr poller);
47 
48  void run() override;
49  void stop() override;
50 
51  void setUPnPTimeout(const Poco::Timespan &timeout);
52  void setHTTPTimeout(const Poco::Timespan &timeout);
53  void setRefresh(const Poco::Timespan &refresh);
54 
55 protected:
56  void handleAccept(const DeviceAcceptCommand::Ptr cmd) override;
57  AsyncWork<>::Ptr startDiscovery(const Poco::Timespan &timeout) override;
59  const DeviceID &id,
60  const Poco::Timespan &timeout) override;
61  AsyncWork<double>::Ptr startSetValue(
62  const DeviceID &id,
63  const ModuleID &module,
64  const double value,
65  const Poco::Timespan &timeout) override;
66 
67  void searchPairedDevices();
68 
72  void eraseUnusedLinks();
73 
74  std::vector<BelkinWemoSwitch::Ptr> seekSwitches(const StopControl& stop);
75  std::vector<BelkinWemoBulb::Ptr> seekBulbs(const StopControl& stop);
76  std::vector<BelkinWemoDimmer::Ptr> seekDimmers(const StopControl& stop);
77 
78  void processNewDevice(BelkinWemoDevice::Ptr newDevice);
79 
80 private:
81  Poco::FastMutex m_linksMutex;
82  Poco::FastMutex m_pairedMutex;
83 
84  std::map<MACAddress, BelkinWemoLink::Ptr> m_links;
85  std::map<DeviceID, BelkinWemoDevice::Ptr> m_devices;
86 
87  RefreshTime m_refresh;
88  PollingKeeper m_pollingKeeper;
89  Poco::Timespan m_httpTimeout;
90  Poco::Timespan m_upnpTimeout;
91 };
92 
93 }
AsyncWork< double >::Ptr startSetValue(const DeviceID &id, const ModuleID &module, const double value, const Poco::Timespan &timeout) override
Starts set-value operation in a technology specific way. The method is always called inside a critica...
Definition: BelkinWemoDeviceManager.cpp:208
void eraseUnusedLinks()
Erases the links which don&#39;t care any bulb.
Definition: BelkinWemoDeviceManager.cpp:146
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: BelkinWemoDeviceManager.cpp:196
Provides searching belkin wemo devices on network in own thread.
Definition: BelkinWemoDeviceManager.h:31
Definition: BelkinWemoDeviceManager.h:25
PollingKeeper takes care of devices that are being polled. It cancels all polled devices it manages u...
Definition: PollingKeeper.h:17
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
StopControl implements the stop mechanism generically.
Definition: StopControl.h:12
Definition: ModuleID.h:12
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: BelkinWemoDeviceManager.cpp:170
Poco::Timespan duration() const
Definition: AbstractSeeker.cpp:17
Definition: DeviceManager.h:48
Definition: DeviceID.h:17
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: BelkinWemoDeviceManager.cpp:163
void stop() override
Definition: BelkinWemoDeviceManager.cpp:79