Implemented on demand/static loading of plugins (part I); ATTENTION: pluginf config...
[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 /// indicates the init method type
52 typedef enum PersInitType_e_
53 {
54         Init_Synchronous   = 0,
55         Init_Asynchronous = 1,
56         Init_Undefined
57 } PersInitType_e;
58
59
60 /// indicates the plugin loading type
61 typedef enum PersLoadingType_e_
62 {
63         LoadType_PclInit   = 0, // load plugin during pclInitLibrary function
64         LoadType_OnDemand = 1,  // load the pluing on demand, when a plugin function will be requested the first time.
65         LoadType_Undefined
66 } PersLoadingType_e;
67
68
69
70 /// structure definition for custom library functions
71 typedef struct _Pers_custom_functs_s
72 {
73    /// custom library handle
74    void* handle;
75
76    /// create backup
77    int (*custom_plugin_create_backup)(const char* backup_id);
78
79    /// custom library deinit function
80    int (*custom_plugin_deinit)();
81
82    /// custom delete function
83    int (*custom_plugin_delete_data)(const char* path);
84
85    /// get backup
86    int (*custom_plugin_get_backup)(char* backup_id, int size);
87
88    // get the size
89    int (*custom_plugin_get_size)(const char* path);
90
91    /// custom get data function
92    int (*custom_plugin_get_data)(const char* path, char* buffer, int size);
93
94    /// custom close function
95    int (*custom_plugin_handle_close)(int handle);
96
97    /// custom get data function
98    int (*custom_plugin_handle_get_data)(int handle, char* buffer, int size);
99
100    /// custom open function
101    int (*custom_plugin_handle_open)(const char* path, int flag, int mode);
102
103    /// custom set data function
104    int (*custom_plugin_handle_set_data)(int handle, char* buffer, int size);
105
106    /// custom library init function
107    int (*custom_plugin_init)();
108
109    /// restore backup
110    int (*custom_plugin_restore_backup)(const char* backup_id);
111
112    /// custom set data function
113    int (*custom_plugin_set_data)(const char* path, char* buffer, int size);
114
115    /// custom status notification function
116    int (*custom_plugin_get_status_notification_clbk)(plugin_callback_t pFunct);
117
118    // get the size
119    int (*custom_plugin_handle_get_size)(int handle);
120
121    /// initialize plugin (non blocking)
122    int (*custom_plugin_init_async)(plugin_callback_async_t pfInitCompletedCB);
123
124    /// clear all data
125    int (*custom_plugin_clear_all_data)(void);
126
127    /// sync all data
128    int (*custom_plugin_sync)(void);
129
130
131 }Pers_custom_functs_s;
132
133
134 /// custom library functions array
135 Pers_custom_functs_s gPersCustomFuncs[PersCustomLib_LastEntry];
136
137
138 /**
139  * @brief Translate a client library name into a id
140  *
141  * @param lib_name the library name
142  * @param substring indicator if a substring search is neccessary
143  *
144  * @return the library id or PersCustomLib_LastEntry if nothing found
145  */
146 PersistenceCustomLibs_e custom_client_name_to_id(const char* lib_name, int substring);
147
148 /**
149  * @brief get the names of the custom libraries to load
150  *
151  * @return 0 for success or a negative value with the following errors:
152  * EPERS_OUTOFBOUNDS
153  */
154 int get_custom_libraries();
155
156
157
158 /**
159  * @brief get the names of the custom libraries to load
160  *
161  * @param customLib the enumerator id identifying the custom library
162  * @param customFuncts function pointer array of loaded custom library functions
163  *
164  * @return 0 for success or a negative value with one of the following errors:
165  *  EPERS_NOPLUGINFCNT   EPERS_DLOPENERROR
166  *
167  */
168 int load_custom_library(PersistenceCustomLibs_e customLib, Pers_custom_functs_s *customFuncts);
169
170
171 /**
172  * @brief get the position in the array
173  *
174  * @param customLib the enumerator id identifying the custom library
175  *
176  * @return the array position or -1 if the position can't be found
177  */
178 int check_valid_idx(int idx);
179
180
181
182 /**
183  * @brief get the custom library name form an index
184  *
185  * @return the name of the custom library ot NULL if invalid
186  */
187 char* get_custom_client_lib_name(int idx);
188
189
190 /**
191  * @brief invalidate customer plugin function
192  */
193 void invalidate_custom_plugin(int idx);
194
195
196
197 PersLoadingType_e getCustomLoadingType(int i);
198
199 PersInitType_e getCustomInitType(int i);
200
201 #endif /* PERSISTENCE_CLIENT_LIBRARY_CUSTOM_LOADER_H */