1 /******************************************************************************
4 * Company XS Embedded GmbH
5 *****************************************************************************/
6 /******************************************************************************
7 * This Source Code Form is subject to the terms of the
8 * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed
9 * with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 ******************************************************************************/
12 * @file persistence_client_library.c
13 * @ingroup Persistence client library
14 * @author Ingo Huerner
15 * @brief Implementation of the persistence client library.
16 * Library provides an API to access persistent data
21 #include "persistence_client_library_lc_interface.h"
22 #include "persistence_client_library_pas_interface.h"
23 #include "persistence_client_library_dbus_service.h"
24 #include "persistence_client_library_handle.h"
25 #include "persistence_client_library_custom_loader.h"
31 #include <dlt/dlt_common.h>
33 #include <dbus/dbus.h>
37 #define ENABLE_DBUS_INTERFACE 1
39 extern char* __progname;
41 /// debug log and trace (DLT) setup
42 DLT_DECLARE_CONTEXT(persClientLibCtx);
46 /// library constructor
47 void pers_library_init(void) __attribute__((constructor));
49 /// library deconstructor
50 void pers_library_destroy(void) __attribute__((destructor));
54 void pers_library_init(void)
59 DLT_REGISTER_APP("Persistence Client Library","persClientLib");
60 DLT_REGISTER_CONTEXT(persClientLibCtx,"persClientLib","Context for Logging");
62 DLT_LOG(persClientLibCtx, DLT_LOG_ERROR, DLT_STRING("Initialize Persistence Client Library!!!!"));
64 /// environment variable for on demand loading of custom libraries
65 const char *pOnDemandLoad = getenv("PERS_CUSTOM_LIB_LOAD_ON_DEMAND");
67 /// environment variable for max key value data
68 const char *pDataSize = getenv("PERS_MAX_KEY_VAL_DATA_SIZE");
72 gMaxKeyValDataSize = atoi(pDataSize);
75 #if ENABLE_DBUS_INTERFACE == 1
76 setup_dbus_mainloop();
78 // register for lifecycle and persistence admin service dbus messages
80 register_pers_admin_service();
83 // clear the open file descriptor array
84 memset(gOpenFdArray, MaxPersHandle, sizeof(int));
86 /// get custom library names to load
87 status = get_custom_libraries();
90 printf("Failed to load custom library config table => error number %d\n", status );
93 // initialize custom library structure
94 for(i = 0; i<PersCustomLib_LastEntry; i++)
96 gPersCustomFuncs[i].handle = NULL;
97 gPersCustomFuncs[i].custom_plugin_init = NULL;
98 gPersCustomFuncs[i].custom_plugin_deinit = NULL;
99 gPersCustomFuncs[i].custom_plugin_handle_open = NULL;
100 gPersCustomFuncs[i].custom_plugin_handle_close = NULL;
101 gPersCustomFuncs[i].custom_plugin_handle_get_data = NULL;
102 gPersCustomFuncs[i].custom_plugin_handle_set_data = NULL;
103 gPersCustomFuncs[i].custom_plugin_get_data = NULL;
104 gPersCustomFuncs[i].custom_plugin_set_data = NULL;
105 gPersCustomFuncs[i].custom_plugin_delete_data = NULL;
106 gPersCustomFuncs[i].custom_plugin_get_status_notification_clbk = NULL;
107 gPersCustomFuncs[i].custom_plugin_handle_get_size = NULL;
108 gPersCustomFuncs[i].custom_plugin_get_size = NULL;
109 gPersCustomFuncs[i].custom_plugin_create_backup = NULL;
110 gPersCustomFuncs[i].custom_plugin_get_backup = NULL;
111 gPersCustomFuncs[i].custom_plugin_restore_backup = NULL;
114 if(pOnDemandLoad == NULL) // load all available libraries now
116 for(i=0; i < get_num_custom_client_libs(); i++ )
118 if(load_custom_library(get_custom_client_position_in_array(i), &gPersCustomFuncs[i] ) == -1)
120 printf("E r r o r could not load plugin: %s \n", get_custom_client_lib_name(get_custom_client_position_in_array(i)));
123 gPersCustomFuncs[i].custom_plugin_init();
127 //gPersCustomFuncs[PersCustomLib_early].custom_plugin_open("Hallo", 88, 99);
128 //gPersCustomFuncs[PersCustomLib_early].custom_plugin_close(17);
131 //printf("A p p l i c a t i o n n a m e => %s \n", __progname /*program_invocation_short_name*/); // TODO: only temp solution for application name
132 strncpy(gAppId, __progname, MaxAppNameLen);
134 pthread_mutex_destroy(&gDbusInitializedMtx);
135 pthread_cond_destroy(&gDbusInitializedCond);
140 void pers_library_destroy(void)
143 #if ENABLE_DBUS_INTERFACE == 1
144 // unregister for lifecycle and persistence admin service dbus messages
145 unregister_lifecycle();
146 unregister_pers_admin_service();
149 DLT_UNREGISTER_CONTEXT(persClientLibCtx);
150 DLT_UNREGISTER_APP();