libhomegear-base  0.7
Base library for Homegear and Homegear family modules.
IDatabaseController.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 IDATABASECONTROLLER_H_
32 #define IDATABASECONTROLLER_H_
33 
34 #include "DatabaseTypes.h"
35 #include "../Variable.h"
36 #include "../Sockets/RpcClientInfo.h"
37 #include "../Systems/Peer.h"
38 #include <set>
39 
40 namespace BaseLib {
41 namespace Database {
42 
44  std::string name;
45  uint64_t room = 0;
46  std::set<uint64_t> categories;
47  std::unordered_map<uint64_t, Role> roles;
48  int32_t flags = 0;
50 };
51 typedef std::shared_ptr<SystemVariable> PSystemVariable;
52 
57  public:
59  enum Enum { version = 0, upnpusn = 1, uniqueid = 2 };
60  };
61 
63  virtual ~IDatabaseController() {}
64  virtual void init() = 0;
65 
66  //General
67  virtual void open(const std::string &databasePath, const std::string &databaseFilename, const std::string &maintenanceDatabasePath, bool databaseSynchronous, bool databaseMemoryJournal, bool databaseWALJournal, const std::string &backupPath, const std::string &maintenanceBackupPath, const std::string &backupFilename) = 0;
68  virtual void hotBackup() = 0;
69  virtual bool isOpen() = 0;
70  virtual void initializeDatabase() = 0;
71  virtual bool convertDatabase(const std::string &databasePath, const std::string &databaseFilename, const std::string &maintenanceDatabasePath, bool databaseSynchronous, bool databaseMemoryJournal, bool databaseWALJournal, const std::string &backupPath, const std::string &maintenanceBackupPath, const std::string &backupFilename) = 0;
72  virtual bool enableMaintenanceMode() = 0;
73  virtual bool disableMaintenanceMode() = 0;
74  virtual void createSavepointSynchronous(std::string &name) = 0;
75  virtual void releaseSavepointSynchronous(std::string &name) = 0;
76  virtual void createSavepointAsynchronous(std::string &name) = 0;
77  virtual void releaseSavepointAsynchronous(std::string &name) = 0;
78  //End general
79 
80  //Homegear variables
81  virtual bool getHomegearVariableString(HomegearVariables::Enum id, std::string &value) = 0;
82  virtual void setHomegearVariableString(HomegearVariables::Enum id, std::string &value) = 0;
83  //End Homegear variables
84 
85  // {{{ Data
86  virtual BaseLib::PVariable setData(std::string &component, std::string &key, BaseLib::PVariable &value) = 0;
87  virtual BaseLib::PVariable getData(std::string &component, std::string &key) = 0;
88  virtual BaseLib::PVariable deleteData(std::string &component, std::string &key) = 0;
89  // }}}
90 
91  // {{{ UI
92  virtual uint64_t addUiElement(const std::string &elementStringId, const BaseLib::PVariable &data, const BaseLib::PVariable &metadata) = 0;
93  virtual std::shared_ptr<DataTable> getUiElements() = 0;
94  virtual BaseLib::PVariable getUiElementMetadata(uint64_t databaseId) = 0;
95  virtual void removeUiElement(uint64_t databaseId) = 0;
96  virtual BaseLib::PVariable setUiElementMetadata(uint64_t databaseId, const BaseLib::PVariable &metadata) = 0;
97  // }}}
98 
99  // {{{ UI notifications
100  virtual uint64_t createUiNotification(const BaseLib::PVariable &notificationDescription) = 0;
101  virtual BaseLib::PVariable getUiNotification(uint64_t databaseId, const std::string& languageCode) = 0;
102  virtual BaseLib::PVariable getUiNotifications(const std::string& languageCode) = 0;
103  virtual void removeUiNotification(uint64_t databaseId) = 0;
104  // }}}
105 
106  // {{{ Buildings
107  virtual BaseLib::PVariable addBuildingPartToBuilding(uint64_t buildingId, uint64_t buildingPartId) = 0;
108  virtual BaseLib::PVariable addStoryToBuilding(uint64_t buildingId, uint64_t storyId) = 0;
109  virtual BaseLib::PVariable createBuilding(BaseLib::PVariable translations, BaseLib::PVariable metadata) = 0;
110  virtual BaseLib::PVariable deleteBuilding(uint64_t buildingId) = 0;
111  virtual BaseLib::PVariable getBuildingPartsInBuilding(PRpcClientInfo clientInfo, uint64_t buildingId, bool checkAcls) = 0;
112  virtual BaseLib::PVariable getStoriesInBuilding(PRpcClientInfo clientInfo, uint64_t buildingId, bool checkAcls) = 0;
113  virtual BaseLib::PVariable getBuildingMetadata(uint64_t buildingId) = 0;
114  virtual BaseLib::PVariable getBuildings(std::string languageCode) = 0;
115  virtual BaseLib::PVariable removeBuildingPartFromBuildings(uint64_t buildingPartId) = 0;
116  virtual BaseLib::PVariable removeBuildingPartFromBuilding(uint64_t buildingId, uint64_t buildingPartId) = 0;
117  virtual BaseLib::PVariable removeStoryFromBuildings(uint64_t storyId) = 0;
118  virtual BaseLib::PVariable removeStoryFromBuilding(uint64_t buildingId, uint64_t storyId) = 0;
119  virtual bool buildingExists(uint64_t buildingId) = 0;
120  virtual BaseLib::PVariable setBuildingMetadata(uint64_t buildingId, BaseLib::PVariable metadata) = 0;
121  virtual BaseLib::PVariable updateBuilding(uint64_t buildingId, BaseLib::PVariable translations, BaseLib::PVariable metadata) = 0;
122  // }}}
123 
124  // {{{ Building parts
125  virtual BaseLib::PVariable createBuildingPart(BaseLib::PVariable translations, BaseLib::PVariable metadata) = 0;
126  virtual BaseLib::PVariable deleteBuildingPart(uint64_t buildingPartId) = 0;
127  virtual BaseLib::PVariable getBuildingPartMetadata(uint64_t buildingPartId) = 0;
128  virtual BaseLib::PVariable getBuildingParts(BaseLib::PRpcClientInfo clientInfo, std::string languageCode, bool checkAcls) = 0;
129  virtual bool buildingPartExists(uint64_t buildingPartId) = 0;
130  virtual BaseLib::PVariable setBuildingPartMetadata(uint64_t buildingPartId, BaseLib::PVariable metadata) = 0;
131  virtual BaseLib::PVariable updateBuildingPart(uint64_t buildingPartId, BaseLib::PVariable translations, BaseLib::PVariable metadata) = 0;
132  // }}}
133 
134  // {{{ Stories
135  virtual BaseLib::PVariable addRoomToStory(uint64_t storyId, uint64_t roomId) = 0;
136  virtual BaseLib::PVariable createStory(BaseLib::PVariable translations, BaseLib::PVariable metadata) = 0;
137  virtual BaseLib::PVariable deleteStory(uint64_t storyId) = 0;
138  virtual BaseLib::PVariable getRoomsInStory(PRpcClientInfo clientInfo, uint64_t storyId, bool checkAcls) = 0;
139  virtual BaseLib::PVariable getStoryMetadata(uint64_t storyId) = 0;
140  virtual BaseLib::PVariable getStories(std::string languageCode) = 0;
141  virtual BaseLib::PVariable removeRoomFromStories(uint64_t roomId) = 0;
142  virtual BaseLib::PVariable removeRoomFromStory(uint64_t storyId, uint64_t roomId) = 0;
143  virtual bool storyExists(uint64_t storyId) = 0;
144  virtual BaseLib::PVariable setStoryMetadata(uint64_t storyId, BaseLib::PVariable metadata) = 0;
145  virtual BaseLib::PVariable updateStory(uint64_t storyId, BaseLib::PVariable translations, BaseLib::PVariable metadata) = 0;
146  // }}}
147 
148  // {{{ Rooms
149  virtual BaseLib::PVariable createRoom(BaseLib::PVariable translations, BaseLib::PVariable metadata) = 0;
150  virtual BaseLib::PVariable deleteRoom(uint64_t roomId) = 0;
151  virtual std::string getRoomName(PRpcClientInfo clientInfo, uint64_t roomId) = 0;
152  virtual BaseLib::PVariable getRoomMetadata(uint64_t roomId) = 0;
153  virtual BaseLib::PVariable getRooms(PRpcClientInfo clientInfo, std::string languageCode, bool checkAcls) = 0;
154  virtual bool roomExists(uint64_t roomId) = 0;
155  virtual BaseLib::PVariable setRoomMetadata(uint64_t roomId, BaseLib::PVariable metadata) = 0;
156  virtual BaseLib::PVariable updateRoom(uint64_t roomId, BaseLib::PVariable translations, BaseLib::PVariable metadata) = 0;
157  // }}}
158 
159  // {{{ Categories
160  virtual BaseLib::PVariable createCategory(BaseLib::PVariable translations, BaseLib::PVariable metadata) = 0;
161  virtual BaseLib::PVariable deleteCategory(uint64_t categoryId) = 0;
162  virtual BaseLib::PVariable getCategories(PRpcClientInfo clientInfo, std::string languageCode, bool checkAcls) = 0;
163  virtual BaseLib::PVariable getCategoryMetadata(uint64_t categoryId) = 0;
164  virtual bool categoryExists(uint64_t categoryId) = 0;
165  virtual BaseLib::PVariable setCategoryMetadata(uint64_t categoryId, BaseLib::PVariable metadata) = 0;
166  virtual BaseLib::PVariable updateCategory(uint64_t categoryId, BaseLib::PVariable translations, BaseLib::PVariable metadata) = 0;
167  // }}}
168 
169  // {{{ Roles
170  virtual void createDefaultRoles() = 0;
171  virtual BaseLib::PVariable createRole(BaseLib::PVariable translations, BaseLib::PVariable metadata) = 0;
172  virtual BaseLib::PVariable deleteRole(uint64_t roleId) = 0;
173  virtual void deleteAllRoles() = 0;
174  virtual BaseLib::PVariable getRoles(PRpcClientInfo clientInfo, std::string languageCode, bool checkAcls) = 0;
175  virtual BaseLib::PVariable getRoleMetadata(uint64_t roleId) = 0;
176  virtual bool roleExists(uint64_t roleId) = 0;
177  virtual BaseLib::PVariable setRoleMetadata(uint64_t roleId, BaseLib::PVariable metadata) = 0;
178  virtual BaseLib::PVariable updateRole(uint64_t roleId, BaseLib::PVariable translations, BaseLib::PVariable metadata) = 0;
179  // }}}
180 
181  // {{{ Node data
182  virtual BaseLib::PVariable setNodeData(const std::string &node, const std::string &key, const BaseLib::PVariable &value) = 0;
183  virtual BaseLib::PVariable getNodeData(const std::string &node, const std::string &key, bool requestFromTrustedServer = false) = 0;
184  virtual std::set<std::string> getAllNodeDataNodes() = 0;
185  virtual BaseLib::PVariable deleteNodeData(const std::string &node, const std::string &key) = 0;
186  // }}}
187 
188  //Metadata
189  virtual BaseLib::PVariable setMetadata(PRpcClientInfo clientInfo, uint64_t peerId, std::string &serialNumber, std::string &dataId, BaseLib::PVariable &metadata) = 0;
190  virtual BaseLib::PVariable getMetadata(uint64_t peerId, std::string &dataId) = 0;
191  virtual BaseLib::PVariable getAllMetadata(PRpcClientInfo clientInfo, std::shared_ptr<Systems::Peer> peer, bool checkAcls) = 0;
192  virtual BaseLib::PVariable deleteMetadata(uint64_t peerId, std::string &serialNumber, std::string &dataId) = 0;
193  //End metadata
194 
195  //System variables
196  virtual void deleteSystemVariable(std::string &variableId) = 0;
197  virtual std::shared_ptr<BaseLib::Database::DataTable> getAllSystemVariables() = 0;
198  virtual std::shared_ptr<BaseLib::Database::DataTable> getSystemVariable(const std::string &variableId) = 0;
199  virtual std::shared_ptr<BaseLib::Database::DataTable> getSystemVariablesInRoom(uint64_t roomId) = 0;
200  virtual void removeCategoryFromSystemVariables(uint64_t categoryId) = 0;
201  virtual void removeRoleFromSystemVariables(uint64_t roleId) = 0;
202  virtual void removeRoomFromSystemVariables(uint64_t roomId) = 0;
203  virtual BaseLib::PVariable setSystemVariable(std::string &variableId, BaseLib::PVariable &value, uint64_t roomId, const std::string &categories, const std::string &roles, int32_t flags) = 0;
204  virtual BaseLib::PVariable setSystemVariableCategories(std::string &variableId, const std::string &categories) = 0;
205  virtual BaseLib::PVariable setSystemVariableRoles(std::string &variableId, const std::string &roles) = 0;
206  virtual BaseLib::PVariable setSystemVariableRoom(std::string &variableId, uint64_t room) = 0;
207  //End system variables
208 
209  //Users
210  virtual bool createUser(const std::string &name, const std::vector<uint8_t> &passwordHash, const std::vector<uint8_t> &salt, const std::vector<uint64_t> &groups) = 0;
211  virtual bool deleteUser(uint64_t userId) = 0;
212  virtual std::shared_ptr<DataTable> getPassword(const std::string &name) = 0;
213  virtual uint64_t getUserId(const std::string &name) = 0;
214  virtual int64_t getUserKeyIndex1(uint64_t userId) = 0;
215  virtual int64_t getUserKeyIndex2(uint64_t userId) = 0;
216  virtual BaseLib::PVariable getUserMetadata(uint64_t userId) = 0;
217  virtual std::shared_ptr<DataTable> getUsers() = 0;
218  virtual std::vector<uint64_t> getUsersGroups(uint64_t userId) = 0;
219  virtual bool updateUser(uint64_t userId, const std::vector<uint8_t> &passwordHash, const std::vector<uint8_t> &salt, const std::vector<uint64_t> &groups) = 0;
220  virtual void setUserKeyIndex1(uint64_t userId, int64_t keyIndex) = 0;
221  virtual void setUserKeyIndex2(uint64_t userId, int64_t keyIndex) = 0;
222  virtual BaseLib::PVariable setUserMetadata(uint64_t userId, BaseLib::PVariable metadata) = 0;
223  virtual bool userNameExists(const std::string &name) = 0;
224  //End users
225 
226  //{{{ User data
227  virtual BaseLib::PVariable setUserData(uint64_t userId, const std::string &component, const std::string &key, const BaseLib::PVariable &value) = 0;
228  virtual BaseLib::PVariable getUserData(uint64_t userId, const std::string &component, const std::string &key) = 0;
229  virtual BaseLib::PVariable deleteUserData(uint64_t userId, const std::string &component, const std::string &key) = 0;
230  //}}}
231 
232  //Groups
233  virtual BaseLib::PVariable createGroup(BaseLib::PVariable translations, BaseLib::PVariable acl) = 0;
234  virtual BaseLib::PVariable deleteGroup(uint64_t groupId) = 0;
235  virtual BaseLib::PVariable getAcl(uint64_t groupId) = 0;
236  virtual BaseLib::PVariable getGroup(uint64_t groupId, std::string languageCode) = 0;
237  virtual BaseLib::PVariable getGroups(std::string languageCode) = 0;
238  virtual bool groupExists(uint64_t groupId) = 0;
239  virtual BaseLib::PVariable updateGroup(uint64_t groupId, BaseLib::PVariable translations, BaseLib::PVariable acl) = 0;
240  //End groups
241 
242  //Family
243  virtual void deleteFamily(int32_t familyId) = 0;
244  virtual void saveFamilyVariableAsynchronous(int32_t familyId, BaseLib::Database::DataRow &data) = 0;
245  virtual std::shared_ptr<BaseLib::Database::DataTable> getFamilyVariables(int32_t familyId) = 0;
246  virtual void deleteFamilyVariable(BaseLib::Database::DataRow &data) = 0;
247  //End family
248 
249  //Device
250  virtual std::shared_ptr<DataTable> getDevices(uint32_t family) = 0;
251  virtual void deleteDevice(uint64_t id) = 0;
252  virtual uint64_t saveDevice(uint64_t id, int32_t address, std::string &serialNumber, uint32_t type, uint32_t family) = 0;
253  virtual void saveDeviceVariableAsynchronous(DataRow &data) = 0;
254  virtual void deletePeers(int32_t deviceID) = 0;
255  virtual std::shared_ptr<DataTable> getPeers(uint64_t deviceID) = 0;
256  virtual std::shared_ptr<DataTable> getDeviceVariables(uint64_t deviceID) = 0;
257  //End device
258 
259  //Peer
260  virtual void deletePeer(uint64_t id) = 0;
261  virtual uint64_t savePeer(uint64_t id, uint32_t parentID, int32_t address, std::string &serialNumber, uint32_t type) = 0;
262  virtual uint64_t savePeerParameterSynchronous(DataRow &data) = 0;
263  virtual void savePeerParameterAsynchronous(DataRow &data) = 0;
264  virtual void saveSpecialPeerParameterAsynchronous(DataRow &data) = 0;
265  virtual void savePeerParameterRoomAsynchronous(BaseLib::Database::DataRow &data) = 0;
266  virtual void savePeerParameterBuildingPartAsynchronous(BaseLib::Database::DataRow &data) = 0;
267  virtual void savePeerParameterCategoriesAsynchronous(BaseLib::Database::DataRow &data) = 0;
268  virtual void savePeerParameterRolesAsynchronous(BaseLib::Database::DataRow &data) = 0;
269  virtual void savePeerVariableAsynchronous(DataRow &data) = 0;
270  virtual std::shared_ptr<DataTable> getPeerParameters(uint64_t peerID) = 0;
271  virtual std::shared_ptr<DataTable> getPeerVariables(uint64_t peerID) = 0;
272  virtual void deletePeerParameter(uint64_t peerID, DataRow &data) = 0;
273 
274  virtual bool peerExists(uint64_t peerId) = 0;
275  virtual bool peerExists(const std::string &serialNumber) = 0;
276 
284  virtual bool setPeerID(uint64_t oldPeerId, uint64_t newPeerId) = 0;
285  virtual bool setPeerSerialNumber(uint64_t peer_id, const std::string &new_serial_number) = 0;
286  //End Peer
287 
288  //Service messages
289  virtual std::shared_ptr<DataTable> getServiceMessages(uint64_t peerId) = 0;
290  virtual void saveServiceMessageAsynchronous(uint64_t peerId, DataRow &data) = 0;
291  virtual void saveGlobalServiceMessageAsynchronous(DataRow &data) = 0;
292  virtual void deleteServiceMessage(uint64_t databaseID) = 0;
293  virtual void deleteGlobalServiceMessage(int32_t familyId, int32_t messageId, std::string &messageSubId, std::string &message) = 0;
294  //End service messages
295 
296  // {{{ License modules
297  virtual std::shared_ptr<DataTable> getLicenseVariables(int32_t moduleId) = 0;
298  virtual void saveLicenseVariable(int32_t moduleId, DataRow &data) = 0;
299  virtual void deleteLicenseVariable(int32_t moduleId, uint64_t mapKey) = 0;
300  // }}}
301 
302  // {{{ Variable profiles
303  virtual uint64_t addVariableProfile(const BaseLib::PVariable &translations, const BaseLib::PVariable &profile) = 0;
304  virtual void deleteVariableProfile(uint64_t profileId) = 0;
305  virtual std::shared_ptr<BaseLib::Database::DataTable> getVariableProfiles() = 0;
306  virtual bool updateVariableProfile(uint64_t profileId, const BaseLib::PVariable &translations, const BaseLib::PVariable &profile) = 0;
307  // }}}
308 };
309 
310 }
311 }
312 #endif
std::shared_ptr< SystemVariable > PSystemVariable
Definition: IDatabaseController.h:51
Definition: BaseLib.cpp:34
std::shared_ptr< RpcClientInfo > PRpcClientInfo
Definition: ScriptInfo.h:47
uint64_t room
Definition: IDatabaseController.h:45
int32_t flags
Definition: IDatabaseController.h:48
std::shared_ptr< Variable > PVariable
Definition: PhysicalInterfaceSettings.h:41
std::string name
Definition: IDatabaseController.h:44
uint64_t peerId
Definition: UiElements.h:214
int32_t moduleId
Definition: Licensing.h:379
int32_t familyId
Definition: Licensing.h:380
IDatabaseController()
Definition: IDatabaseController.h:62
Definition: IDatabaseController.h:43
std::unordered_map< uint64_t, Role > roles
Definition: IDatabaseController.h:47
BaseLib::PVariable value
Definition: IDatabaseController.h:49
virtual ~IDatabaseController()
Definition: IDatabaseController.h:63
Base class for the database controller.
Definition: IDatabaseController.h:56
std::set< uint64_t > categories
Definition: IDatabaseController.h:46
std::deque< std::shared_ptr< DataColumn > > DataRow
Type definition to easily create a DataRow.
Definition: DatabaseTypes.h:181