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
26 /** \ingroup GEN_PERS */
27 /** \defgroup PERS_KEYVALUE Client: Key-value access
30 /** \defgroup PERS_KEYVALUE_INTERFACE API document
38 /** \defgroup PCL_DEFINES_KEYVALUE Defines, Struct, Enum
42 #define PERSIST_KEYVALUEAPI_INTERFACE_VERSION (0x06010000U)
44 #include "persistence_client_library.h"
48 * status returned in notification structure
50 typedef enum _pclNotifyStatus_e
52 pclNotifyStatus_no_changed = 0,
53 pclNotifyStatus_created,
54 pclNotifyStatus_changed,
55 pclNotifyStatus_deleted,
56 /* insert new_ entries here .. */
57 pclNotifyStatus_lastEntry
62 * structure to return in case of notification
64 typedef struct _pclNotification_s
66 pclNotifyStatus_e pclKeyNotify_Status; /// notification status
67 unsigned int ldbid; /// logical db id
68 const char * resource_id; /// resource id
69 unsigned int user_no; /// user id
70 unsigned int seat_no; /// seat id
73 /** \defgroup SHUTDOWN_TYPE shutdown notification type definitions
74 * according to Node State Manager component
83 /** definition of the change callback
85 * @param notifyStruct structure for notifcation
87 * @return positive value: success;
88 * On error a negative value will be returned with the following error codes: ::EPERS_LOCKFS
90 typedef int(* pclChangeNotifyCallback_t)(pclNotification_s * notifyStruct);
93 /** \defgroup PCL_KEYVALUE functions Key-Value access
98 * @brief delete persistent data
100 * @param ldbid logical database ID
101 * @param resource_id the resource ID
102 * @param user_no the user ID; user_no=0 can not be used as user-ID beacause ‘0’ is defined as System/node
103 * @param seat_no the seat number
105 * @return positive value: success; On error a negative value will be returned with the following error codes:
108 int pclKeyDelete(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no);
113 * @brief gets the size of persistent data in bytes
115 * @param ldbid logical database ID
116 * @param resource_id the resource ID
117 * @param user_no the user ID; user_no=0 can not be used as user-ID beacause ‘0’ is defined as System/node
118 * @param seat_no the seat number
120 * @return positive value: the size; On error a negative value will be returned with the following error codes:
121 * ::EPERS_LOCKFS, ::EPERS_BADPOL, ::EPERS_NOKEY, ::EPERS_NOKEYDATA or ::EPERS_NOPRCTABLE
123 int pclKeyGetSize(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no);
126 * @brief close the access to a key-value identified by key handle
128 * @param key_handle key value handle return by key_handle_open()
130 * @return positive value: success; On error a negative value will be returned with the following error codes:
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: the size; On error a negative value will be returned with the following error codes:
145 int pclKeyHandleGetSize(int key_handle);
150 * @brief open a key-value
152 * @param ldbid logical database ID
153 * @param resource_id the resource ID
154 * @param user_no the user ID; user_no=0 can not be used as user-ID beacause ‘0’ is defined as System/node
155 * @param seat_no the seat number
157 * @return positive value: the key handle to access the value;
158 * On error a negative value will be returned with the following error codes:
161 int pclKeyHandleOpen(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no);
166 * @brief reads persistent data identified by key handle
168 * @param key_handle key value handle return by key_handle_open()
169 * @param buffer the buffer for persistent data
170 * @param buffer_size size of buffer for reading
172 * @return positive value: the bytes read; On error a negative value will be returned with the following error codes:
175 int pclKeyHandleReadData(int key_handle, unsigned char* buffer, int buffer_size);
180 * @brief register a change notification for persistent data
182 * @param key_handle key value handle return by key_handle_open()
183 * @param callback notification callback
185 * @return positive value: registration OK; On error a negative value will be returned with the following error codes:
188 int pclKeyHandleRegisterNotifyOnChange(int key_handle, pclChangeNotifyCallback_t callback);
193 * @brief writes persistent data identified by key handle
195 * @param key_handle key value handle return by key_handle_open()
196 * @param buffer the buffer containing the persistent data to write
197 * @param buffer_size the number of bytes to write (default max size is set to 16kB)
198 * use environment variable PERS_MAX_KEY_VAL_DATA_SIZE to modify default size in bytes
200 * @return positive value: the bytes written; On error a negative value will be returned with the following error codes:
203 int pclKeyHandleWriteData(int key_handle, unsigned char* buffer, int buffer_size);
208 * @brief reads persistent data identified by ldbid and resource_id
210 * @param ldbid logical database ID
211 * @param resource_id the resource ID
212 * @param user_no the user ID; user_no=0 can not be used as user-ID beacause ‘0’ is defined as System/node
213 * @param seat_no the seat number
214 * @param buffer the buffer to read the persistent data
215 * @param buffer_size size of buffer for reading
217 * @return positive value: the bytes read; On error a negative value will be returned with th follwoing error codes:
220 int pclKeyReadData(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no, unsigned char* buffer, int buffer_size);
225 * @brief register a change notification for persistent data
227 * @param ldbid logical database ID of the resource to monitor
228 * @param resource_id the resource ID
229 * @param user_no the user ID; user_no=0 can not be used as user-ID beacause ‘0’ is defined as System/node
230 * @param seat_no the seat number
231 * @param callback notification callback
233 * @return positive value: registration OK; On error a negative value will be returned with the following error codes:
234 * ::EPERS_RES_NO_KEY ::EPERS_NOKEYDATA ::EPERS_NOPRCTABLE
236 int pclKeyRegisterNotifyOnChange(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no, pclChangeNotifyCallback_t callback);
241 * @brief writes persistent data identified by ldbid and resource_id
243 * @param ldbid logical database ID
244 * @param resource_id the resource ID
245 * @param user_no the user ID; user_no=0 can not be used as user-ID beacause ‘0’ is defined as System/node
246 * @param seat_no the seat number
247 * @param buffer the buffer containing the persistent data to write
248 * @param buffer_size the number of bytes to write (default max size is set to 16kB)
249 * use environment variable PERS_MAX_KEY_VAL_DATA_SIZE to modify default size in bytes
251 * @return positive value: the bytes written; On error a negative value will be returned with the following error codes:
254 int pclKeyWriteData(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no, unsigned char* buffer, int buffer_size);
262 /** \} */ /* End of API */
263 /** \} */ /* End of MODULE */
265 #endif /* PERSISTENCY_CLIENT_LIBRARY_KEY_H */