1 /******************************************************************************
4 * Company XS Embedded GmbH
5 *****************************************************************************/
6 /******************************************************************************
7 Permission is hereby granted, free of charge, to any person obtaining
8 a copy of this software and associated documentation files (the "Software"),
9 to deal in the Software without restriction, including without limitation
10 the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 and/or sell copies of the Software, and to permit persons to whom the
12 Software is furnished to do so, subject to the following conditions:
14 The above copyright notice and this permission notice shall be included
15 in all copies or substantial portions of the Software.
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
21 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTIcacheON WITH THE SOFTWARE
23 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 ******************************************************************************/
26 * @file persistence_client_library.c
27 * @ingroup Persistence client library
28 * @author Ingo Huerner
29 * @brief Implementation of the persistence client library.
30 * Library provides an API to access persistent data
35 #include "persistence_client_library.h"
36 #include "persistence_client_library_lc_interface.h"
37 #include "persistence_client_library_pas_interface.h"
38 #include "persistence_client_library_dbus_service.h"
39 #include "persistence_client_library_handle.h"
40 #include "persistence_client_library_data_access.h"
41 #include "persistence_client_library_custom_loader.h"
42 #include "persistence_client_library_access_helper.h"
49 #include <dlt/dlt_common.h>
51 extern char* __progname;
53 /// debug log and trace (DLT) setup
54 DLT_DECLARE_CONTEXT(persClientLibCtx);
57 /// resource configuration table name
58 const char* gResTableCfg = "/resource-table-cfg.gvdb";
60 /// shared cached default database
61 //static const char* gSharedCachedDefault = "cached-default.dconf";
62 /// shared cached database
63 const char* gSharedCached = "/cached.dconf";
64 /// shared write through default database
65 const char* gSharedWtDefault = "wt-default.dconf";
66 /// shared write through database
67 const char* gSharedWt = "/wt.dconf";
69 /// local cached default database
70 const char* gLocalCachedDefault = "cached-default.gvdb";
71 /// local cached default database
72 const char* gLocalCached = "/cached.gvdb";
73 /// local write through default database
74 const char* gLocalWtDefault = "wt-default.gvdb";
75 /// local write through default database
76 const char* gLocalWt = "/wt.gvdb";
79 /// directory structure node name defintion
80 const char* gNode = "/Node";
81 /// directory structure user name defintion
82 const char* gUser = "/User/";
83 /// directory structure seat name defintion
84 const char* gSeat = "/Seat/";
87 /// path prefic for local cached database: /Data/mnt_c/<appId>/<database_name>
88 const char* gLocalCachePath = "/Data/mnt-c/%s%s";
89 /// path prefic for local write through database /Data/mnt_wt/<appId>/<database_name>
90 const char* gLocalWtPath = "/Data/mnt-wt/%s%s";
91 /// path prefic for shared cached database: /Data/mnt_c/Shared/Group/<group_no>/<database_name>
92 const char* gSharedCachePath = "/Data/mnt-c/shared/group/%x%s";
93 /// path prefic for shared write through database: /Data/mnt_wt/Shared/Group/<group_no>/<database_name>
94 const char* gSharedWtPath = "/Data/mnt-wt/shared/group/%x%s";
95 /// path prefic for shared public cached database: /Data/mnt_c/Shared/Public//<database_name>
96 const char* gSharedPublicCachePath = "/Data/mnt-c/shared/public%s";
97 /// path prefic for shared public write through database: /Data/mnt_wt/Shared/Public/<database_name>
98 const char* gSharedPublicWtPath = "/Data/mnt-wt/shared/public%s";
102 char gAppId[maxAppNameLen];
104 /// max key value data size [default 16kB]
105 int gMaxKeyValDataSize = defaultMaxKeyValDataSize;
108 /// library constructor
109 void pers_library_init(void) __attribute__((constructor));
111 /// library deconstructor
112 void pers_library_destroy(void) __attribute__((destructor));
116 void pers_library_init(void)
118 DLT_REGISTER_APP("Persistence Client Library","persClientLib");
119 DLT_REGISTER_CONTEXT(persClientLibCtx,"persClientLib","Context for Logging");
121 DLT_LOG(persClientLibCtx, DLT_LOG_ERROR, DLT_STRING("Initialize Persistence Client Library!!!!"));
123 /// environment variable for on demand loading of custom libraries
124 const char *pOnDemandLoad = getenv("PERS_CUSTOM_LIB_LOAD_ON_DEMAND");
126 /// environment variable for max key value data
127 const char *pDataSize = getenv("PERS_MAX_KEY_VAL_DATA_SIZE");
129 if(pDataSize != NULL)
131 gMaxKeyValDataSize = atoi(pDataSize);
135 pthread_mutex_init(&gDbusInitializedMtx, NULL);
137 // setup dbus main dispatching loop
138 setup_dbus_mainloop();
140 // wain until dbus main loop has been setup and running
141 pthread_mutex_lock(&gDbusInitializedMtx);
143 // register for lifecycle and persistence admin service dbus messages
144 register_lifecycle();
145 register_pers_admin_service();
147 // clear the open file descriptor array
148 memset(gOpenFdArray, maxPersHandle, sizeof(int));
150 /// get custom library names to load
151 get_custom_libraries();
153 if(pOnDemandLoad == NULL) // load all available libraries now
157 for(i=0; i < get_num_custom_client_libs(); i++ )
159 if(load_custom_library(get_custom_client_position_in_array(i), &gPersCustomFuncs[i] ) == -1)
161 printf("E r r o r could not load plugin: %s \n", get_custom_client_lib_name(get_custom_client_position_in_array(i)));
164 gPersCustomFuncs[i].custom_plugin_init();
168 //gPersCustomFuncs[PersCustomLib_early].custom_plugin_open("Hallo", 88, 99);
169 //gPersCustomFuncs[PersCustomLib_early].custom_plugin_close(17);
172 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
173 strncpy(gAppId, __progname, maxAppNameLen);
178 void pers_library_destroy(void)
181 pthread_mutex_destroy(&gDbusInitializedMtx);
183 // unregister for lifecycle and persistence admin service dbus messages
184 unregister_lifecycle();
185 unregister_pers_admin_service();
188 DLT_UNREGISTER_CONTEXT(persClientLibCtx);
189 DLT_UNREGISTER_APP();