libhomegear-base  0.7
Base library for Homegear and Homegear family modules.
Devices.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 DEVICES_H_
32 #define DEVICES_H_
33 
34 #include <vector>
35 #include <memory>
36 #include <unordered_set>
37 
38 #include "../Systems/Packet.h"
39 #include "../Sockets/RpcClientInfo.h"
40 #include "HomegearDevice.h"
41 #include "../IEvents.h"
42 #include "DeviceTranslations.h"
43 
44 namespace BaseLib
45 {
46 
47 class SharedObjects;
48 
49 namespace DeviceDescription
50 {
51 
55 class Devices : public IEvents
56 {
57 public:
58  // {{{ Event handling
60  {
61  public:
62  virtual void onDecryptDeviceDescription(int32_t moduleId, const std::vector<char>& input, std::vector<char>& output) = 0;
63  };
64  // }}}
65 
66  Devices(BaseLib::SharedObjects* baseLib, IDevicesEventSink* eventHandler, int32_t family);
67  ~Devices() override = default;
68  bool empty() { return _devices.empty(); }
69  void clear();
70  void load();
71  void load(std::string& xmlPath);
72  std::shared_ptr<HomegearDevice> loadFile(std::string& filepath);
73  uint64_t getTypeNumberFromTypeId(const std::string& typeId);
74  uint64_t getTypeNumberFromProductId(const std::string& productId);
75  std::shared_ptr<HomegearDevice> find(uint64_t typeNumber, uint32_t firmwareVersion, int32_t countFromSysinfo = -1);
76  std::unordered_map<std::string, uint64_t> getIdTypeNumberMap();
77  std::unordered_set<uint64_t> getKnownTypeNumbers();
78 
79  // {{{ RPC
80  std::shared_ptr<Variable> getParamsetDescription(PRpcClientInfo clientInfo, uint64_t deviceId, int32_t firmwareVersion, int32_t channel, ParameterGroup::Type::Enum type);
81  PVariable listKnownDeviceType(PRpcClientInfo clientInfo, std::shared_ptr<HomegearDevice>& device, PSupportedDevice deviceType, int32_t channel, std::set<std::string>& fields);
82  PVariable listKnownDeviceTypes(PRpcClientInfo clientInfo, bool channels, std::set<std::string>& fields);
83  // }}}
84 protected:
86  int32_t _family = -1;
87  std::mutex _devicesMutex;
88  std::vector<std::shared_ptr<HomegearDevice>> _devices;
89  std::vector<std::shared_ptr<HomegearDevice>> _dynamicDevices;
90  std::shared_ptr<DeviceDescription::DeviceTranslations> _translations;
91 
92  std::shared_ptr<HomegearDevice> loadHomeMatic(std::string& filepath);
93 };
94 
95 }
96 }
97 #endif /* DEVICES_H_ */
PVariable listKnownDeviceTypes(PRpcClientInfo clientInfo, bool channels, std::set< std::string > &fields)
Definition: Devices.cpp:1452
void clear()
Definition: Devices.cpp:47
int32_t deviceId
Definition: Licensing.h:381
uint64_t getTypeNumberFromTypeId(const std::string &typeId)
Definition: Devices.cpp:1054
Definition: IEvents.h:72
This is the base library main class.
Definition: BaseLib.h:95
Definition: BaseLib.cpp:34
int32_t _family
Definition: Devices.h:86
std::shared_ptr< RpcClientInfo > PRpcClientInfo
Definition: ScriptInfo.h:47
BaseLib::SharedObjects * _bl
Definition: Devices.h:85
Class to work with the device description files of one device family.
Definition: Devices.h:55
std::shared_ptr< Variable > PVariable
Definition: PhysicalInterfaceSettings.h:41
uint64_t getTypeNumberFromProductId(const std::string &productId)
Definition: Devices.cpp:1069
std::shared_ptr< Variable > getParamsetDescription(PRpcClientInfo clientInfo, uint64_t deviceId, int32_t firmwareVersion, int32_t channel, ParameterGroup::Type::Enum type)
Definition: Devices.cpp:1156
int32_t channel
Definition: UiElements.h:215
std::vector< std::shared_ptr< HomegearDevice > > _dynamicDevices
Definition: Devices.h:89
std::shared_ptr< DeviceDescription::DeviceTranslations > _translations
Definition: Devices.h:90
std::unordered_set< uint64_t > getKnownTypeNumbers()
Definition: Devices.cpp:1136
virtual void onDecryptDeviceDescription(int32_t moduleId, const std::vector< char > &input, std::vector< char > &output)=0
int32_t moduleId
Definition: Licensing.h:379
std::mutex _devicesMutex
Definition: Devices.h:87
std::shared_ptr< HomegearDevice > find(uint64_t typeNumber, uint32_t firmwareVersion, int32_t countFromSysinfo=-1)
Definition: Devices.cpp:1084
std::vector< std::shared_ptr< HomegearDevice > > _devices
Definition: Devices.h:88
std::unordered_map< std::string, uint64_t > getIdTypeNumberMap()
Definition: Devices.cpp:1117
PVariable listKnownDeviceType(PRpcClientInfo clientInfo, std::shared_ptr< HomegearDevice > &device, PSupportedDevice deviceType, int32_t channel, std::set< std::string > &fields)
Definition: Devices.cpp:1326
std::shared_ptr< HomegearDevice > loadFile(std::string &filepath)
Definition: Devices.cpp:99
void load()
Definition: Devices.cpp:52
bool empty()
Definition: Devices.h:68
std::shared_ptr< HomegearDevice > loadHomeMatic(std::string &filepath)
Definition: Devices.cpp:145
Devices(BaseLib::SharedObjects *baseLib, IDevicesEventSink *eventHandler, int32_t family)
Definition: Devices.cpp:40
Definition: IEvents.h:66
std::shared_ptr< SupportedDevice > PSupportedDevice
Definition: SupportedDevice.h:51