libhomegear-base  0.7
Base library for Homegear and Homegear family modules.
IDeviceFamily.h
Go to the documentation of this file.
1 /* Copyright 2013-2019 Homegear GmbH
2  *
3  * libhomegear-base is free software: you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public License as
5  * published by the Free Software Foundation, either version 3 of the
6  * License, or (at your option) any later version.
7  *
8  * libhomegear-base is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with libhomegear-base. If not, see
15  * <http://www.gnu.org/licenses/>.
16  *
17  * In addition, as a special exception, the copyright holders give
18  * permission to link the code of portions of this program with the
19  * OpenSSL library under certain conditions as described in each
20  * individual source file, and distribute linked combinations
21  * including the two.
22  * You must obey the GNU Lesser General Public License in all respects
23  * for all of the code used other than OpenSSL. If you modify
24  * file(s) with this exception, you may extend this exception to your
25  * version of the file(s), but you are not obligated to do so. If you
26  * do not wish to do so, delete this exception statement from your
27  * version. If you delete this exception statement from all source
28  * files in the program, then also delete it here.
29 */
30 
31 #ifndef IDEVICEFAMILY_H_
32 #define IDEVICEFAMILY_H_
33 
34 #include "FamilySettings.h"
35 #include "../Database/DatabaseTypes.h"
36 #include "ICentral.h"
38 #include "IPhysicalInterface.h"
39 #include "../Variable.h"
40 #include "../DeviceDescription/Devices.h"
41 
42 #include <string>
43 #include <memory>
44 
45 #include "PhysicalInterfaces.h"
46 
47 namespace BaseLib {
48 
49 class SharedObjects;
50 
51 namespace Systems {
52 enum class FamilyType {
53  unknown = 0,
54  sharedObject = 1,
55  socket = 2
56 };
57 
59  public:
60  //Hooks
61  virtual void onAddWebserverEventHandler(BaseLib::Rpc::IWebserverEventSink *eventHandler, std::map<int32_t, PEventHandler> &eventHandlers) = 0;
62  virtual void onRemoveWebserverEventHandler(std::map<int32_t, PEventHandler> &eventHandlers) = 0;
63 
64  virtual void onRPCEvent(std::string source, uint64_t id, int32_t channel, std::string deviceAddress, std::shared_ptr<std::vector<std::string>> valueKeys, std::shared_ptr<std::vector<std::shared_ptr<Variable>>> values) = 0;
65  virtual void onRPCUpdateDevice(uint64_t id, int32_t channel, std::string address, int32_t hint) = 0;
66  virtual void onRPCNewDevices(std::vector<uint64_t> &ids, std::shared_ptr<Variable> deviceDescriptions) = 0;
67  virtual void onRPCDeleteDevices(std::vector<uint64_t> &ids, std::shared_ptr<Variable> deviceAddresses, std::shared_ptr<Variable> deviceInfo) = 0;
68  virtual void onEvent(std::string source, uint64_t peerID, int32_t channel, std::shared_ptr<std::vector<std::string>> variables, std::shared_ptr<std::vector<std::shared_ptr<Variable>>> values) = 0;
69  virtual void onServiceMessageEvent(const PServiceMessage &serviceMessage) = 0;
70  virtual void onRunScript(ScriptEngine::PScriptInfo &scriptInfo, bool wait) = 0;
71  virtual BaseLib::PVariable onInvokeRpc(std::string &methodName, BaseLib::PArray &parameters) = 0;
72  virtual int32_t onCheckLicense(int32_t moduleId, int32_t familyId, int32_t deviceId, const std::string &licenseKey) = 0;
73  virtual uint64_t onGetRoomIdByName(std::string &name) = 0;
74 
75  //Device description
76  virtual void onDecryptDeviceDescription(int32_t moduleId, const std::vector<char> &input, std::vector<char> &output) = 0;
77 };
78 
80  public:
81  IDeviceFamily(BaseLib::SharedObjects *bl, IFamilyEventSink *eventHandler, int32_t id, std::string name, FamilyType type);
82  virtual ~IDeviceFamily();
83 
84  FamilyType type();
85  virtual bool enabled();
86  virtual bool init() = 0;
87  virtual void dispose() {};
88 
89  virtual bool lifetick() = 0;
90  virtual void lock();
91  virtual void unlock();
92  virtual bool locked();
93 
94  virtual int32_t getFamily();
95  virtual FamilySettings::PFamilySetting getFamilySetting(const std::string &name);
96  virtual void setFamilySetting(const std::string &name, const std::string &value);
97  virtual void setFamilySetting(const std::string &name, int32_t value);
98  virtual void setFamilySetting(const std::string &name, const std::vector<char> &value);
99  virtual void deleteFamilySettingFromDatabase(const std::string &name);
100  virtual void load() = 0;
101  virtual void save(bool full) = 0;
102  virtual std::string getName();
103  virtual std::string handleCliCommand(std::string &command) = 0;
104 
105  /*
106  * Executed when Homegear is fully started.
107  */
108  virtual void homegearStarted() = 0;
109 
110  /*
111  * Executed before Homegear starts shutting down.
112  */
113  virtual void homegearShuttingDown() = 0;
114 
115  // {{{ RPC
116  virtual std::shared_ptr<Variable> getPairingInfo() = 0;
117  virtual std::shared_ptr<Variable> getParamsetDescription(PRpcClientInfo clientInfo, int32_t deviceId, int32_t firmwareVersion, int32_t channel, ParameterGroup::Type::Enum type) = 0;
118  virtual PVariable listKnownDeviceTypes(PRpcClientInfo clientInfo, bool channels, std::set<std::string> &fields) = 0;
119  // }}}
120  protected:
121  BaseLib::SharedObjects *_bl = nullptr;
123  std::shared_ptr<FamilySettings> _settings;
124  std::atomic_bool _locked{false};
125  bool _disposed = false;
126 
127  // {{{ Event handling
128  //Hooks
129  virtual void raiseAddWebserverEventHandler(BaseLib::Rpc::IWebserverEventSink *eventHandler, std::map<int32_t, PEventHandler> &eventHandlers);
130  virtual void raiseRemoveWebserverEventHandler(std::map<int32_t, PEventHandler> &eventHandlers);
131 
132  virtual void raiseRPCEvent(std::string &source, uint64_t id, int32_t channel, std::string &deviceAddress, std::shared_ptr<std::vector<std::string>> &valueKeys, std::shared_ptr<std::vector<std::shared_ptr<Variable>>> &values);
133  virtual void raiseRPCUpdateDevice(uint64_t id, int32_t channel, std::string address, int32_t hint);
134  virtual void raiseRPCNewDevices(std::vector<uint64_t> &ids, std::shared_ptr<Variable> deviceDescriptions);
135  virtual void raiseRPCDeleteDevices(std::vector<uint64_t> &ids, std::shared_ptr<Variable> deviceAddresses, std::shared_ptr<Variable> deviceInfo);
136  virtual void raiseEvent(std::string &source, uint64_t peerID, int32_t channel, std::shared_ptr<std::vector<std::string>> &variables, std::shared_ptr<std::vector<std::shared_ptr<Variable>>> &values);
137  virtual void raiseServiceMessageEvent(const PServiceMessage &serviceMessage);
138  virtual void raiseRunScript(ScriptEngine::PScriptInfo &scriptInfo, bool wait);
139  virtual BaseLib::PVariable raiseInvokeRpc(std::string &methodName, BaseLib::PArray &parameters);
140  virtual int32_t raiseCheckLicense(int32_t moduleId, int32_t familyId, int32_t deviceId, const std::string &licenseKey);
141  virtual uint64_t raiseGetRoomIdByName(std::string &name);
142 
143  // {{{ Device description event handling
144  virtual void raiseDecryptDeviceDescription(int32_t moduleId, const std::vector<char> &input, std::vector<char> &output);
145  // }}}
146  // }}}
147 
148  // {{{ Device event handling
149  //Hooks
150  void onAddWebserverEventHandler(BaseLib::Rpc::IWebserverEventSink *eventHandler, std::map<int32_t, PEventHandler> &eventHandlers) override;
151  void onRemoveWebserverEventHandler(std::map<int32_t, PEventHandler> &eventHandlers) override;
152 
153  void onRPCEvent(std::string &source, uint64_t id, int32_t channel, std::string &deviceAddress, std::shared_ptr<std::vector<std::string>> &valueKeys, std::shared_ptr<std::vector<std::shared_ptr<Variable>>> &values) override;
154  void onRPCUpdateDevice(uint64_t id, int32_t channel, std::string address, int32_t hint) override;
155  void onRPCNewDevices(std::vector<uint64_t> &ids, std::shared_ptr<Variable> deviceDescriptions) override;
156  void onRPCDeleteDevices(std::vector<uint64_t> &ids, std::shared_ptr<Variable> deviceAddresses, std::shared_ptr<Variable> deviceInfo) override;
157  void onEvent(std::string &source, uint64_t peerID, int32_t channel, std::shared_ptr<std::vector<std::string>> &variables, std::shared_ptr<std::vector<std::shared_ptr<Variable>>> &values) override;
158  void onServiceMessageEvent(const PServiceMessage &serviceMessage) override;
159  void onRunScript(ScriptEngine::PScriptInfo &scriptInfo, bool wait) override;
160  BaseLib::PVariable onInvokeRpc(std::string &methodName, BaseLib::PArray &parameters) override;
161  uint64_t onGetRoomIdByName(std::string &name) override;
162  // }}}
163 
164  // {{{ Device description event handling
165  void onDecryptDeviceDescription(int32_t moduleId, const std::vector<char> &input, std::vector<char> &output) override;
166  // }}}
167 
168  std::shared_ptr<DeviceDescription::Devices> _rpcDevices;
169 
170  virtual std::shared_ptr<ICentral> initializeCentral(uint32_t deviceId, int32_t address, std::string serialNumber) = 0;
171  virtual void createCentral() = 0;
172  private:
173  IDeviceFamily(const IDeviceFamily &) = delete;
174  IDeviceFamily &operator=(const IDeviceFamily &) = delete;
175 
176  IFamilyEventSink *_eventHandler;
177  int32_t _family = -1;
178  std::string _name;
179 };
180 
181 }
182 }
183 #endif
Definition: IDeviceFamily.h:58
FamilyType
Definition: IDeviceFamily.h:52
std::shared_ptr< FamilySettings > _settings
Definition: IDeviceFamily.h:123
int32_t deviceId
Definition: Licensing.h:381
Definition: IEvents.h:72
std::shared_ptr< FamilySetting > PFamilySetting
Definition: FamilySettings.h:56
This is the base library main class.
Definition: BaseLib.h:95
Definition: BaseLib.cpp:34
std::shared_ptr< Array > PArray
Definition: Variable.h:72
std::shared_ptr< RpcClientInfo > PRpcClientInfo
Definition: ScriptInfo.h:47
Definition: IDeviceFamily.h:79
std::shared_ptr< ScriptInfo > PScriptInfo
Definition: ScriptInfo.h:56
PVariable value
Definition: UiElements.h:217
std::shared_ptr< Variable > PVariable
Definition: PhysicalInterfaceSettings.h:41
int32_t channel
Definition: UiElements.h:215
std::string licenseKey
Definition: Licensing.h:383
int32_t moduleId
Definition: Licensing.h:379
int32_t familyId
Definition: Licensing.h:380
virtual void dispose()
Definition: IDeviceFamily.h:87
This class provides hooks into the web server so get and post requests can be passed into family modu...
Definition: IWebserverEventSink.h:43
std::string name
Definition: UiElements.h:216
std::shared_ptr< DeviceDescription::Devices > _rpcDevices
Definition: IDeviceFamily.h:168
Definition: IEvents.h:66
std::shared_ptr< ServiceMessage > PServiceMessage
Definition: ServiceMessage.h:74