From b13802972ee82370c33a14150e480220761cac75 Mon Sep 17 00:00:00 2001 From: Ingo Huerner Date: Wed, 2 Jul 2014 15:46:13 +0200 Subject: [PATCH] Protected global variables with mutex; minor optimizations; corrected doxygen documentation --- include/persistence_client_library.h | 22 +- src/persistence_client_library.c | 12 +- src/persistence_client_library_backup_filelist.c | 22 +- src/persistence_client_library_backup_filelist.h | 8 +- src/persistence_client_library_custom_loader.c | 29 +-- src/persistence_client_library_custom_loader.h | 45 ++-- src/persistence_client_library_data_organization.c | 34 +-- src/persistence_client_library_data_organization.h | 202 +++++++++------ src/persistence_client_library_db_access.c | 14 +- src/persistence_client_library_db_access.h | 14 +- src/persistence_client_library_dbus_cmd.c | 1 + src/persistence_client_library_dbus_cmd.h | 33 ++- src/persistence_client_library_dbus_service.c | 27 +- src/persistence_client_library_dbus_service.h | 100 +++++--- src/persistence_client_library_file.c | 131 +++++----- src/persistence_client_library_handle.c | 275 +++++++++++++++++++-- src/persistence_client_library_handle.h | 253 +++++++++++++++++-- src/persistence_client_library_key.c | 87 +++---- src/persistence_client_library_lc_interface.c | 6 +- src/persistence_client_library_lc_interface.h | 4 +- src/persistence_client_library_pas_interface.c | 6 +- src/persistence_client_library_pas_interface.h | 10 +- src/persistence_client_library_prct_access.c | 7 +- src/persistence_client_library_prct_access.h | 15 +- src/rbtree.c | 2 +- src/rbtree.h | 2 +- 26 files changed, 947 insertions(+), 414 deletions(-) diff --git a/include/persistence_client_library.h b/include/persistence_client_library.h index f7a835c..b63ff0f 100644 --- a/include/persistence_client_library.h +++ b/include/persistence_client_library.h @@ -41,12 +41,22 @@ * via a key-value and a file interface.
* It also provide a plugin API to allow users to extend the client library with custom storage solutions. * - * @section Custom plugin configuration file + * @section doc Further documentation + * @subsection docUser User Manual + * There is a a user manual for the client library available, + * see: http://docs.projects.genivi.org/persistence-client-library/1.0/GENIVI_Persistence_Client_Library_UserManual.pdf + * + * @subsection docArch Architecture Manual + * For more information about the persistence architecture, + * see: http://docs.projects.genivi.org/persistence-client-library/1.0/GENIVI_Persistence_ArchitectureDocumentation.pdf + * + * + * @section plugin Custom plugin configuration file * @attention * The plugin configuration file has been changed! * * The configuration file has now the following format
- * + * <predefinedPluginName> <pathAndLibraryName> <loadingType> <initType> * * Predefined plugin name
* Use one of the following names: @@ -125,7 +135,7 @@ extern "C" { * * @return positive value: success; * On error a negative value will be returned with the following error codes: - * ::EPERS_NOT_INITIALIZED, ::EPERS_INIT_DBUS_MAINLOOP, + * ::EPERS_NOT_INITIALIZED, ::EPERS_DBUS_MAINLOOP, * ::EPERS_REGISTER_LIFECYCLE, ::EPERS_REGISTER_ADMIN */ int pclInitLibrary(const char* appname, int shutdownMode); @@ -159,12 +169,12 @@ int pclDeinitLibrary(void); * In the next lifecycle the application can store data again until the limit above * has been reached. * - * @parm PCL_SHUTDOWN for write back data when shutdown is requested, - * and PCL_SHUTDOWN_CANEL when shutdown cancel request has been received. + * @param shutdown PCL_SHUTDOWN for write back data when shutdown is requested, + * and PCL_SHUTDOWN_CANEL when shutdown cancel request has been received. * * @return positive value: success; * On error a negative value will be returned with the following error codes: - * ::EPERS_COMMON, ::EPERS_MAX_CANCEL_SHUTDOWN, ::EPERS_SHTDWN_NO_PERMIT + * ::EPERS_COMMON, ::EPERS_SHUTDOWN_MAX_CANCEL, ::EPERS_SHUTDOWN_NO_PERMIT */ int pclLifecycleSet(int shutdown); diff --git a/src/persistence_client_library.c b/src/persistence_client_library.c index 5bcda0f..93e2339 100644 --- a/src/persistence_client_library.c +++ b/src/persistence_client_library.c @@ -41,8 +41,10 @@ /// debug log and trace (DLT) setup DLT_DECLARE_CONTEXT(gPclDLTContext); -static int gShutdownMode = 0; +/// global variable to store lifecycle shutdown mode +static int gShutdownMode = 0; +/// global shutdown cancel counter static int gCancelCounter = 0; @@ -134,7 +136,7 @@ int pclInitLibrary(const char* appName, int shutdownMode) } // initialize keyHandle array - memset(gKeyHandleArray, 0, MaxPersHandle * sizeof(PersistenceKeyHandle_s)); + init_key_handle_array(); pers_unlock_access(); @@ -163,7 +165,7 @@ int pclDeinitLibrary(void) if(gPclInitialized == PCLinitialized) { int* retval; - tMainLoopData data; + MainLoopData_u data; data.message.cmd = (uint32_t)CMD_QUIT; data.message.string[0] = '\0'; // no string parameter, set to 0 @@ -240,11 +242,11 @@ int pclLifecycleSet(int shutdown) if(gShutdownMode == PCL_SHUTDOWN_TYPE_NONE) { - if(PCL_SHUTDOWN) + if(shutdown == PCL_SHUTDOWN) { process_prepare_shutdown(Shutdown_Partial); // close all db's and fd's and block access } - else if(PCL_SHUTDOWN_CANEL) + else if(shutdown == PCL_SHUTDOWN_CANEL) { if(gCancelCounter < Shutdown_MaxCount) { diff --git a/src/persistence_client_library_backup_filelist.c b/src/persistence_client_library_backup_filelist.c index 6fb152d..11312f7 100644 --- a/src/persistence_client_library_backup_filelist.c +++ b/src/persistence_client_library_backup_filelist.c @@ -44,17 +44,15 @@ typedef struct _key_value_s }key_value_s; -void key_val_rel(void *p); +static void key_val_rel(void *p); -void* key_val_dup(void *p); +static void* key_val_dup(void *p); -int key_val_cmp(const void *p1, const void *p2 ); - -char* gpConfigFileMap = 0; +static char* gpConfigFileMap = 0; static char* gpTokenArray[TOKENARRAYSIZE] = {0}; -int gTokenCounter = 0; -unsigned int gConfigFileSize = 0; +static int gTokenCounter = 0; +static unsigned int gConfigFileSize = 0; /// the rb tree @@ -62,10 +60,10 @@ static jsw_rbtree_t *gRb_tree_bl = NULL; // local function prototypes -int need_backup_key(unsigned int key); - +static int need_backup_key(unsigned int key); +static int key_val_cmp(const void *p1, const void *p2 ); -void fillFileBackupCharTokenArray() +static void fillFileBackupCharTokenArray() { unsigned int i=0; int blankCount=0; @@ -100,7 +98,7 @@ void fillFileBackupCharTokenArray() } -void createAndStoreFileNames() +static void createAndStoreFileNames() { int i= 0, j =0; char path[128]; @@ -309,7 +307,7 @@ void key_val_rel(void *p ) } -int pclBackupDoFileCopy(int srcFd, int dstFd) +static int pclBackupDoFileCopy(int srcFd, int dstFd) { struct stat buf; int rval = 0; diff --git a/src/persistence_client_library_backup_filelist.h b/src/persistence_client_library_backup_filelist.h index ac668f0..c940967 100644 --- a/src/persistence_client_library_backup_filelist.h +++ b/src/persistence_client_library_backup_filelist.h @@ -49,7 +49,7 @@ int pclCreateFile(const char* path); * * @param srcPath the path of the file * @param srcfd the file descriptor of the file - * @param csumpath the path where to checksum will be stored + * @param csumPath the path where to checksum will be stored * @param csumBuf the checksum string * * @return -1 on error or a positive value indicating number of bytes of the backup file created @@ -60,7 +60,7 @@ int pclCreateBackup(const char* srcPath, int srcfd, const char* csumPath, const /** * @brief recover file form backup * - * @param backupfd the file descriptor of the backup file + * @param backupFd the file descriptor of the backup file * @param original the path of the file to be recovered * * @return 0 on success -1 on error @@ -85,7 +85,7 @@ int pclCalcCrc32Csum(int fd, char crc32sum[]); * @param origPath the path of the file to verify * @param backupPath the path of the backup file * @param csumPath the path to the checksum file - * @param openFlag the file open flags + * @param openFlags the file open flags * * @return -1 if the file could not be recovered or a positive value (>=0) on successful recovery */ @@ -106,7 +106,7 @@ inline int pclBackupNeeded(const char* path); /** * @brief translate persistence permission into POSIX file open permissions * - * @param permission the permission enumerator ::PersistencePermission_e + * @param permission the permission enumerator PersistencePermission_e * * @return the POSIX file permission will be returned of -1 in an error case. * If an unknown PersistencePermission_e will be detected the diff --git a/src/persistence_client_library_custom_loader.c b/src/persistence_client_library_custom_loader.c index db3a16d..8a5c1a4 100644 --- a/src/persistence_client_library_custom_loader.c +++ b/src/persistence_client_library_custom_loader.c @@ -43,14 +43,14 @@ typedef struct sPersCustomLibInfo /// array with custom client library names static PersCustomLibInfo gCustomLibArray[PersCustomLib_LastEntry]; -char* gpCustomConfigFileMap = 0; +static char* gpCustomConfigFileMap = 0; static char* gpCustomTokenArray[TOKENARRAYSIZE]; -int gCustomTokenCounter = 0; -unsigned int gCustomConfigFileSize = 0; +static int gCustomTokenCounter = 0; +static unsigned int gCustomConfigFileSize = 0; int(* gPlugin_callback_async_t)(int errcode); -void fillCustomCharTokenArray() +static void fillCustomCharTokenArray() { unsigned int i=0; int blankCount=0; @@ -81,12 +81,8 @@ void fillCustomCharTokenArray() } } -PersLoadingType_e getCustomLoadingType(int i) -{ - return gCustomLibArray[i].loadingType; -} -PersLoadingType_e getLoadingType(const char* type) +static PersLoadingType_e getLoadingType(const char* type) { PersLoadingType_e persLoadingType = LoadType_Undefined; @@ -102,12 +98,8 @@ PersLoadingType_e getLoadingType(const char* type) return persLoadingType; } -PersInitType_e getCustomInitType(int i) -{ - return gCustomLibArray[i].initFunction; -} -PersInitType_e getInitType(const char* policy) +static PersInitType_e getInitType(const char* policy) { PersInitType_e persInitType = Init_Undefined; @@ -124,7 +116,16 @@ PersInitType_e getInitType(const char* policy) } +PersLoadingType_e getCustomLoadingType(int i) +{ + return gCustomLibArray[i].loadingType; +} + +PersInitType_e getCustomInitType(int i) +{ + return gCustomLibArray[i].initFunction; +} PersistenceCustomLibs_e custom_client_name_to_id(const char* lib_name, int substring) diff --git a/src/persistence_client_library_custom_loader.h b/src/persistence_client_library_custom_loader.h index 80eb2ba..fb758ae 100644 --- a/src/persistence_client_library_custom_loader.h +++ b/src/persistence_client_library_custom_loader.h @@ -25,17 +25,25 @@ /// enumerator used to identify the policy to manage the data typedef enum _PersistenceCustomLibs_e { - PersCustomLib_early = 0, /// predefined custom library for early persistence - PersCustomLib_secure = 1, /// predefined custom library for secure persistence - PersCustomLib_emergency = 2, /// predefined custom library for emengency persistence - PersCustomLib_HWinfo = 3, /// predefined custom library for hw information - PersCustomLib_Custom1 = 4, /// custom library 1 - PersCustomLib_Custom2 = 5, /// custom library 2 - PersCustomLib_Custom3 = 6, /// custom library 3 + /// predefined custom library for early persistence + PersCustomLib_early = 0, + /// predefined custom library for secure persistence + PersCustomLib_secure = 1, + /// predefined custom library for emengency persistence + PersCustomLib_emergency = 2, + /// predefined custom library for hw information + PersCustomLib_HWinfo = 3, + /// custom library 1 + PersCustomLib_Custom1 = 4, + /// custom library 2 + PersCustomLib_Custom2 = 5, + /// custom library 3 + PersCustomLib_Custom3 = 6, // insert new entries here ... - PersCustomLib_LastEntry /// last entry + /// last entry + PersCustomLib_LastEntry } PersistenceCustomLibs_e; @@ -43,7 +51,8 @@ typedef enum _PersistenceCustomLibs_e /// enumerator fo custom library defines enum _PersCustomLibDefines_e { - PersCustomPathSize = 12 /// the custom library path size + /// the custom library path size + PersCustomPathSize = 12 } PersCustomLibDefines_e; @@ -51,8 +60,11 @@ enum _PersCustomLibDefines_e /// indicates the init method type typedef enum PersInitType_e_ { - Init_Synchronous = 0, /// initialize the plugin with the synchronous init function - Init_Asynchronous = 1, /// initialize the plugin with the asynchronous init function + /// initialize the plugin with the synchronous init function + Init_Synchronous = 0, + /// initialize the plugin with the asynchronous init function + Init_Asynchronous = 1, + /// undefined Init_Undefined } PersInitType_e; @@ -60,8 +72,11 @@ typedef enum PersInitType_e_ /// indicates the plugin loading type typedef enum PersLoadingType_e_ { - LoadType_PclInit = 0, /// load plugin during pclInitLibrary function - LoadType_OnDemand = 1, /// load the pluing on demand, when a plugin function will be requested the first time. + /// load plugin during pclInitLibrary function + LoadType_PclInit = 0, + /// load the pluing on demand, when a plugin function will be requested the first time. + LoadType_OnDemand = 1, + /// undefined LoadType_Undefined } PersLoadingType_e; @@ -178,7 +193,7 @@ int load_custom_library(PersistenceCustomLibs_e customLib, Pers_custom_functs_s /** * @brief get the position in the array * - * @param customLib the enumerator id identifying the custom library + * @param idx the index to identifying the custom library * * @return the array position or -1 if the position can't be found */ @@ -189,6 +204,8 @@ int check_valid_idx(int idx); /** * @brief get the custom library name form an index * + * @param idx the index to identifying the custom library + * * @return the name of the custom library ot NULL if invalid */ char* get_custom_client_lib_name(int idx); diff --git a/src/persistence_client_library_data_organization.c b/src/persistence_client_library_data_organization.c index 83ecaec..0723f75 100644 --- a/src/persistence_client_library_data_organization.c +++ b/src/persistence_client_library_data_organization.c @@ -32,44 +32,44 @@ /// path for the backup location const char* gBackupPrefix = PERS_ORG_ROOT_PATH "/mnt-backup/"; -/// size of cached path string +// size of cached path string const int gCPathPrefixSize = sizeof(CACHEPREFIX)-1; -/// size of write through string +// size of write through string const int gWTPathPrefixSize = sizeof(WTPREFIX)-1; -/// backup filename postfix +// backup filename postfix const char* gBackupPostfix = "~"; -/// backup checksum filename postfix +// backup checksum filename postfix const char* gBackupCsPostfix = "~.crc"; -/// path prefix for local cached database: /Data/mnt_c// ( +// path prefix for local cached database: /Data/mnt_c// ( const char* gLocalCachePath = CACHEPREFIX "%s"; -/// path prefix for local write through database /Data/mnt_wt// +// path prefix for local write through database /Data/mnt_wt// const char* gLocalWtPath = WTPREFIX "%s"; -/// path prefix for shared cached database: /Data/mnt_c/Shared/Group// +// path prefix for shared cached database: /Data/mnt_c/Shared/Group// const char* gSharedCachePath = CACHEPREFIX "%s/shared_group_%x"; -/// path prefix for shared write through database: /Data/mnt_wt/Shared/Group// +// path prefix for shared write through database: /Data/mnt_wt/Shared/Group// const char* gSharedWtPath = WTPREFIX "%s/shared_group_%x"; -/// path prefix for shared public cached database: /Data/mnt_c/Shared/Public// +// path prefix for shared public cached database: /Data/mnt_c/Shared/Public// const char* gSharedPublicCachePath = CACHEPREFIX "%s/shared_public"; -/// path prefix for shared public write through database: /Data/mnt_wt/Shared/Public/ +// path prefix for shared public write through database: /Data/mnt_wt/Shared/Public/ const char* gSharedPublicWtPath = WTPREFIX "%s/shared_public"; -/// path prefix for local cached database: /Data/mnt_c// ( +// path prefix for local cached database: /Data/mnt_c// ( const char* gLocalCachePathKey = CACHEPREFIX "%s%s"; -/// path prefix for local write through database /Data/mnt_wt// +// path prefix for local write through database /Data/mnt_wt// const char* gLocalWtPathKey = WTPREFIX "%s%s"; -/// path prefix for shared cached database: /Data/mnt_c/Shared/Group// +// path prefix for shared cached database: /Data/mnt_c/Shared/Group// const char* gSharedCachePathKey = CACHEPREFIX "%s/shared_group_%x%s"; -/// path prefix for shared write through database: /Data/mnt_wt/Shared/Group// +// path prefix for shared write through database: /Data/mnt_wt/Shared/Group// const char* gSharedWtPathKey = WTPREFIX "%s/shared_group_%x%s"; -/// path prefix for shared public cached database: /Data/mnt_c/Shared/Public// +// path prefix for shared public cached database: /Data/mnt_c/Shared/Public// const char* gSharedPublicCachePathKey = CACHEPREFIX "%s/shared_public%s"; -/// path prefix for shared public write through database: /Data/mnt_wt/Shared/Public/ +// path prefix for shared public write through database: /Data/mnt_wt/Shared/Public/ const char* gSharedPublicWtPathKey = WTPREFIX "%s/shared_public%s"; -/// path prefix for local cached files: /Data/mnt_c//// +// path prefix for local cached files: /Data/mnt_c//// const char* gLocalCacheFilePath = CACHEPREFIX "%s"PERS_ORG_USER_FOLDER_NAME_"%d"PERS_ORG_SEAT_FOLDER_NAME_"%d/%s"; diff --git a/src/persistence_client_library_data_organization.h b/src/persistence_client_library_data_organization.h index 5b22ae4..1efb88a 100644 --- a/src/persistence_client_library_data_organization.h +++ b/src/persistence_client_library_data_organization.h @@ -44,109 +44,151 @@ extern "C" { /// structure used to manage database context typedef struct _PersistenceDbContext_s { + /// lofical database id unsigned int ldbid; + /// user number unsigned int user_no; + /// seat number unsigned int seat_no; } PersistenceDbContext_s; /// persistence information typedef struct _PersistenceInfo_s { - PersistenceDbContext_s context; /**< database context*/ - PersistenceConfigurationKey_s configKey; /**< prct configuration key*/ + /// database context ::PersistenceDbContext_s + PersistenceDbContext_s context; + /// Persistence resource configuration key + PersistenceConfigurationKey_s configKey; } PersistenceInfo_s; -/** storages to manage the data */ +/// 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 */ + /// get the data from configurable defaults + PersDefaultType_Configurable = 0, + /// get the data from factory defaults + PersDefaultType_Factory, /** insert new entries here ... */ - PersDefaultType_LastEntry /**< last entry */ + + /// last entry + PersDefaultType_LastEntry } PersDefaultType_e; -/** storages to manage the data */ +/// 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 */ + /// get the data from configurable defaults + PersGetDefault_Data = 0, + /// get the data from factory defaults + PersGetDefault_Size, /** insert new entries here ... */ - PersGetDefault_LastEntry /**< last entry */ + + /// last entry + PersGetDefault_LastEntry } PersGetDefault_e; /// enumerator used to identify the policy to manage the data typedef enum _PersNotifyRegPolicy_e { - Notify_register = 0, /**< register to change notifications*/ - Notify_unregister = 1, /**< unregister for change notifications */ - Notify_lastEntry, /**/ +/// path prefix for local cached database: /Data/mnt_c/<appId>/<database_name> extern const char* gLocalCachePath; -/// path prefix for local write through database /Data/mnt_wt// +/// path prefix for local write through database /Data/mnt_wt/<appId>/<database_name> extern const char* gLocalWtPath; -/// path prefix for shared cached database: /Data/mnt_c/Shared/Group// +/// path prefix for shared cached database: /Data/mnt_c/Shared/Group/<group_no>/<database_name> extern const char* gSharedCachePath; -/// path prefix for shared write through database: /Data/mnt_wt/Shared/Group// +/// path prefix for shared write through database: /Data/mnt_wt/Shared/Group/<group_no>/<database_name> extern const char* gSharedWtPath; -/// path prefix for shared public cached database: /Data/mnt_c/Shared/Public// +/// path prefix for shared public cached database: /Data/mnt_c/Shared/Public//<database_name> extern const char* gSharedPublicCachePath; -/// path prefix for shared public write through database: /Data/mnt_wt/Shared/Public/ +/// path prefix for shared public write through database: /Data/mnt_wt/Shared/Public/<database_name> extern const char* gSharedPublicWtPath; -/// path prefix for local cached database: /Data/mnt_c// +/// path prefix for local cached database: /Data/mnt_c/<appId>/<database_name> extern const char* gLocalCachePathKey; -/// path prefix for local write through database /Data/mnt_wt// +/// path prefix for local write through database /Data/mnt_wt/<appId>/<database_name> extern const char* gLocalWtPathKey; -/// path prefix for shared cached database: /Data/mnt_c/Shared/Group// +/// path prefix for shared cached database: /Data/mnt_c/Shared/Group/<group_no>/<database_name> extern const char* gSharedCachePathKey; -/// path prefix for shared write through database: /Data/mnt_wt/Shared/Group// +/// path prefix for shared write through database: /Data/mnt_wt/Shared/Group/<group_no>/<database_name> extern const char* gSharedWtPathKey; -/// path prefix for shared public cached database: /Data/mnt_c/Shared/Public// +/// path prefix for shared public cached database: /Data/mnt_c/Shared/Public//<database_name> extern const char* gSharedPublicCachePathKey; -/// path prefix for shared public write through database: /Data/mnt_wt/Shared/Public/ +/// path prefix for shared public write through database: /Data/mnt_wt/Shared/Public/<database_name> extern const char* gSharedPublicWtPathKey; -/// path prefix for local cached files: /Data/mnt_c///>userno>//>seatno>/ +/// path prefix for local cached files: /Data/mnt_c/<appId>/<user>/>userno>/<seat>/>seatno>/<resource> extern const char* gLocalCacheFilePath; /// application id diff --git a/src/persistence_client_library_db_access.c b/src/persistence_client_library_db_access.c index 3406849..2749882 100644 --- a/src/persistence_client_library_db_access.c +++ b/src/persistence_client_library_db_access.c @@ -9,7 +9,7 @@ * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. ******************************************************************************/ /** - * @file persistence_client_library_data_access.c + * @file persistence_client_library_db_access.c * @ingroup Persistence client library * @author Ingo Huerner * @brief Implementation of persistence database access @@ -167,7 +167,7 @@ int pers_get_defaults(char* dbPath, char* key, unsigned char* buffer, unsigned i } -int database_get(PersistenceInfo_s* info, const char* dbPath) +static int database_get(PersistenceInfo_s* info, const char* dbPath) { int arrayIdx = 0; int handleDB = -1; @@ -718,7 +718,7 @@ int persistence_notify_on_change(const char* key, unsigned int ldbid, unsigned i if(regPolicy < Notify_lastEntry) { - tMainLoopData data; + MainLoopData_u data; data.message.cmd = (uint32_t)CMD_REG_NOTIFY_SIGNAL; data.message.params[0] = ldbid; @@ -763,7 +763,7 @@ int pers_send_Notification_Signal(const char* key, PersistenceDbContext_s* conte int rval = 1; if(reason < pclNotifyStatus_lastEntry) { - tMainLoopData data; + MainLoopData_u data; data.message.cmd = (uint32_t)CMD_SEND_NOTIFY_SIGNAL; data.message.params[0] = context->ldbid; @@ -795,14 +795,14 @@ void pers_rct_close_all() // close all open persistence resource configuration tables for(i=0; i< PrctDbTableSize; i++) { - if(gResource_table[i] != -1) + if(get_resource_cfg_table_by_idx(i) != -1) { - if(persComRctClose(gResource_table[i]) != 0) + if(persComRctClose(get_resource_cfg_table_by_idx(i)) != 0) { DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("process_prepare_shutdown => failed to close db => index:"), DLT_INT(i)); } - gResource_table[i] = -1; + invalidate_resource_cfg_table(i); } } } diff --git a/src/persistence_client_library_db_access.h b/src/persistence_client_library_db_access.h index 22986aa..dc80496 100644 --- a/src/persistence_client_library_db_access.h +++ b/src/persistence_client_library_db_access.h @@ -12,7 +12,7 @@ * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. ******************************************************************************/ /** - * @file persistence_client_library_data_access.h + * @file persistence_client_library_db_access.h * @ingroup Persistence client library * @author Ingo Huerner * @brief Header of the persistence client library database access. @@ -51,6 +51,7 @@ 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. + * @param DefaultType the default type * * @return >= 0 for valid handler; if an error occured the following error code: * EPERS_COMMON @@ -70,7 +71,7 @@ int pers_db_open_default(const char* dbPath, PersDefaultType_e DefaultType); * * @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 + * EPERS_NOKEY */ int pers_get_defaults(char* dbPath, char* key, unsigned char* buffer, unsigned int buffer_size, PersGetDefault_e job); @@ -97,6 +98,7 @@ int persistence_set_data(char* dbPath, char* key, PersistenceInfo_s* info, unsig * * @param dbPath the path to the database where the key is in * @param key the database key + * @param resourceID the resource id * @param info persistence information * @param buffer the buffer holding the data * @param buffer_size the size of the buffer @@ -160,9 +162,9 @@ void database_close_all(); * @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 + * @param regPolicy ::Notify_register to register; ::Notify_unregister to unregister * - * @return 0 of registration was successfull; -1 if registration failes + * @return 0 of registration was successful; -1 if registration fails */ int persistence_notify_on_change(const char* key, unsigned int ldbid, unsigned int user_no, unsigned int seat_no, pclChangeNotifyCallback_t callback, PersNotifyRegPolicy_e regPolicy); @@ -176,13 +178,13 @@ int persistence_notify_on_change(const char* key, unsigned int ldbid, unsigned i * @param context the database context * @param reason the reason of the signal, values see pclNotifyStatus_e. * - * @return 0 of registration was successfull; -1 if registration failes + * @return 0 of registration was successful; -1 if registration failes */ int pers_send_Notification_Signal(const char* key, PersistenceDbContext_s* context, pclNotifyStatus_e reason); + /** * @brief close all open persistence resource configuration tables - * */ void pers_rct_close_all(); diff --git a/src/persistence_client_library_dbus_cmd.c b/src/persistence_client_library_dbus_cmd.c index 04d5789..d23c4ad 100644 --- a/src/persistence_client_library_dbus_cmd.c +++ b/src/persistence_client_library_dbus_cmd.c @@ -40,6 +40,7 @@ extern int pfcWriteBackAndSync(int handle); #endif + // function prototype void msg_pending_func(DBusPendingCall *call, void *data); diff --git a/src/persistence_client_library_dbus_cmd.h b/src/persistence_client_library_dbus_cmd.h index 9e15b9b..14a7cab 100644 --- a/src/persistence_client_library_dbus_cmd.h +++ b/src/persistence_client_library_dbus_cmd.h @@ -35,6 +35,11 @@ void process_prepare_shutdown(int complete); * @brief send notification signal * * @param conn the dbus connection + * @param notifyLdbid the ldbid to notify on + * @param notifyUserNo the user number to notify on + * @param notifySeatNo the seat to notify on + * @param notifyReason the notify reason to notify on + * @param notifyKey the notification key */ void process_send_notification_signal(DBusConnection* conn, unsigned int notifyLdbid, unsigned int notifyUserNo, unsigned int notifySeatNo, unsigned int notifyReason, const char* notifyKey); @@ -44,14 +49,32 @@ void process_send_notification_signal(DBusConnection* conn, unsigned int notifyL * @brief register for notification signal * * @param conn the dbus connection + * @param notifyLdbid the ldbid to notify on + * @param notifyUserNo the user number to notify on + * @param notifySeatNo the seat to notify on + * @param notifyPolicy the notify policy to notify on + * @param notifyKey the notification key */ void process_reg_notification_signal(DBusConnection* conn, unsigned int notifyLdbid, unsigned int notifyUserNo, unsigned int notifySeatNo, unsigned int notifyPolicy, const char* notifyKey); - +/** + * @brief send lifecycle request + * + * @param conn the dbus connection + * @param requestId the request id + * @param status the status + */ void process_send_lifecycle_request(DBusConnection* conn, unsigned int requestId, unsigned int status); +/** + * @brief send lifecycle register message + * + * @param conn the dbus connection + * @param regType the request type + * @param shutdownMode the shutdown mode to register on + */ void process_send_lifecycle_register(DBusConnection* conn, int regType, int shutdownMode); @@ -59,7 +82,7 @@ void process_send_lifecycle_register(DBusConnection* conn, int regType, int shut /** * @brief block persistence access and write data back to device * - * @param requestId the requestID + * @param requestID the requestID * @param status the status */ void process_block_and_write_data_back(unsigned int requestID, unsigned int status); @@ -69,7 +92,8 @@ void process_block_and_write_data_back(unsigned int requestID, unsigned int stat /** * @brief process a request of the persistence admin service * - * @param requestId the requestID + * @param conn the dbus connection + * @param requestID the requestID * @param status the status */ void process_send_pas_request(DBusConnection* conn, unsigned int requestID, int status); @@ -79,8 +103,9 @@ void process_send_pas_request(DBusConnection* conn, unsigned int requestID, int /** * @brief process a request of the persistence admin service * + * @param conn the dbus connection * @param regType the registration type (1 for register; 0 for unregister) - * @param notification flag the notificatin flag + * @param notificationFlag flag the notificatin flag */ void process_send_pas_register(DBusConnection* conn, int regType, int notificationFlag); diff --git a/src/persistence_client_library_dbus_service.c b/src/persistence_client_library_dbus_service.c index 94a616f..1969081 100644 --- a/src/persistence_client_library_dbus_service.c +++ b/src/persistence_client_library_dbus_service.c @@ -59,8 +59,9 @@ const char* gDbusPersAdminPath = "/org/genivi/persistence/admin"; const char* gDbusPersAdminInterface = "org.genivi.persistence.admin"; const char* gDbusPersAdminConsMsg = "PersistenceAdminRequest"; +/// communication channel into the dbus mainloop +static int gPipeFd[2] = {0}; -int gPipeFd[2] = {0}; // communication channel int dbus mainloop typedef enum EDBusObjectType { @@ -70,13 +71,15 @@ typedef enum EDBusObjectType } tDBusObjectType; + +/// object entry typedef struct SObjectEntry { - tDBusObjectType objtype; /** libdbus' object */ + tDBusObjectType objtype; /// libdbus' object union { - DBusWatch * watch; /** watch "object" */ - DBusTimeout * timeout; /** timeout "object" */ + DBusWatch * watch; /// watch "object" + DBusTimeout * timeout; /// timeout "object" }; } tObjectEntry; @@ -85,16 +88,16 @@ typedef struct SObjectEntry /// polling structure typedef struct SPollInfo { - int nfds; - struct pollfd fds[10]; - tObjectEntry objects[10]; + int nfds; /// number of polls + struct pollfd fds[10]; /// poll file descriptors array + tObjectEntry objects[10]; /// poll object } tPollInfo; /// polling information -static tPollInfo gPollInfo; +static tPollInfo gPollInfo; /// polling information -int bContinue = 0; +int bContinue = 0; /// indicator if dbus mainloop shall continue #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0])) @@ -600,7 +603,7 @@ int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtable2, /* internal command */ if (0!=(gPollInfo.fds[i].revents & POLLIN)) { - tMainLoopData readData; + MainLoopData_u readData; bContinue = TRUE; while ((-1==(ret = read(gPollInfo.fds[i].fd, readData.payload, 128)))&&(EINTR == errno)); if(ret < 0) @@ -700,7 +703,7 @@ int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtable2, -int deliverToMainloop(tMainLoopData* payload) +int deliverToMainloop(MainLoopData_u* payload) { int rval = 0; @@ -719,7 +722,7 @@ int deliverToMainloop(tMainLoopData* payload) return rval; } -int deliverToMainloop_NM(tMainLoopData* payload) +int deliverToMainloop_NM(MainLoopData_u* payload) { int rval = 0, length = 128; diff --git a/src/persistence_client_library_dbus_service.h b/src/persistence_client_library_dbus_service.h index 59666ce..cc40b58 100644 --- a/src/persistence_client_library_dbus_service.h +++ b/src/persistence_client_library_dbus_service.h @@ -27,30 +27,56 @@ #include "persistence_client_library_data_organization.h" -/// mutex to make sure main loop is running -extern pthread_mutex_t gDbusInitializedMtx; -extern pthread_cond_t gDbusInitializedCond; -extern pthread_mutex_t gDbusPendingRegMtx; - -extern pthread_mutex_t gMainCondMtx; - -extern pthread_t gMainLoopThread; - - /// command definitions for main loop typedef enum ECmd { - CMD_NONE = 0, /// command none - CMD_PAS_BLOCK_AND_WRITE_BACK, /// command block access and write data back - CMD_LC_PREPARE_SHUTDOWN, /// command to prepare shutdown - CMD_SEND_NOTIFY_SIGNAL, /// command send changed notification signal - CMD_REG_NOTIFY_SIGNAL, /// command send register/unregister command - CMD_SEND_PAS_REGISTER, /// command send admin register/unregister - CMD_SEND_LC_REGISTER, /// command send lifecycle register/unregister - CMD_QUIT /// quit command + /// command none + CMD_NONE = 0, + /// command block access and write data back + CMD_PAS_BLOCK_AND_WRITE_BACK, + /// command to prepare shutdown + CMD_LC_PREPARE_SHUTDOWN, + /// command send changed notification signal + CMD_SEND_NOTIFY_SIGNAL, + /// command send register/unregister command + CMD_REG_NOTIFY_SIGNAL, + /// command send admin register/unregister + CMD_SEND_PAS_REGISTER, + /// command send lifecycle register/unregister + CMD_SEND_LC_REGISTER, + /// quit command + CMD_QUIT } tCmd; +/// command data union definition +typedef union MainLoopData_u_{ + + /// message structure + struct { + /// dbus mainloop command + uint32_t cmd; + /// unsigned int parameters + uint32_t params[4]; + /// string parameter + char string[DbKeyMaxLen]; + } message; + + /// the message payload + char payload[128]; +} MainLoopData_u; + + +/// mutex to make sure main loop is running +extern pthread_mutex_t gDbusInitializedMtx; +/// dbus init conditional variable +extern pthread_cond_t gDbusInitializedCond; +/// dbus pending mutex +extern pthread_mutex_t gDbusPendingRegMtx; +/// dbus mainloop conditional variable +extern pthread_mutex_t gMainCondMtx; +/// dbus mainloop mutex +extern pthread_t gMainLoopThread; /// lifecycle consumer interface dbus name extern const char* gDbusLcConsterface; @@ -77,21 +103,6 @@ extern const char* gDbusPersAdminInterface; extern const char* gPersAdminConsumerPath; -/// command data union definition -typedef union MainLoopData{ - struct { - uint32_t cmd; /// dbus mainloop command - uint32_t params[4]; /// unsignet int parameters - char string[DbKeyMaxLen]; /// char parameter - } message; - char payload[128]; -} tMainLoopData; - - -/// pipe file descriptors -extern int gEfds; - - /** * @brief DBus main loop to dispatch events and dbus messages * @@ -106,7 +117,6 @@ int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtable2, DBusObjectPathVTable vtableFallback, void* userData); - /** * @brief Setup the dbus main dispatching loop * @@ -115,10 +125,28 @@ int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtable2, int setup_dbus_mainloop(void); -int deliverToMainloop(tMainLoopData* payload); +/** + * @brief deliver message to mainloop (blocking) + * The function blocks until the message has + * been delivered to the mainloop + * + * @param payload the message to deliver to the mainloop (command and data) + * + * @return 0 + */ +int deliverToMainloop(MainLoopData_u* payload); -int deliverToMainloop_NM(tMainLoopData* payload); +/** + * @brief deliver message to mainloop (non blocking) + * The function does N O T block until the message has + * been delivered to the mainloop + * + * @param payload the message to deliver to the mainloop (command and data) + * + * @return 0 + */ +int deliverToMainloop_NM(MainLoopData_u* payload); #endif /* PERSISTENCE_CLIENT_LIBRARY_DBUS_SERVICE_H_ */ diff --git a/src/persistence_client_library_file.c b/src/persistence_client_library_file.c index 861f175..3f4cb32 100644 --- a/src/persistence_client_library_file.c +++ b/src/persistence_client_library_file.c @@ -26,10 +26,12 @@ #include "persistence_client_library_db_access.h" #include "crc32.h" + #if USE_FILECACHE #include #endif + #include // for open flags #include #include @@ -44,7 +46,6 @@ int pclFileGetDefaultData(int handle, const char* resource_id, int policy); - int pclFileClose(int fd) { int rval = EPERS_NOT_INITIALIZED; @@ -53,16 +54,18 @@ int pclFileClose(int fd) if(gPclInitialized >= PCLinitialized) { - if(fd < MaxPersHandle) + int permission = get_file_permission(fd); + + if(permission != -1) // permission is here also used for range check { - // check if a backup and checksum file needs to bel deleted - if( gFileHandleArray[fd].permission != PersistencePermission_ReadOnly) + // check if a backup and checksum file needs to be deleted + if(permission != PersistencePermission_ReadOnly || permission != PersistencePermission_LastEntry) { // remove backup file - remove(gFileHandleArray[fd].backupPath); // we don't care about return value + remove(get_file_backup_path(fd)); // we don't care about return value // remove checksum file - remove(gFileHandleArray[fd].csumPath); // we don't care about return value + remove(get_file_checksum_path(fd)); // we don't care about return value } __sync_fetch_and_sub(&gOpenFdArray[fd], FileClosed); // set closed flag @@ -78,7 +81,6 @@ int pclFileClose(int fd) rval = EPERS_MAXHANDLE; } } - return rval; } @@ -230,23 +232,19 @@ int pclFileOpen(unsigned int ldbid, const char* resource_id, unsigned int user_n } } - if(handle < MaxPersHandle && handle > 0 ) - { - __sync_fetch_and_add(&gOpenFdArray[handle], FileOpen); // set open flag + if(dbContext.configKey.permission != PersistencePermission_ReadOnly) + { + if(set_file_handle_data(handle, dbContext.configKey.permission, 0 /*backupCreated*/, backupPath, csumPath, NULL) != -1) + { + __sync_fetch_and_add(&gOpenFdArray[handle], FileOpen); // set open flag + } + else + { + close(handle); + handle = EPERS_MAXHANDLE; + } + } - if(dbContext.configKey.permission != PersistencePermission_ReadOnly) - { - strcpy(gFileHandleArray[handle].backupPath, backupPath); - strcpy(gFileHandleArray[handle].csumPath, csumPath); - gFileHandleArray[handle].backupCreated = 0; - gFileHandleArray[handle].permission = dbContext.configKey.permission; - } - } - else - { - close(handle); - handle = EPERS_MAXHANDLE; - } } else // requested resource is not in the RCT, so create resource as local/cached. { @@ -256,20 +254,16 @@ int pclFileOpen(unsigned int ldbid, const char* resource_id, unsigned int user_n if(handle != -1) { - if(handle < MaxPersHandle) - { - __sync_fetch_and_add(&gOpenFdArray[handle], FileOpen); // set open flag - - strcpy(gFileHandleArray[handle].backupPath, backupPath); - strcpy(gFileHandleArray[handle].csumPath, csumPath); - gFileHandleArray[handle].backupCreated = 0; - gFileHandleArray[handle].permission = PersistencePermission_ReadWrite; // make it writable - } - else - { - close(handle); - handle = EPERS_MAXHANDLE; - } + + if(set_file_handle_data(handle, PersistencePermission_ReadWrite, 0 /*backupCreated*/, backupPath, csumPath, NULL) != -1) + { + __sync_fetch_and_add(&gOpenFdArray[handle], FileOpen); // set open flag + } + else + { + close(handle); + handle = EPERS_MAXHANDLE; + } } } } @@ -411,21 +405,23 @@ int pclFileWriteData(int fd, const void * buffer, int buffer_size) { if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked { - if(fd < MaxPersHandle) + int permission = get_file_permission(fd); + if(permission != -1) { - if(gFileHandleArray[fd].permission != PersistencePermission_ReadOnly) + if(permission != PersistencePermission_ReadOnly) { // check if a backup file has to be created - if(gFileHandleArray[fd].backupCreated == 0) + if(get_file_backup_status(fd) == 0) { char csumBuf[ChecksumBufSize] = {0}; // calculate checksum pclCalcCrc32Csum(fd, csumBuf); + // create checksum and backup file - pclCreateBackup(gFileHandleArray[fd].backupPath, fd, gFileHandleArray[fd].csumPath, csumBuf); + pclCreateBackup(get_file_backup_path(fd), fd, get_file_checksum_path(fd), csumBuf); - gFileHandleArray[fd].backupCreated = 1; + set_file_backup_status(fd, 1); } #if USE_FILECACHE @@ -439,6 +435,10 @@ int pclFileWriteData(int fd, const void * buffer, int buffer_size) size = EPERS_RESOURCE_READ_ONLY; } } + else + { + size = EPERS_MAXHANDLE; + } } else { @@ -503,17 +503,6 @@ int pclFileCreatePath(unsigned int ldbid, const char* resource_id, unsigned int { if(handle < MaxPersHandle) { - __sync_fetch_and_add(&gOpenHandleArray[handle], FileOpen); // set open flag - - if(dbContext.configKey.permission != PersistencePermission_ReadOnly) - { - strncpy(gOssHandleArray[handle].backupPath, backupPath, DbPathMaxLen); - strncpy(gOssHandleArray[handle].csumPath, csumPath, DbPathMaxLen); - - gOssHandleArray[handle].backupCreated = 0; - gOssHandleArray[handle].permission = dbContext.configKey.permission; - } - *size = strlen(dbPath); *path = malloc((*size)+1); // allocate 1 byte for the string termination @@ -522,7 +511,6 @@ int pclFileCreatePath(unsigned int ldbid, const char* resource_id, unsigned int { memcpy(*path, dbPath, (*size)); (*path)[(*size)] = '\0'; // terminate string - gOssHandleArray[handle].filePath = *path; if(access(*path, F_OK) == -1) { @@ -541,15 +529,16 @@ int pclFileCreatePath(unsigned int ldbid, const char* resource_id, unsigned int close(handle); // don't need the open file } } + + __sync_fetch_and_add(&gOpenHandleArray[handle], FileOpen); // set open flag + + set_ossfile_handle_data(handle, dbContext.configKey.permission, 0/*backupCreated*/, backupPath, csumPath, *path); } else { handle = EPERS_DESER_ALLOCMEM; - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, - DLT_STRING("pclFileCreatePath: malloc() failed for path:"), - DLT_STRING(dbPath), - DLT_STRING("With the size:"), - DLT_UINT(*size)); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclFileCreatePath: malloc() failed for path:"), + DLT_STRING(dbPath), DLT_STRING("With the size:"), DLT_UINT(*size)); } } else @@ -573,10 +562,8 @@ int pclFileCreatePath(unsigned int ldbid, const char* resource_id, unsigned int snprintf(csumPath, DbPathMaxLen, "%s%s", dbPath, gBackupCsPostfix); __sync_fetch_and_add(&gOpenHandleArray[handle], FileOpen); // set open flag - strncpy(gOssHandleArray[handle].backupPath, backupPath, DbPathMaxLen); - strncpy(gOssHandleArray[handle].csumPath, csumPath, DbPathMaxLen); - gOssHandleArray[handle].backupCreated = 0; - gOssHandleArray[handle].permission = PersistencePermission_ReadWrite; // make it writable + + set_ossfile_handle_data(handle, PersistencePermission_ReadWrite, 0/*backupCreated*/, backupPath, csumPath, NULL); } else { @@ -605,22 +592,26 @@ int pclFileReleasePath(int pathHandle) if(gPclInitialized >= PCLinitialized) { - if(pathHandle < MaxPersHandle) + int permission = get_ossfile_permission(pathHandle); + if(permission != -1) // permission is here also used for range check { // check if a backup and checksum file needs to bel deleted - if( gFileHandleArray[pathHandle].permission != PersistencePermission_ReadOnly) + if(permission != PersistencePermission_ReadOnly) { // remove backup file - remove(gOssHandleArray[pathHandle].backupPath); // we don't care about return value + remove(get_ossfile_backup_path(pathHandle)); // we don't care about return value // remove checksum file - remove(gOssHandleArray[pathHandle].csumPath); // we don't care about return value + remove(get_ossfile_checksum_path(pathHandle)); // we don't care about return value } - free(gOssHandleArray[pathHandle].filePath); + free(get_ossfile_file_path(pathHandle)); + __sync_fetch_and_sub(&gOpenHandleArray[pathHandle], FileClosed); // set closed flag - set_persistence_handle_close_idx(pathHandle); - gOssHandleArray[pathHandle].filePath = NULL; + + set_persistence_handle_close_idx(pathHandle); // TODO + + set_ossfile_file_path(pathHandle, NULL); rval = 1; } else diff --git a/src/persistence_client_library_handle.c b/src/persistence_client_library_handle.c index 23eba1f..bcb4e23 100644 --- a/src/persistence_client_library_handle.c +++ b/src/persistence_client_library_handle.c @@ -17,40 +17,40 @@ * @see */ - #include "persistence_client_library_handle.h" #include #include #include -/// handle index -static int gHandleIdx = 1; - -/// open file descriptor handle array -int gOpenFdArray[MaxPersHandle] = { [0 ...MaxPersHandle-1] = 0 }; - -/// handle array -int gOpenHandleArray[MaxPersHandle] = { [0 ...MaxPersHandle-1] = 0 }; - -/// persistence key handle array -PersistenceKeyHandle_s gKeyHandleArray[MaxPersHandle]; -/// persistence file handle array -PersistenceFileHandle_s gFileHandleArray[MaxPersHandle]; +pthread_mutex_t gKeyHandleAccessMtx = PTHREAD_MUTEX_INITIALIZER; +pthread_mutex_t gFileHandleAccessMtx = PTHREAD_MUTEX_INITIALIZER; +pthread_mutex_t gOssFileHandleAccessMtx = PTHREAD_MUTEX_INITIALIZER; +pthread_mutex_t gMtx = PTHREAD_MUTEX_INITIALIZER; -/// persistence handle array for OSS and third party handles -PersistenceFileHandle_s gOssHandleArray[MaxPersHandle]; +// open file descriptor handle array +int gOpenFdArray[MaxPersHandle] = { [0 ...MaxPersHandle-1] = 0 }; +// handle array +int gOpenHandleArray[MaxPersHandle] = { [0 ...MaxPersHandle-1] = 0 }; +// handle index +static int gHandleIdx = 1; /// free handle array -int gFreeHandleArray[MaxPersHandle] = { [0 ...MaxPersHandle-1] = 0 }; -int gFreeHandleIdxHead = 0; -pthread_mutex_t gMtx = PTHREAD_MUTEX_INITIALIZER; +static int gFreeHandleArray[MaxPersHandle] = { [0 ...MaxPersHandle-1] = 0 }; +/// free handle array head index +static int gFreeHandleIdxHead = 0; + +// persistence key handle array +static PersistenceKeyHandle_s gKeyHandleArray[MaxPersHandle]; +// persistence file handle array +static PersistenceFileHandle_s gFileHandleArray[MaxPersHandle]; +// persistence handle array for OSS and third party handles +static PersistenceFileHandle_s gOssHandleArray[MaxPersHandle]; -/// get persistence handle int get_persistence_handle_idx() { int handle = 0; @@ -75,12 +75,10 @@ int get_persistence_handle_idx() } pthread_mutex_unlock(&gMtx); } - return handle; } -/// close persistence handle void set_persistence_handle_close_idx(int handle) { if(pthread_mutex_lock(&gMtx) == 0) @@ -94,7 +92,6 @@ void set_persistence_handle_close_idx(int handle) } - void close_all_persistence_handle() { if(pthread_mutex_lock(&gMtx) == 0) @@ -104,7 +101,6 @@ void close_all_persistence_handle() memset(gOpenHandleArray, 0, sizeof(gOpenHandleArray)); memset(gOpenFdArray, 0, sizeof(gOpenFdArray)); - // reset variables gHandleIdx = 1; gFreeHandleIdxHead = 0; @@ -112,3 +108,234 @@ void close_all_persistence_handle() pthread_mutex_unlock(&gMtx); } } + + +int set_key_handle_data(int idx, const char* id, unsigned int ldbid, unsigned int user_no, unsigned int seat_no) +{ + int handle = -1; + + if(pthread_mutex_lock(&gKeyHandleAccessMtx) == 0) + { + if((idx < MaxPersHandle) && (0 < idx)) + { + strncpy(gKeyHandleArray[idx].resource_id, id, DbResIDMaxLen); + gKeyHandleArray[idx].resource_id[DbResIDMaxLen-1] = '\0'; // Ensures 0-Termination + gKeyHandleArray[idx].ldbid = ldbid; + gKeyHandleArray[idx].user_no = user_no; + gKeyHandleArray[idx].seat_no = seat_no; + + handle = idx; + } + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("set_key_handle_data: error - index out of bounds:"), DLT_INT(idx)); + } + + pthread_mutex_unlock(&gKeyHandleAccessMtx); + } + + return handle; +} + + +int get_key_handle_data(int idx, PersistenceKeyHandle_s* handleStruct) +{ + int rval = -1; + + if(pthread_mutex_lock(&gKeyHandleAccessMtx) == 0) + { + if((idx < MaxPersHandle) && (idx > 0)) + { + strncpy(handleStruct->resource_id, gKeyHandleArray[idx].resource_id, DbResIDMaxLen); + + handleStruct->ldbid = gKeyHandleArray[idx].ldbid; + handleStruct->user_no = gKeyHandleArray[idx].user_no; + handleStruct->seat_no = gKeyHandleArray[idx].seat_no; + + rval = 0; + } + + pthread_mutex_unlock(&gKeyHandleAccessMtx); + } + + return rval; +} + + +void init_key_handle_array() +{ + if(pthread_mutex_lock(&gKeyHandleAccessMtx) == 0) + { + memset(gKeyHandleArray, 0, MaxPersHandle * sizeof(PersistenceKeyHandle_s)); + + pthread_mutex_unlock(&gKeyHandleAccessMtx); + } +} + + +void clear_key_handle_array(int idx) +{ + if(pthread_mutex_lock(&gKeyHandleAccessMtx) == 0) + { + memset(&gKeyHandleArray[idx], 0, sizeof(gKeyHandleArray[idx])); + pthread_mutex_unlock(&gKeyHandleAccessMtx); + } +} + + +int set_file_handle_data(int idx, PersistencePermission_e permission, int backupCreated, + const char* backup, const char* csumPath, char* filePath) +{ + int rval = 0; + + if(pthread_mutex_lock(&gFileHandleAccessMtx) == 0) + { + if(idx < MaxPersHandle && idx > 0 ) + { + strcpy(gFileHandleArray[idx].backupPath, backup); + strcpy(gFileHandleArray[idx].csumPath, csumPath); + gFileHandleArray[idx].backupCreated = backupCreated; + gFileHandleArray[idx].permission = permission; + gFileHandleArray[idx].filePath = filePath; // check to do if this works + } + pthread_mutex_unlock(&gFileHandleAccessMtx); + } + + return rval; +} + + +int get_file_permission(int idx) +{ + int permission = (int)PersistencePermission_LastEntry; + + if(pthread_mutex_lock(&gFileHandleAccessMtx) == 0) + { + if(idx < MaxPersHandle && idx > 0 ) + { + permission = gFileHandleArray[idx].permission; + } + else + { + permission = -1; + } + pthread_mutex_unlock(&gFileHandleAccessMtx); + } + return permission; +} + + +char* get_file_backup_path(int idx) +{ + return gFileHandleArray[idx].backupPath; +} + +char* get_file_checksum_path(int idx) +{ + return gFileHandleArray[idx].csumPath; +} + + +void set_file_backup_status(int idx, int status) +{ + if(pthread_mutex_lock(&gFileHandleAccessMtx) == 0) + { + gFileHandleArray[idx].backupCreated = status; + + pthread_mutex_unlock(&gFileHandleAccessMtx); + } +} + +int get_file_backup_status(int idx) +{ + return gFileHandleArray[idx].backupCreated; +} + +//---------------------------------------------------------- +//---------------------------------------------------------- + +int set_ossfile_handle_data(int idx, PersistencePermission_e permission, int backupCreated, + const char* backup, const char* csumPath, char* filePath) +{ + int rval = 0; + + if(pthread_mutex_lock(&gOssFileHandleAccessMtx) == 0) + { + if(idx < MaxPersHandle && idx > 0 ) + { + strcpy(gOssHandleArray[idx].backupPath, backup); + strcpy(gOssHandleArray[idx].csumPath, csumPath); + gOssHandleArray[idx].backupCreated = backupCreated; + gOssHandleArray[idx].permission = permission; + gOssHandleArray[idx].filePath = filePath; // check to do if this works + } + pthread_mutex_unlock(&gOssFileHandleAccessMtx); + } + + return rval; +} + + +int get_ossfile_permission(int idx) +{ + int permission = (int)PersistencePermission_LastEntry; + + if(pthread_mutex_lock(&gOssFileHandleAccessMtx) == 0) + { + if(idx < MaxPersHandle && idx > 0 ) + { + permission = gOssHandleArray[idx].permission; + } + else + { + permission = -1; + } + pthread_mutex_unlock(&gOssFileHandleAccessMtx); + } + + return permission; +} + + +char* get_ossfile_backup_path(int idx) +{ + return gOssHandleArray[idx].backupPath; +} + + +char* get_ossfile_file_path(int idx) +{ + return gOssHandleArray[idx].filePath; +} + +void set_ossfile_file_path(int idx, char* file) +{ + if(pthread_mutex_lock(&gOssFileHandleAccessMtx) == 0) + { + gOssHandleArray[idx].filePath = file; + + pthread_mutex_unlock(&gOssFileHandleAccessMtx); + } +} + + +char* get_ossfile_checksum_path(int idx) +{ + return gOssHandleArray[idx].csumPath; +} + + +void set_ossfile_backup_status(int idx, int status) +{ + if(pthread_mutex_lock(&gOssFileHandleAccessMtx) == 0) + { + gOssHandleArray[idx].backupCreated = status; + + pthread_mutex_unlock(&gOssFileHandleAccessMtx); + } +} + +int get_ossfile_backup_status(int idx) +{ + return gOssHandleArray[idx].backupCreated; +} diff --git a/src/persistence_client_library_handle.h b/src/persistence_client_library_handle.h index b4f40c1..5bd82cb 100644 --- a/src/persistence_client_library_handle.h +++ b/src/persistence_client_library_handle.h @@ -27,43 +27,41 @@ /// key handle structure definition typedef struct _PersistenceKeyHandle_s { - char resource_id[DbResIDMaxLen]; /* Resource ID */ - unsigned int ldbid; /* LDBID */ - unsigned int user_no; /* User No */ - unsigned int seat_no; /* Seat No */ + /// Resource ID + char resource_id[DbResIDMaxLen]; + /// logical database id + unsigned int ldbid; + /// User No + unsigned int user_no; + /// Seat No + unsigned int seat_no; } PersistenceKeyHandle_s; /// file handle structure definition typedef struct _PersistenceFileHandle_s { - PersistencePermission_e permission; /// access permission read/write - int backupCreated; /// flag to indicate if a backup has already been created - char backupPath[DbPathMaxLen]; /// path to the backup file - char csumPath[DbPathMaxLen]; /// path to the checksum file - char* filePath; /// the path + /// access permission read/write + PersistencePermission_e permission; + /// flag to indicate if a backup has already been created + int backupCreated; + /// path to the backup file + char backupPath[DbPathMaxLen]; + /// path to the checksum file + char csumPath[DbPathMaxLen]; + /// the file path + char* filePath; } PersistenceFileHandle_s; - - - -/// persistence key handle array -extern PersistenceKeyHandle_s gKeyHandleArray[MaxPersHandle]; - - -/// persistence file handle array -extern PersistenceFileHandle_s gFileHandleArray[MaxPersHandle]; - -/// persistence handle array for OSS and third party handles -extern PersistenceFileHandle_s gOssHandleArray[MaxPersHandle]; - - /// open file descriptor handle array extern int gOpenFdArray[MaxPersHandle]; /// handle array extern int gOpenHandleArray[MaxPersHandle]; +//---------------------------------------------------------------- +//---------------------------------------------------------------- + /** * @brief get persistence handle * @@ -75,7 +73,7 @@ int get_persistence_handle_idx(); /** * @brief close persistence handle * - * @param the handle to close + * @param handle to close */ void set_persistence_handle_close_idx(int handle); @@ -86,6 +84,213 @@ void set_persistence_handle_close_idx(int handle); */ void close_all_persistence_handle(); +//---------------------------------------------------------------- +//---------------------------------------------------------------- + +/** + * @brief set data to the key handle + * + * @param idx the index + * @param id the resource id + * @param ldbid the logical database id + * @param user_no the user identifier + * @param seat_no the seat number + * + * @return a positive value (0 or greather) or -1 on error + */ +int set_key_handle_data(int idx, const char* id, unsigned int ldbid, unsigned int user_no, unsigned int seat_no); + + +/** + * @brief set data to the key handle + * + * @param idx the index + * @param handleStruct the handle structure + * + * @return 0 on success, -1 on error + */ +int get_key_handle_data(int idx, PersistenceKeyHandle_s* handleStruct); + + +/** + * @brief initialize the key handle array to defined values + */ +void init_key_handle_array(); + + +/** + * @brief set data to the key handle + * + * @param idx the index + * + */ +void clear_key_handle_array(int idx); + +//---------------------------------------------------------------- +//---------------------------------------------------------------- + +/** + * @brief set data to the key handle + * + * @param idx the index + * @param permission the permission (read/write, read only, write only) + * @param backupCreated 0 is a backup has not been created or 1 if a backup has been created + * @param backup path to the backup file + * @param csumPath the path to the checksum file + * @param filePath the path to the file + * + */ +int set_file_handle_data(int idx, PersistencePermission_e permission, int backupCreated, + const char* backup, const char* csumPath, char* filePath); + + +/** + * @brief set data to the key handle + * + * @param idx the index + * + * @return the file permission + */ +int get_file_permission(int idx); + + +/** + * @brief set data to the key handle + * @attention "N index check will be done" + * + * @param idx the index + * + * @return the path to the backup + */ +char* get_file_backup_path(int idx); + + +/** + * @brief get the file checksum path + * @attention "N index check will be done" + * + * @param idx the index + * + * @return the checksum path + */ +char* get_file_checksum_path(int idx); + + +/** + * @brief set the file backup status of the file + * @attention "No index check will be done" + * + * @param idx the index + * @param status the backup status, 0 backup has been created, + * 1 backup has not been created + */ +void set_file_backup_status(int idx, int status); + + +/** + * @brief get the backup status of the file + * @attention "No index check will be done" + * + * @param idx the index + * + * @return 0 if no backup has been created, + * 1 if backup has been created + */ +int get_file_backup_status(int idx); + +//---------------------------------------------------------------- +//---------------------------------------------------------------- + +/** + * @brief set data to the key handle + * + * @param idx the index + * @param permission the permission (read/write, read only, write only) + * @param backupCreated 0 is a backup has not been created or 1 if a backup has been created + * @param backup path to the backup file + * @param csumPath the path to the checksum file + * @param filePath the path to the file + * + */ +int set_ossfile_handle_data(int idx, PersistencePermission_e permission, int backupCreated, + const char* backup, const char* csumPath, char* filePath); + + +/** + * @brief set data to the key handle + * + * @param idx the index + * + * @return the file permission + */ +int get_ossfile_permission(int idx); + + +/** + * @brief get file backup path + * @attention "No index check will be done" + * + * @param idx the index + * + * @return the path to the backup + */ +char* get_ossfile_backup_path(int idx); + + +/** + * @brief get file path + * @attention "No index check will be done" + * + * @param idx the index + * + * @return the path to the backup + */ +char* get_ossfile_file_path(int idx); + + +/** + * @brief get the file checksum path + * @attention "No index check will be done" + * + * @param idx the index + * + * @return the checksum path + */ +char* get_ossfile_checksum_path(int idx); + +/** + * @brief get the file checksum path + * @attention "No index check will be done" + * + * @param idx the index + * @param file pointer to the file and path + * + * @return the checksum path + */ +void set_ossfile_file_path(int idx, char* file); + +/** + * @brief set the file backup status of the file + * @attention "No index check will be done" + * + * @param idx the index + * @param status the backup status, 0 backup has been created, + * 1 backup has not been created + */ +void set_ossfile_backup_status(int idx, int status); + + +/** + * @brief get the backup status of the file + * @attention "No index check will be done" + * + * @param idx the index + * + * @return 0 if no backup has been created, + * 1 if backup has been created + */ +int get_ossfile_backup_status(int idx); + #endif /* PERSISTENCY_CLIENT_LIBRARY_HANDLE_H */ diff --git a/src/persistence_client_library_key.c b/src/persistence_client_library_key.c index 41fe58e..3540251 100644 --- a/src/persistence_client_library_key.c +++ b/src/persistence_client_library_key.c @@ -30,8 +30,8 @@ // function declaration -int handleRegNotifyOnChange(int key_handle, pclChangeNotifyCallback_t callback, PersNotifyRegPolicy_e regPolicy); -int regNotifyOnChange(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no, +static int handleRegNotifyOnChange(int key_handle, pclChangeNotifyCallback_t callback, PersNotifyRegPolicy_e regPolicy); +static int regNotifyOnChange(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no, pclChangeNotifyCallback_t callback, PersNotifyRegPolicy_e regPolicy); // ---------------------------------------------------------------------------- @@ -62,22 +62,8 @@ int pclKeyHandleOpen(unsigned int ldbid, const char* resource_id, unsigned int u { if(dbContext.configKey.storage < PersistenceStorage_LastEntry) // check if store policy is valid { - // generate handle for custom and for normal key - handle = get_persistence_handle_idx(); - - if((handle < MaxPersHandle) && (0 < handle)) - { - // remember data in handle array - strncpy(gKeyHandleArray[handle].resource_id, resource_id, DbResIDMaxLen); - gKeyHandleArray[handle].resource_id[DbResIDMaxLen-1] = '\0'; /* Ensures 0-Termination */ - gKeyHandleArray[handle].ldbid = ldbid; - gKeyHandleArray[handle].user_no = user_no; - gKeyHandleArray[handle].seat_no = seat_no; - } - else - { - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyHandleOpen: error - handleId out of bounds:"), DLT_INT(handle)); - } + // remember data in handle array + handle = set_key_handle_data(get_persistence_handle_idx(), resource_id, ldbid, user_no, seat_no); } else { @@ -101,13 +87,15 @@ int pclKeyHandleClose(int key_handle) if(gPclInitialized >= PCLinitialized) { - if((key_handle < MaxPersHandle) && (key_handle > 0)) + PersistenceKeyHandle_s persHandle; + + if(get_key_handle_data(key_handle, &persHandle) != -1) { - if ('\0' != gKeyHandleArray[key_handle].resource_id[0]) + if ('\0' != persHandle.resource_id[0]) { /* Invalidate key handle data */ set_persistence_handle_close_idx(key_handle); - memset(&gKeyHandleArray[key_handle], 0, sizeof(gKeyHandleArray[key_handle])); + clear_key_handle_array(key_handle); rval = 1; } else @@ -132,14 +120,14 @@ int pclKeyHandleGetSize(int key_handle) if(gPclInitialized >= PCLinitialized) { - if((key_handle < MaxPersHandle) && (key_handle > 0)) + PersistenceKeyHandle_s persHandle; + + if(get_key_handle_data(key_handle, &persHandle) != -1) { - if ('\0' != gKeyHandleArray[key_handle].resource_id[0]) + if ('\0' != persHandle.resource_id[0]) { - size = pclKeyGetSize(gKeyHandleArray[key_handle].ldbid, - gKeyHandleArray[key_handle].resource_id, - gKeyHandleArray[key_handle].user_no, - gKeyHandleArray[key_handle].seat_no); + size = pclKeyGetSize(persHandle.ldbid, persHandle.resource_id, + persHandle.user_no, persHandle.seat_no); } else { @@ -163,16 +151,15 @@ int pclKeyHandleReadData(int key_handle, unsigned char* buffer, int buffer_size) if(gPclInitialized >= PCLinitialized) { - if((key_handle < MaxPersHandle) && (key_handle > 0)) + PersistenceKeyHandle_s persHandle; + + if(get_key_handle_data(key_handle, &persHandle) != -1) { - if ('\0' != gKeyHandleArray[key_handle].resource_id[0]) + if ('\0' != persHandle.resource_id[0]) { - size = pclKeyReadData(gKeyHandleArray[key_handle].ldbid, - gKeyHandleArray[key_handle].resource_id, - gKeyHandleArray[key_handle].user_no, - gKeyHandleArray[key_handle].seat_no, - buffer, - buffer_size); + size = pclKeyReadData(persHandle.ldbid, persHandle.resource_id, + persHandle.user_no, persHandle.seat_no, + buffer, buffer_size); } else { @@ -220,16 +207,15 @@ int handleRegNotifyOnChange(int key_handle, pclChangeNotifyCallback_t callback, if(gPclInitialized >= PCLinitialized) { - if((key_handle < MaxPersHandle) && (key_handle > 0)) + PersistenceKeyHandle_s persHandle; + + if(get_key_handle_data(key_handle, &persHandle) != -1) { - if ('\0' != gKeyHandleArray[key_handle].resource_id[0]) + if ('\0' != persHandle.resource_id[0]) { - rval = regNotifyOnChange(gKeyHandleArray[key_handle].ldbid, - gKeyHandleArray[key_handle].resource_id, - gKeyHandleArray[key_handle].user_no, - gKeyHandleArray[key_handle].seat_no, - callback, - regPolicy); + rval = regNotifyOnChange(persHandle.ldbid, persHandle.resource_id, + persHandle.user_no, persHandle.seat_no, + callback, regPolicy); } else { @@ -252,16 +238,15 @@ int pclKeyHandleWriteData(int key_handle, unsigned char* buffer, int buffer_size if(gPclInitialized >= PCLinitialized) { - if((key_handle < MaxPersHandle) && (key_handle > 0)) + PersistenceKeyHandle_s persHandle; + + if(get_key_handle_data(key_handle, &persHandle) != -1) { - if ('\0' != gKeyHandleArray[key_handle].resource_id[0]) + if ('\0' != persHandle.resource_id[0]) { - size = pclKeyWriteData(gKeyHandleArray[key_handle].ldbid, - gKeyHandleArray[key_handle].resource_id, - gKeyHandleArray[key_handle].user_no, - gKeyHandleArray[key_handle].seat_no, - buffer, - buffer_size); + size = pclKeyWriteData(persHandle.ldbid, persHandle.resource_id, + persHandle.user_no, persHandle.seat_no, + buffer, buffer_size); } else { diff --git a/src/persistence_client_library_lc_interface.c b/src/persistence_client_library_lc_interface.c index 4e9a71f..32ab659 100644 --- a/src/persistence_client_library_lc_interface.c +++ b/src/persistence_client_library_lc_interface.c @@ -44,7 +44,7 @@ int check_lc_request(unsigned int request, unsigned int requestID) { case NsmShutdownNormal: { - tMainLoopData data; + MainLoopData_u data; data.message.cmd = (uint32_t)CMD_LC_PREPARE_SHUTDOWN; data.message.params[0] = request; data.message.params[1] = requestID; @@ -154,7 +154,7 @@ DBusHandlerResult checkLifecycleMsg(DBusConnection * connection, DBusMessage * m int register_lifecycle(int shutdownMode) { - tMainLoopData data; + MainLoopData_u data; data.message.cmd = (uint32_t)CMD_SEND_LC_REGISTER; data.message.params[0] = 1; @@ -168,7 +168,7 @@ int register_lifecycle(int shutdownMode) int unregister_lifecycle(int shutdownMode) { - tMainLoopData data; + MainLoopData_u data; data.message.cmd = (uint32_t)CMD_SEND_LC_REGISTER; data.message.params[0] = 0; diff --git a/src/persistence_client_library_lc_interface.h b/src/persistence_client_library_lc_interface.h index 00a4d2a..a0aea3d 100644 --- a/src/persistence_client_library_lc_interface.h +++ b/src/persistence_client_library_lc_interface.h @@ -37,7 +37,7 @@ DBusHandlerResult checkLifecycleMsg(DBusConnection * connection, DBusMessage * m /** * @brief send register message 'RegisterShutdownClient' to com.contiautomotive.NodeStateManager.Consumer * - * @param the shutdown mode: NSM_SHUTDOWN_TYPE_NORMAL or NSM_SHUTDOWN_TYPE_FAST; + * @param shutdownMode NSM_SHUTDOWN_TYPE_NORMAL or NSM_SHUTDOWN_TYPE_FAST; * * @return 0 on success or -1 on error */ @@ -47,7 +47,7 @@ int register_lifecycle(int shutdownMode); /** * @brief send register message 'UnRegisterShutdownClient' to com.contiautomotive.NodeStateManager.Consumer * - * @param the shutdown mode: NSM_SHUTDOWN_TYPE_NORMAL or NSM_SHUTDOWN_TYPE_FAST; + * @param shutdownMode NSM_SHUTDOWN_TYPE_NORMAL or NSM_SHUTDOWN_TYPE_FAST; * * @return 0 on success or -1 on error */ diff --git a/src/persistence_client_library_pas_interface.c b/src/persistence_client_library_pas_interface.c index 4c0d2fc..d94d709 100644 --- a/src/persistence_client_library_pas_interface.c +++ b/src/persistence_client_library_pas_interface.c @@ -52,7 +52,7 @@ int check_pas_request(unsigned int request, unsigned int requestID) { case (PasMsg_Block|PasMsg_WriteBack): { - tMainLoopData data; + MainLoopData_u data; data.message.cmd = (uint32_t)CMD_PAS_BLOCK_AND_WRITE_BACK; data.message.params[0] = request; @@ -232,7 +232,7 @@ int register_pers_admin_service(void) { int rval = 0; - tMainLoopData data; + MainLoopData_u data; data.message.cmd = (uint32_t)CMD_SEND_PAS_REGISTER; data.message.params[0] = 1; @@ -258,7 +258,7 @@ int unregister_pers_admin_service(void) { int rval = 0; - tMainLoopData data; + MainLoopData_u data; data.message.cmd = (uint32_t)CMD_SEND_PAS_REGISTER; data.message.params[0] = 0; data.message.params[1] = (PasMsg_Block | PasMsg_WriteBack | PasMsg_Unblock); diff --git a/src/persistence_client_library_pas_interface.h b/src/persistence_client_library_pas_interface.h index b074272..b865058 100644 --- a/src/persistence_client_library_pas_interface.h +++ b/src/persistence_client_library_pas_interface.h @@ -34,9 +34,15 @@ */ DBusHandlerResult checkPersAdminMsg(DBusConnection * connection, DBusMessage * message, void * user_data); -//DBusHandlerResult checkPersAdminSignal(DBusConnection * connection, DBusMessage * message, void * user_data); - +/** + * @brief Check if the persMode changed signal has been received + * + * @param connection the debus connection + * @param message the dbus message + * + * @return DBUS_HANDLER_RESULT_HANDLED or DBUS_HANDLER_RESULT_NOT_YET_HANDLED + */ int signal_persModeChange(DBusConnection *connection, DBusMessage *message); diff --git a/src/persistence_client_library_prct_access.c b/src/persistence_client_library_prct_access.c index b482c34..a53dad3 100644 --- a/src/persistence_client_library_prct_access.c +++ b/src/persistence_client_library_prct_access.c @@ -30,16 +30,19 @@ /// pointer to resource table database -int gResource_table[PrctDbTableSize] = {[0 ... PrctDbTableSize-1] = -1}; +static int gResource_table[PrctDbTableSize] = {[0 ... PrctDbTableSize-1] = -1}; /// array to hold the information of database is already open -int gResourceOpen[PrctDbTableSize] = { [0 ... PrctDbTableSize-1] = 0 }; +static int gResourceOpen[PrctDbTableSize] = { [0 ... PrctDbTableSize-1] = 0 }; /// persistence resource config table type definition typedef enum _PersistenceRCT_e { + /// resource is local (only visible for an application) PersistenceRCT_local = 0, + /// resource is visible for public PersistenceRCT_shared_public = 1, + /// resource is visible for a group PersistenceRCT_shared_group = 2, PersistenceRCT_LastEntry // last Entry diff --git a/src/persistence_client_library_prct_access.h b/src/persistence_client_library_prct_access.h index 0bba971..53669c5 100644 --- a/src/persistence_client_library_prct_access.h +++ b/src/persistence_client_library_prct_access.h @@ -22,17 +22,13 @@ #include "persistence_client_library_data_organization.h" - /** * @brief Create database search key and database location path * * @param dbContext the database context * @param resource_id the resource id - * @param user_no user identification - * @param seat_no seat identifier * @param dbKey the array where the database key will be stored * @param dbPath the array where the database location path will be stored - * @param cached_resource flag to identify if the resource is cached (value 1)or write through (value 0) * * @return 1 if shared database and 0 if local database or PersistenceStoragePolicy_LastEntry * when no valid database has been found @@ -46,12 +42,9 @@ int get_db_path_and_key(PersistenceInfo_s* dbContext, const char* resource_id, c * * @param dbContext the database context * @param resource_id the resource id - * @param user_no user identification - * @param seat_no seat identifier * @param isFile identifier if this resource is a file (used for file/key creation if resource does not exist) * @param dbKey the array where the database key will be stored * @param dbPath the array where the database location path will be stored - * @param cached_resource flag to identify if the resource is cached (value 1)or write through (value 0) * * @return 0 or a negative value with one of the following errors: EPERS_NOKEYDATA or EPERS_NOPRCTABLE */ @@ -62,16 +55,10 @@ int get_db_context(PersistenceInfo_s* dbContext, const char* resource_id, unsign /** * @brief get the resource configuration table gvbd database by id * - * @return Handle to the gvdb database table or negative value if no valid database has been found + * @return i Handle to the gvdb database table or negative value if no valid database has been found */ int get_resource_cfg_table_by_idx(int i); -/** - * Global array for the storage of pointers to resource table databases - */ -extern int gResource_table[PrctDbTableSize]; - - /** * @brief mark the resource configuration table as closed diff --git a/src/rbtree.c b/src/rbtree.c index 6a20221..a1439f8 100644 --- a/src/rbtree.c +++ b/src/rbtree.c @@ -23,7 +23,7 @@ OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ /** - * @file pers_rbtree.c + * @file rbtree.c * @ingroup Persistence device access layer * @author Ingo Huerner * @brief Implementation of rbtree functions diff --git a/src/rbtree.h b/src/rbtree.h index 660e869..81d8ed0 100644 --- a/src/rbtree.h +++ b/src/rbtree.h @@ -26,7 +26,7 @@ OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ /** - * @file pers_rbtree.h + * @file rbtree.h * @ingroup Persistence device access layer * @author Ingo Huerner * @brief Definition of rbtree functions -- 2.7.4