diff options
author | Ingo Huerner <ingo.huerner@xse.de> | 2015-01-16 13:36:17 +0100 |
---|---|---|
committer | Ingo Huerner <ingo.huerner@xse.de> | 2015-01-16 13:36:17 +0100 |
commit | b4d4132157a9c7ea44cedda856b2bf76a021431c (patch) | |
tree | db88a35971554e38ebd602024735cbae5aec2305 | |
parent | 600343905a7b72ba2352a05e735a77f3417cf4ff (diff) | |
download | persistence-client-library-b4d4132157a9c7ea44cedda856b2bf76a021431c.tar.gz |
Now persistence common object will now be loaded like a plugin and not linked anymore
-rw-r--r-- | README | 23 | ||||
-rw-r--r-- | config/pclCustomLibConfigFile.cfg | 1 | ||||
-rw-r--r-- | configure.ac | 3 | ||||
-rw-r--r-- | include/persistence_client_custom.h | 94 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/persistence_client_library.c | 4 | ||||
-rw-r--r-- | src/persistence_client_library_custom_loader.c | 718 | ||||
-rw-r--r-- | src/persistence_client_library_custom_loader.h | 110 | ||||
-rw-r--r-- | src/persistence_client_library_db_access.c | 33 | ||||
-rw-r--r-- | src/persistence_client_library_handle.c | 15 | ||||
-rw-r--r-- | src/persistence_client_library_prct_access.c | 22 |
11 files changed, 678 insertions, 347 deletions
@@ -70,6 +70,19 @@ details about DLT, please refer to the GENIVI DLT p roject page (http://projects.genivi.org/diagnostic-log-trace/). +Persistence Common Object +------------------------------- +The Persistence Common Object (libpers_common.so) is the default plugin to read/write +persistent data managed by the key-value API. + +Attention: +The Persistence Common Object must be added to the plugin configuration file with the +appropriate path to the library + +Example: “default /usr/local/lib/libpers_common.so init sync” + + + Running tests: -------------- There are unit tests available for the persistency client library component available. @@ -101,6 +114,16 @@ Precondition: * Make sure D-Bus system bus is available +Application verification +-------------- +To check if an application is valid/trusted and allowed to access persistent data an application check +functionality can be enabled (configure step --enable-appcheck, see section 6 “How to build”). +If an application is not valid/trusted every API call to the key-value or file API returns the +error EPERS_SHUTDOWN_NO_TRUSTED will be returned. +A trusted/valid application has a corresponding resource configuration table installed by the +Persistence Administration Service under /Data/mnt-c or /Data/mnt-wt. + + Data location and partitions -------------- 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 25d7b19..7a8f73a 100644 --- a/configure.ac +++ b/configure.ac @@ -69,8 +69,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 d0cd0e0..b0f9cfe 100644 --- a/include/persistence_client_custom.h +++ b/include/persistence_client_custom.h @@ -19,6 +19,7 @@ * Library provides an plugin API to extend persistence client library * @par change history * Date Author Version Description + * - 2015.01.16 ihuerner 1.7.0.0 Added function prototypes for function loaded from persistence common object * - 2015.01.14 ihuerner 1.6.0.0 Extended header documentation for function plugin_init_async. * - 2014.01.20 iieremie 1.6.0.0 multiple extensions: * - error codes @@ -98,6 +99,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 dd52eb1..2484658 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 #if USE_XSTRACE_PERS #libpersistence_client_library_la_LIBADD += -lxsm_user diff --git a/src/persistence_client_library.c b/src/persistence_client_library.c index 893c860..3123b61 100644 --- a/src/persistence_client_library.c +++ b/src/persistence_client_library.c @@ -78,7 +78,7 @@ void doInitAppcheck(const char* appName) { #if USE_APPCHECK char rctFilename[DbPathMaxLen] = {0}; - snprintf(rctFilename, DbPathMaxLen, gLocalWtPathKey, appName, gResTableCfg); + snprintf(rctFilename, DbPathMaxLen, gLocalWtPathKey, appName, plugin_gResTableCfg); if(access(rctFilename, F_OK) == 0) { @@ -102,7 +102,7 @@ int doAppcheck(void) if(gAppCheckFlag != 1) { char rctFilename[DbPathMaxLen] = {0}; - snprintf(rctFilename, DbPathMaxLen, gLocalWtPathKey, gAppId, gResTableCfg); + snprintf(rctFilename, DbPathMaxLen, gLocalWtPathKey, gAppId, plugin_gResTableCfg); if(access(rctFilename, F_OK) == 0) { gAppCheckFlag = 1; // "trusted" application diff --git a/src/persistence_client_library_custom_loader.c b/src/persistence_client_library_custom_loader.c index fdbae94..e3bda0f 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 */ @@ -33,10 +33,10 @@ /// type definition of persistence custom library information typedef struct sPersCustomLibInfo { - char libname[CustLibMaxLen]; - int valid; - PersInitType_e initFunction; - PersLoadingType_e loadingType; + char libname[CustLibMaxLen]; + int valid; + PersInitType_e initFunction; + PersLoadingType_e loadingType; } PersCustomLibInfo; @@ -81,15 +81,15 @@ static void fillCustomCharTokenArray(unsigned int customConfigFileSize, char* fi static PersLoadingType_e getLoadingType(const char* type) { - PersLoadingType_e persLoadingType = LoadType_Undefined; + PersLoadingType_e persLoadingType = LoadType_Undefined; if(0 == strcmp(type, "init") ) { - persLoadingType = LoadType_PclInit; + persLoadingType = LoadType_PclInit; } else if(0 == strcmp(type, "od") ) { - persLoadingType = LoadType_OnDemand; + persLoadingType = LoadType_OnDemand; } return persLoadingType; @@ -98,15 +98,15 @@ static PersLoadingType_e getLoadingType(const char* type) static PersInitType_e getInitType(const char* policy) { - PersInitType_e persInitType = Init_Undefined; + PersInitType_e persInitType = Init_Undefined; if(0 == strcmp(policy, "sync")) { - persInitType = Init_Synchronous; + persInitType = Init_Synchronous; } else if (0 == strcmp(policy, "async")) { - persInitType = Init_Asynchronous; + persInitType = Init_Asynchronous; } return persInitType; @@ -115,13 +115,13 @@ static PersInitType_e getInitType(const char* policy) PersLoadingType_e getCustomLoadingType(int i) { - return gCustomLibArray[i].loadingType; + return gCustomLibArray[i].loadingType; } PersInitType_e getCustomInitType(int i) { - return gCustomLibArray[i].initFunction; + return gCustomLibArray[i].initFunction; } @@ -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; } @@ -161,12 +165,16 @@ PersistenceCustomLibs_e custom_client_name_to_id(const char* lib_name, int subst } else { - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("customNameToId - id not found lib:"), DLT_STRING(lib_name)); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("custom_libname_to_id - error - id not found for lib:"), DLT_STRING(lib_name)); } } 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; } @@ -196,7 +204,7 @@ PersistenceCustomLibs_e custom_client_name_to_id(const char* lib_name, int subst } else { - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("customNameToId - id not found lib:"), DLT_STRING(lib_name)); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("custom_libname_to_id - error - id not found for lib:"), DLT_STRING(lib_name)); } } @@ -211,90 +219,215 @@ int get_custom_libraries() struct stat buffer; const char *filename = getenv("PERS_CLIENT_LIB_CUSTOM_LOAD"); - if(filename == NULL) - { - filename = "/etc/pclCustomLibConfigFile.cfg"; // use default filename - } + if(filename == NULL) + { + filename = "/etc/pclCustomLibConfigFile.cfg"; // use default filename + } for(j=0; j<PersCustomLib_LastEntry; j++) { - gCustomLibArray[j].valid = -1; // init pos to -1 + gCustomLibArray[j].valid = -1; // init pos to -1 } memset(&buffer, 0, sizeof(buffer)); if(stat(filename, &buffer) != -1) { - if(buffer.st_size > 0) // check for empty file - { - char* customConfFileMap = NULL; - int i = 0; - int fd = open(filename, O_RDONLY); - - DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("gCusLib - load config - "), DLT_STRING(filename)); - - if (fd == -1) - { - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("gCusLib - Err file open: "), - DLT_STRING(filename), DLT_STRING("err msg: "), DLT_STRING(strerror(errno)) ); - return EPERS_COMMON; - } - - // map the config file into memory - customConfFileMap = (char*)mmap(0, buffer.st_size, PROT_WRITE, MAP_PRIVATE, fd, 0); - - if (customConfFileMap == MAP_FAILED) - { - close(fd); - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("gCusLib - Err mapping file")); - return EPERS_COMMON; - } - - fillCustomCharTokenArray(buffer.st_size, customConfFileMap); - - while( i < TOKENARRAYSIZE ) - { - if(gpCustomTokenArray[i] != 0 && gpCustomTokenArray[i+1] != 0 && gpCustomTokenArray[i+2] != 0 &&gpCustomTokenArray[i+3] != 0 ) - { - int libId = custom_client_name_to_id(gpCustomTokenArray[i], 0); // get the custom libID - - // assign the libraryname - strncpy(gCustomLibArray[libId].libname, gpCustomTokenArray[i+1], CustLibMaxLen); - gCustomLibArray[libId].libname[CustLibMaxLen-1] = '\0'; // Ensures 0-Termination - - gCustomLibArray[libId].loadingType = getLoadingType(gpCustomTokenArray[i+2]); - gCustomLibArray[libId].initFunction = getInitType(gpCustomTokenArray[i+3]); - gCustomLibArray[libId].valid = 1; // marks as valid; - #if 0 - // debug - printf(" 1. => %s => %d \n", gpCustomTokenArray[i], libId); - printf(" 2. => %s => %s \n", gpCustomTokenArray[i+1], gCustomLibArray[libId].libname); - printf(" 3. => %s => %d \n", gpCustomTokenArray[i+2], (int)gCustomLibArray[libId].initFunction); - printf(" 4. => %s => %d \n\n", gpCustomTokenArray[i+3], (int)gCustomLibArray[libId].loadingType); - #endif - } - else - { - break; - } - i+=4; // move to the next configuration file entry - } - - if(munmap(customConfFileMap, buffer.st_size) == -1) - { - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("gCusLib - Err unmap - "), DLT_STRING(strerror(errno))); - } - close(fd); - } - else - { - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("gCusLib - Err file size is 0")); - rval = EPERS_COMMON; - } + if(buffer.st_size > 0) // check for empty file + { + char* customConfFileMap = NULL; + int i = 0; + int fd = open(filename, O_RDONLY); + + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("load custom library config file ==> "), DLT_STRING(filename)); + + if (fd == -1) + { + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("load custom library config file error ==> Error file open: "), + DLT_STRING(filename), DLT_STRING("err msg: "), DLT_STRING(strerror(errno)) ); + return EPERS_COMMON; + } + + // map the config file into memory + customConfFileMap = (char*)mmap(0, buffer.st_size, PROT_WRITE, MAP_PRIVATE, fd, 0); + + if (customConfFileMap == MAP_FAILED) + { + close(fd); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("load custom library config file error ==> Error mapping the file")); + return EPERS_COMMON; + } + + fillCustomCharTokenArray(buffer.st_size, customConfFileMap); + + while( i < TOKENARRAYSIZE ) + { + if(gpCustomTokenArray[i] != 0 && gpCustomTokenArray[i+1] != 0 && gpCustomTokenArray[i+2] != 0 &&gpCustomTokenArray[i+3] != 0 ) + { + int libId = custom_client_name_to_id(gpCustomTokenArray[i], 0); // get the custom libID + + // assign the libraryname + strncpy(gCustomLibArray[libId].libname, gpCustomTokenArray[i+1], CustLibMaxLen); + gCustomLibArray[libId].libname[CustLibMaxLen-1] = '\0'; // Ensures 0-Termination + + gCustomLibArray[libId].loadingType = getLoadingType(gpCustomTokenArray[i+2]); + gCustomLibArray[libId].initFunction = getInitType(gpCustomTokenArray[i+3]); + gCustomLibArray[libId].valid = 1; // marks as valid; + #if 0 + // debug + printf(" 1. => %s => %d \n", gpCustomTokenArray[i], libId); + printf(" 2. => %s => %s \n", gpCustomTokenArray[i+1], gCustomLibArray[libId].libname); + printf(" 3. => %s => %d \n", gpCustomTokenArray[i+2], (int)gCustomLibArray[libId].initFunction); + printf(" 4. => %s => %d \n\n", gpCustomTokenArray[i+3], (int)gCustomLibArray[libId].loadingType); + #endif + } + else + { + break; + } + i+=4; // move to the next configuration file entry + } + close(fd); + } + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("load custom library config file error ==> Error file size is 0")); + rval = EPERS_COMMON; + } + } + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("load custom library config file error ==> failed to stat() file")); + rval = EPERS_COMMON; + } + return rval; +} + + + +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 { - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("customLib - failed stat() file")); - rval = EPERS_COMMON; + error = dlerror(); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); + rval = EPERS_DLOPENERROR; } return rval; } @@ -308,177 +441,188 @@ int load_custom_library(PersistenceCustomLibs_e customLib, Pers_custom_functs_s if(customLib < PersCustomLib_LastEntry) { - PersInitType_e initType = getCustomInitType(customLib); + PersInitType_e initType = getCustomInitType(customLib); 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("lCusLib - err:"), 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("lCusLib - err:"), 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("lCusLib - err:"), 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("lCusLib - err:"), 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("lCusLib - err:"), 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("lCusLib - err:"), 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("lCusLib - err:"), 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("lCusLib - err:"), 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("lCusLib - err:"), 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("lCusLib - err:"), 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("lCusLib - err:"), 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("lCusLib - err:"), 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("lCusLib - err:"), DLT_STRING(error)); - } - // restore backup - *(void **) (&customFuncts->custom_plugin_get_backup) = dlsym(handle, "plugin_get_backup"); - if ((error = dlerror()) != NULL) + if(load_default_library(handle ) < 0) { - DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("lCusLib - err:"), DLT_STRING(error)); + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("Failed to load default plugin")); + rval = EPERS_DLOPENERROR; } - - // 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("lCusLib - err:"), 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("lCusLib - err:"), DLT_STRING(error)); - } - - // clear all data - *(void **) (&customFuncts->custom_plugin_clear_all_data) = dlsym(handle, "plugin_clear_all_data"); - if ((error = dlerror()) != NULL) + } + else + { + if(handle != NULL) { - DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("lCusLib - error:"), DLT_STRING(error)); + 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)); + } + + // 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)); + } + + // 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)); + } + + // 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)); + } + + // 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)); + } + + // + // initialize the library + // + if(initType == Init_Synchronous) + { + 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) + { + 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); + } + 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: unknown init type "), + DLT_STRING(get_custom_client_lib_name(customLib))); + rval = EPERS_COMMON; + } } - - // sync data - *(void **) (&customFuncts->custom_plugin_sync) = dlsym(handle, "plugin_sync"); - if ((error = dlerror()) != NULL) + else { - DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("lCusLib - err:"), DLT_STRING(error)); + error = dlerror(); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); + rval = EPERS_DLOPENERROR; } - - // - // initialize the library - // - if(initType == Init_Synchronous) - { - if( (gPersCustomFuncs[customLib].custom_plugin_init) != NULL) - { - DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("lCusLib => (sync) : "), DLT_STRING(get_custom_client_lib_name(customLib))); - gPersCustomFuncs[customLib].custom_plugin_init(); - } - else - { - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("lCusLib - Err load plug funct: "), - DLT_STRING(get_custom_client_lib_name(customLib))); - rval = EPERS_COMMON; - } - } - else if(initType == Init_Asynchronous) - { - if( (gPersCustomFuncs[customLib].custom_plugin_init_async) != NULL) - { - DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("lCusLib => (async) : "), - DLT_STRING(get_custom_client_lib_name(customLib))); - - gPersCustomFuncs[customLib].custom_plugin_init_async(gPlugin_callback_async_t); - } - else - { - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("lCusLib - Err load plug funct: "), - DLT_STRING(get_custom_client_lib_name(customLib))); - rval = EPERS_COMMON; - } - } - else - { - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("lCusLib - unknown init type "), - DLT_STRING(get_custom_client_lib_name(customLib))); - rval = EPERS_COMMON; - } - } - else - { - error = dlerror(); - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("lCusLib - "), DLT_STRING(error)); - rval = EPERS_DLOPENERROR; } } else { - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("lCusLib - customLib out of bounds")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_library - error: - customLib out of bounds")); rval = EPERS_DLOPENERROR; } @@ -514,46 +658,46 @@ int check_valid_idx(int idx) int load_custom_plugins(plugin_callback_async_t pfInitCompletedCB) { - int rval = 0, i = 0; - - /// get custom library names to load - if(get_custom_libraries() >= 0) - { - gPlugin_callback_async_t = pfInitCompletedCB; // assign init callback - - // initialize custom library structure - for(i = 0; i < PersCustomLib_LastEntry; i++) - { - invalidate_custom_plugin(i); - } - - for(i=0; i < PersCustomLib_LastEntry; i++ ) - { - if(check_valid_idx(i) != -1) - { - if(getCustomLoadingType(i) == LoadType_PclInit) // check if the plugin must be loaded on plc init - { - if(load_custom_library(i, &gPersCustomFuncs[i] ) <= 0) - { - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("lCusPlug - could not load plugin: "), - DLT_STRING(get_custom_client_lib_name(i))); - rval = EPERS_COMMON; - } - } - } - else - { - continue; - } - } - } - else - { - DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("lCusPlug - Failed load cus lib conf table")); - rval = EPERS_COMMON; - } - - return rval; + int rval = 0, i = 0; + + /// get custom library names to load + if(get_custom_libraries() >= 0) + { + gPlugin_callback_async_t = pfInitCompletedCB; // assign init callback + + // initialize custom library structure + for(i=0; i < PersCustomLib_LastEntry; i++) + { + invalidate_custom_plugin(i); + } + + for(i=0; i < PersCustomLib_LastEntry; i++ ) + { + if(check_valid_idx(i) != -1) + { + if(getCustomLoadingType(i) == LoadType_PclInit) // check if the plugin must be loaded on pclInitLibrary + { + if(load_custom_library(i, &gPersCustomFuncs[i] ) <= 0) + { + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_plugins => E r r o r could not load plugin: "), + DLT_STRING(get_custom_client_lib_name(i))); + rval = EPERS_COMMON; + } + } + } + else + { + continue; + } + } + } + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclInit => Failed to load custom library config table")); + rval = EPERS_COMMON; + } + + return rval; } diff --git a/src/persistence_client_library_custom_loader.h b/src/persistence_client_library_custom_loader.h index fb758ae..7002317 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 { - /// predefined custom library for early persistence - PersCustomLib_early = 0, + PersCustomLib_default = 0, + /// predefined custom library for early persistence + 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 ... @@ -51,7 +52,7 @@ typedef enum _PersistenceCustomLibs_e /// enumerator fo custom library defines enum _PersCustomLibDefines_e { - /// the custom library path size + /// the custom library path size PersCustomPathSize = 12 } PersCustomLibDefines_e; @@ -60,27 +61,83 @@ enum _PersCustomLibDefines_e /// indicates the init method type typedef enum PersInitType_e_ { - /// initialize the plugin with the synchronous init function - Init_Synchronous = 0, - /// initialize the plugin with the asynchronous init function - Init_Asynchronous = 1, - /// undefined - Init_Undefined + /// initialize the plugin with the synchronous init function + Init_Synchronous = 0, + /// initialize the plugin with the asynchronous init function + Init_Asynchronous = 1, + /// undefined + Init_Undefined } PersInitType_e; /// indicates the plugin loading type typedef enum PersLoadingType_e_ { - /// load plugin during pclInitLibrary function - LoadType_PclInit = 0, - /// load the pluing on demand, when a plugin function will be requested the first time. - LoadType_OnDemand = 1, - /// undefined - LoadType_Undefined + /// load plugin during pclInitLibrary function + LoadType_PclInit = 0, + /// load the pluing on demand, when a plugin function will be requested the first time. + LoadType_OnDemand = 1, + /// undefined + LoadType_Undefined } 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 aedda39..cc391f5 100644 --- a/src/persistence_client_library_db_access.c +++ b/src/persistence_client_library_db_access.c @@ -24,7 +24,6 @@ #include <persComErrors.h> #include <persComDataOrg.h> -#include <persComDbAccess.h> #include <dbus/dbus.h> #include <string.h> @@ -79,19 +78,19 @@ static int database_get(PersistenceInfo_s* info, const char* dbPath, int dbType) if(PersistencePolicy_wt == dbType) /// write through database { - snprintf(path, DbPathMaxLen, "%s%s", dbPath, gLocalWt); + snprintf(path, DbPathMaxLen, "%s%s", dbPath, plugin_gLocalWt); } else if(PersistencePolicy_wc == dbType) // cached database { - snprintf(path, DbPathMaxLen, "%s%s", dbPath, gLocalCached); + snprintf(path, DbPathMaxLen, "%s%s", dbPath, plugin_gLocalCached); } else if(PersistenceDB_confdefault == dbType) // configurable default database { - snprintf(path, DbPathMaxLen, "%s%s", dbPath, gLocalConfigurableDefault); + snprintf(path, DbPathMaxLen, "%s%s", dbPath, plugin_gLocalConfigurableDefault); } else if(PersistenceDB_default == dbType) // default database { - snprintf(path, DbPathMaxLen, "%s%s", dbPath, gLocalFactoryDefault); + snprintf(path, DbPathMaxLen, "%s%s", dbPath, plugin_gLocalFactoryDefault); } else { @@ -100,7 +99,7 @@ static int database_get(PersistenceInfo_s* info, const char* dbPath, int dbType) if (handleDB == -1) { - handleDB = persComDbOpen(path, 0x01); + handleDB = plugin_persComDbOpen(path, 0x01); if(handleDB >= 0) { gHandlesDB[arrayIdx][dbType] = handleDB ; @@ -143,11 +142,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 { @@ -166,11 +165,11 @@ int pers_get_defaults(char* dbPath, char* key, PersistenceInfo_s* info, unsigned { if (PersDefaultType_Configurable == i) { - snprintf(dltMessage, DbPathMaxLen, "%s%s", dbPath, gLocalConfigurableDefault); + snprintf(dltMessage, DbPathMaxLen, "%s%s", dbPath, plugin_gLocalConfigurableDefault); } if (PersDefaultType_Factory == i) { - snprintf(dltMessage, DbPathMaxLen, "%s%s", dbPath, gLocalFactoryDefault); + snprintf(dltMessage, DbPathMaxLen, "%s%s", dbPath, plugin_gLocalFactoryDefault); } DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("getDefaults - default data will be used for Key"), DLT_STRING(key), DLT_STRING("from"), DLT_STRING(dltMessage)); @@ -197,7 +196,7 @@ void database_close(PersistenceInfo_s* info) if(info->configKey.storage <= PersistenceStorage_shared ) { - int iErrorCode = persComDbClose(gHandlesDB[arrayIdx][info->configKey.policy]) ; + int iErrorCode = plugin_persComDbClose(gHandlesDB[arrayIdx][info->configKey.policy]) ; if (iErrorCode < 0) { DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("database_close ==> persComDbClose() failed")); @@ -223,7 +222,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("dbCloseAll - Err close db")); @@ -250,7 +249,7 @@ int persistence_get_data(char* dbPath, char* key, const char* resourceID, Persis int handleDB = database_get(info, dbPath, info->configKey.policy); 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 */ @@ -363,7 +362,7 @@ int persistence_set_data(char* dbPath, char* key, const char* resource_id, Persi if(handleDB >= 0) { - write_size = persComDbWriteKey(handleDB, dbInput, (char*)buffer, buffer_size) ; + write_size = plugin_persComDbWriteKey(handleDB, dbInput, (char*)buffer, buffer_size) ; if(write_size < 0) { DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("setData - persComDbWriteKey() failure")); @@ -478,7 +477,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); @@ -574,7 +573,7 @@ int persistence_delete_data(char* dbPath, char* key, const char* resource_id, Pe int handleDB = database_get(info, dbPath, info->configKey.policy); if(handleDB >= 0) { - ret = persComDbDeleteKey(handleDB, key) ; + ret = plugin_persComDbDeleteKey(handleDB, key) ; if(ret < 0) { DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("deleteData - failed: "), DLT_STRING(key)); @@ -756,7 +755,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("prepShtdwn - Err close db => index:"), DLT_INT(i)); } diff --git a/src/persistence_client_library_handle.c b/src/persistence_client_library_handle.c index 10fe283..4ed1988 100644 --- a/src/persistence_client_library_handle.c +++ b/src/persistence_client_library_handle.c @@ -288,8 +288,10 @@ void set_file_cache_status(int idx, int status) { if(pthread_mutex_lock(&gFileHandleAccessMtx) == 0) { - gFileHandleArray[idx].cacheStatus = status; - + if(MaxPersHandle >= idx && idx > 0 ) + { + gFileHandleArray[idx].cacheStatus = status; + } pthread_mutex_unlock(&gFileHandleAccessMtx); } } @@ -299,7 +301,7 @@ int get_file_cache_status(int idx) int status = -1; if(pthread_mutex_lock(&gFileHandleAccessMtx) == 0) { - if(MaxPersHandle >= idx) + if(MaxPersHandle >= idx && idx > 0 ) { status = gFileHandleArray[idx].cacheStatus; } @@ -313,7 +315,10 @@ void set_file_user_id(int idx, int userID) { if(pthread_mutex_lock(&gFileHandleAccessMtx) == 0) { - gFileHandleArray[idx].userId = userID; + if(MaxPersHandle >= idx && idx > 0 ) + { + gFileHandleArray[idx].userId = userID; + } pthread_mutex_unlock(&gFileHandleAccessMtx); } @@ -324,7 +329,7 @@ int get_file_user_id(int idx) int id = -1; if(pthread_mutex_lock(&gFileHandleAccessMtx) == 0) { - if(MaxPersHandle >= idx) + if(MaxPersHandle >= idx && idx > 0 ) { id = gFileHandleArray[idx].userId; } diff --git a/src/persistence_client_library_prct_access.c b/src/persistence_client_library_prct_access.c index 646e444..e169fa6 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> @@ -109,20 +110,19 @@ 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("gRCT - no valid PersistenceRCT_e")); break; } - - gResource_table[arrayIdx] = persComRctOpen(filename, 0x00); + gResource_table[arrayIdx] = plugin_persComRctOpen(filename, 0x00); if(gResource_table[arrayIdx] < 0) { @@ -157,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) { @@ -241,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 { @@ -251,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; @@ -272,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; } |