libhomegear-base  0.7
Base library for Homegear and Homegear family modules.
FamilySettings.h
Go to the documentation of this file.
1 /* Copyright 2013-2019 Homegear GmbH
2  *
3  * Homegear is free software: you can redistribute it and/or modify
4  * 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  * Homegear 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 Homegear. 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 FAMILYSETTINGS_H_
32 #define FAMILYSETTINGS_H_
33 
35 
36 #include <memory>
37 #include <mutex>
38 #include <string>
39 #include <map>
40 #include <cstring>
41 #include <vector>
42 
43 namespace BaseLib {
44 
45 class SharedObjects;
46 
47 namespace Systems {
48 
50  public:
51  struct FamilySetting {
52  std::string stringValue;
53  int32_t integerValue;
54  std::vector<char> binaryValue;
55  };
56  typedef std::shared_ptr<FamilySetting> PFamilySetting;
57 
59  virtual ~FamilySettings();
60  void dispose();
61  void load(const std::string& filename);
62  bool changed();
63  PFamilySetting get(std::string name);
64  std::string getString(std::string name);
65  int32_t getNumber(std::string name);
66  std::vector<char> getBinary(std::string name);
67  void set(std::string name, const std::string &value);
68  void set(std::string name, int32_t value);
69  void set(std::string name, const std::vector<char> &value);
70  void deleteFromDatabase(std::string name);
71  std::map<std::string, PPhysicalInterfaceSettings> getPhysicalInterfaceSettings();
72  private:
73  BaseLib::SharedObjects *_bl = nullptr;
74  int32_t _familyId = -1;
75  std::mutex _settingsMutex;
76  std::map<std::string, PFamilySetting> _settings;
77  std::map<std::string, PPhysicalInterfaceSettings> _physicalInterfaceSettings;
78 
79  void loadFromDatabase();
80  void processStringSetting(std::string &name, std::string &value, PPhysicalInterfaceSettings &settings);
81  void processDatabaseSetting(std::string &name, PFamilySetting &value, PPhysicalInterfaceSettings &settings);
82 };
83 
84 }
85 
86 }
87 
88 #endif
std::map< std::string, PPhysicalInterfaceSettings > getPhysicalInterfaceSettings()
Definition: FamilySettings.cpp:239
void deleteFromDatabase(std::string name)
Definition: FamilySettings.cpp:225
std::shared_ptr< FamilySetting > PFamilySetting
Definition: FamilySettings.h:56
This is the base library main class.
Definition: BaseLib.h:95
int32_t getNumber(std::string name)
Definition: FamilySettings.cpp:89
void load(const std::string &filename)
Definition: FamilySettings.cpp:243
Definition: BaseLib.cpp:34
FamilySettings(BaseLib::SharedObjects *bl, int32_t familyId)
Definition: FamilySettings.cpp:40
int32_t integerValue
Definition: FamilySettings.h:53
Definition: FamilySettings.h:49
PVariable value
Definition: UiElements.h:217
std::vector< char > getBinary(std::string name)
Definition: FamilySettings.cpp:106
std::vector< char > binaryValue
Definition: FamilySettings.h:54
void dispose()
Definition: FamilySettings.cpp:49
int32_t familyId
Definition: Licensing.h:380
std::shared_ptr< PhysicalInterfaceSettings > PPhysicalInterfaceSettings
Definition: PhysicalInterfaceSettings.h:113
std::string getString(std::string name)
Definition: FamilySettings.cpp:72
std::string name
Definition: UiElements.h:216
virtual ~FamilySettings()
Definition: FamilySettings.cpp:45
std::string stringValue
Definition: FamilySettings.h:52