BeeeOn Gateway  v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
PhilipsHueDeviceManager.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 "core/AbstractSeeker.h"
10 #include "core/DeviceManager.h"
11 #include "core/PollingKeeper.h"
12 #include "credentials/FileCredentialsStorage.h"
13 #include "loop/StopControl.h"
14 #include "model/DeviceID.h"
15 #include "model/RefreshTime.h"
16 #include "net/MACAddress.h"
17 #include "philips/PhilipsHueBridge.h"
18 #include "philips/PhilipsHueBulb.h"
19 #include "philips/PhilipsHueListener.h"
20 #include "util/AsyncWork.h"
21 #include "util/CryptoConfig.h"
22 #include "util/EventSource.h"
23 
24 namespace BeeeOn {
25 
32 public:
38  public:
39  typedef Poco::SharedPtr<PhilipsHueSeeker> Ptr;
40 
41  PhilipsHueSeeker(PhilipsHueDeviceManager& parent, const Poco::Timespan& duration);
42 
43  protected:
44  void seekLoop(StopControl &control) override;
45 
46  private:
47  PhilipsHueDeviceManager& m_parent;
48  };
49 
50  static const Poco::Timespan SEARCH_DELAY;
51 
53 
54  void run() override;
55  void stop() override;
56 
57  void setDevicePoller(DevicePoller::Ptr poller);
58  void setUPnPTimeout(const Poco::Timespan &timeout);
59  void setHTTPTimeout(const Poco::Timespan &timeout);
60  void setRefresh(const Poco::Timespan &refresh);
61  void setCredentialsStorage(Poco::SharedPtr<FileCredentialsStorage> storage);
62  void setCryptoConfig(Poco::SharedPtr<CryptoConfig> config);
63  void setEventsExecutor(AsyncExecutor::Ptr executor);
64  void registerListener(PhilipsHueListener::Ptr listener);
65 
66 protected:
67  void handleAccept(const DeviceAcceptCommand::Ptr cmd) override;
68  AsyncWork<>::Ptr startDiscovery(const Poco::Timespan &timeout) override;
70  const DeviceID &id,
71  const Poco::Timespan &timeout) override;
72  AsyncWork<double>::Ptr startSetValue(
73  const DeviceID &id,
74  const ModuleID &module,
75  const double value,
76  const Poco::Timespan &timeout) override;
77 
78  void searchPairedDevices();
79 
83  void eraseUnusedBridges();
84 
85  std::vector<PhilipsHueBulb::Ptr> seekBulbs(const StopControl& stop);
86 
87  void authorizationOfBridge(PhilipsHueBridge::Ptr bridge);
88 
89  void processNewDevice(PhilipsHueBulb::Ptr newDevice);
90 
91  void fireBridgeStatistics(PhilipsHueBridge::Ptr bridge);
92  void fireBulbStatistics(PhilipsHueBulb::Ptr bulb);
93 
94 private:
95  Poco::FastMutex m_bridgesMutex;
96  Poco::FastMutex m_pairedMutex;
97 
98  std::map<MACAddress, PhilipsHueBridge::Ptr> m_bridges;
99  std::map<DeviceID, PhilipsHueBulb::Ptr> m_devices;
100 
101  PollingKeeper m_pollingKeeper;
102  RefreshTime m_refresh;
103  Poco::Timespan m_httpTimeout;
104  Poco::Timespan m_upnpTimeout;
105 
106  Poco::SharedPtr<FileCredentialsStorage> m_credentialsStorage;
107  Poco::SharedPtr<CryptoConfig> m_cryptoConfig;
108 
109  EventSource<PhilipsHueListener> m_eventSource;
110 };
111 
112 }
RefreshTime represents time of refreshing values from sensors. E.g. sensors are polled periodically o...
Definition: RefreshTime.h:24
EventSource implements common logic for firing events to listeners.
Definition: EventSource.h:24
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: PhilipsHueDeviceManager.cpp:212
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
Poco::Timespan duration() const
Definition: AbstractSeeker.cpp:17
The class implements the work with Philips Hue bulbs. Allows us to process and execute the commands f...
Definition: PhilipsHueDeviceManager.h:31
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: PhilipsHueDeviceManager.cpp:238
Definition: DeviceManager.h:48
Provides searching philips devices on network in own thread.
Definition: PhilipsHueDeviceManager.h:37
void eraseUnusedBridges()
Erases the bridges which don&#39;t care any bulb.
Definition: PhilipsHueDeviceManager.cpp:174
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: PhilipsHueDeviceManager.cpp:204
void stop() override
Definition: PhilipsHueDeviceManager.cpp:88
Definition: DeviceID.h:17
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: PhilipsHueDeviceManager.cpp:250