1 #ifndef PERSISTENCE_CLIENT_LIBRARY_KEY_H
2 #define PERSISTENCE_CLIENT_LIBRARY_KEY_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_key.h
16 * @ingroup Persistence client library
17 * vauthor Ingo Huerner (XSe) / Guy Sagnes (Continental)
18 * @brief Header of the persistence client library.
19 * Library provides an API to access persistent data
22 * 27/03/13 Ingo Hürner 4.0.0 - Add registration for callback notification
23 * 28/05/13 Ingo Hürner 5.0.0 - Add pclInitLibrary(), pcl DeInitLibrary() incl. shutdown notification
24 * 05/06/13 Oliver Bach 6.0.0 - Rework of Init functions
25 * 04/11/13 Ingo Hürner 6.1.0 - Added functions to unregister notifications
27 /** \ingroup GEN_PERS */
28 /** \defgroup PERS_KEYVALUE Client: Key-value access
31 /** \defgroup PERS_KEYVALUE_INTERFACE API document
39 /** \defgroup PCL_DEFINES_KEYVALUE Defines, Struct, Enum
43 #define PERSIST_KEYVALUEAPI_INTERFACE_VERSION (0x06010000U)
45 #include "persistence_client_library.h"
49 * status returned in notification structure
51 typedef enum _pclNotifyStatus_e
53 pclNotifyStatus_no_changed = 0,
54 pclNotifyStatus_created,
55 pclNotifyStatus_changed,
56 pclNotifyStatus_deleted,
57 /* insert new_ entries here .. */
58 pclNotifyStatus_lastEntry
63 * structure to return in case of notification
65 typedef struct _pclNotification_s
67 pclNotifyStatus_e pclKeyNotify_Status; /// notification status
68 unsigned int ldbid; /// logical db id
69 const char * resource_id; /// resource id
70 unsigned int user_no; /// user id
71 unsigned int seat_no; /// seat id
79 /** definition of the change callback
81 * @param notifyStruct structure for notifcation
83 * @return positive value (0 or greater): success;
84 * On error a negative value will be returned with the following error codes: ::EPERS_LOCKFS
86 typedef int(* pclChangeNotifyCallback_t)(pclNotification_s * notifyStruct);
89 /** \defgroup PCL_KEYVALUE functions Key-Value access
94 * @brief delete persistent data
96 * @param ldbid logical database ID
97 * @param resource_id the resource ID
98 * @param user_no the user ID; user_no=0 can not be used as user-ID beacause ‘0’ is defined as System/node
99 * @param seat_no the seat number
101 * @return positive value (0 or greater) : success;
102 * On error a negative value will be returned with the following error codes:
103 * ::EPERS_LOCKFS, ::EPERS_NOTIFY_SIG, ::EPERS_NOT_INITIALIZED, ::EPERS_BADPOL
105 int pclKeyDelete(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no);
110 * @brief gets the size of persistent data in bytes
112 * @param ldbid logical database ID
113 * @param resource_id the resource ID
114 * @param user_no the user ID; user_no=0 can not be used as user-ID beacause ‘0’ is defined as System/node
115 * @param seat_no the seat number
117 * @return positive value (0 or greater): the size;
118 * On error a negative value will be returned with the following error codes:
119 * ::EPERS_LOCKFS, ::EPERS_BADPOL, ::EPERS_NOKEY, ::EPERS_NOKEYDATA or ::EPERS_NOPRCTABLE
120 * ::EPERS_NOT_INITIALIZED
122 int pclKeyGetSize(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no);
125 * @brief close the access to a key-value identified by key handle
127 * @param key_handle key value handle return by key_handle_open()
129 * @return positive value (0 or greater): success;
130 * On error a negative value will be returned with the following error codes:
131 * ::EPERS_LOCKFS ::EPERS_MAXHANDLE ::EPERS_NOPLUGINFUNCT ::EPERS_NOT_INITIALIZED
133 int pclKeyHandleClose(int key_handle);
138 * @brief gets the size of persistent data in bytes identified by key handle
140 * @param key_handle key value handle return by key_handle_open()
142 * @return positive value (0 or greater): the size;
143 * On error a negative value will be returned with the following error codes:
144 * ::EPERS_NOT_INITIALIZED ::EPERS_LOCKFS ::EPERS_NOPLUGINFUNCT ::EPERS_MAXHANDLE
145 * ::EPERS_NOKEY ::EPERS_DB_KEY_SIZE ::EPERS_NOPRCTABLE
147 int pclKeyHandleGetSize(int key_handle);
152 * @brief open a key-value
154 * @param ldbid logical database ID
155 * @param resource_id the resource ID
156 * @param user_no the user ID; user_no=0 can not be used as user-ID beacause ‘0’ is defined as System/node
157 * @param seat_no the seat number
159 * @return positive value (0 or greater): the key handle to access the value;
160 * On error a negative value will be returned with the following error codes:
161 * ::EPERS_NOT_INITIALIZED ::EPERS_NOPLUGINFUNCT ::
163 int pclKeyHandleOpen(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no);
168 * @brief reads persistent data identified by key handle
170 * @param key_handle key value handle return by key_handle_open()
171 * @param buffer the buffer for persistent data
172 * @param buffer_size size of buffer for reading
174 * @return positive value (0 or greater): the bytes read;
175 * On error a negative value will be returned with the following error codes:
176 * ::EPERS_NOT_INITIALIZED ::EPERS_NOPLUGINFUNCT ::EPERS_MAXHANDLE
178 int pclKeyHandleReadData(int key_handle, unsigned char* buffer, int buffer_size);
183 * @brief register a change notification for persistent data
185 * @param key_handle key value handle return by key_handle_open()
186 * @param callback notification callback
188 * @return positive value (0 or greater): registration OK;
189 * On error a negative value will be returned with the following error codes:
190 * ::EPERS_NOT_INITIALIZED ::EPERS_MAXHANDLE ::EPERS_NOTIFY_NOT_ALLOWED
192 int pclKeyHandleRegisterNotifyOnChange(int key_handle, pclChangeNotifyCallback_t callback);
197 * @brief unregister a change notification for persistent data
199 * @param key_handle key value handle return by key_handle_open()
200 * @param callback notification callback
202 * @return positive value (0 or greater): registration OK;
203 * On error a negative value will be returned with the following error codes:
204 * ::EPERS_NOT_INITIALIZED ::EPERS_LOCKFS ::EPERS_MAXHANDLE ::EPERS_NOTIFY_NOT_ALLOWED
206 int pclKeyHandleUnRegisterNotifyOnChange(int key_handle, pclChangeNotifyCallback_t callback);
211 * @brief writes persistent data identified by key handle
213 * @param key_handle key value handle return by key_handle_open()
214 * @param buffer the buffer containing the persistent data to write
215 * @param buffer_size the number of bytes to write (default max size is set to 16kB)
216 * use environment variable PERS_MAX_KEY_VAL_DATA_SIZE to modify default size in bytes
218 * @return positive value (0 or greater): the bytes written;
219 * On error a negative value will be returned with the following error codes:
220 * ::EPERS_LOCKFS ::EPERS_MAX_BUFF_SIZE ::EPERS_NOTIFY_SIG ::EPERS_DB_VALUE_SIZE ::EPERS_DB_KEY_SIZE
221 * ::EPERS_NOPRCTABLE ::EPERS_DB_VALUE_SIZE ::EPERS_RESOURCE_READ_ONLY
223 int pclKeyHandleWriteData(int key_handle, unsigned char* buffer, int buffer_size);
228 * @brief reads persistent data identified by ldbid and resource_id
230 * @param ldbid logical database ID
231 * @param resource_id the resource ID
232 * @param user_no the user ID; user_no=0 can not be used as user-ID beacause ‘0’ is defined as System/node
233 * @param seat_no the seat number
234 * @param buffer the buffer to read the persistent data
235 * @param buffer_size size of buffer for reading
237 * @return positive value (0 or greater): the bytes read;
238 * On error a negative value will be returned with th following error codes:
239 * ::EPERS_LOCKFS ::EPERS_NOT_INITIALIZED ::EPERS_BADPOL ::EPERS_NOPLUGINFUNCT
241 int pclKeyReadData(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no, unsigned char* buffer, int buffer_size);
246 * @brief register a change notification for persistent data
248 * @param ldbid logical database ID of the resource to monitor
249 * @param resource_id the resource ID
250 * @param user_no the user ID; user_no=0 can not be used as user-ID beacause ‘0’ is defined as System/node
251 * @param seat_no the seat number
252 * @param callback notification callback
254 * @return positive value (0 or greater): registration OK;
255 * On error a negative value will be returned with the following error codes:
256 * ::EPERS_RES_NO_KEY ::EPERS_NOKEYDATA ::EPERS_NOPRCTABLE ::EPERS_NOTIFY_NOT_ALLOWED
258 int pclKeyRegisterNotifyOnChange(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no, pclChangeNotifyCallback_t callback);
263 * @brief unregister a change notification for persistent data
265 * @param ldbid logical database ID of the resource to monitor
266 * @param resource_id the resource ID
267 * @param user_no the user ID; user_no=0 can not be used as user-ID beacause ‘0’ is defined as System/node
268 * @param seat_no the seat number
269 * @param callback notification callback
271 * @return positive value (0 or greater): registration OK;
272 * On error a negative value will be returned with the following error codes:
273 * ::EPERS_RES_NO_KEY ::EPERS_NOKEYDATA ::EPERS_NOPRCTABLE ::EPERS_NOTIFY_NOT_ALLOWED
275 int pclKeyUnRegisterNotifyOnChange( unsigned int ldbid, const char * resource_id, unsigned int user_no, unsigned int seat_no, pclChangeNotifyCallback_t callback);
280 * @brief writes persistent data identified by ldbid and resource_id
282 * @param ldbid logical database ID
283 * @param resource_id the resource ID
284 * @param user_no the user ID; user_no=0 can not be used as user-ID beacause ‘0’ is defined as System/node
285 * @param seat_no the seat number
286 * @param buffer the buffer containing the persistent data to write
287 * @param buffer_size the number of bytes to write (default max size is set to 16kB)
288 * use environment variable PERS_MAX_KEY_VAL_DATA_SIZE to modify default size in bytes
290 * @return positive value (0 or greater): the bytes written;
291 * On error a negative value will be returned with the following error codes:
292 * ::EPERS_LOCKFS ::EPERS_BADPOL ::EPERS_BUFLIMIT ::EPERS_DB_VALUE_SIZE ::EPERS_DB_KEY_SIZE
293 * ::EPERS_NOTIFY_SIG ::EPERS_RESOURCE_READ_ONLY
295 int pclKeyWriteData(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no, unsigned char* buffer, int buffer_size);
304 /** \} */ /* End of API */
305 /** \} */ /* End of MODULE */
307 #endif /* PERSISTENCY_CLIENT_LIBRARY_KEY_H */