diff options
author | Ingo Huerner <ingo.huerner@xse.de> | 2014-07-21 19:31:59 +0200 |
---|---|---|
committer | Ingo Huerner <ingo.huerner@xse.de> | 2014-07-21 19:31:59 +0200 |
commit | 4a203e554a523df7f59fe05d9d30831de00ef535 (patch) | |
tree | 8355d70cff51ef8812d1c03c7437617ee35cb69a | |
parent | 7742bf57b12575e0959cda104736e2ac417139da (diff) | |
download | persistence-client-library-generic_backend.tar.gz |
First step to make every storage backend loadable as plugingeneric_backend
-rw-r--r-- | config/pclCustomLibConfigFile.cfg | 1 | ||||
-rw-r--r-- | configure.ac | 3 | ||||
-rw-r--r-- | include/persistence_client_custom.h | 93 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/persistence_client_library.c | 7 | ||||
-rw-r--r-- | src/persistence_client_library_custom_loader.c | 441 | ||||
-rw-r--r-- | src/persistence_client_library_custom_loader.h | 82 | ||||
-rw-r--r-- | src/persistence_client_library_db_access.c | 26 | ||||
-rw-r--r-- | src/persistence_client_library_prct_access.c | 21 |
9 files changed, 493 insertions, 183 deletions
diff --git a/config/pclCustomLibConfigFile.cfg b/config/pclCustomLibConfigFile.cfg index 040cbf0..cd1f893 100644 --- a/config/pclCustomLibConfigFile.cfg +++ b/config/pclCustomLibConfigFile.cfg @@ -1,6 +1,7 @@ hwinfo /usr/lib/libhwinfoperscustom.so init async secure /usr/lib/libsecureperscustom.so init sync custom3 /usr/lib/libcustom3perscustom.so od sync +default /usr/lib/libpers_common.so init sync emergency /usr/lib/libemergencyperscustom.so od async early /usr/lib/libearlyperscustom.so od sync custom2 /usr/lib/libcustom2perscustom.so init sync diff --git a/configure.ac b/configure.ac index 2c7f02f..26f2a7b 100644 --- a/configure.ac +++ b/configure.ac @@ -68,8 +68,7 @@ AC_CHECK_FUNCS([fdatasync ftruncate mkdir munmap rmdir strerror utime dlopen]) PKG_CHECK_MODULES(DEPS, automotive-dlt - dbus-1 - libperscommon) + dbus-1) AC_SUBST(DEPS_CFLAGS) AC_SUBST(DEPS_LIBS) diff --git a/include/persistence_client_custom.h b/include/persistence_client_custom.h index 302226a..4361dd7 100644 --- a/include/persistence_client_custom.h +++ b/include/persistence_client_custom.h @@ -97,6 +97,99 @@ The lower significant byte is equal 0 for released version only * \{ */ + + +/** + * \brief Obtain a handler to DB indicated by dbPathname + * \note : DB is created if it does not exist and (bForceCreationIfNotPresent != 0) + * + * \param dbPathname [in] absolute path to database (length limited to \ref PERS_ORG_MAX_LENGTH_PATH_FILENAME) + * \param bForceCreationIfNotPresent [in] if !=0x0, the database is created if it does not exist + * + * \return >= 0 for valid handler, negative value for error (\ref PERS_COM_ERROR_CODES_DEFINES) + */ +signed int persComDbOpen(char const * dbPathname, unsigned char bForceCreationIfNotPresent) ; + +/** + * \brief Close handler to DB + * + * \param handlerDB [in] handler obtained with persComDbOpen + * + * \return 0 for success, negative value for error (\ref PERS_COM_ERROR_CODES_DEFINES) + */ +signed int persComDbClose(signed int handlerDB) ; + +/** + * \brief write a key-value pair into local/shared database + * + * \param handlerDB [in] handler obtained with persComDbOpen + * \param key [in] key's name (length limited to \ref PERS_DB_MAX_LENGTH_KEY_NAME) + * \param data [in] buffer with key's data + * \param dataSize [in] size of key's data (max allowed \ref PERS_DB_MAX_SIZE_KEY_DATA) + * + * \return 0 for success, negative value otherwise (\ref PERS_COM_ERROR_CODES_DEFINES) + */ +signed int persComDbWriteKey(signed int handlerDB, char const * key, char const * data, signed int dataSize) ; + + +/** + * \brief read a key's value from local/shared database + * + * \param handlerDB [in] handler obtained with persComDbOpen + * \param key [in] key's name (length limited to \ref PERS_DB_MAX_LENGTH_KEY_NAME) + * \param dataBuffer_out [out]buffer where to return the read data + * \param dataBufferSize [in] size of dataBuffer_out + * + * \return read size, or negative value in case of error (\ref PERS_COM_ERROR_CODES_DEFINES) + */ +signed int persComDbReadKey(signed int handlerDB, char const * key, char* dataBuffer_out, signed int dataBufferSize) ; + +/** + * \brief read a key's value from local/shared database + * + * \param handlerDB [in] handler obtained with persComDbOpen + * \param key [in] key's name (length limited to \ref PERS_DB_MAX_LENGTH_KEY_NAME) + * + * \return key's size, or negative value in case of error (\ref PERS_COM_ERROR_CODES_DEFINES) + */ +signed int persComDbGetKeySize(signed int handlerDB, char const * key) ; + +/** + * \brief delete key from local/shared database + * + * \param handlerDB [in] handler obtained with persComDbOpen + * \param key [in] key's name (length limited to \ref PERS_DB_MAX_LENGTH_KEY_NAME) + * + * \return 0 for success, negative value otherwise (\ref PERS_COM_ERROR_CODES_DEFINES) + */ +signed int persComDbDeleteKey(signed int handlerDB, char const * key) ; + + +/** + * \brief Find the buffer's size needed to accomodate the list of keys' names in local/shared database + * + * \param handlerDB [in] handler obtained with persComDbOpen + * + * \return needed size, or negative value in case of error (\ref PERS_COM_ERROR_CODES_DEFINES) + */ +signed int persComDbGetSizeKeysList(signed int handlerDB) ; + + +/** + * \brief Obtain the list of the keys' names in local/shared database + * \note : keys in the list are separated by '\0' + * + * \param handlerDB [in] handler obtained with persComDbOpen + * \param listBuffer_out [out]buffer where to return the list of keys + * \param listBufferSize [in] size of listingBuffer_out + * \return >=0 for size of the list, or negative value in case of error (\ref PERS_COM_ERROR_CODES_DEFINES) + */ +signed int persComDbGetKeysList(signed int handlerDB, char* listBuffer_out, signed int listBufferSize) ; + + + + + /** * @brief typdef of callback function prototype for asynchronous init/deinit * diff --git a/src/Makefile.am b/src/Makefile.am index 26248f0..4474649 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -17,7 +17,7 @@ include_HEADERS = ../include/persistence_client_library_key.h \ lib_LTLIBRARIES = libpersistence_client_library.la -libpersistence_client_library_la_LIBADD = $(DEPS_LIBS) $(PFC_LIBS) -ldl -lpers_common +libpersistence_client_library_la_LIBADD = $(DEPS_LIBS) $(PFC_LIBS) -ldl libpersistence_client_library_la_SOURCES = \ persistence_client_library.c \ diff --git a/src/persistence_client_library.c b/src/persistence_client_library.c index 2bc2608..2d8b93b 100644 --- a/src/persistence_client_library.c +++ b/src/persistence_client_library.c @@ -68,8 +68,6 @@ int pclInitLibrary(const char* appName, int shutdownMode) DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclInitLibrary => I N I T Persistence Client Library - "), DLT_STRING(appName), DLT_STRING("- init counter: "), DLT_INT(gPclInitialized) ); - /// environment variable for max key value data - const char *pDataSize = getenv("PERS_MAX_KEY_VAL_DATA_SIZE"); char blacklistPath[DbPathMaxLen] = {0}; #if USE_FILECACHE @@ -79,10 +77,13 @@ int pclInitLibrary(const char* appName, int shutdownMode) pthread_mutex_lock(&gDbusPendingRegMtx); // block until pending received + /* key value data size can't be set during runtime, because + * this has also an influence on the database creation and must be + * set to compile time if(pDataSize != NULL) { gMaxKeyValDataSize = atoi(pDataSize); - } + }*/ // Assemble backup blacklist path sprintf(blacklistPath, "%s%s/%s", CACHEPREFIX, appName, gBackupFilename); diff --git a/src/persistence_client_library_custom_loader.c b/src/persistence_client_library_custom_loader.c index f9633cd..9fb606f 100644 --- a/src/persistence_client_library_custom_loader.c +++ b/src/persistence_client_library_custom_loader.c @@ -12,7 +12,7 @@ * @file persistence_client_library_custom_loader.c * @ingroup Persistence client library * @author Ingo Huerner - * @brief Implementation of persistence custom loadedr + * @brief Implementation of persistence custom loader * @see */ @@ -131,7 +131,11 @@ PersistenceCustomLibs_e custom_client_name_to_id(const char* lib_name, int subst if(substring == 0) { - if(0 == strncmp(lib_name, "early", PersCustomPathSize) ) + if (0 == strncmp(lib_name, "default", PersCustomPathSize) ) + { + libId = PersCustomLib_default; + } + else if(0 == strncmp(lib_name, "early", PersCustomPathSize) ) { libId = PersCustomLib_early; } @@ -166,7 +170,11 @@ PersistenceCustomLibs_e custom_client_name_to_id(const char* lib_name, int subst } else { - if(NULL != strstr(lib_name, "early") ) + if(NULL != strstr(lib_name, "default") ) + { + libId = PersCustomLib_default; + } + else if(NULL != strstr(lib_name, "early") ) { libId = PersCustomLib_early; } @@ -296,6 +304,136 @@ int get_custom_libraries() +int load_default_library(void* handle) +{ + int rval = 0; + char *error = NULL; + + if(handle != NULL) + { + /// + *(void **) (&plugin_persComDbOpen) = dlsym(handle, "persComDbOpen"); + if ((error = dlerror()) != NULL) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_default_library - error:"), DLT_STRING(error)); + } + *(void **) (&plugin_persComDbClose) = dlsym(handle, "persComDbClose"); + if ((error = dlerror()) != NULL) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_default_library - error:"), DLT_STRING(error)); + } + *(void **) (&plugin_persComDbWriteKey) = dlsym(handle, "persComDbWriteKey"); + if ((error = dlerror()) != NULL) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_default_library - error:"), DLT_STRING(error)); + } + + *(void **) (&plugin_persComDbReadKey) = dlsym(handle, "persComDbReadKey"); + if ((error = dlerror()) != NULL) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_default_library - error:"), DLT_STRING(error)); + } + *(void **) (&plugin_persComDbGetKeySize) = dlsym(handle, "persComDbGetKeySize"); + if ((error = dlerror()) != NULL) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_default_library - error:"), DLT_STRING(error)); + } + *(void **) (&plugin_persComDbDeleteKey) = dlsym(handle, "persComDbDeleteKey"); + if ((error = dlerror()) != NULL) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_default_library - error:"), DLT_STRING(error)); + } + *(void **) (&plugin_persComDbGetSizeKeysList) = dlsym(handle, "persComDbGetSizeKeysList"); + if ((error = dlerror()) != NULL) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_default_library - error:"), DLT_STRING(error)); + } + *(void **) (&plugin_persComDbGetKeysList) = dlsym(handle, "persComDbGetKeysList"); + if ((error = dlerror()) != NULL) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_default_library - error:"), DLT_STRING(error)); + } + + + /// R C T F U N C T I O N S + *(void **) (&plugin_persComRctOpen) = dlsym(handle, "persComRctOpen"); + if ((error = dlerror()) != NULL) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_default_library - error:"), DLT_STRING(error)); + } + + *(void **) (&plugin_persComRctClose) = dlsym(handle, "persComRctClose"); + if ((error = dlerror()) != NULL) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_default_library - error:"), DLT_STRING(error)); + } + + *(void **) (&plugin_persComRctRead) = dlsym(handle, "persComRctRead"); + if ((error = dlerror()) != NULL) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_default_library - error:"), DLT_STRING(error)); + } + + /// V A R I A B L E S + plugin_gUser = *(char**)dlsym(handle, "gUser"); + if ((error = dlerror()) != NULL) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_default_library - error:"), DLT_STRING(error)); + } + + plugin_gLocalWt = *(char**)dlsym(handle, "gLocalWt"); + if ((error = dlerror()) != NULL) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_default_library - error:"), DLT_STRING(error)); + } + + plugin_gSeat = *(char**)dlsym(handle, "gSeat"); + if ((error = dlerror()) != NULL) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_default_library - error:"), DLT_STRING(error)); + } + + plugin_gLocalFactoryDefault = *(char**)dlsym(handle, "gLocalFactoryDefault"); + if ((error = dlerror()) != NULL) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_default_library - error:"), DLT_STRING(error)); + } + + plugin_gLocalCached = *(char**) dlsym(handle, "gLocalCached"); + if ((error = dlerror()) != NULL) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_default_library - error:"), DLT_STRING(error)); + } + + plugin_gNode = *(char**)dlsym(handle, "gNode"); + if ((error = dlerror()) != NULL) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_default_library - error:"), DLT_STRING(error)); + } + + plugin_gLocalConfigurableDefault = *(char**)dlsym(handle, "gLocalConfigurableDefault"); + if ((error = dlerror()) != NULL) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_default_library - error:"), DLT_STRING(error)); + } + + plugin_gResTableCfg = *(char**)dlsym(handle, "gResTableCfg"); + if ((error = dlerror()) != NULL) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_default_library - error:"), DLT_STRING(error)); + } + } + else + { + error = dlerror(); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); + rval = EPERS_DLOPENERROR; + } + return rval; +} + + + int load_custom_library(PersistenceCustomLibs_e customLib, Pers_custom_functs_s *customFuncts) { int rval = 1; @@ -307,169 +445,180 @@ int load_custom_library(PersistenceCustomLibs_e customLib, Pers_custom_functs_s void* handle = dlopen(gCustomLibArray[customLib].libname, RTLD_LAZY); customFuncts->handle = handle; - if(handle != NULL) + if(customLib == PersCustomLib_default) { - dlerror(); // reset error - - // plugin_close - *(void **) (&customFuncts->custom_plugin_handle_close) = dlsym(handle, "plugin_handle_close"); - if ((error = dlerror()) != NULL) - { - DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); - } - // custom_plugin_delete_data - *(void **) (&customFuncts->custom_plugin_delete_data) = dlsym(handle, "plugin_delete_data"); - if ((error = dlerror()) != NULL) - { - DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); - } - // custom_plugin_get_data - *(void **) (&customFuncts->custom_plugin_handle_get_data) = dlsym(handle, "plugin_handle_get_data"); - if ((error = dlerror()) != NULL) - { - DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); - } - // custom_plugin_get_data - *(void **) (&customFuncts->custom_plugin_get_data) = dlsym(handle, "plugin_get_data"); - if ((error = dlerror()) != NULL) - { - DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); - } - // custom_plugin_init - *(void **) (&customFuncts->custom_plugin_init) = dlsym(handle, "plugin_init"); - if ((error = dlerror()) != NULL) - { - DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); - } - // custom_plugin_deinit - *(void **) (&customFuncts->custom_plugin_deinit) = dlsym(handle, "plugin_deinit"); - if ((error = dlerror()) != NULL) - { - DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); - } - // custom_plugin_open - *(void **) (&customFuncts->custom_plugin_handle_open) = dlsym(handle, "plugin_handle_open"); - if ((error = dlerror()) != NULL) - { - DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); - } - // custom_plugin_set_data - *(void **) (&customFuncts->custom_plugin_handle_set_data) = dlsym(handle, "plugin_handle_set_data"); - if ((error = dlerror()) != NULL) - { - DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); - } - // custom_plugin_set_data - *(void **) (&customFuncts->custom_plugin_set_data) = dlsym(handle, "plugin_set_data"); - if ((error = dlerror()) != NULL) - { - DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); - } - // custom_plugin_get_size_handle - *(void **) (&customFuncts->custom_plugin_handle_get_size) = dlsym(handle, "plugin_handle_get_size"); - if ((error = dlerror()) != NULL) - { - DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); - } - // custom_plugin_get_size - *(void **) (&customFuncts->custom_plugin_get_size) = dlsym(handle, "plugin_get_size"); - if ((error = dlerror()) != NULL) - { - DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); - } - // create backup - *(void **) (&customFuncts->custom_plugin_create_backup) = dlsym(handle, "plugin_create_backup"); - if ((error = dlerror()) != NULL) - { - DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); - } - // restore backup - *(void **) (&customFuncts->custom_plugin_restore_backup) = dlsym(handle, "plugin_restore_backup"); - if ((error = dlerror()) != NULL) - { - DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); - } - // restore backup - *(void **) (&customFuncts->custom_plugin_get_backup) = dlsym(handle, "plugin_get_backup"); - if ((error = dlerror()) != NULL) - { - DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); - } + if(load_default_library(handle ) < 0) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("Failed to load default plugin")); + rval = EPERS_DLOPENERROR; + } + } + else + { + if(handle != NULL) + { + dlerror(); // reset error - // custom_plugin_get_status_notification_clbk - *(void **) (&customFuncts->custom_plugin_get_status_notification_clbk) = dlsym(handle, "plugin_get_status_notification_clbk"); - if ((error = dlerror()) != NULL) - { - DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); - } + // plugin_close + *(void **) (&customFuncts->custom_plugin_handle_close) = dlsym(handle, "plugin_handle_close"); + if ((error = dlerror()) != NULL) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); + } + // custom_plugin_delete_data + *(void **) (&customFuncts->custom_plugin_delete_data) = dlsym(handle, "plugin_delete_data"); + if ((error = dlerror()) != NULL) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); + } + // custom_plugin_get_data + *(void **) (&customFuncts->custom_plugin_handle_get_data) = dlsym(handle, "plugin_handle_get_data"); + if ((error = dlerror()) != NULL) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); + } + // custom_plugin_get_data + *(void **) (&customFuncts->custom_plugin_get_data) = dlsym(handle, "plugin_get_data"); + if ((error = dlerror()) != NULL) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); + } + // custom_plugin_init + *(void **) (&customFuncts->custom_plugin_init) = dlsym(handle, "plugin_init"); + if ((error = dlerror()) != NULL) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); + } + // custom_plugin_deinit + *(void **) (&customFuncts->custom_plugin_deinit) = dlsym(handle, "plugin_deinit"); + if ((error = dlerror()) != NULL) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); + } + // custom_plugin_open + *(void **) (&customFuncts->custom_plugin_handle_open) = dlsym(handle, "plugin_handle_open"); + if ((error = dlerror()) != NULL) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); + } + // custom_plugin_set_data + *(void **) (&customFuncts->custom_plugin_handle_set_data) = dlsym(handle, "plugin_handle_set_data"); + if ((error = dlerror()) != NULL) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); + } + // custom_plugin_set_data + *(void **) (&customFuncts->custom_plugin_set_data) = dlsym(handle, "plugin_set_data"); + if ((error = dlerror()) != NULL) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); + } + // custom_plugin_get_size_handle + *(void **) (&customFuncts->custom_plugin_handle_get_size) = dlsym(handle, "plugin_handle_get_size"); + if ((error = dlerror()) != NULL) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); + } + // custom_plugin_get_size + *(void **) (&customFuncts->custom_plugin_get_size) = dlsym(handle, "plugin_get_size"); + if ((error = dlerror()) != NULL) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); + } + // create backup + *(void **) (&customFuncts->custom_plugin_create_backup) = dlsym(handle, "plugin_create_backup"); + if ((error = dlerror()) != NULL) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); + } + // restore backup + *(void **) (&customFuncts->custom_plugin_restore_backup) = dlsym(handle, "plugin_restore_backup"); + if ((error = dlerror()) != NULL) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); + } + // restore backup + *(void **) (&customFuncts->custom_plugin_get_backup) = dlsym(handle, "plugin_get_backup"); + if ((error = dlerror()) != NULL) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); + } - // initialize plugin (non blocking) - *(void **) (&customFuncts->custom_plugin_init_async) = dlsym(handle, "plugin_init_async"); - if ((error = dlerror()) != NULL) - { - DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); - } + // custom_plugin_get_status_notification_clbk + *(void **) (&customFuncts->custom_plugin_get_status_notification_clbk) = dlsym(handle, "plugin_get_status_notification_clbk"); + if ((error = dlerror()) != NULL) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); + } - // clear all data - *(void **) (&customFuncts->custom_plugin_clear_all_data) = dlsym(handle, "plugin_clear_all_data"); - if ((error = dlerror()) != NULL) - { - DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); - } + // initialize plugin (non blocking) + *(void **) (&customFuncts->custom_plugin_init_async) = dlsym(handle, "plugin_init_async"); + if ((error = dlerror()) != NULL) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); + } - // sync data - *(void **) (&customFuncts->custom_plugin_sync) = dlsym(handle, "plugin_sync"); - if ((error = dlerror()) != NULL) - { - DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); - } + // clear all data + *(void **) (&customFuncts->custom_plugin_clear_all_data) = dlsym(handle, "plugin_clear_all_data"); + if ((error = dlerror()) != NULL) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); + } - // - // initialize the library - // - if(initType == Init_Synchronous) - { - if( (gPersCustomFuncs[customLib].custom_plugin_init) != NULL) + // sync data + *(void **) (&customFuncts->custom_plugin_sync) = dlsym(handle, "plugin_sync"); + if ((error = dlerror()) != NULL) { - DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("load_custom_library => (sync) : "), DLT_STRING(get_custom_client_lib_name(customLib))); - gPersCustomFuncs[customLib].custom_plugin_init(); + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); } - else + + // + // initialize the library + // + if(initType == Init_Synchronous) { - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_library - error: could not load plugin functions: "), - DLT_STRING(get_custom_client_lib_name(customLib))); - rval = EPERS_COMMON; + if( (gPersCustomFuncs[customLib].custom_plugin_init) != NULL) + { + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("load_custom_library => (sync) : "), DLT_STRING(get_custom_client_lib_name(customLib))); + gPersCustomFuncs[customLib].custom_plugin_init(); + } + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_library - error: could not load plugin functions: "), + DLT_STRING(get_custom_client_lib_name(customLib))); + rval = EPERS_COMMON; + } } - } - else if(initType == Init_Asynchronous) - { - if( (gPersCustomFuncs[customLib].custom_plugin_init_async) != NULL) + else if(initType == Init_Asynchronous) { - DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("load_custom_library => (async) : "), - DLT_STRING(get_custom_client_lib_name(customLib))); + if( (gPersCustomFuncs[customLib].custom_plugin_init_async) != NULL) + { + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("load_custom_library => (async) : "), + DLT_STRING(get_custom_client_lib_name(customLib))); - gPersCustomFuncs[customLib].custom_plugin_init_async(gPlugin_callback_async_t); + gPersCustomFuncs[customLib].custom_plugin_init_async(gPlugin_callback_async_t); + } + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_library => error: could not load plugin functions: "), + DLT_STRING(get_custom_client_lib_name(customLib))); + rval = EPERS_COMMON; + } } else { - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_library => error: could not load plugin functions: "), - DLT_STRING(get_custom_client_lib_name(customLib))); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_library - error: unknown init type "), + DLT_STRING(get_custom_client_lib_name(customLib))); rval = EPERS_COMMON; } } else { - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_library - error: unknown init type "), - DLT_STRING(get_custom_client_lib_name(customLib))); - rval = EPERS_COMMON; + error = dlerror(); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); + rval = EPERS_DLOPENERROR; } } - else - { - error = dlerror(); - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); - rval = EPERS_DLOPENERROR; - } } else { @@ -517,7 +666,7 @@ int load_custom_plugins(plugin_callback_async_t pfInitCompletedCB) gPlugin_callback_async_t = pfInitCompletedCB; // assign init callback // initialize custom library structure - for(i = 0; i < PersCustomLib_LastEntry; i++) + for(i=0; i < PersCustomLib_LastEntry; i++) { invalidate_custom_plugin(i); } @@ -526,7 +675,7 @@ int load_custom_plugins(plugin_callback_async_t pfInitCompletedCB) { if(check_valid_idx(i) != -1) { - if(getCustomLoadingType(i) == LoadType_PclInit) // check if the plugin must be loaded on plc init + if(getCustomLoadingType(i) == LoadType_PclInit) // check if the plugin must be loaded on pclInitLibrary { if(load_custom_library(i, &gPersCustomFuncs[i] ) <= 0) { diff --git a/src/persistence_client_library_custom_loader.h b/src/persistence_client_library_custom_loader.h index fb758ae..3c9ee0d 100644 --- a/src/persistence_client_library_custom_loader.h +++ b/src/persistence_client_library_custom_loader.h @@ -20,25 +20,26 @@ */ #include "../include/persistence_client_custom.h" - +#include <persComRct.h> /// enumerator used to identify the policy to manage the data typedef enum _PersistenceCustomLibs_e { + PersCustomLib_default = 0, /// predefined custom library for early persistence - PersCustomLib_early = 0, + PersCustomLib_early = 1, /// predefined custom library for secure persistence - PersCustomLib_secure = 1, + PersCustomLib_secure = 2, /// predefined custom library for emengency persistence - PersCustomLib_emergency = 2, + PersCustomLib_emergency = 4, /// predefined custom library for hw information - PersCustomLib_HWinfo = 3, + PersCustomLib_HWinfo = 5, /// custom library 1 - PersCustomLib_Custom1 = 4, + PersCustomLib_Custom1 = 6, /// custom library 2 - PersCustomLib_Custom2 = 5, + PersCustomLib_Custom2 = 7, /// custom library 3 - PersCustomLib_Custom3 = 6, + PersCustomLib_Custom3 = 8, // insert new entries here ... @@ -81,6 +82,62 @@ typedef enum PersLoadingType_e_ } PersLoadingType_e; +/// directory structure seat name definition +char* plugin_gSeat; +/// path prefix for local write through database /Data/mnt-wt/\<appId\>/\<database_name\> +char* plugin_gLocalWt; +///directory structure user name definition +char* plugin_gUser; +/// local factory-default database +char* plugin_gLocalFactoryDefault; +/// local cached default database +char* plugin_gLocalCached; +/// directory structure node name definition +char* plugin_gNode; +/// local configurable-default database +char* plugin_gLocalConfigurableDefault; +/// resource configuration table name +char* plugin_gResTableCfg; + + +/// Obtain a handler to DB indicated by dbPathname +signed int (*plugin_persComDbOpen)(char const * dbPathname, unsigned char bForceCreationIfNotPresent) ; + +/// Close handler to DB +signed int (*plugin_persComDbClose)(signed int handlerDB) ; + +/// write a key-value pair into local/shared database +signed int (*plugin_persComDbWriteKey)(signed int handlerDB, char const * key, char const * data, signed int dataSize) ; + +/// read a key's value from local/shared database +signed int (*plugin_persComDbReadKey)(signed int handlerDB, char const * key, char* dataBuffer_out, signed int dataBufferSize) ; + +/// read a key's value from local/shared database +signed int (*plugin_persComDbGetKeySize)(signed int handlerDB, char const * key) ; + +/// delete key from local/shared database +signed int (*plugin_persComDbDeleteKey)(signed int handlerDB, char const * key) ; + +/// Find the buffer's size needed to accomodate the list of keys' names in local/shared database +signed int (*plugin_persComDbGetSizeKeysList)(signed int handlerDB) ; + +/// Obtain the list of the keys' names in local/shared database +signed int (*plugin_persComDbGetKeysList)(signed int handlerDB, char* listBuffer_out, signed int listBufferSize) ; + + +/** + * \brief Obtain a handler to RCT indicated by rctPathname + * \note : RCT is created if it does not exist and (bForceCreationIfNotPresent != 0) + */ +signed int (*plugin_persComRctOpen)(char const * rctPathname, unsigned char bForceCreationIfNotPresent) ; + +/// Close handler to RCT +signed int (*plugin_persComRctClose)(signed int handlerRCT) ; + +/// read a resourceID's configuration from RCT +signed int (*plugin_persComRctRead)(signed int handlerRCT, char const * resourceID, PersistenceConfigurationKey_s const * psConfig_out) ; + + /** * @brief definition of async init callback function. * This function will be called when the asynchronous @@ -90,6 +147,7 @@ typedef enum PersLoadingType_e_ */ extern int(* gPlugin_callback_async_t)(int errcode); + /// structure definition for custom library functions typedef struct _Pers_custom_functs_s { @@ -177,6 +235,14 @@ PersistenceCustomLibs_e custom_client_name_to_id(const char* lib_name, int subst int get_custom_libraries(); +/** + * @brief load default plugin + * + * handle the library handle + * + * @return default library + */ +int load_default_library(void* handle); /** * @brief get the names of the custom libraries to load diff --git a/src/persistence_client_library_db_access.c b/src/persistence_client_library_db_access.c index 97f8f1e..41b5e3c 100644 --- a/src/persistence_client_library_db_access.c +++ b/src/persistence_client_library_db_access.c @@ -79,19 +79,19 @@ static int database_get(PersistenceInfo_s* info, const char* dbPath) if(PersistencePolicy_wt == info->configKey.policy) /// write through database { - snprintf(path, DbPathMaxLen, "%s%s", dbPath, gLocalWt); + snprintf(path, DbPathMaxLen, "%s%s", dbPath, plugin_gLocalWt); } else if(PersistencePolicy_wc == info->configKey.policy) // cached database { - snprintf(path, DbPathMaxLen, "%s%s", dbPath, gLocalCached); + snprintf(path, DbPathMaxLen, "%s%s", dbPath, plugin_gLocalCached); } else if(PersistencePolicy_cd == info->configKey.policy) // configurable default database { - snprintf(path, DbPathMaxLen, "%s%s", dbPath, gLocalConfigurableDefault); + snprintf(path, DbPathMaxLen, "%s%s", dbPath, plugin_gLocalConfigurableDefault); } else if(PersistencePolicy_d == info->configKey.policy) // default database { - snprintf(path, DbPathMaxLen, "%s%s", dbPath, gLocalFactoryDefault); + snprintf(path, DbPathMaxLen, "%s%s", dbPath, plugin_gLocalFactoryDefault); } else { @@ -100,7 +100,7 @@ static int database_get(PersistenceInfo_s* info, const char* dbPath) if (handleDB == -1) { - handleDB = persComDbOpen(path, 0x01); + handleDB = plugin_persComDbOpen(path, 0x01); if(handleDB >= 0) { gHandlesDB[arrayIdx][info->configKey.policy] = handleDB ; @@ -145,11 +145,11 @@ int pers_get_defaults(char* dbPath, char* key, PersistenceInfo_s* info, unsigned { if (PersGetDefault_Data == job) { - read_size = persComDbReadKey(handleDefaultDB, key, (char*)buffer, buffer_size); + read_size = plugin_persComDbReadKey(handleDefaultDB, key, (char*)buffer, buffer_size); } else if (PersGetDefault_Size == job) { - read_size = persComDbGetKeySize(handleDefaultDB, key); + read_size = plugin_persComDbGetKeySize(handleDefaultDB, key); } else { @@ -225,7 +225,7 @@ void database_close_all() { if(gHandlesDBCreated[i][j] == 1) { - int iErrorCode = persComDbClose(gHandlesDB[i][j]); + int iErrorCode = plugin_persComDbClose(gHandlesDB[i][j]); if (iErrorCode < 0) { DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("database_close_all => failed to close db => persComDbClose")); @@ -252,7 +252,7 @@ int persistence_get_data(char* dbPath, char* key, const char* resourceID, Persis int handleDB = database_get(info, dbPath); if(handleDB >= 0) { - read_size = persComDbReadKey(handleDB, key, (char*)buffer, buffer_size); + read_size = plugin_persComDbReadKey(handleDB, key, (char*)buffer, buffer_size); if(read_size < 0) { read_size = pers_get_defaults(dbPath, (char*)resourceID, info, buffer, buffer_size, PersGetDefault_Data); /* 0 ==> Get data */ @@ -357,7 +357,7 @@ int persistence_set_data(char* dbPath, char* key, PersistenceInfo_s* info, unsig handleDB = database_get(info, dbPath); if(handleDB >= 0) { - write_size = persComDbWriteKey(handleDB, key, (char*)buffer, buffer_size) ; + write_size = plugin_persComDbWriteKey(handleDB, key, (char*)buffer, buffer_size) ; if(write_size < 0) { DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("persistence_set_data ==> persComDbWriteKey() failure")); @@ -473,7 +473,7 @@ int persistence_get_data_size(char* dbPath, char* key, const char* resourceID, P if(handleDB >= 0) { - read_size = persComDbGetKeySize(handleDB, key); + read_size = plugin_persComDbGetKeySize(handleDB, key); if(read_size < 0) { read_size = pers_get_defaults( dbPath, (char*)resourceID, info, NULL, 0, PersGetDefault_Size); @@ -569,7 +569,7 @@ int persistence_delete_data(char* dbPath, char* key, PersistenceInfo_s* info) int handleDB = database_get(info, dbPath); if(handleDB >= 0) { - ret = persComDbDeleteKey(handleDB, key) ; + ret = plugin_persComDbDeleteKey(handleDB, key) ; if(ret < 0) { DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("persistence_delete_data => persComDbDeleteKey failed: "), DLT_STRING(key)); @@ -751,7 +751,7 @@ void pers_rct_close_all() { if(get_resource_cfg_table_by_idx(i) != -1) { - if(persComRctClose(get_resource_cfg_table_by_idx(i)) != 0) + if(plugin_persComRctClose(get_resource_cfg_table_by_idx(i)) != 0) { DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("process_prepare_shutdown => failed to close db => index:"), DLT_INT(i)); } diff --git a/src/persistence_client_library_prct_access.c b/src/persistence_client_library_prct_access.c index dcbcbea..f8b6e40 100644 --- a/src/persistence_client_library_prct_access.c +++ b/src/persistence_client_library_prct_access.c @@ -21,6 +21,7 @@ #include "persistence_client_library_prct_access.h" #include "persistence_client_library_db_access.h" +#include "persistence_client_library_custom_loader.h" #include <stdlib.h> #include <string.h> @@ -108,20 +109,20 @@ int get_resource_cfg_table(PersistenceRCT_e rct, int group) switch(rct) // create db name { case PersistenceRCT_local: - snprintf(filename, DbPathMaxLen, gLocalWtPathKey, gAppId, gResTableCfg); + snprintf(filename, DbPathMaxLen, gLocalWtPathKey, gAppId, plugin_gResTableCfg); break; case PersistenceRCT_shared_public: - snprintf(filename, DbPathMaxLen, gSharedPublicWtPathKey, gAppId, gResTableCfg); + snprintf(filename, DbPathMaxLen, gSharedPublicWtPathKey, gAppId, plugin_gResTableCfg); break; case PersistenceRCT_shared_group: - snprintf(filename, DbPathMaxLen, gSharedWtPathKey, gAppId, group, gResTableCfg); + snprintf(filename, DbPathMaxLen, gSharedWtPathKey, gAppId, group, plugin_gResTableCfg); break; default: DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("get_resource_cfg_table - error: no valid PersistenceRCT_e")); break; } - gResource_table[arrayIdx] = persComRctOpen(filename, 0x00); + gResource_table[arrayIdx] = plugin_persComRctOpen(filename, 0x00); if(gResource_table[arrayIdx] < 0) { @@ -156,7 +157,7 @@ int get_db_context(PersistenceInfo_s* dbContext, const char* resource_id, unsign PersistenceConfigurationKey_s sRctEntry ; // check if resouce id is in write through table - int iErrCode = persComRctRead(handleRCT, resource_id, &sRctEntry) ; + int iErrCode = plugin_persComRctRead(handleRCT, resource_id, &sRctEntry) ; if(sizeof(PersistenceConfigurationKey_s) == iErrCode) { @@ -240,7 +241,7 @@ int get_db_path_and_key(PersistenceInfo_s* dbContext, const char* resource_id, c // // Node is added in front of the resource ID as the key string. // - snprintf(dbKey, DbKeyMaxLen, "%s/%s", gNode, resource_id); + snprintf(dbKey, DbKeyMaxLen, "%s/%s", plugin_gNode, resource_id); } else { @@ -250,12 +251,12 @@ int get_db_path_and_key(PersistenceInfo_s* dbContext, const char* resource_id, c if(dbContext->context.seat_no == 0) { // /User/<user_no_parameter> is added in front of the resource ID as the key string. - snprintf(dbKey, DbKeyMaxLen, "%s%d/%s", gUser, dbContext->context.user_no, resource_id); + snprintf(dbKey, DbKeyMaxLen, "%s%d/%s", plugin_gUser, dbContext->context.user_no, resource_id); } else { // /User/<user_no_parameter>/Seat/<seat_no_parameter> is added in front of the resource ID as the key string. - snprintf(dbKey, DbKeyMaxLen, "%s%d%s%d/%s", gUser, dbContext->context.user_no, gSeat, dbContext->context.seat_no, resource_id); + snprintf(dbKey, DbKeyMaxLen, "%s%d%s%d/%s", plugin_gUser, dbContext->context.user_no, plugin_gSeat, dbContext->context.seat_no, resource_id); } } storePolicy = PersistenceStorage_local; @@ -271,11 +272,11 @@ int get_db_path_and_key(PersistenceInfo_s* dbContext, const char* resource_id, c if(dbContext->context.seat_no != 0) { - snprintf(dbKey, DbKeyMaxLen, "/%x%s%d%s%d/%s", dbContext->context.ldbid, gUser, dbContext->context.user_no, gSeat, dbContext->context.seat_no, resource_id); + snprintf(dbKey, DbKeyMaxLen, "/%x%s%d%s%d/%s", dbContext->context.ldbid, plugin_gUser, dbContext->context.user_no, plugin_gSeat, dbContext->context.seat_no, resource_id); } else { - snprintf(dbKey, DbKeyMaxLen, "/%x%s%d/%s", dbContext->context.ldbid, gUser, dbContext->context.user_no, resource_id); + snprintf(dbKey, DbKeyMaxLen, "/%x%s%d/%s", dbContext->context.ldbid, plugin_gUser, dbContext->context.user_no, resource_id); } storePolicy = PersistenceStorage_local; } |