diff options
author | Ingo Huerner <ingo.huerner@xse.de> | 2014-04-04 16:58:18 +0200 |
---|---|---|
committer | Ingo Huerner <ingo.huerner@xse.de> | 2014-04-04 16:58:18 +0200 |
commit | 236796526d94f802508d31f6ea234bf0fb8c1719 (patch) | |
tree | e9c2bc6ed3208d828da15d57bdee06cf7713c6bd | |
parent | 184bbd512b7f64b53e72376a0b892a11b34f9094 (diff) | |
download | persistence-client-library-236796526d94f802508d31f6ea234bf0fb8c1719.tar.gz |
Removed itzam, and switched to commom library; Known issues: delete key test fails, DLT warnings
29 files changed, 788 insertions, 1407 deletions
diff --git a/configure.ac b/configure.ac index 8cdfb7b..3e68985 100644 --- a/configure.ac +++ b/configure.ac @@ -69,7 +69,7 @@ AC_CHECK_FUNCS([fdatasync ftruncate mkdir munmap rmdir strerror utime dlopen]) PKG_CHECK_MODULES(DEPS, automotive-dlt dbus-1 - libitzam) + libperscommon) AC_SUBST(DEPS_CFLAGS) AC_SUBST(DEPS_LIBS) @@ -115,6 +115,28 @@ else fi ###################################################################### +# enable persistence file cahce component ########### +AC_ARG_ENABLE([filecache], + [AS_HELP_STRING([--enable-filecache],[Enable file cache component])], + [use_filecache=$enableval], + [use_filecache="no"]) + +AM_CONDITIONAL([USE_FILECACHE], [test x"$use_filecache" = "no"]) + +if test "$use_filecache" != "yes" -a "$use_filecache" != "no"; then + AC_MSG_ERROR([Invalid file cache check mode specified: $use_filecache. Only "yes" or "no" is valid]) +else + AC_MSG_NOTICE([Use file cache: $use_filecache]) + + if test "$use_filecache" = "yes"; then + PKG_CHECK_MODULES(PFC, persistence_file_cache) + AC_DEFINE_UNQUOTED([USE_FILECACHE], [1], [filecache enabled]) + fi +fi + AC_SUBST(PFC_CFLAGS) + AC_SUBST(PFC_LIBS) +###################################################################### + AC_ARG_ENABLE(debug, AS_HELP_STRING([--enable-debug], diff --git a/include_protected/persistence_client_library_rc_table.h b/include_protected/persistence_client_library_rc_table.h deleted file mode 100644 index 6cb0668..0000000 --- a/include_protected/persistence_client_library_rc_table.h +++ /dev/null @@ -1,144 +0,0 @@ -#ifndef PERSISTENCE_CLIENT_LIBRARY_RC_TABLE_H -#define PERSISTENCE_CLIENT_LIBRARY_RC_TABLE_H - -/****************************************************************************** - * Project Persistency - * (c) copyright 2012 - * Company XS Embedded GmbH - *****************************************************************************/ -/****************************************************************************** - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed - * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -******************************************************************************/ - /** - * @file persistence_client_library_rc_table.h - * @ingroup Persistence client library - * @author Ingo Huerner - * @brief Header of the persistence client library resource config table. - * @see - */ - -#ifdef __cplusplus -extern "C" { -#endif - -#include <fcntl.h> // needed for file open flags - -#define PERSIST_DATA_RC_TABLE_INTERFACE_VERSION (0x03000000U) - -#include "persistence_client_library_data_organization.h" - - -/// enumerator used to identify the policy to manage the data -typedef enum _PersistencePolicy_e -{ - PersistencePolicy_wc = 0, /**< the data is managed write cached */ - PersistencePolicy_wt = 1, /**< the data is managed write through */ - PersistencePolicy_na = 2, /**< the data is not applicable */ - - /** insert new entries here ... */ - PersistencePolicy_LastEntry /**< last entry */ - -} PersistencePolicy_e; - - -/// enumerator used to identify the persistence storage to manage the data -typedef enum _PersistenceStorage_e -{ - PersistenceStorage_local = 0, /**< the data is managed local */ - PersistenceStorage_shared = 1, /**< the data is managed shared */ - PersistenceStorage_custom = 2, /**< the data is managed over custom client implementation */ - - /** insert new entries here ... */ - PersistenceStorage_LastEntry /**< last entry */ - -} PersistenceStorage_e; - - - -/** specify the type of the resource */ -typedef enum PersistenceResourceType_e_ -{ - PersistenceResourceType_key = 0, /**< key type resource */ - PersistenceResourceType_file, /**< file type resource */ - - /** insert new entries here ... */ - PersistenceResourceType_LastEntry /**< last entry */ - -} PersistenceResourceType_e; - - - -/// structure used to manage database context -typedef struct _PersistenceDbContext_s -{ - unsigned int ldbid; - unsigned int user_no; - unsigned int seat_no; -} PersistenceDbContext_s; - - -typedef enum PersistencePermission_e_ -{ - PersistencePermission_ReadWrite = 0, - PersistencePermission_ReadOnly = 1, - PersistencePermission_WriteOnly = 2, - - /** insert new entries here ... */ - PersistencePermission_LastEntry /**< last entry */ -} PersistencePermission_e; - - - -/// structure used to manage the persistence configuration for a key -typedef struct _PersistenceConfigurationKey_s -{ - PersistencePolicy_e policy; /**< policy */ - PersistenceStorage_e storage; /**< definition of storage to use */ - PersistenceResourceType_e type; /**< type of the resource - since 4.0.0.0*/ - PersistencePermission_e permission; /**< file access flags*/ - unsigned int max_size; /**< max size expected for the key */ - char reponsible[MaxConfKeyLengthResp]; /**< name of responsible application */ - char custom_name[MaxConfKeyLengthCusName]; /**< name of the customer plugin */ - char customID[MaxRctLengthCustom_ID]; /**< internal ID for the custom type resource */ -} PersistenceConfigurationKey_s; - - -/// structure definition of an persistence resource configuration table entry -typedef struct _PersistenceRctEntry_s -{ - char key[PrctKeySize]; /**< the key */ - PersistenceConfigurationKey_s data; /**< data for the key */ -} -PersistenceRctEntry_s; - - -/// persistence information -typedef struct _PersistenceInfo_s -{ - PersistenceDbContext_s context; /**< database context*/ - PersistenceConfigurationKey_s configKey; /**< prct configuration key*/ - -} PersistenceInfo_s; - - - -/// persistence resource config table type definition -typedef enum _PersistenceRCT_e -{ - PersistenceRCT_local = 0, - PersistenceRCT_shared_public = 1, - PersistenceRCT_shared_group = 2, - - PersistenceRCT_LastEntry // last Entry - -} PersistenceRCT_e; - - - -#ifdef __cplusplus -} -#endif - -#endif /* PERSISTENCY_CLIENT_LIBRARY_RC_TABLE_H */ diff --git a/persistence_client_library.pc.in b/persistence_client_library.pc.in index 2b40b17..b5e4e14 100644 --- a/persistence_client_library.pc.in +++ b/persistence_client_library.pc.in @@ -8,8 +8,8 @@ datadir=@datadir@ Name: persistence client library Description: persistence client library Version: @VERSION@ -Requires: automotive-dlt -Requires.private: libitzam dbus-1 +Requires: automotive-dlt libperscommon +Requires.private: dbus-1 Libs: -L${libdir} -lpersistence_client_library -lrt -ldl -Libs.private: -lpersistence_client_library_common_data -ldbus +Libs.private: -ldbus Cflags: -I${includedir} diff --git a/src/Makefile.am b/src/Makefile.am index 8f51515..7a2248a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -15,18 +15,10 @@ include_HEADERS = ../include/persistence_client_library_key.h \ ../include/persistence_client_library.h \ ../include/persistence_client_library_error_def.h \ ../include/persistence_client_custom.h - -lib_LTLIBRARIES = libpersistence_client_library_common_data.la libpersistence_client_library.la +lib_LTLIBRARIES = libpersistence_client_library.la - - -libpersistence_client_library_common_data_la_SOURCES = \ - persistence_client_library_data_organization.c - - - -libpersistence_client_library_la_LIBADD = $(DEPS_LIBS) -ldl -lpersistence_client_library_common_data +libpersistence_client_library_la_LIBADD = $(DEPS_LIBS) $(PFC_LIBS) -ldl -lpers_common libpersistence_client_library_la_SOURCES = \ persistence_client_library.c \ @@ -39,7 +31,7 @@ libpersistence_client_library_la_SOURCES = \ persistence_client_library_dbus_service.c \ persistence_client_library_custom_loader.c \ persistence_client_library_prct_access.c \ - persistence_client_library_itzam_errors.c \ + persistence_client_library_data_organization.c \ persistence_client_library_backup_filelist.c \ persistence_client_library_dbus_cmd.c \ crc32.c \ diff --git a/src/crc32.c b/src/crc32.c index ad325ad..709a974 100644 --- a/src/crc32.c +++ b/src/crc32.c @@ -51,7 +51,7 @@ */ -#include "../include_protected/crc32.h" +#include "crc32.h" enum crc32ConstantDefinition @@ -107,7 +107,7 @@ static unsigned int crc32_tab[] = 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d }; -const unsigned int pclCrc32(unsigned int crc, const unsigned char *buf, size_t theSize) +unsigned int pclCrc32(unsigned int crc, const unsigned char *buf, size_t theSize) { const unsigned char *p = 0; unsigned int rval = 0; @@ -119,10 +119,10 @@ const unsigned int pclCrc32(unsigned int crc, const unsigned char *buf, size_t t { while(theSize--) { - unsigned int index = (crc ^ *p++) & 0xFF; + unsigned int idx = (crc ^ *p++) & 0xFF; - if(index < crc32_array_size) - crc = crc32_tab[index] ^ (crc >> 8); + if(idx < crc32_array_size) + crc = crc32_tab[idx] ^ (crc >> 8); } rval = crc ^ ~0U; } diff --git a/include_protected/crc32.h b/src/crc32.h index 8a4e0b9..1d43392 100644 --- a/include_protected/crc32.h +++ b/src/crc32.h @@ -30,7 +30,7 @@ extern "C" { #include <string.h> -const unsigned int pclCrc32(unsigned int crc, const unsigned char *buf, size_t theSize); +unsigned int pclCrc32(unsigned int crc, const unsigned char *buf, size_t theSize); #ifdef __cplusplus diff --git a/src/persistence_client_library.c b/src/persistence_client_library.c index 4eba3bf..9c22464 100644 --- a/src/persistence_client_library.c +++ b/src/persistence_client_library.c @@ -25,20 +25,20 @@ #include "persistence_client_library_custom_loader.h" #include "persistence_client_library.h" #include "persistence_client_library_backup_filelist.h" -#include "../include_protected/persistence_client_library_db_access.h" +#include "persistence_client_library_db_access.h" + +#if USE_FILECACHE + #include <persistence_file_cache.h> +#endif #include <string.h> #include <errno.h> #include <stdlib.h> #include <dlfcn.h> - -#include <dlt/dlt.h> -#include <dlt/dlt_common.h> - #include <dbus/dbus.h> /// debug log and trace (DLT) setup -DLT_DECLARE_CONTEXT(gDLTContext); +DLT_DECLARE_CONTEXT(gPclDLTContext); static int gShutdownMode = 0; @@ -52,8 +52,8 @@ int pclInitLibrary(const char* appName, int shutdownMode) { gShutdownMode = shutdownMode; - DLT_REGISTER_CONTEXT(gDLTContext,"PCL","Context for persistence client library logging"); - DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclInitLibrary => I N I T Persistence Client Library - "), DLT_STRING(gAppId), + DLT_REGISTER_CONTEXT(gPclDLTContext,"PCL","Context for persistence client library logging"); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclInitLibrary => I N I T Persistence Client Library - "), DLT_STRING(gAppId), DLT_STRING("- init counter: "), DLT_INT(gPclInitialized) ); /// environment variable for on demand loading of custom libraries @@ -63,12 +63,20 @@ int pclInitLibrary(const char* appName, int shutdownMode) /// blacklist path environment variable const char *pBlacklistPath = getenv("PERS_BLACKLIST_PATH"); +#if USE_FILECACHE + printf("* * * * * * Using the filecache! * * * * * * * * *\n"); + + pfcInitCache(appName); +#else + printf("* * * * * * N O T using the filecache! * * * * * *\n"); +#endif + #if USE_PASINTERFACE == 1 //printf("* ADMIN INTERFACE is - e n a b l e d - \n"); - DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("PAS interface is enabled!!")); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("PAS interface is enabled!!")); #else //printf("* ADMIN INTERFACE is - d i s a b l e d - enable with \"./configure --enable-pasinterface\"\n"); - DLT_LOG(gDLTContext, DLT_LOG_WARN, DLT_STRING("PAS interface is not enabled, enable with \"./configure --enable-pasinterface\"")); + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("PAS interface is not enabled, enable with \"./configure --enable-pasinterface\"")); #endif @@ -86,12 +94,12 @@ int pclInitLibrary(const char* appName, int shutdownMode) if(readBlacklistConfigFile(pBlacklistPath) == -1) { - DLT_LOG(gDLTContext, DLT_LOG_WARN, DLT_STRING("pclInitLibrary -> failed to access blacklist:"), DLT_STRING(pBlacklistPath)); + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclInitLibrary -> failed to access blacklist:"), DLT_STRING(pBlacklistPath)); } if(setup_dbus_mainloop() == -1) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclInitLibrary => Failed to setup main loop")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclInitLibrary => Failed to setup main loop")); pthread_mutex_unlock(&gDbusPendingRegMtx); return EPERS_DBUS_MAINLOOP; } @@ -102,7 +110,7 @@ int pclInitLibrary(const char* appName, int shutdownMode) // register for lifecycle and persistence admin service dbus messages if(register_lifecycle(shutdownMode) == -1) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclInitLibrary => Failed to register to lifecycle dbus interface")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclInitLibrary => Failed to register to lifecycle dbus interface")); pthread_mutex_unlock(&gDbusPendingRegMtx); return EPERS_REGISTER_LIFECYCLE; } @@ -110,7 +118,7 @@ int pclInitLibrary(const char* appName, int shutdownMode) #if USE_PASINTERFACE == 1 if(register_pers_admin_service() == -1) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclInitLibrary => Failed to register to pers admin dbus interface")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclInitLibrary => Failed to register to pers admin dbus interface")); pthread_mutex_unlock(&gDbusPendingRegMtx); return EPERS_REGISTER_ADMIN; } @@ -136,19 +144,19 @@ int pclInitLibrary(const char* appName, int shutdownMode) { if( (gPersCustomFuncs[i].custom_plugin_init) != NULL) { - DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclInitLibrary => Loaded plugin: "), + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclInitLibrary => Loaded plugin: "), DLT_STRING(get_custom_client_lib_name(i))); gPersCustomFuncs[i].custom_plugin_init(); } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclInitLibrary => E r r o r could not load plugin functions: "), + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclInitLibrary => E r r o r could not load plugin functions: "), DLT_STRING(get_custom_client_lib_name(i))); } } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclInitLibrary => E r r o r could not load plugin: "), + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclInitLibrary => E r r o r could not load plugin: "), DLT_STRING(get_custom_client_lib_name(i))); } } @@ -161,7 +169,7 @@ int pclInitLibrary(const char* appName, int shutdownMode) } else { - DLT_LOG(gDLTContext, DLT_LOG_WARN, DLT_STRING("pclInit => Failed to load custom library config table => error number:"), DLT_INT(status)); + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclInit => Failed to load custom library config table => error number:"), DLT_INT(status)); } // assign application name @@ -173,7 +181,7 @@ int pclInitLibrary(const char* appName, int shutdownMode) else if(gPclInitialized >= PCLinitialized) { gPclInitialized++; // increment init counter - DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclInitLibrary => I N I T Persistence Client Library - "), DLT_STRING(gAppId), + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclInitLibrary => I N I T Persistence Client Library - "), DLT_STRING(gAppId), DLT_STRING("- ONLY INCREMENT init counter: "), DLT_INT(gPclInitialized) ); } return rval; @@ -188,7 +196,7 @@ int pclDeinitLibrary(void) if(gPclInitialized == PCLinitialized) { int* retval; - DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclDeinitLibrary -> D E I N I T client library - "), DLT_STRING(gAppId), + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclDeinitLibrary -> D E I N I T client library - "), DLT_STRING(gAppId), DLT_STRING("- init counter: "), DLT_INT(gPclInitialized)); // unregister for lifecycle and persistence admin service dbus messages @@ -217,7 +225,7 @@ int pclDeinitLibrary(void) pers_rct_close_all(); // close opend database - pers_db_close_all(); + database_close_all(); // close persistence handles close_all_persistence_handle(); @@ -236,11 +244,11 @@ int pclDeinitLibrary(void) gPclInitialized = PCLnotInitialized; - DLT_UNREGISTER_CONTEXT(gDLTContext); + DLT_UNREGISTER_CONTEXT(gPclDLTContext); } else if(gPclInitialized > PCLinitialized) { - DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclDeinitLibrary -> D E I N I T client library - "), DLT_STRING(gAppId), + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclDeinitLibrary -> D E I N I T client library - "), DLT_STRING(gAppId), DLT_STRING("- ONLY DECREMENT init counter: "), DLT_INT(gPclInitialized)); gPclInitialized--; // decrement init counter } diff --git a/src/persistence_client_library_backup_filelist.c b/src/persistence_client_library_backup_filelist.c index f87942d..060901c 100644 --- a/src/persistence_client_library_backup_filelist.c +++ b/src/persistence_client_library_backup_filelist.c @@ -19,18 +19,15 @@ #include "persistence_client_library_backup_filelist.h" #include "persistence_client_library_handle.h" #include "rbtree.h" -#include "../include_protected/crc32.h" -#include "../include_protected/persistence_client_library_data_organization.h" + +#include "crc32.h" +#include "persistence_client_library_data_organization.h" -#include <fcntl.h> -#include <string.h> #include <sys/mman.h> #include <sys/stat.h> #include <errno.h> -#include <unistd.h> #include <stdlib.h> -#include <stdio.h> #include <sys/sendfile.h> @@ -176,14 +173,14 @@ int readBlacklistConfigFile(const char* filename) fd = open(filename, O_RDONLY); if (fd == -1) { - DLT_LOG(gDLTContext, DLT_LOG_WARN, DLT_STRING("configReader::readConfigFile ==> Error file open"), DLT_STRING(filename), DLT_STRING(strerror(errno)) ); + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("configReader::readConfigFile ==> Error file open"), DLT_STRING(filename), DLT_STRING(strerror(errno)) ); return -1; } // check for empty file if(gConfigFileSize == 0) { - DLT_LOG(gDLTContext, DLT_LOG_WARN, DLT_STRING("configReader::readConfigFile ==> Error file size is 0:"), DLT_STRING(filename)); + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("configReader::readConfigFile ==> Error file size is 0:"), DLT_STRING(filename)); close(fd); return -1; } @@ -195,7 +192,7 @@ int readBlacklistConfigFile(const char* filename) { gpConfigFileMap = 0; close(fd); - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("configReader::readConfigFile ==> Error mapping the file:"), DLT_STRING(filename), DLT_STRING(strerror(errno)) ); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("configReader::readConfigFile ==> Error mapping the file:"), DLT_STRING(filename), DLT_STRING(strerror(errno)) ); return -1; } @@ -245,7 +242,7 @@ int need_backup_key(unsigned int key) free(item); rval = -1; - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("need_backup_key ==> item or gRb_tree_bl is NULL")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("need_backup_key ==> item or gRb_tree_bl is NULL")); } return rval; @@ -376,7 +373,7 @@ int pclCreateFile(const char* path) } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclCreateFile ==> no valid path to create: "), DLT_STRING(path) ); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclCreateFile ==> no valid path to create: "), DLT_STRING(path) ); } return handle; @@ -402,7 +399,7 @@ int pclVerifyConsistency(const char* origPath, const char* backupPath, const cha // ************************************************* if( (backupAvail == 0) && (csumAvail == 0) ) { - DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclVerifyConsistency => there is a backup file AND a checksum")); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclVerifyConsistency => there is a backup file AND a checksum")); // calculate checksum form backup file fdBackup = open(backupPath, O_RDONLY); if(fdBackup != -1) @@ -461,7 +458,7 @@ int pclVerifyConsistency(const char* origPath, const char* backupPath, const cha // ************************************************* else if(csumAvail == 0) { - DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclVerifyConsistency => there is ONLY a checksum file")); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclVerifyConsistency => there is ONLY a checksum file")); fdCsum = open(csumPath, O_RDONLY); if(fdCsum != -1) @@ -469,7 +466,7 @@ int pclVerifyConsistency(const char* origPath, const char* backupPath, const cha readSize = read(fdCsum, csumBuf, ChecksumBufSize); if(readSize <= 0) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclVerifyConsistency => read checksum: invalid readSize")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclVerifyConsistency => read checksum: invalid readSize")); } close(fdCsum); @@ -503,7 +500,7 @@ int pclVerifyConsistency(const char* origPath, const char* backupPath, const cha // ************************************************* else if(backupAvail == 0) { - DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclVerifyConsistency => there is ONLY a backup file")); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclVerifyConsistency => there is ONLY a backup file")); // calculate checksum form backup file fdBackup = open(backupPath, O_RDONLY); @@ -564,7 +561,7 @@ int pclRecoverFromBackup(int backupFd, const char* original) // copy data from one file to another if((handle = pclBackupDoFileCopy(backupFd, handle)) == -1) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclRecoverFromBackup => couldn't write whole buffer")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclRecoverFromBackup => couldn't write whole buffer")); } } @@ -595,13 +592,13 @@ int pclCreateBackup(const char* dstPath, int srcfd, const char* csumPath, const int csumSize = strlen(csumBuf); if(write(csfd, csumBuf, csumSize) != csumSize) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclCreateBackup => failed to write checksum to file")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclCreateBackup => failed to write checksum to file")); } close(csfd); } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclCreateBackup => failed to create checksum file:"), DLT_STRING(strerror(errno)) ); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclCreateBackup => failed to create checksum file:"), DLT_STRING(strerror(errno)) ); } // create backup file, user and group has read/write permission, others have read permission @@ -615,12 +612,12 @@ int pclCreateBackup(const char* dstPath, int srcfd, const char* csumPath, const // copy data from one file to another if((readSize = pclBackupDoFileCopy(srcfd, dstFd)) == -1) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pcl_create_backup => error copying file")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pcl_create_backup => error copying file")); } if(close(dstFd) == -1) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pcl_create_backup => error closing fd")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pcl_create_backup => error closing fd")); } // set back to the position @@ -628,7 +625,7 @@ int pclCreateBackup(const char* dstPath, int srcfd, const char* csumPath, const } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclCreateBackup => failed to open backup file"), + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclCreateBackup => failed to open backup file"), DLT_STRING(dstPath), DLT_STRING(strerror(errno))); } diff --git a/src/persistence_client_library_backup_filelist.h b/src/persistence_client_library_backup_filelist.h index 0771ae4..1350bbf 100644 --- a/src/persistence_client_library_backup_filelist.h +++ b/src/persistence_client_library_backup_filelist.h @@ -20,7 +20,8 @@ */ -#include "../include_protected/persistence_client_library_rc_table.h" +//#include "../include_protected/persistence_client_library_rc_table.h" +#include <persComRct.h> /** * @brief Read the blacklist configuration file diff --git a/src/persistence_client_library_custom_loader.c b/src/persistence_client_library_custom_loader.c index 4f6e5fe..d0dc4ae 100644 --- a/src/persistence_client_library_custom_loader.c +++ b/src/persistence_client_library_custom_loader.c @@ -17,7 +17,7 @@ */ #include "persistence_client_library_custom_loader.h" -#include "../include_protected/persistence_client_library_data_organization.h" +#include "persistence_client_library_data_organization.h" #include <stdio.h> #include <errno.h> @@ -78,7 +78,7 @@ PersistenceCustomLibs_e custom_client_name_to_id(const char* lib_name, int subst } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("custom_libname_to_id - error - id not found for 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 @@ -113,7 +113,7 @@ PersistenceCustomLibs_e custom_client_name_to_id(const char* lib_name, int subst } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("custom_libname_to_id - error - id not found for 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)); } } @@ -225,25 +225,25 @@ int get_custom_libraries() else { rval = EPERS_CONFIGMAPFAILED; - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("load config file error - mapping of file failed")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("load config file error - mapping of file failed")); } close(fd); } else { rval = EPERS_CONFIGNOTAVAILABLE; - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("load config file error - no file with plugins available:"), DLT_STRING(filename), DLT_STRING(strerror(errno))); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("load config file error - no file with plugins available:"), DLT_STRING(filename), DLT_STRING(strerror(errno))); } } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("load config file error - invalid file size"), DLT_STRING(filename), DLT_STRING(strerror(errno))); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("load config file error - invalid file size"), DLT_STRING(filename), DLT_STRING(strerror(errno))); } } else { rval = EPERS_CONFIGNOSTAT; - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("lload config file error - can't stat config file:"), DLT_STRING(filename), DLT_STRING(strerror(errno))); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("lload config file error - can't stat config file:"), DLT_STRING(filename), DLT_STRING(strerror(errno))); } return rval; } @@ -268,125 +268,125 @@ int load_custom_library(PersistenceCustomLibs_e customLib, Pers_custom_functs_s *(void **) (&customFuncts->custom_plugin_handle_close) = dlsym(handle, "plugin_handle_close"); if ((error = dlerror()) != NULL) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); + 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(gDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); + 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(gDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); + 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(gDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); + 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(gDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); + 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(gDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); + 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(gDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); + 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(gDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); + 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(gDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); + 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(gDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); + 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(gDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); + 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(gDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); + 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(gDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); + 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(gDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); + 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(gDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); + 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(gDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); + 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(gDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); + 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(gDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); } } else { error = dlerror(); - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_library - error:"), DLT_STRING(error)); rval = EPERS_DLOPENERROR; } } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_library - error: - customLib out of bounds")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_library - error: - customLib out of bounds")); rval = EPERS_DLOPENERROR; } diff --git a/src/persistence_client_library_data_organization.c b/src/persistence_client_library_data_organization.c index 12d5eea..4ea78db 100644 --- a/src/persistence_client_library_data_organization.c +++ b/src/persistence_client_library_data_organization.c @@ -16,7 +16,7 @@ * @see */ -#include "../include_protected/persistence_client_library_data_organization.h" +#include "persistence_client_library_data_organization.h" #include <string.h> #include <stdio.h> @@ -63,26 +63,26 @@ const char* gLocalCachePath = CACHEPREFIX "%s"; /// path prefix for local write through database /Data/mnt_wt/<appId>/<database_name> const char* gLocalWtPath = WTPREFIX "%s"; /// path prefix for shared cached database: /Data/mnt_c/Shared/Group/<group_no>/<database_name> -const char* gSharedCachePath = CACHEPREFIX "%s/Shared_Group_%x"; +const char* gSharedCachePath = CACHEPREFIX "%s/shared_group_%x"; /// path prefix for shared write through database: /Data/mnt_wt/Shared/Group/<group_no>/<database_name> -const char* gSharedWtPath = WTPREFIX "%s/Shared_Group_%x"; +const char* gSharedWtPath = WTPREFIX "%s/shared_group_%x"; /// path prefix for shared public cached database: /Data/mnt_c/Shared/Public//<database_name> -const char* gSharedPublicCachePath = CACHEPREFIX "%s/Shared_Public"; +const char* gSharedPublicCachePath = CACHEPREFIX "%s/shared_public"; /// path prefix for shared public write through database: /Data/mnt_wt/Shared/Public/<database_name> -const char* gSharedPublicWtPath = WTPREFIX "%s/Shared_Public"; +const char* gSharedPublicWtPath = WTPREFIX "%s/shared_public"; /// path prefix for local cached database: /Data/mnt_c/<appId>/ (<database_name> const char* gLocalCachePathKey = CACHEPREFIX "%s%s"; /// path prefix for local write through database /Data/mnt_wt/<appId>/<database_name> const char* gLocalWtPathKey = WTPREFIX "%s%s"; /// path prefix for shared cached database: /Data/mnt_c/Shared/Group/<group_no>/<database_name> -const char* gSharedCachePathKey = CACHEPREFIX "%s/Shared_Group_%x%s"; +const char* gSharedCachePathKey = CACHEPREFIX "%s/shared_group_%x%s"; /// path prefix for shared write through database: /Data/mnt_wt/Shared/Group/<group_no>/<database_name> -const char* gSharedWtPathKey = WTPREFIX "%s/Shared_Group_%x%s"; +const char* gSharedWtPathKey = WTPREFIX "%s/shared_group_%x%s"; /// path prefix for shared public cached database: /Data/mnt_c/Shared/Public//<database_name> -const char* gSharedPublicCachePathKey = CACHEPREFIX "%s/Shared_Public%s"; +const char* gSharedPublicCachePathKey = CACHEPREFIX "%s/shared_public%s"; /// path prefix for shared public write through database: /Data/mnt_wt/Shared/Public/<database_name> -const char* gSharedPublicWtPathKey = WTPREFIX "%s/Shared_Public%s"; +const char* gSharedPublicWtPathKey = WTPREFIX "%s/shared_public%s"; /// path prefix for local cached files: /Data/mnt_c/<appId>/<user>/<seat>/<resource> const char* gLocalCacheFilePath = CACHEPREFIX "%s/user/%d/seat/%d/%s"; @@ -117,7 +117,7 @@ int gMaxKeyValDataSize = defaultMaxKeyValDataSize; unsigned int gPclInitialized = PCLnotInitialized; -DltContext gDLTContext; +DltContext gPclDLTContext; int(* gChangeNotifyCallback)(pclNotification_s * notifyStruct); diff --git a/include_protected/persistence_client_library_data_organization.h b/src/persistence_client_library_data_organization.h index 17fa9f7..21075b4 100644 --- a/include_protected/persistence_client_library_data_organization.h +++ b/src/persistence_client_library_data_organization.h @@ -29,6 +29,8 @@ extern "C" { #include "../include/persistence_client_library_error_def.h" #include "../include/persistence_client_library_key.h" +#include <persComRct.h> + #include <dlt/dlt.h> #include <dlt/dlt_common.h> @@ -36,6 +38,46 @@ extern "C" { #include <stdio.h> + +/// structure used to manage database context +typedef struct _PersistenceDbContext_s +{ + unsigned int ldbid; + unsigned int user_no; + unsigned int seat_no; +} PersistenceDbContext_s; + +/// persistence information +typedef struct _PersistenceInfo_s +{ + PersistenceDbContext_s context; /**< database context*/ + PersistenceConfigurationKey_s configKey; /**< prct configuration key*/ + +} PersistenceInfo_s; + + +/** storages to manage the data */ +typedef enum PersDefaultType_e_ +{ + PersDefaultType_Configurable = 0, /**< get the data from configurable defaults */ + PersDefaultType_Factory, /**< get the data from factory defaults */ + + /** insert new entries here ... */ + PersDefaultType_LastEntry /**< last entry */ + +} PersDefaultType_e; + +/** storages to manage the data */ +typedef enum PersGetDefault_e_ +{ + PersGetDefault_Data = 0, /**< get the data from configurable defaults */ + PersGetDefault_Size, /**< get the data from factory defaults */ + + /** insert new entries here ... */ + PersGetDefault_LastEntry /**< last entry */ + +} PersGetDefault_e; + /// enumerator used to identify the policy to manage the data typedef enum _PersNotifyRegPolicy_e { @@ -165,7 +207,7 @@ extern char gAppId[MaxAppNameLen]; extern int gMaxKeyValDataSize; /// the DLT context -extern DltContext gDLTContext; +extern DltContext gPclDLTContext; /// flag to indicate if client library has been initialized extern unsigned int gPclInitialized; diff --git a/src/persistence_client_library_db_access.c b/src/persistence_client_library_db_access.c index 3818218..5ecbfac 100644 --- a/src/persistence_client_library_db_access.c +++ b/src/persistence_client_library_db_access.c @@ -17,13 +17,14 @@ * @see */ -#include "../include_protected/persistence_client_library_db_access.h" -#include "../include_protected/persistence_client_library_rc_table.h" +#include "persistence_client_library_db_access.h" #include "persistence_client_library_custom_loader.h" -#include "persistence_client_library_itzam_errors.h" +#include "persistence_client_library_dbus_service.h" #include "persistence_client_library_prct_access.h" -#include "persistence_client_library_dbus_service.h" +#include <persComErrors.h> +#include <persComDataOrg.h> +#include <persComDbAccess.h> #include <dbus/dbus.h> #include <string.h> @@ -32,237 +33,281 @@ #include <errno.h> -/// definition of a key-value pair stored in the database -typedef struct _KeyValuePair_s -{ - char m_key[DbKeySize]; /// the key - char m_data[DbValueSize]; /// the data - unsigned int m_data_size; /// the size of the data -} -KeyValuePair_s; - - -// definition of a cursor entry -typedef struct _CursorEntry_s -{ - itzam_btree_cursor m_cursor; - itzam_btree m_btree; - int m_empty; -} -CursorEntry_s; - -// cursor array handle -CursorEntry_s gCursorArray[MaxPersHandle]; - -/// handle index -static int gHandleIdx = 1; - -/// free handle array -int gFreeCursorHandleArray[MaxPersHandle]; -// free head index -int gFreeCursorHandleIdxHead = 0; - -// mutex to controll access to the cursor array -pthread_mutex_t gCursorMtx = PTHREAD_MUTEX_INITIALIZER; - /// btree array -static itzam_btree gBtree[DbTableSize][PersistencePolicy_LastEntry]; -static int gBtreeCreated[DbTableSize][PersistencePolicy_LastEntry] = { {0} }; +static int gHandlesDB[DbTableSize][PersistencePolicy_LastEntry]; +static int gHandlesDBCreated[DbTableSize][PersistencePolicy_LastEntry] = { {0} }; // function prototype int pers_send_Notification_Signal(const char* key, PersistenceDbContext_s* context, unsigned int reason); -int pers_get_default_data(char* dbPath, char* key, unsigned char* buffer, unsigned int buffer_size); +char* pers_get_raw_key(char *key) +{ + char *temp = NULL; + char *rawKey = key; + + temp = strrchr(key, (int)'/'); + + if (NULL != temp) + { + rawKey = temp + 1; + } + + return rawKey; +} -int pers_db_open_default(itzam_btree* btree, const char* dbPath, int configDefault) +int pers_db_open_default(const char* dbPath, PersDefaultType_e DefaultType) { - itzam_state state = ITZAM_FAILED; + int ret = 0; char path[DbPathMaxLen] = {0}; - if(1 == configDefault) + if (PersDefaultType_Configurable == DefaultType) { - snprintf(path, DbPathMaxLen, "%s%s", dbPath, gConfigDefault); + snprintf(path, DbPathMaxLen, "%s%s", dbPath, gLocalConfigurableDefault); } - else if(0 == configDefault) + else if (PersDefaultType_Factory== DefaultType) { - snprintf(path, DbPathMaxLen, "%s%s", dbPath, gDefault); + snprintf(path, DbPathMaxLen, "%s%s", dbPath, gLocalFactoryDefault); } else { - return -1; // invalid + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_open_default ==> unknown DefaultType")); + ret = EPERS_COMMON; + } + + if (EPERS_COMMON != ret) + { + ret = persComDbOpen(path, 0); + if (ret < 0) + { + ret = EPERS_COMMON; + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, + DLT_STRING("pers_db_open_default() -> persComDbOpen() -> problem open db: "), + DLT_STRING(path), + DLT_STRING(" Code: "), + DLT_INT(ret)); + } } - state = itzam_btree_open(btree, path, itzam_comparator_string, error_handler, 0/*recover*/, 0/*read_only*/); - if (state != ITZAM_OKAY) + return ret; +} + + +int pers_get_defaults(char* dbPath, char* key, unsigned char* buffer, unsigned int buffer_size, PersGetDefault_e job) +{ + PersDefaultType_e i = PersDefaultType_Configurable; + int handleDefaultDB = -1; + int read_size = EPERS_NOKEY; + + key = pers_get_raw_key(key); /* We need only the raw key without a prefixed '/node/' or '/user/1/seat/0' etc... */ + + for(i=0; i<PersDefaultType_LastEntry; i++) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_open_default ==> itzam_btree_open => Itzam problem"), DLT_STRING(STATE_MESSAGES[state])); + handleDefaultDB = pers_db_open_default(dbPath, i); + if(handleDefaultDB >= 0) + { + if (PersGetDefault_Data == job) + { + } + else if (PersGetDefault_Size == job) + { + read_size = persComDbGetKeySize(handleDefaultDB, key); + } + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_get_defaults ==> unknown job")); + break; + } + + if (0 > persComDbClose(handleDefaultDB)) + { + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_get_defaults ==> persComDbClose returned with error")); + } + + if(read_size < 0) // check read_size + { + if (PersDefaultType_Configurable == i) + { + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("Key '"), + DLT_STRING(key), + DLT_STRING("' not found in "), + DLT_STRING(dbPath), + DLT_STRING(gLocalConfigurableDefault)); + } + else if (PersDefaultType_Factory == i) + { + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("Key '"), + DLT_STRING(key), + DLT_STRING("' not found in "), + DLT_STRING(dbPath), + DLT_STRING(gLocalFactoryDefault)); + } + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_get_defaults ==> unknown PersDefaultType: "), + DLT_INT(i)); + } + + if(PERS_COM_ERR_NOT_FOUND == read_size) + { + read_size = EPERS_NOKEY; + } + } + else + { + break; + } + } } - return 1; + return read_size; + } -itzam_btree* pers_db_open(PersistenceInfo_s* info, const char* dbPath) +int database_get(PersistenceInfo_s* info, const char* dbPath) { int arrayIdx = 0; - itzam_btree* btree = NULL; + int handleDB = -1; // create array index: index is a combination of resource config table type and group - arrayIdx = info->configKey.storage + info->context.ldbid; + arrayIdx = info->configKey.storage + info->context.ldbid ; //if(arrayIdx <= DbTableSize) if(arrayIdx < DbTableSize) { - if(gBtreeCreated[arrayIdx][info->configKey.policy] == 0) + if(gHandlesDBCreated[arrayIdx][info->configKey.policy] == 0) { - itzam_state state = ITZAM_FAILED; + char path[DbPathMaxLen] = {0}; if(PersistencePolicy_wt == info->configKey.policy) { - snprintf(path, DbPathMaxLen, "%s%s", dbPath, gWt); + snprintf(path, DbPathMaxLen, "%s%s", dbPath, gLocalWt); } else if(PersistencePolicy_wc == info->configKey.policy) { - snprintf(path, DbPathMaxLen, "%s%s", dbPath, gCached); + snprintf(path, DbPathMaxLen, "%s%s", dbPath, gLocalCached); } else { - return btree; + handleDB = -2; } - state = itzam_btree_open(&gBtree[arrayIdx][info->configKey.policy], path, - itzam_comparator_string, error_handler, 0/*recover*/, 0/*read_only*/); - if (state != ITZAM_OKAY) + if (handleDB == -1) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_open ==> itzam_btree_open => Itzam problem"), DLT_STRING(STATE_MESSAGES[state])); + handleDB = persComDbOpen(path, 0x01); + if(handleDB >= 0) + { + gHandlesDB[arrayIdx][info->configKey.policy] = handleDB ; + gHandlesDBCreated[arrayIdx][info->configKey.policy] = 1; + } + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("database_get ==> persComDbOpen() failed")); + } + } + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("database_get ==> wrong policy! Cannot extend dbPath wit database.")); } - gBtreeCreated[arrayIdx][info->configKey.policy] = 1; } - // assign database - btree = &gBtree[arrayIdx][info->configKey.policy]; + else + { + handleDB = gHandlesDB[arrayIdx][info->configKey.policy]; + } } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_open ==> invalid storage type"), DLT_STRING(dbPath)); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("database_get ==> invalid storage type"), DLT_STRING(dbPath)); } - return btree; -} -void pers_db_close(PersistenceInfo_s* info) + return handleDB; +} + + +void database_close(PersistenceInfo_s* info) { int arrayIdx = info->configKey.storage + info->context.ldbid; if(info->configKey.storage <= PersistenceStorage_shared ) { - itzam_state state = ITZAM_FAILED; - state = itzam_btree_close(&gBtree[arrayIdx][info->configKey.policy]); - if (state != ITZAM_OKAY) + int iErrorCode = persComDbClose(gHandlesDB[arrayIdx][info->configKey.policy]) ; + if (iErrorCode < 0) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_close ==> itzam_btree_close => Itzam problem"), DLT_STRING(STATE_MESSAGES[state])); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("database_close ==> persComDbClose() failed")); + } + else + { + gHandlesDBCreated[arrayIdx][info->configKey.policy] = 0; } - gBtreeCreated[arrayIdx][info->configKey.policy] = 0; } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_close ==> invalid storage type"), DLT_INT(info->context.ldbid )); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("database_close ==> invalid storage type"), DLT_INT(info->context.ldbid )); } } - - -void pers_db_close_all() +void database_close_all() { int i = 0; for(i=0; i<DbTableSize; i++) { // close write cached database - if(gBtreeCreated[i][PersistencePolicy_wc] == 1) + if(gHandlesDBCreated[i][PersistencePolicy_wc] == 1) { - itzam_state state = ITZAM_FAILED; - state = itzam_btree_close(&gBtree[i][PersistencePolicy_wc]); - if (state != ITZAM_OKAY) + int iErrorCode = persComDbClose(gHandlesDB[i][PersistencePolicy_wc]); + if (iErrorCode < 0) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_close_all ==> itzam_btree_close => Itzam problem:"), DLT_STRING(STATE_MESSAGES[state]) ); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("database_close_all => failed to close db => persComDbClose")); + } + else + { + gHandlesDBCreated[i][PersistencePolicy_wc] = 0; } - gBtreeCreated[i][PersistencePolicy_wc] = 0; } // close write through database - if(gBtreeCreated[i][PersistencePolicy_wt] == 1) + if(gHandlesDBCreated[i][PersistencePolicy_wt] == 1) { - itzam_state state = ITZAM_FAILED; - state = itzam_btree_close(&gBtree[i][PersistencePolicy_wt]); - if (state != ITZAM_OKAY) + int iErrorCode = persComDbClose(gHandlesDB[i][PersistencePolicy_wt]); + if (iErrorCode < 0) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_close_all ==>itzam_btree_close => Itzam problem:"), DLT_STRING(STATE_MESSAGES[state])); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("database_close_all => failed to close db => persComDbClose")); } - gBtreeCreated[i][PersistencePolicy_wt] = 0; - } - } -} - - -void pers_rct_close_all() -{ - int i = 0; - itzam_btree* resourceTable = NULL; - itzam_state state = ITZAM_FAILED; - - // close open persistence resource configuration table - for(i=0; i< PrctDbTableSize; i++) - { - resourceTable = (itzam_btree*)get_resource_cfg_table_by_idx(i); - // dereference opend database - if(resourceTable != NULL && get_resource_cfg_table_status(i) == 1) - { - state = itzam_btree_close(resourceTable); - invalidate_resource_cfg_table(i); - if (state != ITZAM_OKAY) + else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("process_prepare_shutdown => itzam_btree_close: Itzam problem"), DLT_STRING(STATE_MESSAGES[state])); + gHandlesDBCreated[i][PersistencePolicy_wt] = 0; } } } } -int pers_db_read_key(char* dbPath, char* key, PersistenceInfo_s* info, unsigned char* buffer, unsigned int buffer_size) + + +int persistence_get_data(char* dbPath, char* key, PersistenceInfo_s* info, unsigned char* buffer, unsigned int buffer_size) { int read_size = -1; + int ret_defaults = -1; if( PersistenceStorage_shared == info->configKey.storage || PersistenceStorage_local == info->configKey.storage) { - itzam_btree* btree = NULL; - int keyFound = 0; - - btree = pers_db_open(info, dbPath); - if(btree != NULL) + int handleDB = database_get(info, dbPath); + if(handleDB >= 0) { - KeyValuePair_s search; - - if(itzam_true == itzam_btree_find(btree, key, &search)) + read_size = persComDbReadKey(handleDB, key, (char*)buffer, buffer_size) ; + if(read_size < 0) { - read_size = search.m_data_size; - if(read_size > buffer_size) - { - read_size = buffer_size; // truncate data size to buffer size - } - memcpy(buffer, search.m_data, read_size); - keyFound = 1; + read_size = pers_get_defaults(dbPath, key, buffer, buffer_size, PersGetDefault_Data); /* 0 ==> Get data */ } } - if(keyFound == 0) // check for default values. - { - read_size = pers_get_default_data(dbPath, key, buffer, buffer_size); - } } else if(PersistenceStorage_custom == info->configKey.storage) // custom storage implementation via custom library { @@ -282,90 +327,25 @@ int pers_db_read_key(char* dbPath, char* key, PersistenceInfo_s* info, unsigned snprintf(pathKeyString, 128, "0x%08X/%s", info->context.ldbid, info->configKey.customID); } read_size = gPersCustomFuncs[idx].custom_plugin_get_data(pathKeyString, (char*)buffer, buffer_size); - - if(read_size < 0) // check if for custom storage default values are available - { - read_size = pers_get_default_data(dbPath, key, buffer, buffer_size); - } } else { read_size = EPERS_NOPLUGINFUNCT; } - } - return read_size; -} - - -int pers_get_default_data(char* dbPath, char* key, unsigned char* buffer, unsigned int buffer_size) -{ - int keyFound = 0; - int read_size = 0; - KeyValuePair_s search; - - itzam_state state = ITZAM_FAILED; - itzam_btree btreeConfDefault; - itzam_btree btreeDefault; - - // 1. check if _configurable_ default data is available - // -------------------------------- - if(pers_db_open_default(&btreeConfDefault, dbPath, 1) != -1) - { - if(itzam_true == itzam_btree_find(&btreeConfDefault, key, &search)) // read db + if (1 > read_size) { - read_size = search.m_data_size; - if(read_size > buffer_size) + info->configKey.policy = PersistencePolicy_wc; /* Set the policy */ + info->configKey.type = PersistenceResourceType_key; /* Set the type */ + (void)get_db_path_and_key(info, key, NULL, dbPath); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("Custom Key not available. Try to get default keys from:"), + DLT_STRING(dbPath), + DLT_STRING(key)); + ret_defaults = pers_get_defaults(dbPath, key, buffer, buffer_size, PersGetDefault_Data); + if (0 < ret_defaults) { - read_size = buffer_size; // truncate data size to buffer size + read_size = ret_defaults; } - memcpy(buffer, search.m_data, read_size); - - keyFound = 1; - } - else - { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_read_key ==> 2. resource not found in default config => search in default db"), DLT_STRING(key)); - } - - state = itzam_btree_close(&btreeConfDefault); - if (state != ITZAM_OKAY) - { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_read_key ==> default: itzam_btree_close => Itzam problem"), DLT_STRING(STATE_MESSAGES[state])); - } - } - - // 2. check if default data is available - // -------------------------------- - if(keyFound == 0) - { - if(pers_db_open_default(&btreeDefault, dbPath, 0) != -1) - { - if(itzam_true == itzam_btree_find(&btreeDefault, key, &search)) // read db - { - read_size = search.m_data_size; - if(read_size > buffer_size) - { - read_size = buffer_size; // truncate data size to buffer size - } - memcpy(buffer, search.m_data, read_size); - } - else - { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_read_key ==> 3. reasoure not found in both default db's"), DLT_STRING(key) ); - read_size = EPERS_NOKEY; // the key is not available neither in regular db nor in the default db's - } - - state = itzam_btree_close(&btreeDefault); - if (state != ITZAM_OKAY) - { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_read_key ==> default: itzam_btree_close => Itzam problem"), DLT_STRING(STATE_MESSAGES[state])); - } - } - else - { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_read_key ==>no resource config table"), DLT_STRING(dbPath), DLT_STRING(key) ); - read_size = EPERS_NOPRCTABLE; } } return read_size; @@ -373,85 +353,39 @@ int pers_get_default_data(char* dbPath, char* key, unsigned char* buffer, unsign -int pers_db_write_key(char* dbPath, char* key, PersistenceInfo_s* info, unsigned char* buffer, unsigned int buffer_size) +int persistence_set_data(char* dbPath, char* key, PersistenceInfo_s* info, unsigned char* buffer, unsigned int buffer_size) { int write_size = -1; if( PersistenceStorage_local == info->configKey.storage || PersistenceStorage_shared == info->configKey.storage ) { - write_size = buffer_size; - itzam_btree* btree = NULL; - itzam_state state = ITZAM_FAILED; - KeyValuePair_s insert; + int handleDB = -1 ; + - btree = pers_db_open(info, dbPath); - if(btree != NULL) + handleDB = database_get(info, dbPath); + if(handleDB >= 0) { - int keySize = 0; - keySize = (int)strlen((const char*)key); - if(keySize < DbKeySize) + write_size = persComDbWriteKey(handleDB, key, (char*)buffer, buffer_size) ; + if(write_size < 0) { - int dataSize = 0; - dataSize = (int)strlen( (const char*)buffer); - if(dataSize < DbValueSize) - { - // ----------------------------------------------------------------------------- - // transaction start - // itzam_btree_transaction_start(btree); - - // key - memset(insert.m_key, 0, DbKeySize); - memcpy(insert.m_key, key, keySize); - if(itzam_true == itzam_btree_find(btree, key, &insert)) - { - // key already available, so delete "old" key - state = itzam_btree_remove(btree, (const void *)&insert); - } - - // data - memset(insert.m_data, 0, DbValueSize); - memcpy(insert.m_data, buffer, dataSize); - - // data size - insert.m_data_size = buffer_size; - - state = itzam_btree_insert(btree,(const void *)&insert); - if (state != ITZAM_OKAY) - { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_write_key ==> itzam_btree_insert => Itzam problem"), DLT_STRING(STATE_MESSAGES[state]) ); - write_size = EPERS_DB_ERROR_INTERNAL; - } - - // itzam_btree_transaction_commit(btree); - // transaction end - // ----------------------------------------------------------------------------- - - if(PersistenceStorage_shared == info->configKey.storage) - { - int rval = pers_send_Notification_Signal(key, &info->context, pclNotifyStatus_changed); - if(rval <= 0) - { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_write_key ==> failed to send notification signal")); - write_size = rval; - } - } - } - else - { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_write_key ==> data to long » size:"), DLT_INT(dataSize), DLT_INT(DbValueSize) ); - write_size = EPERS_DB_VALUE_SIZE; - } + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("persistence_set_data ==> persComDbWriteKey() failure")); } - else + + if(PersistenceStorage_shared == info->configKey.storage) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_write_key ==> key to long » size"), DLT_INT(keySize), DLT_INT(DbKeySize) ); - write_size = EPERS_DB_KEY_SIZE; + int rval = pers_send_Notification_Signal(key, &info->context, pclNotifyStatus_changed); + if(rval <= 0) + { + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("persistence_set_data ==> failed to send notification signal")); + write_size = rval; + } } + } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_write_key ==> no resource config table"), DLT_STRING(dbPath), DLT_STRING(key)); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("persistence_set_data ==> no resource config table"), DLT_STRING(dbPath), DLT_STRING(key)); write_size = EPERS_NOPRCTABLE; } } @@ -471,12 +405,12 @@ int pers_db_write_key(char* dbPath, char* key, PersistenceInfo_s* info, unsigned } write_size = gPersCustomFuncs[idx].custom_plugin_set_data(pathKeyString, (char*)buffer, buffer_size); - if(write_size >= 0) // success ==> send deleted notification + if (write_size == buffer_size) /* Check return value and send notification if OK */ { int rval = pers_send_Notification_Signal(key, &info->context, pclNotifyStatus_changed); if(rval <= 0) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_write_key ==> failed to send notification signal")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("persistence_set_data ==> failed to send notification signal")); write_size = rval; } } @@ -491,44 +425,22 @@ int pers_db_write_key(char* dbPath, char* key, PersistenceInfo_s* info, unsigned -int pers_db_get_key_size(char* dbPath, char* key, PersistenceInfo_s* info) +int persistence_get_data_size(char* dbPath, char* key, PersistenceInfo_s* info) { int read_size = -1; + int ret_defaults = -1; if( PersistenceStorage_shared == info->configKey.storage || PersistenceStorage_local == info->configKey.storage) { - int keySize = 0; - itzam_btree* btree = NULL; - KeyValuePair_s search; - - btree = pers_db_open(info, dbPath); - if(btree != NULL) + int handleDB = database_get(info, dbPath); + if(handleDB >= 0) { - keySize = (int)strlen((const char*)key); - if(keySize < DbKeySize) + read_size = persComDbGetKeySize(handleDB, key); + if(read_size < 0) { - memset(search.m_key,0, DbKeySize); - memcpy(search.m_key, key, keySize); - if(itzam_true == itzam_btree_find(btree, key, &search)) - { - read_size = search.m_data_size; - } - else - { - read_size = EPERS_NOKEY; - } + read_size = pers_get_defaults(dbPath, key, NULL, 0, PersGetDefault_Size); } - else - { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_get_key_size ==> key to long"), DLT_INT(keySize), DLT_INT(DbKeySize)); - read_size = EPERS_DB_KEY_SIZE; - } - } - else - { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_get_key_size ==> no config table"), DLT_STRING(dbPath), DLT_STRING(key)); - read_size = EPERS_NOPRCTABLE; } } else if(PersistenceStorage_custom == info->configKey.storage) // custom storage implementation via custom library @@ -551,59 +463,57 @@ int pers_db_get_key_size(char* dbPath, char* key, PersistenceInfo_s* info) { read_size = EPERS_NOPLUGINFUNCT; } + + if (1 > read_size) + { + info->configKey.policy = PersistencePolicy_wc; /* Set the policy */ + info->configKey.type = PersistenceResourceType_key; /* Set the type */ + (void)get_db_path_and_key(info, key, NULL, dbPath); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("Custom Key not available. Try to get default keys from:"), + DLT_STRING(dbPath), + DLT_STRING(key)); + ret_defaults = pers_get_defaults(dbPath, key, NULL, 0, PersGetDefault_Size); + if (0 < ret_defaults) + { + read_size = ret_defaults; + } + } } return read_size; } -int pers_db_delete_key(char* dbPath, char* key, PersistenceInfo_s* info) +int persistence_delete_data(char* dbPath, char* key, PersistenceInfo_s* info) { int ret = 0; if(PersistenceStorage_custom != info->configKey.storage) { - itzam_btree* btree = NULL; - KeyValuePair_s delete; - - btree = pers_db_open(info, dbPath); - if(btree != NULL) + int handleDB = database_get(info, dbPath); + if(handleDB >= 0) { - int keySize = 0; - keySize = (int)strlen((const char*)key); - if(keySize < DbKeySize) + ret = persComDbDeleteKey(handleDB, key) ; + if(ret < 0) { - // ----------------------------------------------------------------------------- - // transaction start - itzam_btree_transaction_start(btree); - - itzam_state state; - - memset(delete.m_key,0, DbKeySize); - memcpy(delete.m_key, key, keySize); - state = itzam_btree_remove(btree, (const void *)&delete); - if (state != ITZAM_OKAY) + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("persistence_delete_data => persComDbDeleteKey failed: "), DLT_STRING(key)); + if(PERS_COM_ERR_NOT_FOUND == ret) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_delete_key ==> itzam_btree_remove => Itzam problem"), DLT_STRING(STATE_MESSAGES[state])); - ret = EPERS_DB_ERROR_INTERNAL; + ret = EPERS_NOKEY ; } - itzam_btree_transaction_commit(btree); - // transaction end - // ----------------------------------------------------------------------------- - - if(PersistenceStorage_shared == info->configKey.storage) + else { - ret = pers_send_Notification_Signal(key, &info->context, pclNotifyStatus_deleted); + ret = EPERS_DB_ERROR_INTERNAL ; } } - else + + if(PersistenceStorage_shared == info->configKey.storage) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_delete_key ==> key to long"), DLT_INT(keySize), DLT_INT(DbKeySize)); - ret = EPERS_DB_KEY_SIZE; + pers_send_Notification_Signal(key, &info->context, pclNotifyStatus_deleted); } } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_delete_key ==> no resource config table"), DLT_STRING(dbPath), DLT_STRING(key)); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("persistence_delete_data ==> no resource config table"), DLT_STRING(dbPath), DLT_STRING(key)); ret = EPERS_NOPRCTABLE; } } @@ -622,9 +532,10 @@ int pers_db_delete_key(char* dbPath, char* key, PersistenceInfo_s* info) snprintf(pathKeyString, 128, "0x%08X/%s", info->context.ldbid, info->configKey.customID); } ret = gPersCustomFuncs[idx].custom_plugin_delete_data(pathKeyString); - if(ret >= 0) // success ==> send deleted notification + + if(0 <= ret) /* Check return value and send notification if OK */ { - ret = pers_send_Notification_Signal(key, &info->context, pclNotifyStatus_deleted); + pers_send_Notification_Signal(key, &info->context, pclNotifyStatus_deleted); } } else @@ -662,7 +573,7 @@ int persistence_notify_on_change(char* key, unsigned int ldbid, unsigned int use if(-1 == deliverToMainloop(CMD_REG_NOTIFY_SIGNAL, 0, 0)) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("persistence_notify_on_change => failed to write to pipe"), DLT_INT(errno)); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("persistence_notify_on_change => failed to write to pipe"), DLT_INT(errno)); rval = -1; } } @@ -693,7 +604,7 @@ int pers_send_Notification_Signal(const char* key, PersistenceDbContext_s* conte if(-1 == deliverToMainloop(CMD_SEND_NOTIFY_SIGNAL, 0,0) ) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_send_Notification_Signal => failed to write to pipe"), DLT_INT(errno)); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_send_Notification_Signal => failed to write to pipe"), DLT_INT(errno)); rval = EPERS_NOTIFY_SIG; } } @@ -706,278 +617,18 @@ int pers_send_Notification_Signal(const char* key, PersistenceDbContext_s* conte } -//--------------------------------------------------------------------------------------------------------- -// C U R S O R F U N C T I O N S -//--------------------------------------------------------------------------------------------------------- - -int get_cursor_handle() -{ - int handle = 0; - - if(pthread_mutex_lock(&gCursorMtx) == 0) - { - if(gFreeCursorHandleIdxHead > 0) // check if we have a free spot in the array before the current max - { - handle = gFreeCursorHandleArray[--gFreeCursorHandleIdxHead]; - } - else - { - if(gHandleIdx < MaxPersHandle-1) - { - handle = gHandleIdx++; // no free spot before current max, increment handle index - } - else - { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("get_cursor_handle ==> Reached maximum of open handles:"), DLT_INT(MaxPersHandle)); - handle = -1; - } - } - pthread_mutex_unlock(&gCursorMtx); - } - return handle; -} - - -void close_cursor_handle(int handlerDB) -{ - if(pthread_mutex_lock(&gCursorMtx) == 0) - { - if(gFreeCursorHandleIdxHead < MaxPersHandle) - { - gFreeCursorHandleArray[gFreeCursorHandleIdxHead++] = handlerDB; - } - pthread_mutex_unlock(&gCursorMtx); - } -} - - - -int pers_db_cursor_create(char* dbPath) -{ - int handle = -1; - itzam_state state = ITZAM_FAILED; - - handle = get_cursor_handle(); - - if(handle < MaxPersHandle && handle >= 0) - { - // open database - state = itzam_btree_open(&gCursorArray[handle].m_btree, dbPath, itzam_comparator_string, error_handler, 1/*recover*/, 0/*read_only*/); - if (state != ITZAM_OKAY) - { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_cursor_create ==> itzam_btree_open"), DLT_STRING(STATE_MESSAGES[state])); - } - else - { - itzam_state state; - - state = itzam_btree_cursor_create(&gCursorArray[handle].m_cursor, &gCursorArray[handle].m_btree); - if(state == ITZAM_OKAY) - { - gCursorArray[handle].m_empty = 0; - } - else - { - gCursorArray[handle].m_empty = 1; - } - } - } - return handle; -} - - - -int pers_db_cursor_next(unsigned int handlerDB) -{ - int rval = -99; - - //if(handlerDB < MaxPersHandle && handlerDB >= 0) - if(handlerDB < MaxPersHandle ) - { - if(gCursorArray[handlerDB].m_empty != 1) - { - itzam_bool success; - success = itzam_btree_cursor_next(&gCursorArray[handlerDB].m_cursor); - - if(success == itzam_true) - { - rval = 0; - } - else - { - rval = EPERS_LAST_ENTRY_IN_DB; - } - } - else - { - printf("Invalid handle\n"); - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_cursor_next ==> invalid handle: "), DLT_INT(handlerDB)); - } - } - else - { - printf("Handle bigger than max\n"); - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_cursor_next ==> handle bigger than max:"), DLT_INT(MaxPersHandle)); - } - return rval; -} - - - -int pers_db_cursor_get_key(unsigned int handlerDB, char * bufKeyName_out, int bufSize) -{ - int rval = -1; - KeyValuePair_s search; - - if(handlerDB < MaxPersHandle) - { - if(gCursorArray[handlerDB].m_empty != 1) - { - int length = 0; - itzam_btree_cursor_read(&gCursorArray[handlerDB].m_cursor ,(void *)&search); - length = strlen(search.m_key); - if(length < bufSize) - { - memcpy(bufKeyName_out, search.m_key, length); - rval = 0; - } - else - { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_cursor_get_key ==> buffer to small » keySize: "), DLT_INT(bufSize)); - } - } - else - { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("persistence_db_cursor_get_key ==> invalid handle:"), DLT_INT(handlerDB)); - } - } - else - { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("persistence_db_cursor_get_key ==> handle bigger than max:"), DLT_INT(MaxPersHandle)); - } - return rval; -} - - - -int pers_db_cursor_get_data(unsigned int handlerDB, char * bufData_out, int bufSize) -{ - int rval = -1; - KeyValuePair_s search; - - if(handlerDB < MaxPersHandle) - { - if(gCursorArray[handlerDB].m_empty != 1) - { - int length = 0; - itzam_btree_cursor_read(&gCursorArray[handlerDB].m_cursor ,(void *)&search); - - length = strlen(search.m_data); - if(length < bufSize) - { - memcpy(bufData_out, search.m_data, length); - rval = 0; - } - else - { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_cursor_get_data ==> buffer to small » keySize: "), DLT_INT(bufSize)); - } - } - else - { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("persistence_db_cursor_get_data ==> invalid handle:"), DLT_INT(handlerDB)); - } - } - else - { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("persistence_db_cursor_get_data ==> handle bigger than max:"), DLT_INT(MaxPersHandle)); - } - return rval; -} - - - -int pers_db_cursor_get_data_size(unsigned int handlerDB) +void pers_rct_close_all() { - int size = -1; - KeyValuePair_s search; + int i = 0, rval = 0; - if(handlerDB < MaxPersHandle) - { - if(gCursorArray[handlerDB].m_empty != 1) - { - itzam_btree_cursor_read(&gCursorArray[handlerDB].m_cursor ,(void *)&search); - size = strlen(search.m_data); - } - else - { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_cursor_get_data_size ==> invalid handle:"), DLT_INT(handlerDB)); - } - } - else - { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("persistence_db_cursor_get_data ==> handle bigger than max:"), DLT_INT(MaxPersHandle)); - } - return size; -} - - - -int pers_db_cursor_destroy(unsigned int handlerDB) -{ - int rval = -1; - if(handlerDB < MaxPersHandle) + // close open persistence resource configuration table + for(i=0; i< PrctDbTableSize; i++) { - itzam_btree_cursor_free(&gCursorArray[handlerDB].m_cursor); - gCursorArray[handlerDB].m_empty = 1; - - itzam_state state = ITZAM_FAILED; - state = itzam_btree_close(&gCursorArray[handlerDB].m_btree); - if (state != ITZAM_OKAY) + rval = persComRctClose(i); + if (rval != 0) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_cursor_destroy ==> itzam_btree_close: Itzam problem"), DLT_STRING(STATE_MESSAGES[state])); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("process_prepare_shutdown => failed to close db:"), DLT_INT(rval)); } - - close_cursor_handle(handlerDB); - - rval = 0; } - return rval; } - - - -//----------------------------------------------------------------------------- -// code to print database content (for debugging) -//----------------------------------------------------------------------------- -// walk the database -/* -KeyValuePair_s rec; -itzam_btree_cursor cursor; -state = itzam_btree_cursor_create(&cursor, &btree); -if(state == ITZAM_OKAY) -{ - printf("==> Database content ==> db size: %d\n", (int)itzam_btree_count(&btree)); - do - { - // get the key pointed to by the cursor - state = itzam_btree_cursor_read(&cursor,(void *)&rec); - if (state == ITZAM_OKAY) - { - printf(" Key: %s \n ==> data: %s\n", rec.m_key, rec.m_data); - } - else - fprintf(stderr, "\nItzam problem: %s\n", STATE_MESSAGES[state]); - } - while (itzam_btree_cursor_next(&cursor)); - - state = itzam_btree_cursor_free(&cursor); -} -*/ -//----------------------------------------------------------------------------- - - - - - diff --git a/include_protected/persistence_client_library_db_access.h b/src/persistence_client_library_db_access.h index 3c560f6..2cb7076 100644 --- a/include_protected/persistence_client_library_db_access.h +++ b/src/persistence_client_library_db_access.h @@ -28,10 +28,54 @@ extern "C" { #include "persistence_client_library_data_organization.h" -#include "persistence_client_library_rc_table.h" + +//#include "persistence_client_library_rc_table.h" +#include <persComRct.h> + #include "../include/persistence_client_library_key.h" + +/** + * @brief get the raw key without prefixed '/node/', '/user/3/' etc + * + * @param key the ptr. to the key which should be stripped + * + * @return the pointer to the stripped 'raw key' + */ +char* pers_get_raw_key(char *key); + + + +/** + * @brief open the default value database specified by the 'DefaultType' + * + * @param dbPath path to the directory were the databases are included in. + * + * @return >= 0 for valid handler; if an error occured the following error code: + * EPERS_COMMON + */ +int pers_db_open_default(const char* dbPath, PersDefaultType_e DefaultType); + + + +/** + * @brief tries to get default values for a key from the configurable and factory default databases. + * + * @param dbPath the path to the directory where the default databases are in + * @param key the database key + * @param buffer the buffer holding the data + * @param buffer_size the size of the buffer + * @param job the info to specify what to do. Get Data or the DataSize. + * + * @return the number of bytes read or the size of the key (depends on parameter 'job'). + negative value if an error occured and the following error code: + * EPERS_NOKEY + */ +int pers_get_defaults(char* dbPath, char* key, unsigned char* buffer, unsigned int buffer_size, PersGetDefault_e job); + + + /** * @brief write data to a key * @@ -44,7 +88,7 @@ extern "C" { * @return the number of bytes written or a negative value if an error occured with the following error codes: * EPERS_SETDTAFAILED EPERS_NOPRCTABLE EPERS_NOKEYDATA EPERS_NOKEY */ -int pers_db_write_key(char* dbPath, char* key, PersistenceInfo_s* info, unsigned char* buffer, unsigned int buffer_size); +int persistence_set_data(char* dbPath, char* key, PersistenceInfo_s* info, unsigned char* buffer, unsigned int buffer_size); @@ -60,7 +104,7 @@ int pers_db_write_key(char* dbPath, char* key, PersistenceInfo_s* info, unsigned * @return the number of bytes read or a negative value if an error occured with the following error codes: * EPERS_NOPRCTABLE EPERS_NOKEYDATA EPERS_NOKEY */ -int pers_db_read_key(char* dbPath, char* key, PersistenceInfo_s* info, unsigned char* buffer, unsigned int buffer_size); +int persistence_get_data(char* dbPath, char* key, PersistenceInfo_s* info, unsigned char* buffer, unsigned int buffer_size); @@ -74,7 +118,7 @@ int pers_db_read_key(char* dbPath, char* key, PersistenceInfo_s* info, unsigned * @return size of data in bytes read from the key or on error a negative value with the following error codes: * EPERS_NOPRCTABLE or EPERS_NOKEY */ -int pers_db_get_key_size(char* dbPath, char* key, PersistenceInfo_s* info); +int persistence_get_data_size(char* dbPath, char* key, PersistenceInfo_s* info); @@ -88,7 +132,7 @@ int pers_db_get_key_size(char* dbPath, char* key, PersistenceInfo_s* info); * @return 0 if deletion was successfull; * or an error code: EPERS_DB_KEY_SIZE, EPERS_NOPRCTABLE, EPERS_DB_ERROR_INTERNAL or EPERS_NOPLUGINFUNCT */ -int pers_db_delete_key(char* dbPath, char* key, PersistenceInfo_s* info); +int persistence_delete_data(char* dbPath, char* key, PersistenceInfo_s* info); @@ -97,20 +141,15 @@ int pers_db_delete_key(char* dbPath, char* key, PersistenceInfo_s* info); * * @param info persistence information */ -void pers_db_close(PersistenceInfo_s* info); +void database_close(PersistenceInfo_s* info); /** * @brief close all databases */ -void pers_db_close_all(); - +void database_close_all(); -/** - * @brief close all rct's - */ -void pers_rct_close_all(); /** @@ -118,7 +157,7 @@ void pers_rct_close_all(); * * @param key the database key to register on * @param ldbid logical database ID of the resource to monitor - * @param user_no the user ID; user_no=0 can not be used as user-ID beacause ‘0’ is defined as System/node + * @param user_no the user ID; user_no=0 can not be used as user-ID beacause '0' is defined as System/node * @param seat_no the seat number * @param callback the function callback to be called * @param regPolic ::Notify_register to register; ::Notify_unregister to unregister @@ -141,70 +180,8 @@ int persistence_notify_on_change(char* key, unsigned int ldbid, unsigned int use */ int pers_send_Notification_Signal(const char* key, PersistenceDbContext_s* context, pclNotifyStatus_e reason); -//--------------------------------------------------------------------------------------------- -// C U R S O R F U N C T I O N S -//--------------------------------------------------------------------------------------------- - -/** - * @brief create a cursor to a DB ; if success, the cursor points to (-1) - * to access the first entry in DB, call persistence_db_cursor_next - * - * @param dbPath[in] absolute path to the database - * - * @return handler to the DB (to be used in successive calls) or error code (< 0) - */ -int pers_db_cursor_create(char* dbPath); - -/** - * @brief move cursor to the next position - * - * @param handlerDB[in] handler to DB (obtained with persistence_db_cursor_create()) - * - * @return 0 for success, negative value in case of error (check against EPERS_LAST_ENTRY_IN_DB) - */ -int pers_db_cursor_next(unsigned int handlerDB); - -/** - * @brief get the name of the key pointed by the cursor associated with the database - * - * @param handlerDB[in] handler to DB (obtained with persistence_db_cursor_create()) - * @param bufKeyName_out[out] buffer where to pass the name of the key - * @param bufSize[out] size of bufKeyName_out - * - * @return read size (if >= 0), error other way - */ -int pers_db_cursor_get_key(unsigned int handlerDB, char * bufKeyName_out, int bufSize) ; - -/** - * @brief get the data of the key pointed by the cursor associated with the database - * - * @param handlerDB[in] handler to DB (obtained with persistence_db_cursor_create()) - * @param bufKeyData_out[out] buffer where to pass the data of the key - * @param bufSize[out] size of bufKeyData_out - * - * @return read size (if >= 0), error other way - */ -int pers_db_cursor_get_data(unsigned int handlerDB, char * bufData_out, int bufSize) ; - -/** - * @brief get the data size of the key pointed by the cursor associated with the database - * - * @param handlerDB[in] handler to DB (obtained with persistence_db_cursor_create()) - * - * @return positive value for data size, negative value for error - */ -int pers_db_cursor_get_data_size(unsigned int handlerDB) ; - - -/** - * @brief remove the cursor - * - * @param handlerDB[in] handler to DB (obtained with persistence_db_cursor_create()) - * - * @return 0 for success, negative value in case of error - */ -int pers_db_cursor_destroy(unsigned int handlerDB) ; +void pers_rct_close_all(); #ifdef __cplusplus } diff --git a/src/persistence_client_library_dbus_cmd.c b/src/persistence_client_library_dbus_cmd.c index c8a138c..e64dfe8 100644 --- a/src/persistence_client_library_dbus_cmd.c +++ b/src/persistence_client_library_dbus_cmd.c @@ -19,15 +19,12 @@ #include "persistence_client_library_dbus_cmd.h" #include "persistence_client_library_handle.h" -#include "persistence_client_library_itzam_errors.h" #include "persistence_client_library_custom_loader.h" -#include "persistence_client_library_prct_access.h" #include "persistence_client_library_pas_interface.h" -#include "../include_protected/persistence_client_library_data_organization.h" -#include "../include_protected/persistence_client_library_db_access.h" +#include "persistence_client_library_data_organization.h" +#include "persistence_client_library_db_access.h" -#include <itzam.h> #include <dlfcn.h> @@ -136,22 +133,22 @@ void process_send_notification_signal(DBusConnection* conn) } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("process_send_Notification_Signal ==> failed to send dbus message!!")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("process_send_Notification_Signal ==> failed to send dbus message!!")); } } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("process_send_Notification_Signal ==> E R R O R C O N E C T I O N NULL!!")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("process_send_Notification_Signal ==> E R R O R C O N E C T I O N NULL!!")); } } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("process_send_Notification_Signal ==> ERROR dbus_message_append_args")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("process_send_Notification_Signal ==> ERROR dbus_message_append_args")); } } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("process_send_Notification_Signal ==> ERROR invalid notification reason")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("process_send_Notification_Signal ==> ERROR invalid notification reason")); } } @@ -159,6 +156,8 @@ void process_send_notification_signal(DBusConnection* conn) void process_block_and_write_data_back(unsigned int requestID, unsigned int status) { + (void)requestID; + (void)status; // lock persistence data access pers_lock_access(); // sync data back to memory device @@ -173,6 +172,9 @@ void process_prepare_shutdown(unsigned char requestId, unsigned int status) { int i = 0; + (void)requestId; + (void)status; + // block write pers_lock_access(); @@ -191,7 +193,7 @@ void process_prepare_shutdown(unsigned char requestId, unsigned int status) pers_rct_close_all(); // close opend database - pers_db_close_all(); + database_close_all(); // unload custom client libraries @@ -230,7 +232,7 @@ void process_send_pas_request(DBusConnection* conn, unsigned int requestID, int if(!dbus_connection_send(conn, message, 0)) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("send_lifecycle_register => Access denied"), DLT_STRING(error.message) ); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("send_lifecycle_register => Access denied"), DLT_STRING(error.message) ); } dbus_connection_flush(conn); @@ -238,12 +240,12 @@ void process_send_pas_request(DBusConnection* conn, unsigned int requestID, int } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("send_pas_request => ERROR: Invalid message") ); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("send_pas_request => ERROR: Invalid message") ); } } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("send_pas_request => ERROR: Invalid connection") ); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("send_pas_request => ERROR: Invalid connection") ); } } @@ -290,24 +292,24 @@ void process_send_pas_register(DBusConnection* conn, int regType, int notificati if(!dbus_pending_call_set_notify(pending, msg_pending_func, method, NULL)) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("process_send_pas_register => dbus_pending_call_set_notify: FAILED\n") ); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("process_send_pas_register => dbus_pending_call_set_notify: FAILED\n") ); } dbus_pending_call_unref(pending); } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("send_pas_register => ERROR: Invalid message") ); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("send_pas_register => ERROR: Invalid message") ); } dbus_message_unref(message); } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("send_pas_register => ERROR: Invalid busname") ); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("send_pas_register => ERROR: Invalid busname") ); } } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("send_pas_register => ERROR: Invalid connection") ); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("send_pas_register => ERROR: Invalid connection") ); } } @@ -351,19 +353,19 @@ void process_send_lifecycle_register(DBusConnection* conn, int regType, int shut if(!dbus_connection_send(conn, message, 0)) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("send_lifecycle_register => Access denied"), DLT_STRING(error.message) ); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("send_lifecycle_register => Access denied"), DLT_STRING(error.message) ); } dbus_connection_flush(conn); dbus_message_unref(message); } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("send_lifecycle_register => ERROR: Invalid message")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("send_lifecycle_register => ERROR: Invalid message")); } } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("send_lifecycle_register => ERROR: connection isn NULL")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("send_lifecycle_register => ERROR: connection isn NULL")); } } @@ -389,7 +391,7 @@ void process_send_lifecycle_request(DBusConnection* conn, int requestId, int sta if(!dbus_connection_send(conn, message, 0)) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("send_lifecycle_request => Access denied"), DLT_STRING(error.message) ); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("send_lifecycle_request => Access denied"), DLT_STRING(error.message) ); } dbus_connection_flush(conn); @@ -397,12 +399,12 @@ void process_send_lifecycle_request(DBusConnection* conn, int requestId, int sta } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("send_lifecycle_request => ERROR: Invalid message")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("send_lifecycle_request => ERROR: Invalid message")); } } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("send_lifecycle_request => ERROR: connection isn NULL")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("send_lifecycle_request => ERROR: connection isn NULL")); } } @@ -414,11 +416,13 @@ void msg_pending_func(DBusPendingCall *call, void *data) DBusError err; dbus_error_init(&err); + (void)data; + DBusMessage *message = dbus_pending_call_steal_reply(call); if (dbus_set_error_from_message(&err, message)) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("msg_pending_func ==> Access denied") ); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("msg_pending_func ==> Access denied") ); } else { diff --git a/src/persistence_client_library_dbus_service.c b/src/persistence_client_library_dbus_service.c index 608ae87..694cd6a 100644 --- a/src/persistence_client_library_dbus_service.c +++ b/src/persistence_client_library_dbus_service.c @@ -21,7 +21,7 @@ #include "persistence_client_library_lc_interface.h" #include "persistence_client_library_pas_interface.h" #include "persistence_client_library_dbus_cmd.h" -#include "../include_protected/persistence_client_library_data_organization.h" +#include "persistence_client_library_data_organization.h" #include <stdio.h> @@ -88,13 +88,16 @@ int bContinue = 0; /* function to unregister ojbect path message handler */ static void unregisterMessageHandler(DBusConnection *connection, void *user_data) { - DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("unregisterObjectPath\n")); + (void)connection; + (void)user_data; + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("unregisterObjectPath\n")); } /* catches messages not directed to any registered object path ("garbage collector") */ static DBusHandlerResult handleObjectPathMessageFallback(DBusConnection * connection, DBusMessage * message, void * user_data) { DBusHandlerResult result = DBUS_HANDLER_RESULT_HANDLED; + (void)user_data; // org.genivi.persistence.admin S I G N A L if((0==strcmp("org.genivi.persistence.admin", dbus_message_get_interface(message)))) @@ -108,7 +111,7 @@ static DBusHandlerResult handleObjectPathMessageFallback(DBusConnection * connec } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("handleObjectPathMessageFallback -> unknown signal:"), DLT_STRING(dbus_message_get_interface(message)) ); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("handleObjectPathMessageFallback -> unknown signal:"), DLT_STRING(dbus_message_get_interface(message)) ); } } } @@ -155,12 +158,12 @@ static DBusHandlerResult handleObjectPathMessageFallback(DBusConnection * connec if (reply == 0) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("handleObjectPathMessageFallback => DBus No memory"), DLT_STRING(dbus_message_get_interface(message)) ); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("handleObjectPathMessageFallback => DBus No memory"), DLT_STRING(dbus_message_get_interface(message)) ); } if (!dbus_connection_send(connection, reply, 0)) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("handleObjectPathMessageFallback => DBus No memory"), DLT_STRING(dbus_message_get_interface(message)) ); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("handleObjectPathMessageFallback => DBus No memory"), DLT_STRING(dbus_message_get_interface(message)) ); } result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;; @@ -179,7 +182,7 @@ static DBusHandlerResult handleObjectPathMessageFallback(DBusConnection * connec } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("handleObjectPathMessageFallback => gChangeNotifyCallback is not set (possibly NULL)") ); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("handleObjectPathMessageFallback => gChangeNotifyCallback is not set (possibly NULL)") ); } result = DBUS_HANDLER_RESULT_HANDLED; } @@ -215,12 +218,12 @@ static DBusHandlerResult handleObjectPathMessageFallback(DBusConnection * connec } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("handleObjectPathMessageFallback -> unknown property:"), DLT_STRING(dbus_message_get_interface(message)) ); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("handleObjectPathMessageFallback -> unknown property:"), DLT_STRING(dbus_message_get_interface(message)) ); } } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("handleObjectPathMessageFallback -> not a signal:"), DLT_STRING(dbus_message_get_member(message)) ); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("handleObjectPathMessageFallback -> not a signal:"), DLT_STRING(dbus_message_get_member(message)) ); } } return result; @@ -230,7 +233,9 @@ static DBusHandlerResult handleObjectPathMessageFallback(DBusConnection * connec static void unregisterObjectPathFallback(DBusConnection *connection, void *user_data) { - DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("unregisterObjectPathFallback\n")); + (void)connection; + (void)user_data; + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("unregisterObjectPathFallback\n")); } @@ -239,15 +244,15 @@ void* run_mainloop(void* dataPtr) { // persistence admin message static const struct DBusObjectPathVTable vtablePersAdmin - = {unregisterMessageHandler, checkPersAdminMsg, NULL, }; + = {unregisterMessageHandler, checkPersAdminMsg, NULL, NULL, NULL, NULL}; // lifecycle message static const struct DBusObjectPathVTable vtableLifecycle - = {unregisterMessageHandler, checkLifecycleMsg, NULL, }; + = {unregisterMessageHandler, checkLifecycleMsg, NULL, NULL, NULL, NULL}; // fallback static const struct DBusObjectPathVTable vtableFallback - = {unregisterObjectPathFallback, handleObjectPathMessageFallback, NULL, }; + = {unregisterObjectPathFallback, handleObjectPathMessageFallback, NULL, NULL, NULL, NULL}; // setup the dbus mainLoop(vtablePersAdmin, vtableLifecycle, vtableFallback, dataPtr); @@ -273,7 +278,7 @@ int setup_dbus_mainloop(void) // Connect to the bus and check for errors if(pAddress != NULL) { - DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("setup_dbus_mainloop -> Use specific dbus address:"), DLT_STRING(pAddress) ); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("setup_dbus_mainloop -> Use specific dbus address:"), DLT_STRING(pAddress) ); conn = dbus_connection_open_private(pAddress, &err); @@ -281,7 +286,7 @@ int setup_dbus_mainloop(void) { if(!dbus_bus_register(conn, &err)) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("dbus_bus_register() Error :"), DLT_STRING(err.message) ); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("dbus_bus_register() Error :"), DLT_STRING(err.message) ); dbus_error_free (&err); pthread_mutex_unlock(&gDbusInitializedMtx); return -1; @@ -289,7 +294,7 @@ int setup_dbus_mainloop(void) } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("dbus_connection_open_private() Error :"), DLT_STRING(err.message) ); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("dbus_connection_open_private() Error :"), DLT_STRING(err.message) ); dbus_error_free(&err); pthread_mutex_unlock(&gDbusInitializedMtx); return -1; @@ -297,7 +302,7 @@ int setup_dbus_mainloop(void) } else { - DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("Use default dbus bus (DBUS_BUS_SYSTEM)")); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("Use default dbus bus (DBUS_BUS_SYSTEM)")); conn = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err); } @@ -306,7 +311,7 @@ int setup_dbus_mainloop(void) rval = pthread_create(&gMainLoopThread, NULL, run_mainloop, conn); if(rval) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pthread_create( DBUS run_mainloop ) returned an error:"), DLT_INT(rval) ); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pthread_create( DBUS run_mainloop ) returned an error:"), DLT_INT(rval) ); pthread_mutex_unlock(&gDbusInitializedMtx); return -1; } @@ -325,6 +330,7 @@ int setup_dbus_mainloop(void) static dbus_bool_t addWatch(DBusWatch *watch, void *data) { dbus_bool_t result = FALSE; + (void)data; if (ARRAY_SIZE(gPollInfo.fds)>gPollInfo.nfds) { @@ -362,7 +368,9 @@ static void removeWatch(DBusWatch *watch, void *data) { void* w_data = dbus_watch_get_data(watch); - DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("removeWatch called "), DLT_INT( (int)watch) ); + (void)data; + + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("removeWatch called "), DLT_INT( (int)watch) ); if(w_data) free(w_data); @@ -374,7 +382,8 @@ static void removeWatch(DBusWatch *watch, void *data) static void watchToggled(DBusWatch *watch, void *data) { - DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("watchToggled called "), DLT_INT( (int)watch) ); + (void)data; + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("watchToggled called "), DLT_INT( (int)watch) ); if(dbus_watch_get_enabled(watch)) addWatch(watch, data); @@ -386,6 +395,7 @@ static void watchToggled(DBusWatch *watch, void *data) static dbus_bool_t addTimeout(DBusTimeout *timeout, void *data) { + (void)data; dbus_bool_t ret = FALSE; if (ARRAY_SIZE(gPollInfo.fds)>gPollInfo.nfds) @@ -409,18 +419,18 @@ static dbus_bool_t addTimeout(DBusTimeout *timeout, void *data) } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("addTimeout => timerfd_settime() failed"), DLT_STRING(strerror(errno)) ); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("addTimeout => timerfd_settime() failed"), DLT_STRING(strerror(errno)) ); } } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("addTimeout => timerfd_create() failed"), DLT_STRING(strerror(errno)) ); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("addTimeout => timerfd_create() failed"), DLT_STRING(strerror(errno)) ); } } } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("addTimeout => cannot create another fd to be poll()'ed")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("addTimeout => cannot create another fd to be poll()'ed")); } return ret; @@ -430,15 +440,16 @@ static dbus_bool_t addTimeout(DBusTimeout *timeout, void *data) static void removeTimeout(DBusTimeout *timeout, void *data) { - int i = gPollInfo.nfds; + (void)data; + while ((0<i--)&&(timeout!=gPollInfo.objects[i].timeout)); if (0<i) { if (-1==close(gPollInfo.fds[i].fd)) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("removeTimeout => close() timerfd"), DLT_STRING(strerror(errno)) ); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("removeTimeout => close() timerfd"), DLT_STRING(strerror(errno)) ); } --gPollInfo.nfds; @@ -460,15 +471,17 @@ static void removeTimeout(DBusTimeout *timeout, void *data) static void timeoutToggled(DBusTimeout *timeout, void *data) { int i = gPollInfo.nfds; + (void)data; + while ((0<i--)&&(timeout!=gPollInfo.objects[i].timeout)); - DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("timeoutToggled") ); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("timeoutToggled") ); if (0<i) { const int interval = (TRUE==dbus_timeout_get_enabled(timeout))?dbus_timeout_get_interval(timeout):0; const struct itimerspec its = { .it_value= {interval/1000, interval%1000} }; if (-1!=timerfd_settime(gPollInfo.fds[i].fd, 0, &its, NULL)) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("timeoutToggled => timerfd_settime()"), DLT_STRING(strerror(errno)) ); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("timeoutToggled => timerfd_settime()"), DLT_STRING(strerror(errno)) ); } } } @@ -487,7 +500,7 @@ int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtable2, if (dbus_error_is_set(&err)) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop => Connection Error:"), DLT_STRING(err.message) ); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop => Connection Error:"), DLT_STRING(err.message) ); dbus_error_free(&err); } else if (NULL != conn) @@ -495,7 +508,7 @@ int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtable2, dbus_connection_set_exit_on_disconnect(conn, FALSE); if (-1 == (gEfds = eventfd(0, 0))) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop => eventfd() failed w/ errno:"), DLT_INT(errno) ); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop => eventfd() failed w/ errno:"), DLT_INT(errno) ); } else { @@ -518,7 +531,7 @@ int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtable2, if( (TRUE!=dbus_connection_set_watch_functions(conn, addWatch, removeWatch, watchToggled, NULL, NULL)) || (TRUE!=dbus_connection_set_timeout_functions(conn, addTimeout, removeTimeout, timeoutToggled, NULL, NULL)) ) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop => dbus_connection_set_watch_functions() failed")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop => dbus_connection_set_watch_functions() failed")); } else { @@ -534,7 +547,7 @@ int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtable2, if (0>ret) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop => poll() failed w/ errno "), DLT_INT(errno) ); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop => poll() failed w/ errno "), DLT_INT(errno) ); } else if (0==ret) { @@ -555,13 +568,13 @@ int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtable2, unsigned long long nExpCount = 0; if ((ssize_t)sizeof(nExpCount)!=read(gPollInfo.fds[i].fd, &nExpCount, sizeof(nExpCount))) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop => read failed")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop => read failed")); } - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop => timeout")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop => timeout")); if (FALSE==dbus_timeout_handle(gPollInfo.objects[i].timeout)) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop => dbus_timeout_handle() failed!?")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop => dbus_timeout_handle() failed!?")); } bContinue = TRUE; } @@ -575,7 +588,7 @@ int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtable2, while ((-1==(ret = read(gPollInfo.fds[i].fd, buf, 64)))&&(EINTR == errno)); if(ret < 0) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop => read() failed"), DLT_STRING(strerror(errno)) ); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop => read() failed"), DLT_STRING(strerror(errno)) ); } else { @@ -617,7 +630,7 @@ int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtable2, */ // ****************************************************** default: - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop => command not handled"), DLT_INT(buf[0]) ); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop => command not handled"), DLT_INT(buf[0]) ); break; } pthread_cond_signal(&gMainLoopCond); @@ -702,7 +715,7 @@ int deliverToMainloop_NM(tCmd mainloopCmd, unsigned int param1, unsigned int par if(-1 == write(gEfds, &cmd, (sizeof(uint64_t)))) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("deliverToMainloop => failed to write to pipe"), DLT_INT(errno)); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("deliverToMainloop => failed to write to pipe"), DLT_INT(errno)); rval = -1; } diff --git a/src/persistence_client_library_file.c b/src/persistence_client_library_file.c index a331140..2bf14bf 100644 --- a/src/persistence_client_library_file.c +++ b/src/persistence_client_library_file.c @@ -19,14 +19,16 @@ #include "persistence_client_library_file.h" #include "persistence_client_library_backup_filelist.h" -#include "../include_protected/persistence_client_library_data_organization.h" -#include "../include_protected/persistence_client_library_db_access.h" -#include "../include_protected/crc32.h" - #include "persistence_client_library_pas_interface.h" #include "persistence_client_library_handle.h" #include "persistence_client_library_prct_access.h" +#include "persistence_client_library_data_organization.h" +#include "persistence_client_library_db_access.h" +#include "crc32.h" +#if USE_FILECACHE + #include <persistence_file_cache.h> +#endif #include <fcntl.h> // for open flags #include <errno.h> @@ -60,7 +62,12 @@ int pclFileClose(int fd) } __sync_fetch_and_sub(&gOpenFdArray[fd], FileClosed); // set closed flag +#if USE_FILECACHE + rval = pfcCloseFile(fd); +#else rval = close(fd); +#endif + } else { @@ -75,23 +82,26 @@ int pclFileClose(int fd) int pclFileGetSize(int fd) { - int rval = EPERS_NOT_INITIALIZED; + int size = EPERS_NOT_INITIALIZED; if(gPclInitialized >= PCLinitialized) { + +#if USE_FILECACHE + size = pfcFileGetSize(fd); +#else struct stat buf; - int ret = 0; - ret = fstat(fd, &buf); + size = fstat(fd, &buf); //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileGetSize fd: "), DLT_INT(fd)); - if(ret != -1) + if(size != -1) { - rval = buf.st_size; + size = buf.st_size; } +#endif } - - return rval; + return size; } @@ -100,6 +110,9 @@ void* pclFileMapData(void* addr, long size, long offset, int fd) { void* ptr = 0; +#if USE_FILECACHE + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclFileMapData not supported when using file cache")); +#else //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileMapData fd: "), DLT_INT(fd)); if(gPclInitialized >= PCLinitialized) @@ -114,6 +127,7 @@ void* pclFileMapData(void* addr, long size, long offset, int fd) ptr = EPERS_MAP_LOCKFS; } } +#endif return ptr; } @@ -131,7 +145,7 @@ int pclFileOpen(unsigned int ldbid, const char* resource_id, unsigned int user_n char dbKey[DbKeyMaxLen] = {0}; // database key char dbPath[DbPathMaxLen] = {0}; // database location - char backupPath[DbKeyMaxLen] = {0}; // backup file + char backupPath[DbPathMaxLen] = {0}; // backup file char csumPath[DbPathMaxLen] = {0}; // checksum file //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileOpen: "), DLT_INT(ldbid), DLT_STRING(resource_id) ); @@ -159,8 +173,8 @@ int pclFileOpen(unsigned int ldbid, const char* resource_id, unsigned int user_n } strncpy(fileSubPath, dbPath+length, DbPathMaxLen); - snprintf(backupPath, DbPathMaxLen, "%s%s", gBackupPrefix, fileSubPath); - snprintf(csumPath, DbPathMaxLen, "%s%s%s", gBackupPrefix, fileSubPath, ".crc"); + snprintf(backupPath, DbPathMaxLen-1, "%s%s", gBackupPrefix, fileSubPath); + snprintf(csumPath, DbPathMaxLen-1, "%s%s%s", gBackupPrefix, fileSubPath, ".crc"); if(shared_DB >= 0) // check valid database context { @@ -172,22 +186,35 @@ int pclFileOpen(unsigned int ldbid, const char* resource_id, unsigned int user_n { if((handle = pclVerifyConsistency(dbPath, backupPath, csumPath, flags)) == -1) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclFileOpen: error => file inconsistent, recovery N O T possible!")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclFileOpen: error => file inconsistent, recovery N O T possible!")); return -1; } } + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileOpen: No Backup => file is read only OR is in blacklist!")); + } + +#if USE_FILECACHE + + if(handle > 0) // when the file is open, close it and do a new open unde PFC control + { + close(handle); + } - // open file + handle = pfcOpenFile(dbPath); +#else if(handle <= 0) // check if open is needed or already done in verifyConsistency { handle = open(dbPath, flags); } +#endif if(handle == -1 && errno == ENOENT) // file does not exist, create file and folder { if( (handle = pclCreateFile(dbPath)) == -1) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclFileOpen: error => failed to create file: "), DLT_STRING(dbPath)); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclFileOpen: error => failed to create file: "), DLT_STRING(dbPath)); } } @@ -236,6 +263,7 @@ int pclFileOpen(unsigned int ldbid, const char* resource_id, unsigned int user_n handle = EPERS_RESOURCE_NO_FILE; } } + return handle; } @@ -248,7 +276,11 @@ int pclFileReadData(int fd, void * buffer, int buffer_size) //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileReadData fd: "), DLT_INT(fd)); if(gPclInitialized >= PCLinitialized) { +#if USE_FILECACHE + readSize = pfcReadFile(fd, buffer, buffer_size); +#else readSize = read(fd, buffer, buffer_size); +#endif } return readSize; } @@ -284,13 +316,13 @@ int pclFileRemove(unsigned int ldbid, const char* resource_id, unsigned int user rval = remove(dbPath); if(rval == -1) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclFileRemove => remove ERROR"), DLT_STRING(strerror(errno)) ); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclFileRemove => remove ERROR"), DLT_STRING(strerror(errno)) ); } } else { rval = shared_DB; - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclFileRemove ==> no valid database context or resource not a file")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclFileRemove ==> no valid database context or resource not a file")); } } else @@ -314,7 +346,11 @@ int pclFileSeek(int fd, long int offset, int whence) { if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked { +#if USE_FILECACHE + rval = pfcFileSeek(fd, offset, whence); +#else rval = lseek(fd, offset, whence); +#endif } else { @@ -377,7 +413,11 @@ int pclFileWriteData(int fd, const void * buffer, int buffer_size) gFileHandleArray[fd].backupCreated = 1; } +#if USE_FILECACHE + size = pfcWriteFile(fd, buffer, buffer_size); +#else size = write(fd, buffer, buffer_size); +#endif } else { @@ -406,7 +446,7 @@ int pclFileCreatePath(unsigned int ldbid, const char* resource_id, unsigned int char dbKey[DbKeyMaxLen] = {0}; // database key char dbPath[DbPathMaxLen] = {0}; // database location - char backupPath[DbKeyMaxLen] = {0}; // backup file + char backupPath[DbPathMaxLen] = {0}; // backup file char csumPath[DbPathMaxLen] = {0}; // checksum file //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileOpen: "), DLT_INT(ldbid), DLT_STRING(resource_id) ); @@ -428,12 +468,12 @@ int pclFileCreatePath(unsigned int ldbid, const char* resource_id, unsigned int if( dbContext.configKey.permission != PersistencePermission_ReadOnly && pclBackupNeeded(dbPath) ) { - snprintf(backupPath, DbPathMaxLen, "%s%s", dbPath, "~"); - snprintf(csumPath, DbPathMaxLen, "%s%s", dbPath, "~.crc"); + snprintf(backupPath, DbPathMaxLen-1, "%s%s", dbPath, "~"); + snprintf(csumPath, DbPathMaxLen-1, "%s%s", dbPath, "~.crc"); if((handle = pclVerifyConsistency(dbPath, backupPath, csumPath, flags)) == -1) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclFileOpen: error => file inconsistent, recovery N O T possible!")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclFileOpen: error => file inconsistent, recovery N O T possible!")); return -1; } // we don't need the file handle here diff --git a/src/persistence_client_library_handle.c b/src/persistence_client_library_handle.c index 7be6e3b..b1c9f6b 100644 --- a/src/persistence_client_library_handle.c +++ b/src/persistence_client_library_handle.c @@ -22,6 +22,7 @@ #include <pthread.h> #include <stdlib.h> +#include <string.h> /// handle index static int gHandleIdx = 1; @@ -69,7 +70,7 @@ int get_persistence_handle_idx() else { handle = EPERS_MAXHANDLE; - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("get_persistence_handle_idx => Reached maximum of open handles: "), DLT_INT(MaxPersHandle)); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("get_persistence_handle_idx => Reached maximum of open handles: "), DLT_INT(MaxPersHandle)); } } pthread_mutex_unlock(&gMtx); @@ -99,9 +100,10 @@ void close_all_persistence_handle() if(pthread_mutex_lock(&gMtx) == 0) { // "free" all handles - memset(gFreeHandleArray, 0, MaxPersHandle); - memset(gOpenFdArray, 0, MaxPersHandle); - memset(gOpenFdArray, 0, MaxPersHandle); + memset(gFreeHandleArray, 0, sizeof(gFreeHandleArray)); + memset(gOpenHandleArray, 0, sizeof(gOpenHandleArray)); + memset(gOpenFdArray, 0, sizeof(gOpenFdArray)); + // reset variables gHandleIdx = 1; diff --git a/src/persistence_client_library_handle.h b/src/persistence_client_library_handle.h index 2a1c200..369884b 100644 --- a/src/persistence_client_library_handle.h +++ b/src/persistence_client_library_handle.h @@ -20,9 +20,9 @@ * @see */ -#include "../include_protected/persistence_client_library_data_organization.h" -#include "../include_protected/persistence_client_library_rc_table.h" +#include "persistence_client_library_data_organization.h" +#include <persComRct.h> /// key handle structure definition typedef struct _PersistenceKeyHandle_s @@ -31,8 +31,7 @@ typedef struct _PersistenceKeyHandle_s char dbPath[DbPathMaxLen]; /// path to the database char dbKey[DbKeyMaxLen]; /// database key char resourceID[DbResIDMaxLen]; /// resourceID -} -PersistenceKeyHandle_s; +} PersistenceKeyHandle_s; /// file handle structure definition @@ -43,8 +42,9 @@ typedef struct _PersistenceFileHandle_s char backupPath[DbPathMaxLen]; /// path to the backup file char csumPath[DbPathMaxLen]; /// path to the checksum file char* filePath; /// the path -} -PersistenceFileHandle_s; +} PersistenceFileHandle_s; + + /// persistence key handle array @@ -80,13 +80,10 @@ int get_persistence_handle_idx(); void set_persistence_handle_close_idx(int handle); - -/** - * @brief close open file handles - * - */ void close_all_persistence_handle(); + + #endif /* PERSISTENCY_CLIENT_LIBRARY_HANDLE_H */ diff --git a/src/persistence_client_library_itzam_errors.c b/src/persistence_client_library_itzam_errors.c deleted file mode 100644 index 843f675..0000000 --- a/src/persistence_client_library_itzam_errors.c +++ /dev/null @@ -1,145 +0,0 @@ -/* - Itzam/C (version 6.0) is an embedded database engine written in Standard C. - - Copyright 2011 Scott Robert Ladd. All rights reserved. - - Older versions of Itzam/C are: - Copyright 2002, 2004, 2006, 2008 Scott Robert Ladd. All rights reserved. - - Ancestral code, from Java and C++ books by the author, is: - Copyright 1992, 1994, 1996, 2001 Scott Robert Ladd. All rights reserved. - - Itzam/C is user-supported open source software. It's continued development is dependent on - financial support from the community. You can provide funding by visiting the Itzam/C - website at: - - http://www.coyotegulch.com - - You may license Itzam/C in one of two fashions: - - 1) Simplified BSD License (FreeBSD License) - - Redistribution and use in source and binary forms, with or without modification, are - permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, this list of - conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, this list - of conditions and the following disclaimer in the documentation and/or other materials - provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY SCOTT ROBERT LADD ``AS IS'' AND ANY EXPRESS OR IMPLIED - WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SCOTT ROBERT LADD OR - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - The views and conclusions contained in the software and documentation are those of the - authors and should not be interpreted as representing official policies, either expressed - or implied, of Scott Robert Ladd. - - 2) Closed-Source Proprietary License - - If your project is a closed-source or proprietary project, the Simplified BSD License may - not be appropriate or desirable. In such cases, contact the Itzam copyright holder to - arrange your purchase of an appropriate license. - - The author can be contacted at: - - scott.ladd@coyotegulch.com - scott.ladd@gmail.com - http:www.coyotegulch.com -*/ - -/****************************************************************************** - * Project Persistency - * (c) copyright 2012 - * Company XS Embedded GmbH - *****************************************************************************/ -/****************************************************************************** -Small changes to use in persistence -******************************************************************************/ - /** - * @file persistence_client_itzam_errors.c - * @ingroup Persistence client library - * @author Ingo Huerner - * @brief Itzam database error definnitions - * @see - */ - -#include "persistence_client_library_itzam_errors.h" -#include "../include_protected/persistence_client_library_data_organization.h" - - -const char * ERROR_STRINGS [] = -{ - "invalid datafile signature", - "invalid version", - "can not open 64-bit datafile on 32-bit operating system", - "write failed", - "open failed", - "read failed", - "close failed", - "seek failed", - "tell failed", - "duplicate remove", - "flush failed", - "rewrite record too small", - "page not found", - "lost key", - "key not written", - "key seek failed", - "unable to remove key record", - "record seek failed", - "unable to remove data record", - "list of deleted records could not be read", - "list of deleted records could not be written", - "iterator record count differs from database internal count", - "rewrite over deleted record", - "invalid column index", - "invalid row index", - "invalid hash value", - "memory allocation failed", - "attempt reading deleted record", - "invalid record signature found", - "invalid file locking mode", - "unable to lock datafile", - "unable to unlock datafile", - "size mismatch when reading record", - "attempt to start new transaction while one is already active", - "no transaction active", - "attempt to free a B-tree cursor when cursors were active", - "invalid datafile object", - "size_t is incompatible with Itzam", - "could not create datafile", - "global shared memory requires Administrator or user with SeCreateGlobalPrivilege", - "cannot create global shared memory", - "another process or thread has already created shared objects for this datafile", - "invalid operation for read only file" -}; - -const char * STATE_MESSAGES [] = -{ - "okay", - "operation failed", - "version mismatch in files", - "iterator at end", - "iterator at beginning", - "key not found", - "duplicate key", - "exceeded maximum file size on 32-bit system", - "unable to write data record for index", - "sizeof(size_t) smaller than required for file references; possibly 64-bit DB on 32-bit platform", - "invalid operation for read only file" -}; - - -void error_handler(const char * function_name, itzam_error error) -{ - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("Itzam error in: "), DLT_STRING(function_name), DLT_STRING(ERROR_STRINGS[error])); -} diff --git a/src/persistence_client_library_itzam_errors.h b/src/persistence_client_library_itzam_errors.h deleted file mode 100644 index 7324ea6..0000000 --- a/src/persistence_client_library_itzam_errors.h +++ /dev/null @@ -1,90 +0,0 @@ -#ifndef PERSISTENCE_CLIENT_ITZAM_ERRORS_H -#define PERSISTENCE_CLIENT_ITZAM_ERRORS_H - -/* - Itzam/C (version 6.0) is an embedded database engine written in Standard C. - - Copyright 2011 Scott Robert Ladd. All rights reserved. - - Older versions of Itzam/C are: - Copyright 2002, 2004, 2006, 2008 Scott Robert Ladd. All rights reserved. - - Ancestral code, from Java and C++ books by the author, is: - Copyright 1992, 1994, 1996, 2001 Scott Robert Ladd. All rights reserved. - - Itzam/C is user-supported open source software. It's continued development is dependent on - financial support from the community. You can provide funding by visiting the Itzam/C - website at: - - http://www.coyotegulch.com - - You may license Itzam/C in one of two fashions: - - 1) Simplified BSD License (FreeBSD License) - - Redistribution and use in source and binary forms, with or without modification, are - permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, this list of - conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, this list - of conditions and the following disclaimer in the documentation and/or other materials - provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY SCOTT ROBERT LADD ``AS IS'' AND ANY EXPRESS OR IMPLIED - WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SCOTT ROBERT LADD OR - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - The views and conclusions contained in the software and documentation are those of the - authors and should not be interpreted as representing official policies, either expressed - or implied, of Scott Robert Ladd. - - 2) Closed-Source Proprietary License - - If your project is a closed-source or proprietary project, the Simplified BSD License may - not be appropriate or desirable. In such cases, contact the Itzam copyright holder to - arrange your purchase of an appropriate license. - - The author can be contacted at: - - scott.ladd@coyotegulch.com - scott.ladd@gmail.com - http:www.coyotegulch.com -*/ - -/****************************************************************************** - * Project Persistency - * (c) copyright 2012 - * Company XS Embedded GmbH - *****************************************************************************/ -/****************************************************************************** -Small changes to use in persistence -******************************************************************************/ - /** - * @file persistence_client_itzam_errors.h - * @ingroup Persistence client library - * @author Ingo Huerner - * @brief Itzam database error definnitions - * @see - */ - -#include <itzam.h> - -/// error string messages definition -extern const char * ERROR_STRINGS []; - -/// error state messages definition -extern const char * STATE_MESSAGES []; - -/// error handler -void error_handler(const char * function_name, itzam_error error); - - -#endif /* PERSISTENCE_CLIENT_ITZAM_ERRORS_H */ diff --git a/src/persistence_client_library_key.c b/src/persistence_client_library_key.c index 015f9e2..0d7c0ee 100644 --- a/src/persistence_client_library_key.c +++ b/src/persistence_client_library_key.c @@ -18,15 +18,15 @@ */ #include "persistence_client_library_key.h" - -#include "../include_protected/persistence_client_library_db_access.h" -#include "../include_protected/persistence_client_library_rc_table.h" -#include "../include_protected/crc32.h" - #include "persistence_client_library_handle.h" #include "persistence_client_library_pas_interface.h" -#include "persistence_client_library_prct_access.h" #include "persistence_client_library_custom_loader.h" +#include "persistence_client_library_prct_access.h" +#include "persistence_client_library_db_access.h" +#include "crc32.h" + +#include <persComRct.h> + // function declaration @@ -90,18 +90,18 @@ int pclKeyHandleOpen(unsigned int ldbid, const char* resource_id, unsigned int u strncpy(gKeyHandleArray[handle].dbKey, dbKey, DbKeyMaxLen); strncpy(gKeyHandleArray[handle].resourceID, resource_id, DbResIDMaxLen); gKeyHandleArray[handle].dbPath[DbPathMaxLen-1] = '\0'; // Ensures 0-Termination - gKeyHandleArray[handle].dbKey[ DbPathMaxLen-1] = '\0'; // Ensures 0-Termination + gKeyHandleArray[handle].dbKey[ DbKeyMaxLen-1] = '\0'; // Ensures 0-Termination gKeyHandleArray[handle].info = dbContext; } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyHandleOpen: error - handleId out of bounds:"), DLT_INT(handle)); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyHandleOpen: error - handleId out of bounds:"), DLT_INT(handle)); } } } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyHandleOpen: error - no database context or resource is not a key ")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyHandleOpen: error - no database context or resource is not a key ")); } } @@ -184,7 +184,7 @@ int pclKeyHandleGetSize(int key_handle) } else { - size = pers_db_get_key_size(gKeyHandleArray[key_handle].dbPath, gKeyHandleArray[key_handle].dbKey, + size = persistence_get_data_size(gKeyHandleArray[key_handle].dbPath, gKeyHandleArray[key_handle].dbKey, &gKeyHandleArray[key_handle].info); } } @@ -225,7 +225,7 @@ int pclKeyHandleReadData(int key_handle, unsigned char* buffer, int buffer_size) } else { - size = pers_db_read_key(gKeyHandleArray[key_handle].dbPath, gKeyHandleArray[key_handle].dbKey, + size = persistence_get_data(gKeyHandleArray[key_handle].dbPath, gKeyHandleArray[key_handle].dbKey, &gKeyHandleArray[key_handle].info, buffer, buffer_size); } } @@ -315,7 +315,7 @@ int pclKeyHandleWriteData(int key_handle, unsigned char* buffer, int buffer_size if(rval <= 0) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyHandleWriteData: error - failed to send notification")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyHandleWriteData: error - failed to send notification")); size = rval; } } @@ -327,7 +327,7 @@ int pclKeyHandleWriteData(int key_handle, unsigned char* buffer, int buffer_size } else { - size = pers_db_write_key(gKeyHandleArray[key_handle].dbPath, gKeyHandleArray[key_handle].dbKey, + size = persistence_set_data(gKeyHandleArray[key_handle].dbPath, gKeyHandleArray[key_handle].dbKey, &gKeyHandleArray[key_handle].info, buffer, buffer_size); } } @@ -344,7 +344,7 @@ int pclKeyHandleWriteData(int key_handle, unsigned char* buffer, int buffer_size } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyHandleWriteData: error - buffer_size to big, limit is [bytes]:"), DLT_INT(gMaxKeyValDataSize)); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyHandleWriteData: error - buffer_size to big, limit is [bytes]:"), DLT_INT(gMaxKeyValDataSize)); size = EPERS_MAX_BUFF_SIZE; } } @@ -394,7 +394,7 @@ int pclKeyDelete(unsigned int ldbid, const char* resource_id, unsigned int user_ if( dbContext.configKey.storage < PersistenceStorage_LastEntry && dbContext.configKey.storage >= PersistenceStorage_local) // check if store policy is valid { - rval = pers_db_delete_key(dbPath, dbKey, &dbContext); + rval = persistence_delete_data(dbPath, dbKey, &dbContext); } else { @@ -439,7 +439,7 @@ int pclKeyGetSize(unsigned int ldbid, const char* resource_id, unsigned int user if( dbContext.configKey.storage < PersistenceStorage_LastEntry && dbContext.configKey.storage >= PersistenceStorage_local) // check if store policy is valid { - data_size = pers_db_get_key_size(dbPath, dbKey, &dbContext); + data_size = persistence_get_data_size(dbPath, dbKey, &dbContext); } else { @@ -487,7 +487,7 @@ int pclKeyReadData(unsigned int ldbid, const char* resource_id, unsigned int use if( dbContext.configKey.storage < PersistenceStorage_LastEntry && dbContext.configKey.storage >= PersistenceStorage_local) // check if store policy is valid { - data_size = pers_db_read_key(dbPath, dbKey, &dbContext, buffer, buffer_size); + data_size = persistence_get_data(dbPath, dbKey, &dbContext, buffer, buffer_size); } else { @@ -496,7 +496,7 @@ int pclKeyReadData(unsigned int ldbid, const char* resource_id, unsigned int use } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyReadData - error - no database context or resource is not a key")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyReadData - error - no database context or resource is not a key")); } } else @@ -548,7 +548,7 @@ int pclKeyWriteData(unsigned int ldbid, const char* resource_id, unsigned int us if( dbContext.configKey.storage < PersistenceStorage_LastEntry && dbContext.configKey.storage >= PersistenceStorage_local) // check if store policy is valid { - data_size = pers_db_write_key(dbPath, dbKey, &dbContext, buffer, buffer_size); + data_size = persistence_set_data(dbPath, dbKey, &dbContext, buffer, buffer_size); } else { @@ -562,13 +562,13 @@ int pclKeyWriteData(unsigned int ldbid, const char* resource_id, unsigned int us } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyWriteData - error - no database context or resource is not a key")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyWriteData - error - no database context or resource is not a key")); } } else { data_size = EPERS_BUFLIMIT; - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyWriteData: error - buffer_size to big, limit is [bytes]:"), DLT_INT(gMaxKeyValDataSize)); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyWriteData: error - buffer_size to big, limit is [bytes]:"), DLT_INT(gMaxKeyValDataSize)); } } else @@ -576,7 +576,6 @@ int pclKeyWriteData(unsigned int ldbid, const char* resource_id, unsigned int us data_size = EPERS_LOCKFS; } } - return data_size; } @@ -631,7 +630,7 @@ int regNotifyOnChange(unsigned int ldbid, const char* resource_id, unsigned int } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyRegisterNotifyOnChange: error - resource is not a shared resource or resource is not a key")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyRegisterNotifyOnChange: error - resource is not a shared resource or resource is not a key")); rval = EPERS_NOTIFY_NOT_ALLOWED; } } diff --git a/src/persistence_client_library_lc_interface.c b/src/persistence_client_library_lc_interface.c index 83deac6..fedccf1 100644 --- a/src/persistence_client_library_lc_interface.c +++ b/src/persistence_client_library_lc_interface.c @@ -19,15 +19,15 @@ #include "persistence_client_library_lc_interface.h" -#include "../include_protected/persistence_client_library_data_organization.h" -#include "../include_protected/persistence_client_library_db_access.h" +#include "persistence_client_library_data_organization.h" +#include "persistence_client_library_db_access.h" #include "persistence_client_library_handle.h" #include "persistence_client_library_pas_interface.h" #include "persistence_client_library_dbus_service.h" #include "persistence_client_library_custom_loader.h" #include "persistence_client_library_prct_access.h" -#include "persistence_client_library_itzam_errors.h" + #include <errno.h> #include <stdio.h> @@ -46,7 +46,7 @@ int check_lc_request(int request, int requestID) { if(-1 == deliverToMainloop_NM(CMD_LC_PREPARE_SHUTDOWN, request, requestID) ) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("check_lc_request => failed to write to pipe"), DLT_INT(errno)); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("check_lc_request => failed to write to pipe"), DLT_INT(errno)); rval = NsmErrorStatus_Fail; } else @@ -57,7 +57,7 @@ int check_lc_request(int request, int requestID) } default: { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("check_lc_request => Unknown lifecycle message"), DLT_INT(request)); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("check_lc_request => Unknown lifecycle message"), DLT_INT(request)); break; } } @@ -84,12 +84,12 @@ int msg_lifecycleRequest(DBusConnection *connection, DBusMessage *message) if (reply == 0) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("msg_lifecycleRequest => DBus No memory")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("msg_lifecycleRequest => DBus No memory")); } if (!dbus_connection_send(connection, reply, 0)) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("msg_lifecycleRequest => DBus No memory")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("msg_lifecycleRequest => DBus No memory")); } dbus_message_unref(reply); @@ -103,17 +103,17 @@ int msg_lifecycleRequest(DBusConnection *connection, DBusMessage *message) if (reply == 0) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("msg_lifecycleRequest => DBus No memory")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("msg_lifecycleRequest => DBus No memory")); } if (!dbus_message_append_args(reply, DBUS_TYPE_INT32, &msgReturn, DBUS_TYPE_INVALID)) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("msg_lifecycleRequest => DBus No memory")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("msg_lifecycleRequest => DBus No memory")); } if (!dbus_connection_send(connection, reply, 0)) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("msg_lifecycleRequest => DBus No memory")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("msg_lifecycleRequest => DBus No memory")); } dbus_connection_flush(connection); @@ -128,6 +128,8 @@ DBusHandlerResult checkLifecycleMsg(DBusConnection * connection, DBusMessage * m { DBusHandlerResult result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + (void)user_data; + if((0==strncmp("org.genivi.NodeStateManager.LifeCycleConsumer", dbus_message_get_interface(message), 46))) { if((0==strncmp("LifecycleRequest", dbus_message_get_member(message), 16))) @@ -136,7 +138,7 @@ DBusHandlerResult checkLifecycleMsg(DBusConnection * connection, DBusMessage * m } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("checkLifecycleMsg -> unknown message "), DLT_STRING(dbus_message_get_interface(message))); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("checkLifecycleMsg -> unknown message "), DLT_STRING(dbus_message_get_interface(message))); } } return result; @@ -156,9 +158,3 @@ int unregister_lifecycle(int shutdownMode) return deliverToMainloop(CMD_SEND_LC_REGISTER, 0, shutdownMode); } -/* -int send_prepare_shutdown_complete(int requestId, int status) -{ - return deliverToMainloop_NM(CMD_SEND_LC_REQUEST, status, requestId); -} -*/ diff --git a/src/persistence_client_library_pas_interface.c b/src/persistence_client_library_pas_interface.c index 1ca9a2b..3e60228 100644 --- a/src/persistence_client_library_pas_interface.c +++ b/src/persistence_client_library_pas_interface.c @@ -20,10 +20,11 @@ #include "persistence_client_library_pas_interface.h" #include "persistence_client_library_dbus_service.h" -#include "../include_protected/persistence_client_library_data_organization.h" +#include "persistence_client_library_data_organization.h" #include <errno.h> #include <unistd.h> +#include <string.h> /// flag if access is locked static int gLockAccess = 0; @@ -31,6 +32,7 @@ static int gLockAccess = 0; int pers_data_sync(void) { + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("PCL: pers_data_sync()")); sync(); return 1; } @@ -58,9 +60,10 @@ int check_pas_request(unsigned int request, unsigned int requestID) { case (PasMsg_Block|PasMsg_WriteBack): { + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("PCL: check_pas_request; case PasMsg_Block o. PasMsg_WriteBack")); if(-1 == deliverToMainloop_NM(CMD_PAS_BLOCK_AND_WRITE_BACK, request, requestID)) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("write failed w/ errno "), DLT_INT(errno), DLT_STRING(strerror(errno))); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("write failed w/ errno "), DLT_INT(errno), DLT_STRING(strerror(errno))); rval = PasErrorStatus_FAIL; } else @@ -71,6 +74,7 @@ int check_pas_request(unsigned int request, unsigned int requestID) } case PasMsg_Unblock: { + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("PCL: check_pas_request; case PasMsg_Unblock")); pers_unlock_access(); rval = PasErrorStatus_OK; break; @@ -106,12 +110,12 @@ DBusHandlerResult msg_persAdminRequest(DBusConnection *connection, DBusMessage * if(reply == 0) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("msg_persAdminRequest => DBus No memory")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("msg_persAdminRequest => DBus No memory")); } if (!dbus_connection_send(connection, reply, 0)) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("msg_persAdminRequest => DBus No memory")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("msg_persAdminRequest => DBus No memory")); } dbus_message_unref(reply); @@ -125,17 +129,17 @@ DBusHandlerResult msg_persAdminRequest(DBusConnection *connection, DBusMessage * if (reply == 0) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("msg_persAdminRequest => DBus No memory")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("msg_persAdminRequest => DBus No memory")); } if (!dbus_message_append_args(reply, DBUS_TYPE_INT32, &errorReturn, DBUS_TYPE_INVALID)) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("msg_persAdminRequest => DBus No memory")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("msg_persAdminRequest => DBus No memory")); } if (!dbus_connection_send(connection, reply, 0)) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("msg_persAdminRequest => DBus No memory")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("msg_persAdminRequest => DBus No memory")); } dbus_connection_flush(connection); @@ -161,12 +165,12 @@ int signal_persModeChange(DBusConnection *connection, DBusMessage *message) if(reply == 0) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("signal_persModeChange => DBus No memory")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("signal_persModeChange => DBus No memory")); } if (!dbus_connection_send(connection, reply, 0)) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("signal_persModeChange => DBus No memory")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("signal_persModeChange => DBus No memory")); } dbus_message_unref(reply); @@ -178,17 +182,17 @@ int signal_persModeChange(DBusConnection *connection, DBusMessage *message) if (reply == 0) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("signal_persModeChange => DBus No memory")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("signal_persModeChange => DBus No memory")); } if (!dbus_message_append_args(reply, DBUS_TYPE_INT32, &errorCode, DBUS_TYPE_INVALID)) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("signal_persModeChange => DBus No memory")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("signal_persModeChange => DBus No memory")); } if (!dbus_connection_send(connection, reply, 0)) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("signal_persModeChange => DBus No memory")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("signal_persModeChange => DBus No memory")); } dbus_connection_flush(connection); @@ -202,6 +206,8 @@ DBusHandlerResult checkPersAdminMsg(DBusConnection * connection, DBusMessage * m { DBusHandlerResult result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + (void)user_data; + if((0==strcmp("org.genivi.persistence.adminconsumer", dbus_message_get_interface(message)))) { if((0==strcmp("PersistenceAdminRequest", dbus_message_get_member(message)))) @@ -210,12 +216,12 @@ DBusHandlerResult checkPersAdminMsg(DBusConnection * connection, DBusMessage * m } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("checkPersAdminMsg => unknown message"), DLT_STRING(dbus_message_get_member(message))); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("checkPersAdminMsg => unknown message"), DLT_STRING(dbus_message_get_member(message))); } } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("checkPersAdminMsg => unknown message"), DLT_STRING(dbus_message_get_interface(message))); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("checkPersAdminMsg => unknown message"), DLT_STRING(dbus_message_get_interface(message))); } return result; } @@ -229,7 +235,7 @@ int register_pers_admin_service(void) if(-1 == deliverToMainloop(CMD_SEND_PAS_REGISTER, 1, (PasMsg_Block | PasMsg_WriteBack | PasMsg_Unblock))) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("register_pers_admin_service => failed to write to pipe"), DLT_INT(errno)); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("register_pers_admin_service => failed to write to pipe"), DLT_INT(errno)); rval = -1; } else @@ -248,7 +254,7 @@ int unregister_pers_admin_service(void) if(-1 == deliverToMainloop(CMD_SEND_PAS_REGISTER, 0, (PasMsg_Block | PasMsg_WriteBack | PasMsg_Unblock))) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("unregister_pers_admin_service => failed to write to pipe"), DLT_INT(errno)); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("unregister_pers_admin_service => failed to write to pipe"), DLT_INT(errno)); rval = -1; } else @@ -259,3 +265,4 @@ int unregister_pers_admin_service(void) return rval; } + diff --git a/src/persistence_client_library_prct_access.c b/src/persistence_client_library_prct_access.c index d1158ca..5fffc3c 100644 --- a/src/persistence_client_library_prct_access.c +++ b/src/persistence_client_library_prct_access.c @@ -18,19 +18,36 @@ */ + #include "persistence_client_library_prct_access.h" -#include "persistence_client_library_itzam_errors.h" -#include "../include_protected/persistence_client_library_db_access.h" +#include "persistence_client_library_db_access.h" #include <stdlib.h> +#include <string.h> +#include <persComRct.h> +#include <persComDbAccess.h> +#include <persComErrors.h> /// pointer to resource table database -itzam_btree gResource_table[PrctDbTableSize] = {{0}}; +int gResource_table[PrctDbTableSize] = {-1}; /// array to hold the information of database is already open int gResourceOpen[PrctDbTableSize] = {0}; +/// persistence resource config table type definition +typedef enum _PersistenceRCT_e +{ + PersistenceRCT_local = 0, + PersistenceRCT_shared_public = 1, + PersistenceRCT_shared_group = 2, + + PersistenceRCT_LastEntry // last Entry + +} PersistenceRCT_e; + + + PersistenceRCT_e get_table_id(int ldbid, int* groupId) { PersistenceRCT_e rctType = PersistenceRCT_LastEntry; @@ -55,32 +72,27 @@ PersistenceRCT_e get_table_id(int ldbid, int* groupId) { // L O C A L database *groupId = 0; // no group ID for local data - rctType = PersistenceStorage_local; // we have a local database + rctType = PersistenceRCT_local; // we have a local database } return rctType; } -itzam_btree* get_resource_cfg_table_by_idx(int i) +int get_resource_cfg_table_by_idx(int i) { - return &gResource_table[i]; + return gResource_table[i]; } -int get_resource_cfg_table_status(int i) -{ - return gResourceOpen[i]; -} void invalidate_resource_cfg_table(int i) { - gResourceOpen[i] = 0; + gResource_table[i] = -1; } // status: OK -itzam_btree* get_resource_cfg_table(PersistenceRCT_e rct, int group) +int get_resource_cfg_table(PersistenceRCT_e rct, int group) { int arrayIdx = 0; - itzam_btree* tree = NULL; // create array index: index is a combination of resource config table type and group arrayIdx = rct + group; @@ -89,7 +101,6 @@ itzam_btree* get_resource_cfg_table(PersistenceRCT_e rct, int group) { if(gResourceOpen[arrayIdx] == 0) // check if database is already open { - itzam_state state; char filename[DbPathMaxLen] = {0}; switch(rct) // create db name @@ -104,30 +115,24 @@ itzam_btree* get_resource_cfg_table(PersistenceRCT_e rct, int group) snprintf(filename, DbPathMaxLen, gSharedWtPathKey, gAppId, group, gResTableCfg); break; default: - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("get_resource_cfg_table - error: no valid PersistenceRCT_e")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("get_resource_cfg_table - error: no valid PersistenceRCT_e")); break; } - state = itzam_btree_open(&gResource_table[arrayIdx], filename, itzam_comparator_string, error_handler, 0 , 0); - if(state != ITZAM_OKAY) + + gResource_table[arrayIdx] = persComRctOpen(filename, 0x00) ; + if(gResource_table[arrayIdx] < 0) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("get_resource_cfg_table => itzam_btree_open => Itzam problem"), DLT_STRING(STATE_MESSAGES[state]) ); - tree = NULL; + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("get_resource_cfg_table => RCT problem")); } else { - gResourceOpen[arrayIdx] = 1; // remember the index has an DB entry - tree = &gResource_table[arrayIdx]; + gResourceOpen[arrayIdx] = 1 ; } } - else - { - tree = &gResource_table[arrayIdx]; - } - } - return tree; + return gResource_table[arrayIdx]; } @@ -141,28 +146,20 @@ int get_db_context(PersistenceInfo_s* dbContext, const char* resource_id, unsign rct = get_table_id(dbContext->context.ldbid, &groupId); // get resource configuration table - itzam_btree* resource_table = get_resource_cfg_table(rct, groupId); + int handleRCT = get_resource_cfg_table(rct, groupId); - if(resource_table != NULL) + if(handleRCT >= 0) { - PersistenceRctEntry_s search; + PersistenceConfigurationKey_s sRctEntry ; + // check if resouce id is in write through table - if(itzam_true == itzam_btree_find(resource_table, resource_id, &search)) + int iErrCode = persComRctRead(handleRCT, resource_id, &sRctEntry) ; + + if(sizeof(PersistenceConfigurationKey_s) == iErrCode) { - memset(dbContext->configKey.reponsible, 0, MaxConfKeyLengthResp); - memset(dbContext->configKey.custom_name, 0, MaxConfKeyLengthCusName); - memset(dbContext->configKey.customID, 0, MaxRctLengthCustom_ID); - - dbContext->configKey.policy = search.data.policy; - dbContext->configKey.storage = search.data.storage; - dbContext->configKey.permission = search.data.permission; - dbContext->configKey.max_size = search.data.max_size; - dbContext->configKey.type = search.data.type; - memcpy(dbContext->configKey.reponsible, search.data.reponsible, MaxConfKeyLengthResp); - memcpy(dbContext->configKey.custom_name, search.data.custom_name, MaxConfKeyLengthCusName); - memcpy(dbContext->configKey.customID, search.data.customID, MaxRctLengthCustom_ID); - - if(dbContext->configKey.storage != PersistenceStorage_custom ) + //printf("get_db_context ==> data: %s\n", search.data); + memcpy(&dbContext->configKey, &sRctEntry, sizeof(dbContext->configKey)) ; + if(sRctEntry.storage != PersistenceStorage_custom ) { rval = get_db_path_and_key(dbContext, resource_id, dbKey, dbPath); } @@ -170,18 +167,21 @@ int get_db_context(PersistenceInfo_s* dbContext, const char* resource_id, unsign { // if customer storage, we use the custom name as dbPath strncpy(dbPath, dbContext->configKey.custom_name, strlen(dbContext->configKey.custom_name)); + + // and resource_id as dbKey + strncpy(dbKey, resource_id, strlen(resource_id)); } resourceFound = 1; } else { - DLT_LOG(gDLTContext, DLT_LOG_WARN, DLT_STRING("get_db_context => itzam_btree_open => resource_table: no value for key:"), DLT_STRING(resource_id) ); + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("get_db_context => persComRctRead => resource_table: no value for key:"), DLT_STRING(resource_id) ); rval = EPERS_NOKEYDATA; } } // resource table else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("get_db_context =>error resource table")); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("get_db_context =>error resource table")); rval = EPERS_NOPRCTABLE; } @@ -207,7 +207,7 @@ int get_db_context(PersistenceInfo_s* dbContext, const char* resource_id, unsign memcpy(dbContext->configKey.reponsible, "default", strlen("default")); memcpy(dbContext->configKey.custom_name, "default", strlen("default")); - DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("get_db_context => create resource not in PRCT => key:"), DLT_STRING(resource_id) ); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("get_db_context => create resource not in PRCT => key:"), DLT_STRING(resource_id) ); // send create notification rval = pers_send_Notification_Signal(dbKey, &dbContext->context, pclNotifyStatus_created); @@ -292,7 +292,7 @@ int get_db_path_and_key(PersistenceInfo_s* dbContext, const char* resource_id, c if(PersistencePolicy_wc == dbContext->configKey.policy) { if(dbContext->configKey.type == PersistenceResourceType_key) - snprintf(dbPath, DbPathMaxLen, gSharedCachePath, gAppId, dbContext->context.ldbid); + snprintf(dbPath, DbPathMaxLen, gSharedCachePath, gAppId, dbContext->context.ldbid, ""); else snprintf(dbPath, DbPathMaxLen, gSharedCachePathKey, gAppId, dbContext->context.ldbid, dbKey); } @@ -313,14 +313,14 @@ int get_db_path_and_key(PersistenceInfo_s* dbContext, const char* resource_id, c if(PersistencePolicy_wc == dbContext->configKey.policy) { if(dbContext->configKey.type == PersistenceResourceType_key) - snprintf(dbPath, DbPathMaxLen, gSharedPublicCachePath, gAppId); + snprintf(dbPath, DbPathMaxLen, gSharedPublicCachePath, gAppId, ""); else snprintf(dbPath, DbPathMaxLen, gSharedPublicCachePathKey, gAppId, dbKey); } else if(PersistencePolicy_wt == dbContext->configKey.policy) { if(dbContext->configKey.type == PersistenceResourceType_key) - snprintf(dbPath, DbPathMaxLen, gSharedPublicWtPath, gAppId); + snprintf(dbPath, DbPathMaxLen, gSharedPublicWtPath, gAppId, ""); else snprintf(dbPath, DbPathMaxLen, gSharedPublicWtPathKey, gAppId, dbKey); } @@ -331,20 +331,19 @@ int get_db_path_and_key(PersistenceInfo_s* dbContext, const char* resource_id, c else { // L O C A L database - if(PersistencePolicy_wc == dbContext->configKey.policy) { if(dbContext->configKey.type == PersistenceResourceType_key) - snprintf(dbPath, DbPathMaxLen, gLocalCachePath, gAppId); + snprintf(dbPath, DbPathMaxLen, gLocalCachePath, gAppId, ""); else snprintf(dbPath, DbPathMaxLen, gLocalCachePathKey, gAppId, dbKey); } else if(PersistencePolicy_wt == dbContext->configKey.policy) { if(dbContext->configKey.type == PersistenceResourceType_key) - snprintf(dbPath, DbPathMaxLen, gLocalWtPath, gAppId); + snprintf(dbPath, DbPathMaxLen-1, gLocalWtPath, gAppId, ""); else - snprintf(dbPath, DbPathMaxLen, gLocalWtPathKey, gAppId, dbKey); + snprintf(dbPath, DbPathMaxLen-1, gLocalWtPathKey, gAppId, dbKey); } storePolicy = PersistenceStorage_local; // we have a local database @@ -352,6 +351,7 @@ int get_db_path_and_key(PersistenceInfo_s* dbContext, const char* resource_id, c //printf("get_db_path_and_key - dbKey : [key ]: %s \n", dbKey); //printf("get_db_path_and_key - dbPath : [path]: %s\n", dbPath); + return storePolicy; } diff --git a/src/persistence_client_library_prct_access.h b/src/persistence_client_library_prct_access.h index a14ebdc..0bba971 100644 --- a/src/persistence_client_library_prct_access.h +++ b/src/persistence_client_library_prct_access.h @@ -20,10 +20,8 @@ * @see */ -#include "../include_protected/persistence_client_library_data_organization.h" -#include "../include_protected/persistence_client_library_rc_table.h" +#include "persistence_client_library_data_organization.h" -#include <itzam.h> /** * @brief Create database search key and database location path @@ -44,7 +42,7 @@ int get_db_path_and_key(PersistenceInfo_s* dbContext, const char* resource_id, c /** - * Create database search key and database location path + * @brief Create database search key and database location path * * @param dbContext the database context * @param resource_id the resource id @@ -62,24 +60,16 @@ int get_db_context(PersistenceInfo_s* dbContext, const char* resource_id, unsign /** - * @brief get the resource configuration table database by id - * - * @param i the index + * @brief get the resource configuration table gvbd database by id * - * @return pointer to the database table or NULL if no valid database has been found + * @return Handle to the gvdb database table or negative value if no valid database has been found */ -itzam_btree* get_resource_cfg_table_by_idx(int i); - - +int get_resource_cfg_table_by_idx(int i); /** - * @brief get the resource configuration table status - * - * @param i the index - * - * @return status of database, 1 is db is opened and 0 is closed + * Global array for the storage of pointers to resource table databases */ -inline int get_resource_cfg_table_status(int i); +extern int gResource_table[PrctDbTableSize]; @@ -88,7 +78,7 @@ inline int get_resource_cfg_table_status(int i); * * @param i the index */ -inline void invalidate_resource_cfg_table(int i); +void invalidate_resource_cfg_table(int i); diff --git a/test/Makefile.am b/test/Makefile.am index da7b652..6264d76 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -24,7 +24,7 @@ persistence_client_library_benchmark_LDADD = $(DEPS_LIBS) \ persistence_client_library_test_SOURCES = persistence_client_library_test.c persistence_client_library_test_LDADD = $(DEPS_LIBS) $(CHECK_LIBS) \ $(top_srcdir)/src/libpersistence_client_library.la - + persistence_admin_service_mockup_SOURCES = persistence_admin_service_mockup.c persistence_admin_service_mockup_LDADD = $(DEPS_LIBS) diff --git a/test/data/Data.tar.gz b/test/data/Data.tar.gz Binary files differindex 93e23cd..0a69c75 100644 --- a/test/data/Data.tar.gz +++ b/test/data/Data.tar.gz diff --git a/test/persistence_client_library_test.c b/test/persistence_client_library_test.c index 4667d55..b1aa3b7 100644 --- a/test/persistence_client_library_test.c +++ b/test/persistence_client_library_test.c @@ -10,7 +10,6 @@ ******************************************************************************/ /** * @file persistence_client_library_test.c - * @ingroup Persistence client library test * @author Ingo Huerner * @brief Test of persistence client library * @see @@ -34,16 +33,14 @@ #include "../include/persistence_client_library_file.h" #include "../include/persistence_client_library_key.h" #include "../include/persistence_client_library.h" +#include "../include/persistence_client_library_error_def.h" -// protected header, should be used only be persistence components -// included here for testing purpose -#include "../include_protected/persistence_client_library_db_access.h" - #define BUF_SIZE 64 #define NUM_OF_FILES 3 #define READ_SIZE 1024 +#define MaxAppNameLen 256 /// application id char gTheAppId[MaxAppNameLen] = {0}; @@ -117,6 +114,9 @@ START_TEST(test_GetData) * ==> local USER value (user 3, seat 2) */ ret = pclKeyReadData(0xFF, "status/open_document", 3, 2, buffer, READ_SIZE); + printf("Ist: %s\n", buffer); + printf("Soll: %s\n", "WT_ /var/opt/user_manual_climateControl.pdf"); + x_fail_unless(strncmp((char*)buffer, "WT_ /var/opt/user_manual_climateControl.pdf", strlen((char*)buffer)) == 0, "Buffer not correctly read"); memset(buffer, 0, READ_SIZE); @@ -310,9 +310,11 @@ START_TEST(test_SetData) * ==> local USER value (user 1, seat 2) * Resource ID: 69 */ - + printf("function: %s ==> line: %d\n", __FUNCTION__, __LINE__); ret = pclKeyWriteData(0xFF, "69", 1, 2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer)); + printf("function: %s ==> line: %d\n", __FUNCTION__, __LINE__); x_fail_unless(ret == strlen(sysTimeBuffer), "Wrong write size"); + printf("function: %s ==> line: %d\n", __FUNCTION__, __LINE__); #if 1 snprintf(write1, 128, "%s %s", "/70", sysTimeBuffer); /** @@ -376,6 +378,8 @@ START_TEST(test_SetData) memset(buffer, 0, READ_SIZE); ret = pclKeyReadData(0xFF, "69", 1, 2, buffer, READ_SIZE); + printf("Verify ist : %s \n", buffer); + printf("Verify soll : %s \n", sysTimeBuffer); x_fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read"); x_fail_unless(ret == strlen(sysTimeBuffer), "Wrong read size"); @@ -482,6 +486,7 @@ START_TEST(test_GetDataSize) * ==> shared user value accessible by A GROUP (user 2 and seat 1) */ size = pclKeyGetSize(0x84, "links/last_link", 2, 1); + printf("=>=>=>=> soll: %d | ist: %d\n", strlen("CACHE_ /last_exit/queens"), size); x_fail_unless(size == strlen("CACHE_ /last_exit/queens"), "Invalid size"); #endif pclDeinitLibrary(); @@ -595,37 +600,55 @@ START_TEST(test_DataFile) x_fail_unless(fd != -1, "Could not open file ==> /media/mediaDB.db"); size = pclFileGetSize(fd); + printf("%s => %d\n", __FUNCTION__, __LINE__); + printf("Soll: 68 | Ist: %d\n", size); + printf("%s => %d\n", __FUNCTION__, __LINE__); x_fail_unless(size == 68, "Wrong file size"); + printf("%s => %d\n", __FUNCTION__, __LINE__); + printf("%s => %d\n", __FUNCTION__, __LINE__); size = pclFileReadData(fd, buffer, READ_SIZE); + printf("%s => %d\n", __FUNCTION__, __LINE__); x_fail_unless(strncmp((char*)buffer, refBuffer, strlen(refBuffer)) == 0, "Buffer not correctly read => media/mediaDB.db"); + printf("%s => %d\n", __FUNCTION__, __LINE__); x_fail_unless(size == (strlen(refBuffer)+1), "Wrong size returned"); // strlen + 1 ==> inlcude cr/lf - + printf("%s => %d\n", __FUNCTION__, __LINE__); ret = pclFileClose(fd); + printf("%s => %d\n", __FUNCTION__, __LINE__); x_fail_unless(ret == 0, "Failed to close file"); + printf("%s => %d\n", __FUNCTION__, __LINE__); // open ------------------------------------------------------------ + printf("%s => %d\n", __FUNCTION__, __LINE__); fd = pclFileOpen(0xFF, "media/mediaDBWrite.db", 1, 1); + printf("%s => %d\n", __FUNCTION__, __LINE__); x_fail_unless(fd != -1, "Could not open file ==> /media/mediaDBWrite.db"); size = pclFileWriteData(fd, writeBuffer, strlen(writeBuffer)); x_fail_unless(size == strlen(writeBuffer), "Failed to write data"); - + printf("%s => %d\n", __FUNCTION__, __LINE__); ret = pclFileClose(fd); + printf("%s => %d\n", __FUNCTION__, __LINE__); x_fail_unless(ret == 0, "Failed to close file"); - + printf("* * %s => %d\n", __FUNCTION__, __LINE__); // remove ---------------------------------------------------------- + printf("* * %s => %d\n", __FUNCTION__, __LINE__); ret = pclFileRemove(0xFF, "media/mediaDBWrite.db", 1, 1); + printf("* * %s => %d\n", __FUNCTION__, __LINE__); x_fail_unless(ret == 0, "File can't be removed ==> /media/mediaDBWrite.db"); + printf("* * %s => %d\n", __FUNCTION__, __LINE__); fd = open("/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media/mediaDBWrite.db",O_RDWR); + printf("* * %s => %d\n", __FUNCTION__, __LINE__); x_fail_unless(fd == -1, "Failed to remove file, file still exists"); + printf("* * %s => %d\n", __FUNCTION__, __LINE__); close(fd); - + printf("* * %s => %d\n", __FUNCTION__, __LINE__); // map file -------------------------------------------------------- + fd = pclFileOpen(0xFF, "media/mediaDB.db", 1, 1); size = pclFileGetSize(fd); @@ -864,6 +887,7 @@ END_TEST +#if 0 /** * Test for i n t e r n a l structures. * Test the cursor functions. @@ -936,6 +960,7 @@ START_TEST(test_Cursor) pclDeinitLibrary(); } END_TEST +#endif @@ -1231,9 +1256,6 @@ static Suite * persistencyClientLib_suite() TCase * tc_persDataFileRecovery = tcase_create("DataFileRecovery"); tcase_add_test(tc_persDataFileRecovery, test_DataFileRecovery); - TCase * tc_Cursor = tcase_create("Cursor"); - tcase_add_test(tc_Cursor, test_Cursor); - TCase * tc_Plugin = tcase_create("Plugin"); tcase_add_test(tc_Plugin, test_Plugin); @@ -1265,7 +1287,6 @@ static Suite * persistencyClientLib_suite() suite_add_tcase(s, tc_persDataHandleOpen); suite_add_tcase(s, tc_persDataFile); suite_add_tcase(s, tc_persDataFileRecovery); - suite_add_tcase(s, tc_Cursor); suite_add_tcase(s, tc_ReadDefault); suite_add_tcase(s, tc_ReadConfDefault); suite_add_tcase(s, tc_GetPath); @@ -1274,6 +1295,7 @@ static Suite * persistencyClientLib_suite() suite_add_tcase(s, tc_FileOpenCreate); //suite_add_tcase(s, tc_Plugin); // activate only if the plugins are available + return s; } @@ -1292,7 +1314,7 @@ int main(int argc, char *argv[]) gTheAppId[MaxAppNameLen-1] = '\0'; /// debug log and trace (DLT) setup - DLT_REGISTER_APP("test","tests the persistence client library"); + DLT_REGISTER_APP("PCLt","tests the persistence client library"); #if 1 Suite * s = persistencyClientLib_suite(); |