1 #ifndef PERSISTENCE_CLIENT_LIBRARY_DB_ACCESS_H
2 #define PERSISTENCE_CLIENT_LIBRARY_DB_ACCESS_H
4 /******************************************************************************
7 * Company XS Embedded GmbH
8 *****************************************************************************/
9 /******************************************************************************
10 * This Source Code Form is subject to the terms of the
11 * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed
12 * with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
13 ******************************************************************************/
15 * @file persistence_client_library_db_access.h
16 * @ingroup Persistence client library
17 * @author Ingo Huerner
18 * @brief Header of the persistence client library database access.
19 * Library provides an API to access persistent data
27 #define PERSIST_DATA_ACCESS_INTERFACE_VERSION (0x05000000U)
30 #include "persistence_client_library_data_organization.h"
32 //#include "persistence_client_library_rc_table.h"
33 #include <persComRct.h>
35 #include "../include/persistence_client_library_key.h"
40 * @brief get the raw key without prefixed '/node/', '/user/3/' etc
42 * @param key the ptr. to the key which should be stripped
44 * @return the pointer to the stripped 'raw key'
46 char* pers_get_raw_key(char *key);
51 * @brief open the default value database specified by the 'DefaultType'
53 * @param dbPath path to the directory were the databases are included in.
54 * @param DefaultType the default type
56 * @return >= 0 for valid handler; if an error occured the following error code:
59 int pers_db_open_default(const char* dbPath, PersDefaultType_e DefaultType);
64 * @brief tries to get default values for a key from the configurable and factory default databases.
66 * @param dbPath the path to the directory where the default databases are in
67 * @param key the database key
68 * @param info the persistence context information
69 * @param buffer the buffer holding the data
70 * @param buffer_size the size of the buffer
71 * @param job the info to specify what to do. Get Data or the DataSize.
73 * @return the number of bytes read or the size of the key (depends on parameter 'job').
74 negative value if an error occured and the following error code:
77 int pers_get_defaults(char* dbPath, char* key, PersistenceInfo_s* info, unsigned char* buffer, unsigned int buffer_size, PersGetDefault_e job);
82 * @brief write data to a key
84 * @param dbPath the path to the database where the key is in
85 * @param key the database key
86 * @param info persistence information
87 * @param buffer the buffer holding the data
88 * @param buffer_size the size of the buffer
90 * @return the number of bytes written or a negative value if an error occured with the following error codes:
91 * EPERS_SETDTAFAILED EPERS_NOPRCTABLE EPERS_NOKEYDATA EPERS_NOKEY
93 int persistence_set_data(char* dbPath, char* key, PersistenceInfo_s* info, unsigned char* buffer, unsigned int buffer_size);
98 * @brief get data of a key
100 * @param dbPath the path to the database where the key is in
101 * @param key the database key
102 * @param resourceID the resource id
103 * @param info persistence information
104 * @param buffer the buffer holding the data
105 * @param buffer_size the size of the buffer
107 * @return the number of bytes read or a negative value if an error occured with the following error codes:
108 * EPERS_NOPRCTABLE EPERS_NOKEYDATA EPERS_NOKEY
110 int persistence_get_data(char* dbPath, char* key, const char* resourceID, PersistenceInfo_s* info, unsigned char* buffer, unsigned int buffer_size);
115 * @brief get the size of the data from a given key
117 * @param dbPath the path to the database where the key is in
118 * @param key the database key
119 * @param resourceID the resource id
120 * @param info persistence information
122 * @return size of data in bytes read from the key or on error a negative value with the following error codes:
123 * EPERS_NOPRCTABLE or EPERS_NOKEY
125 int persistence_get_data_size(char* dbPath, char* key, const char* resourceID, PersistenceInfo_s* info);
132 * @param dbPath the path to the database where the key is in
133 * @param key the database key to register on
134 * @param info persistence information
136 * @return 0 if deletion was successfull;
137 * or an error code: EPERS_DB_KEY_SIZE, EPERS_NOPRCTABLE, EPERS_DB_ERROR_INTERNAL or EPERS_NOPLUGINFUNCT
139 int persistence_delete_data(char* dbPath, char* key, PersistenceInfo_s* info);
144 * @brief close the database for the given storage type
146 * @param info persistence information
148 //void database_close(PersistenceInfo_s* info);
153 * @brief close all databases
155 void database_close_all();
160 * @brief register or unregister for change notifications of a key
162 * @param key the database key to register on
163 * @param ldbid logical database ID of the resource to monitor
164 * @param user_no the user ID; user_no=0 can not be used as user-ID beacause '0' is defined as System/node
165 * @param seat_no the seat number
166 * @param callback the function callback to be called
167 * @param regPolicy ::Notify_register to register; ::Notify_unregister to unregister
169 * @return 0 of registration was successful; -1 if registration fails
171 int persistence_notify_on_change(const char* key, unsigned int ldbid, unsigned int user_no, unsigned int seat_no,
172 pclChangeNotifyCallback_t callback, PersNotifyRegPolicy_e regPolicy);
177 * @brief send a notification signal
179 * @param key the database key to register on
180 * @param context the database context
181 * @param reason the reason of the signal, values see pclNotifyStatus_e.
183 * @return 0 of registration was successful; -1 if registration failes
185 int pers_send_Notification_Signal(const char* key, PersistenceDbContext_s* context, pclNotifyStatus_e reason);
189 * @brief close all open persistence resource configuration tables
191 void pers_rct_close_all();
197 #endif /* PERSISTENCY_CLIENT_LIBRARY_DB_ACCESS_H */