summaryrefslogtreecommitdiff
path: root/src/persistence_client_library_db_access.h
blob: ee970461b8d2a973562e90307e34389f39b177ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#ifndef PERSISTENCE_CLIENT_LIBRARY_DB_ACCESS_H
#define PERSISTENCE_CLIENT_LIBRARY_DB_ACCESS_H

/******************************************************************************
 * Project         Persistency
 * (c) copyright   2012
 * Company         XS Embedded GmbH
 *****************************************************************************/
/******************************************************************************
 * This Source Code Form is subject to the terms of the
 * Mozilla Public License, v. 2.0. If a  copy of the MPL was not distributed
 * with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
******************************************************************************/
 /**
 * @file           persistence_client_library_db_access.h
 * @ingroup        Persistence client library
 * @author         Ingo Huerner
 * @brief          Header of the persistence client library database access.
 *                 Library provides an API to access persistent data
 * @see            
 */

#ifdef __cplusplus
extern "C" {
#endif

#define  PERSIST_DATA_ACCESS_INTERFACE_VERSION   (0x05000000U)


#include "persistence_client_library_data_organization.h"
#include "../include/persistence_client_library_key.h"

#include <persComRct.h>



/// default database definitions
typedef enum PersistenceDB_e_
{
	/// configurable default database
	PersistenceDB_confdefault = PersistencePolicy_LastEntry,
	/// default database
	PersistenceDB_default,

	PersistenceDB_LastEntry

} PersistenceDefaultDB_e;


/**
 * @brief get the raw key without prefixed '/node/', '/user/3/' etc
 *
 * @param key the ptr. to the key which should be stripped
 *
 * @return the pointer to the stripped 'raw key'
 */
char* pers_get_raw_key(char *key);



/**
 * @brief tries to get default values for a key from the configurable and factory default databases.
 *
 * @param dbPath the path to the directory where the default databases are in 
 * @param key the database key
 * @param info the persistence context information
 * @param buffer the buffer holding the data
 * @param buffer_size the size of the buffer
 * @param job the info to specify what to do. Get Data or the DataSize.
 *
 * @return the number of bytes read or the size of the key (depends on parameter 'job').
           negative value if an error occured and the following error code:
 *         EPERS_NO_PLUGIN_FUNCT, EPERS_NOKEY
 */
int pers_get_defaults(char* dbPath, char* key, PersistenceInfo_s* info, unsigned char* buffer, unsigned int buffer_size, PersGetDefault_e job);



/**
 * @brief write data to a key
 *
 * @param dbPath the path to the database where the key is in 
 * @param key the database key
 * @param resource_id the resource identifier
 * @param info persistence information
 * @param buffer the buffer holding the data
 * @param buffer_size the size of the buffer
 *
 * @return the number of bytes written or a negative value if an error occured with the following error codes:
 *   EPERS_NO_PLUGIN_FUNCT, EPERS_SETDTAFAILED  EPERS_NOPRCTABLE  EPERS_NOKEYDATA  EPERS_NOKEY
 */
int persistence_set_data(char* dbPath, char* key, const char* resource_id, PersistenceInfo_s* info, unsigned char* buffer, int buffer_size);



/**
 * @brief get data of a key
 *
 * @param dbPath the path to the database where the key is in
 * @param key the database key
 * @param resourceID the resource id
 * @param info persistence information
 * @param buffer the buffer holding the data
 * @param buffer_size the size of the buffer
 *
 * @return the number of bytes read or a negative value if an error occured with the following error codes:
 *  EPERS_NO_PLUGIN_FUNCT, EPERS_NOPRCTABLE  EPERS_NOKEYDATA  EPERS_NOKEY
 */
int persistence_get_data(char* dbPath, char* key, const char* resourceID, PersistenceInfo_s* info, unsigned char* buffer, int buffer_size);



/**
 * @brief get the size of the data from a given key
 *
 * @param dbPath the path to the database where the key is in
 * @param key the database key
 * @param resourceID the resource id
 * @param info persistence information
 *
 * @return size of data in bytes read from the key or on error a negative value with the following error codes:
 *  EPERS_NO_PLUGIN_FUNCT, EPERS_NOPRCTABLE or EPERS_NOKEY
 */
int persistence_get_data_size(char* dbPath, char* key, const char* resourceID, PersistenceInfo_s* info);



/**
 * @brief delete data
 *
 * @param dbPath the path to the database where the key is in
 * @param key the database key to register on
 * @param resource_id the resource identifier
 * @param info persistence information
 *
 * @return 0 if deletion was successfull;
 *         or an error code: EPERS_NO_PLUGIN_FUNCT, EPERS_DB_KEY_SIZE, EPERS_NOPRCTABLE, EPERS_DB_ERROR_INTERNAL or EPERS_NOPLUGINFUNCT
 */
int persistence_delete_data(char* dbPath, char* key, const char* resource_id, PersistenceInfo_s* info);



/**
 * @brief close all databases
 */
void database_close_all();



/**
 * @brief register or unregister for change notifications of a key
 *
 * @param resource_id the database resource_id to register on
 * @param ldbid logical database ID of the resource to monitor
 * @param user_no  the user ID; user_no=0 can not be used as user-ID beacause '0' is defined as System/node
 * @param seat_no  the seat number
 * @param callback the function callback to be called
 * @param regPolicy ::Notify_register to register; ::Notify_unregister to unregister
 *
 * @return 0 of registration was successful; -1 if registration fails
 */
int persistence_notify_on_change(const char* resource_id, const char* dbKey, unsigned int ldbid, unsigned int user_no, unsigned int seat_no,
                                     pclChangeNotifyCallback_t callback, PersNotifyRegPolicy_e regPolicy);



/**
 * @brief send a notification signal
 *
 * @param key the database key to register on
 * @param context the database context
 * @param reason the reason of the signal, values see pclNotifyStatus_e.
 *
 * @return 0 of registration was successful; -1 if registration failes
 */
int pers_send_Notification_Signal(const char* key, PersistenceDbContext_s* context, pclNotifyStatus_e reason);


/**
 * @brief close all open persistence resource configuration tables
 */
void pers_rct_close_all();


/**
 * @brief delete notification tree
 */
void deleteNotifyTree(void);


#ifdef __cplusplus
}
#endif

#endif /* PERSISTENCY_CLIENT_LIBRARY_DB_ACCESS_H */