BeeeOn Gateway  v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
ConradDeviceManager.h
1 #pragma once
2 
3 #include <string>
4 
5 #include <Poco/Timespan.h>
6 #include <Poco/JSON/Object.h>
7 
8 #include "core/DeviceManager.h"
9 #include "conrad/ConradDevice.h"
10 #include "conrad/ConradListener.h"
11 #include "conrad/FHEMClient.h"
12 #include "model/DeviceID.h"
13 #include "util/AsyncExecutor.h"
14 #include "util/BlockingAsyncWork.h"
15 #include "util/EventSource.h"
16 #include "util/JsonUtil.h"
17 
18 namespace BeeeOn {
19 
28 public:
30 
31  void run() override;
32  void stop() override;
33 
34  void setFHEMClient(FHEMClient::Ptr fhemClient);
35  void setEventsExecutor(AsyncExecutor::Ptr executor);
36 
37  void registerListener(ConradListener::Ptr listener);
38 
39 protected:
40  AsyncWork<>::Ptr startDiscovery(const Poco::Timespan &timeout) override;
41  AsyncWork<double>::Ptr startSetValue(
42  const DeviceID &id,
43  const ModuleID &module,
44  const double value,
45  const Poco::Timespan &timeout);
47  const DeviceID &id,
48  const Poco::Timespan &) override;
49  void handleAccept(const DeviceAcceptCommand::Ptr cmd) override;
50 
55  void processEvent(const Poco::JSON::Object::Ptr event);
56 
62  const DeviceID& deviceID,
63  const Poco::JSON::Object::Ptr event);
64 
68  void createNewDeviceUnlocked(const DeviceID &deviceID, const std::string &type);
69 
73  void fireMessage(DeviceID const &deviceID, const Poco::JSON::Object::Ptr message);
74 
75 private:
76  Poco::FastMutex m_devicesMutex;
77  std::map<DeviceID, ConradDevice::Ptr> m_devices;
78 
79  FHEMClient::Ptr m_fhemClient;
80  EventSource<ConradListener> m_eventSource;
81 };
82 
83 }
void fireMessage(DeviceID const &deviceID, const Poco::JSON::Object::Ptr message)
Transforms received/sent message into ConradEvent and fires it.
AsyncWork< double >::Ptr startSetValue(const DeviceID &id, const ModuleID &module, const double value, const Poco::Timespan &timeout)
Starts set-value operation in a technology specific way. The method is always called inside a critica...
EventSource implements common logic for firing events to listeners.
Definition: EventSource.h:24
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...
void processEvent(const Poco::JSON::Object::Ptr event)
Processes the incoming event, which means creating a new device or sending the gathered data to the s...
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
Definition: ModuleID.h:12
The class implements the work with Conrad devices. Allows us to process and execute the commands from...
Definition: ConradDeviceManager.h:27
Definition: DeviceManager.h:48
void createNewDeviceUnlocked(const DeviceID &deviceID, const std::string &type)
Creates instance of Conrad device appends it into m_devices.
AsyncWork< std::set< DeviceID > >::Ptr startUnpair(const DeviceID &id, const Poco::Timespan &) override
Starts device unpair process in a technology-specific way. This method is always called inside a crit...
void processMessageEvent(const DeviceID &deviceID, const Poco::JSON::Object::Ptr event)
Processes the message event. If the event&#39;s device is paired then the data from the event are sent to...
Definition: DeviceID.h:17
void handleAccept(const DeviceAcceptCommand::Ptr cmd) override
Generic handler of the DeviceAcceptCommand. It might be helpful to override this method in case we ne...