82ccadcf9a2b117181cdd632282fed2783bbb30c
[profile/ivi/persistence-client-library.git] / src / persistence_client_library_custom_loader.h
1 #ifndef PERSISTENCE_CLIENT_LIBRARY_CUSTOM_LOADER_H
2 #define PERSISTENCE_CLIENT_LIBRARY_CUSTOM_LOADER_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_custom_loader.h
16  * @ingroup        Persistence client library
17  * @author         Ingo Huerner
18  * @brief          Header of the persistence client library custom library_loader.
19  * @see
20  */
21
22 #include "../include/persistence_client_custom.h"
23
24
25 /// enumerator used to identify the policy to manage the data
26 typedef enum _PersistenceCustomLibs_e
27 {
28    PersCustomLib_early       = 0,  /// predefined custom library for early persistence
29    PersCustomLib_secure      = 1,  /// predefined custom library for secure persistence
30    PersCustomLib_emergency   = 2,  /// predefined custom library for emengency persistence
31    PersCustomLib_HWinfo      = 3,  /// predefined custom library for hw information
32    PersCustomLib_Custom1     = 4,  /// custom library 1
33    PersCustomLib_Custom2     = 5,  /// custom library 2
34    PersCustomLib_Custom3     = 6,  /// custom library 3
35
36    // insert new entries here ...
37
38    PersCustomLib_LastEntry         /// last entry
39
40 } PersistenceCustomLibs_e;
41
42
43 /// enumerator fo custom library defines
44 enum _PersCustomLibDefines_e
45 {
46    PersCustomPathSize = 12
47
48 } PersCustomLibDefines_e;
49
50
51
52 /// structure definition for custom library functions
53 typedef struct _Pers_custom_functs_s
54 {
55    /// custom library handle
56    void* handle;
57
58    /// create backup
59    int (*custom_plugin_create_backup)(const char* backup_id);
60
61    /// custom library deinit function
62    int (*custom_plugin_deinit)();
63
64    /// custom delete function
65    int (*custom_plugin_delete_data)(const char* path);
66
67    /// get backup
68    int (*custom_plugin_get_backup)(char* backup_id, int size);
69
70    // get the size
71    int (*custom_plugin_get_size)(const char* path);
72
73    /// custom get data function
74    int (*custom_plugin_get_data)(const char* path, char* buffer, int size);
75
76    /// custom close function
77    int (*custom_plugin_handle_close)(int handle);
78
79    /// custom get data function
80    int (*custom_plugin_handle_get_data)(int handle, char* buffer, int size);
81
82    /// custom open function
83    int (*custom_plugin_handle_open)(const char* path, int flag, int mode);
84
85    /// custom set data function
86    int (*custom_plugin_handle_set_data)(int handle, char* buffer, int size);
87
88    /// custom library init function
89    int (*custom_plugin_init)();
90
91    /// restore backup
92    int (*custom_plugin_restore_backup)(const char* backup_id);
93
94    /// custom set data function
95    int (*custom_plugin_set_data)(const char* path, char* buffer, int size);
96
97    /// custom status notification function
98    int (*custom_plugin_get_status_notification_clbk)(plugin_callback_t pFunct);
99
100    // get the size
101    int (*custom_plugin_handle_get_size)(int handle);
102
103    /// initialize plugin (non blocking)
104    int (*custom_plugin_init_async)(plugin_callback_async_t pfInitCompletedCB);
105
106    /// clear all data
107    int (*custom_plugin_clear_all_data)(void);
108
109    /// sync all data
110    int (*custom_plugin_sync)(void);
111
112
113 }Pers_custom_functs_s;
114
115
116 /// custom library functions array
117 Pers_custom_functs_s gPersCustomFuncs[PersCustomLib_LastEntry];
118
119
120 /**
121  * @brief Translate a client library name into a id
122  *
123  * @param lib_name the library name
124  * @param substring indicator if a substring search is neccessary
125  *
126  * @return the library id or PersCustomLib_LastEntry if nothing found
127  */
128 PersistenceCustomLibs_e custom_client_name_to_id(const char* lib_name, int substring);
129
130 /**
131  * @brief get the names of the custom libraries to load
132  *
133  * @return 0 for success or a negative value with the following errors:
134  * EPERS_OUTOFBOUNDS
135  */
136 int get_custom_libraries();
137
138
139
140 /**
141  * @brief get the names of the custom libraries to load
142  *
143  * @param customLib the enumerator id identifying the custom library
144  * @param customFuncts function pointer array of loaded custom library functions
145  *
146  * @return 0 for success or a negative value with one of the following errors:
147  *  EPERS_NOPLUGINFCNT   EPERS_DLOPENERROR
148  *
149  */
150 int load_custom_library(PersistenceCustomLibs_e customLib, Pers_custom_functs_s *customFuncts);
151
152
153
154 /**
155  * @brief get the names of the custom libraries to load
156  *
157  * @return 0 for success orr a negative value with one of the following errors:
158  *  EPERS_NOPLUGINFCNT   EPERS_DLOPENERROR
159  */
160 int load_all_custom_libraries();
161
162
163 /**
164  * @brief get the position in the array
165  *
166  * @param customLib the enumerator id identifying the custom library
167  *
168  * @return the array position or -1 if the position can't be found
169  */
170 int check_valid_idx(int idx);
171
172
173
174 /**
175  * @brief get the custom library name form an index
176  *
177  * @return the name of the custom library ot NULL if invalid
178  */
179 char* get_custom_client_lib_name(int idx);
180
181
182 /**
183  * @brief invalidate customer plugin function
184  */
185 void invalidate_custom_plugin(int idx);
186
187
188 #endif /* PERSISTENCE_CLIENT_LIBRARY_CUSTOM_LOADER_H */