Protected global variables with mutex; minor optimizations; corrected doxygen documen...
[profile/ivi/persistence-client-library.git] / src / persistence_client_library_handle.h
1 #ifndef PERSISTENCE_CLIENT_LIBRARY_HANDLE_H
2 #define PERSISTENCE_CLIENT_LIBRARY_HANDLE_H
3
4 /******************************************************************************
5  * Project         Persistency
6  * (c) copyright   2012
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 ******************************************************************************/
14  /**
15  * @file           persistence_client_library_handle.h
16  * @ingroup        Persistence client library
17  * @author         Ingo Huerner
18  * @brief          Header of the persistence client library handle.
19  *                 Library provides an API to access persistent data
20  * @see            
21  */
22
23 #include "persistence_client_library_data_organization.h"
24
25 #include <persComRct.h>
26
27 /// key handle structure definition
28 typedef struct _PersistenceKeyHandle_s
29 {
30         /// Resource ID
31    char resource_id[DbResIDMaxLen];
32    /// logical database id
33    unsigned int ldbid;
34    /// User No
35    unsigned int user_no;
36    /// Seat No
37    unsigned int seat_no;
38 } PersistenceKeyHandle_s;
39
40
41 /// file handle structure definition
42 typedef struct _PersistenceFileHandle_s
43 {
44         /// access permission read/write
45         PersistencePermission_e permission;
46         /// flag to indicate if a backup has already been created
47    int backupCreated;
48    /// path to the backup file
49    char backupPath[DbPathMaxLen];
50    /// path to the checksum file
51    char csumPath[DbPathMaxLen];
52    /// the file path
53    char* filePath;
54 } PersistenceFileHandle_s;
55
56 /// open file descriptor handle array
57 extern int gOpenFdArray[MaxPersHandle];
58
59 /// handle array
60 extern int gOpenHandleArray[MaxPersHandle];
61
62 //----------------------------------------------------------------
63 //----------------------------------------------------------------
64
65 /**
66  * @brief get persistence handle
67  *
68  * @return a new handle or 0 if an error occured or EPERS_MAXHANDLE if max no of handles is reached
69  */
70 int get_persistence_handle_idx();
71
72
73 /**
74  * @brief close persistence handle
75  *
76  * @param handle to close
77  */
78 void set_persistence_handle_close_idx(int handle);
79
80
81 /**
82  * @brief close open key handles
83  *
84  */
85 void close_all_persistence_handle();
86
87 //----------------------------------------------------------------
88 //----------------------------------------------------------------
89
90 /**
91  * @brief set data to the key handle
92  *
93  * @param idx the index
94  * @param id the resource id
95  * @param ldbid the logical database id
96  * @param user_no the user identifier
97  * @param seat_no the seat number
98  *
99  * @return a positive value (0 or greather) or -1 on error
100  */
101 int set_key_handle_data(int idx, const char* id, unsigned int ldbid,  unsigned int user_no, unsigned int seat_no);
102
103
104 /**
105  * @brief set data to the key handle
106  *
107  * @param idx the index
108  * @param handleStruct the handle structure
109  *
110  * @return 0 on success, -1 on error
111  */
112 int get_key_handle_data(int idx, PersistenceKeyHandle_s* handleStruct);
113
114
115 /**
116  * @brief initialize the key handle array to defined values
117  */
118 void init_key_handle_array();
119
120
121 /**
122  * @brief set data to the key handle
123  *
124  * @param idx the index
125  *
126  */
127 void clear_key_handle_array(int idx);
128
129 //----------------------------------------------------------------
130 //----------------------------------------------------------------
131
132 /**
133  * @brief set data to the key handle
134  *
135  * @param idx the index
136  * @param permission the permission (read/write, read only, write only)
137  * @param backupCreated 0 is a backup has not been created or 1 if a backup has been created
138  * @param backup path to the backup file
139  * @param csumPath the path to the checksum file
140  * @param filePath the path to the file
141  *
142  */
143 int set_file_handle_data(int idx, PersistencePermission_e permission, int backupCreated,
144                                    const char* backup, const char* csumPath,  char* filePath);
145
146
147 /**
148  * @brief set data to the key handle
149  *
150  * @param idx the index
151  *
152  * @return the file permission
153  */
154 int get_file_permission(int idx);
155
156
157 /**
158  * @brief set data to the key handle
159  * @attention "N index check will be done"
160  *
161  * @param idx the index
162  *
163  * @return the path to the backup
164  */
165 char* get_file_backup_path(int idx);
166
167
168 /**
169  * @brief get the file checksum path
170  * @attention "N index check will be done"
171  *
172  * @param idx the index
173  *
174  * @return the checksum path
175  */
176 char* get_file_checksum_path(int idx);
177
178
179 /**
180  * @brief set the file backup status of the file
181  * @attention "No index check will be done"
182  *
183  * @param idx the index
184  * @param status the backup status, 0 backup has been created,
185  *                                  1 backup has not been created
186  */
187 void set_file_backup_status(int idx, int status);
188
189
190 /**
191  * @brief get the backup status of the file
192  * @attention "No index check will be done"
193  *
194  * @param idx the index
195  *
196  * @return 0 if no backup has been created,
197  *         1 if backup has been created
198  */
199 int get_file_backup_status(int idx);
200
201 //----------------------------------------------------------------
202 //----------------------------------------------------------------
203
204 /**
205  * @brief set data to the key handle
206  *
207  * @param idx the index
208  * @param permission the permission (read/write, read only, write only)
209  * @param backupCreated 0 is a backup has not been created or 1 if a backup has been created
210  * @param backup path to the backup file
211  * @param csumPath the path to the checksum file
212  * @param filePath the path to the file
213  *
214  */
215 int set_ossfile_handle_data(int idx, PersistencePermission_e permission, int backupCreated,
216                                    const char* backup, const char* csumPath,  char* filePath);
217
218
219 /**
220  * @brief set data to the key handle
221  *
222  * @param idx the index
223  *
224  * @return the file permission
225  */
226 int get_ossfile_permission(int idx);
227
228
229 /**
230  * @brief get file backup path
231  * @attention "No index check will be done"
232  *
233  * @param idx the index
234  *
235  * @return the path to the backup
236  */
237 char* get_ossfile_backup_path(int idx);
238
239
240 /**
241  * @brief get file path
242  * @attention "No index check will be done"
243  *
244  * @param idx the index
245  *
246  * @return the path to the backup
247  */
248 char* get_ossfile_file_path(int idx);
249
250
251 /**
252  * @brief get the file checksum path
253  * @attention "No index check will be done"
254  *
255  * @param idx the index
256  *
257  * @return the checksum path
258  */
259 char* get_ossfile_checksum_path(int idx);
260
261 /**
262  * @brief get the file checksum path
263  * @attention "No index check will be done"
264  *
265  * @param idx the index
266  * @param file pointer to the file and path
267  *
268  * @return the checksum path
269  */
270 void set_ossfile_file_path(int idx, char* file);
271
272 /**
273  * @brief set the file backup status of the file
274  * @attention "No index check will be done"
275  *
276  * @param idx the index
277  * @param status the backup status, 0 backup has been created,
278  *                                  1 backup has not been created
279  */
280 void set_ossfile_backup_status(int idx, int status);
281
282
283 /**
284  * @brief get the backup status of the file
285  * @attention "No index check will be done"
286  *
287  * @param idx the index
288  *
289  * @return 0 if no backup has been created,
290  *         1 if backup has been created
291  */
292 int get_ossfile_backup_status(int idx);
293
294
295 #endif /* PERSISTENCY_CLIENT_LIBRARY_HANDLE_H */
296