diff options
author | Ingo Huerner <ingo.huerner@xse.de> | 2013-06-25 01:18:53 +0200 |
---|---|---|
committer | Ingo Huerner <ingo.huerner@xse.de> | 2013-06-25 01:18:53 +0200 |
commit | b3b3094e5967b3644c69e9f82de8e39f9e9362d6 (patch) | |
tree | dead6c4d20b7b89feb9637c7e36f4279a981567f | |
parent | 3e1b8364beae20755494bbd2ba198a1fca9a1eba (diff) | |
download | persistence-client-library-b3b3094e5967b3644c69e9f82de8e39f9e9362d6.tar.gz |
Added ref counter for init/deinit; updated header doxygen tags; removed several printf; different minor optimizations
25 files changed, 1112 insertions, 782 deletions
diff --git a/Makefile.am b/Makefile.am index 580b7a9..c36060a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -4,6 +4,15 @@ if WANT_TESTS SUBDIRS+=test endif + +sysconfdir = "/etc/" + +# Write the config file for customer plugins to the config destination +sysconf_DATA = config/pclCustomLibConfigFile.cfg + +# Add config file to distribution +EXTRA_DIST = $(sysconf_DATA) + pkgconfigdir=$(libdir)/pkgconfig pkgconfig_DATA=persistence_client_library.pc @@ -5,7 +5,7 @@ The Persistence Client Library has been developed using Ubuntu 11.10 Required packages - automotive-dlt: available via GENIVI projects -- Itzam/C: download from here +- Itzam/C: download from http://www.coyotegulch.com/products/itzam/c/index.html In order to work with the PCL package config replace in the Itzam/C configure.ac GENERIC_LIBRARY_NAME=libitzam with GENERIC_LIBRARY_NAME=itzam copy itzam package confiuration file libitzam.pc into folder /usr/local/lib/pkgconfig There is an error like: "aclocal: couldn't open directory `m4': No such file or directory" just create the 'm4' directory diff --git a/config/pclCustomLibConfigFile.cfg b/config/pclCustomLibConfigFile.cfg new file mode 100644 index 0000000..df7468c --- /dev/null +++ b/config/pclCustomLibConfigFile.cfg @@ -0,0 +1,5 @@ +hwinfo /usr/local/lib/libhwinfoperscustom.so +secure /usr/local/lib/libsecureperscustom.so +custom3 /usr/local/lib/libcustom3perscustom.so +emergency /usr/local/lib/libemergencyperscustom.so +early /usr/local/lib/libearlyperscustom.so diff --git a/configure.ac b/configure.ac index f50ced4..81ae113 100644 --- a/configure.ac +++ b/configure.ac @@ -4,7 +4,7 @@ # create tag version information m4_define([pers_client_library_tag_version_major], [0]) -m4_define([pers_client_library_tag_version_minor], [5]) +m4_define([pers_client_library_tag_version_minor], [6]) m4_define([pers_client_library_tag_version_micro], [0]) m4_define([pers_client_library_tag_version], [pers_client_library_tag_version_major().pers_client_library_tag_version_minor().pers_client_library_tag_version_micro()]) @@ -16,7 +16,7 @@ AC_GNU_SOURCE() # create library version information -m4_define([pers_client_library_version_current], [5]) +m4_define([pers_client_library_version_current], [6]) m4_define([pers_client_library_version_revision], [0]) m4_define([pers_client_library_version_age], [0]) m4_define([pers_client_library_version], [pers_client_library_version_current():pers_client_library_version_revision():pers_client_library_version_age()]) diff --git a/include/persistence_client_custom.h b/include/persistence_client_custom.h index f33df45..3fc894e 100644 --- a/include/persistence_client_custom.h +++ b/include/persistence_client_custom.h @@ -17,6 +17,7 @@ * \par change history * \verbatim * Date Author Version Description + * 2013.06.26 ihuerner 1.5.0.0 added description of parameters * 2013.01.06 ihuerner 1.4.0.0 plugin_handle_open and plugin_set_data changed from char* to const char* * 2012.11.22 gsagnes 1.3.0.0 add the handle_get_size, correct the type to int * 2012.10.16 gsagnes 1.2.0.0 add get_size, create_backup, restore_backup @@ -33,7 +34,7 @@ /** Module version The lower significant byte is equal 0 for released version only */ -#define PERSIST_CUSTOMER_INTERFACE_VERSION (0x01040000U) +#define PERSIST_CUSTOMER_INTERFACE_VERSION (0x01050000U)
/** * <b>Plugin interface:</b> @@ -46,149 +47,152 @@ The lower significant byte is equal 0 for released version only */ /** - * \brief create backup + * @brief create backup * - * \param backup_id Name of the backup / identifier + * @param backup_id Name of the backup / identifier * - * \return positive value: backup success (size of backup, bytes); negative value: error + * @return positive value: backup success (size of backup, bytes); negative value: error */ int plugin_create_backup(const char* backup_id); /** - * \brief deinitialize plugin (during shutdown) + * @brief deinitialize plugin (during shutdown) * - * \return positive value: init success; negative value: error + * @return positive value: init success; negative value: error */ int plugin_deinit(); /** - * \brief delete data + * @brief delete data * - * \param path the path to the data to delete + * @param path the path to the data to delete * - * \return positive value: delete success; negative value: error + * @return positive value: delete success; negative value: error */ int plugin_delete_data(const char* path); /** - * \brief get backup name + * @brief get backup name * - * \param backup_id Name of the backup / identifier - * \param size size of the buffer to return the identifier + * @param backup_id Name of the backup / identifier + * @param size size of the buffer to return the identifier * - * \return positive value: success, length of identifier; negative value: error + * @return positive value: success, length of identifier; negative value: error */ int plugin_get_backup(char* backup_id, int size); /** - * \brief gets the size of persistent data in bytes + * @brief gets the size of persistent data in bytes * - * \param path the path to the data + * @param path the path to the data * - * \return positive value: the size; negative value: error code + * @return positive value: the size; negative value: error code */ int plugin_get_size(const char* path); /** - * \brief get data + * @brief get data * - * \param path the path to the resource to get - * \param buffer the buffer to store data - * \param size the number of bytes to get data + * @param path the path to the resource to get + * @param buffer the buffer to store data + * @param size the number of bytes to get data * - * \return positive value: size data read in bytes; negative value: error + * @return positive value: size data read in bytes; negative value: error */ int plugin_get_data(const char* path, char* buffer, int size); /** - * \brief close the given handle + * @brief close the given handle * - * \param handle the handle to close + * @param handle the handle to close * - * \return positive value: successfully closed; negative value: error + * @return positive value: successfully closed; negative value: error */ int plugin_handle_close(int handle); /** - * \brief get data + * @brief get data * - * \param handle the handle returned from open - * \param buffer the buffer to store data - * \param size the number of bytes to get data + * @param handle the handle returned from open + * @param buffer the buffer to store data + * @param size the number of bytes to get data * - * \return positive value: size data read in bytes; negative value: error + * @return positive value: size data read in bytes; negative value: error */ int plugin_handle_get_data(int handle, char* buffer, int size); /** - * \brief open a resource + * @brief open a resource * - * \param path the path to the resource to open - * \param flag open flags - * \param mode the open mode + * @param path the path to the resource to open + * @param flag open flags + * @param mode the open mode * - * \return positive value: handle; negative value: error + * @return positive value: handle; negative value: error */ int plugin_handle_open(const char* path, int flag, int mode); /** - * \brief set data + * @brief set data * - * \param handle the handle given by open - * \param buffer the data to write - * \param size the number of bytes to write + * @param handle the handle given by open + * @param buffer the data to write + * @param size the number of bytes to write * - * \return positive size data set; negative value: error + * @return positive size data set; negative value: error */ int plugin_handle_set_data(int handle, char* buffer, int size); /** - * \brief initialize plugin + * @brief initialize plugin * - * \return positive value: init success; negative value: error + * @return positive value: init success; negative value: error */ int plugin_init(); /** - * \brief restore backup + * @brief restore backup * - * \param backup_id Name of the backup / identifier + * @param backup_id Name of the backup / identifier * - * \return positive value: backup success (size of backup, bytes); negative value: error + * @return positive value: backup success (size of backup, bytes); negative value: error */ int plugin_restore_backup(const char* backup_id); /** - * \brief set data + * @brief set data * - * \param path the path to the resource to set - * \param buffer the data to write - * \param size the number of bytes to write + * @param path the path to the resource to set + * @param buffer the data to write + * @param size the number of bytes to write * - * \return positive size data set; negative value: error + * @return positive size data set; negative value: error */ int plugin_set_data(const char* path, char* buffer, int size); /** - * \brief typdef of callback function prototype + * @brief typdef of callback function prototype + * + * @param int pass a statusId to the function + * @param void* pass an argument to the function */ typedef int (*plugin_callback_t) (int, void*); /** - * \brief registercallback for status notifications + * @brief registercallback for status notifications * - * \param pFunct the callback + * @param pFunct the callback * - * \return positive value: register success; negative value error + * @return positive value: register success; negative value error */ int plugin_get_status_notification_clbk(plugin_callback_t pFunct); /** - * \brief get size + * @brief get size * - * \param handle the handle given by open + * @param handle the handle given by open * - * \return positive value: the size; negative value: error code + * @return positive value: the size; negative value: error code */ int plugin_handle_get_size(int handle); diff --git a/include/persistence_client_library.h b/include/persistence_client_library.h new file mode 100644 index 0000000..646215e --- /dev/null +++ b/include/persistence_client_library.h @@ -0,0 +1,81 @@ +#ifndef PERSISTENCY_CLIENT_LIBRARY_H +#define PERSISTENCY_CLIENT_LIBRARY_H + +/****************************************************************************** + * Project Persistency + * (c) copyright 2011 + * 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_key.h + * \ingroup Persistence client library + * \author Ingo Huerner (XSe) / Guy Sagnes (Continental) + * \brief Header of the persistence client library. + * Library provides an API to access persistent data + * \par change history + * Date Author Version + * 25/06/13 Ingo Hürner 1.0.0 - Rework of Init functions + * + */ +/** \ingroup GEN_PERS */ +/** \defgroup PERS_CLIENT Client: initialisation access + * \{ + */ +/** \defgroup PERS_CLIENT_INTERFACE API document + * \{ + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** \defgroup PCL_DEFINES_API Defines, Struct, Enum + * \{ + */ + +#define PERSIST_API_INTERFACE_VERSION (0x01000000U) + +/** \} */ + + +/** \defgroup PCL_OVERALL functions for Library Initialisation + * The following functions have to be called to allow intialisation of the internal interfaces. + * \{ + */ + +/** + * @brief initalize client library + * + * @attention This function is currently N O T part of the GENIVI compliance specification + * + * @param appname application name, the name must be a unique name in the system + * @param shutdownMode shutdown mode ::PCL_SHUTDOWN_TYPE_FAST or ::PCL_SHUTDOWN_TYPE_NORMAL + * + * @return positive value: success; + * On error a negative value will be returned with th follwoing error codes: + * ::EPERS_LOCKFS, ::EPERS_NOT_INITIALIZED + */ +int pclInitLibrary(const char* appname, int shutdownMode); + + +/** + * @brief deinitialize client library + * + * @attention This function is currently N O T part of the GENIVI compliance specification + * + * @return positive value: success; + * On error a negative value will be returned with th follwoing error codes: ::EPERS_LOCKFS + */ +int pclDeinitLibrary(void); + +/** \} */ + +/** \} */ /* End of API */ +/** \} */ /* End of MODULE */ + +#endif /* PERSISTENCY_CLIENT_LIBRARY_H */ diff --git a/include/persistence_client_library_error_def.h b/include/persistence_client_library_error_def.h index 458af90..6897667 100644 --- a/include/persistence_client_library_error_def.h +++ b/include/persistence_client_library_error_def.h @@ -18,6 +18,10 @@ * @brief Error definition header * @see */ +/** \ingroup GEN_PERS */ +/** \defgroup PERS_GEN_ERROR Client Library: Generic errors + * \{ + */ #ifdef __cplusplus extern "C" { @@ -85,19 +89,13 @@ extern "C" { #define EPERS_DB_VALUE_SIZE (-29) /// resource is not a key #define EPERS_RES_NO_KEY (-30) -/// chnage notification signal could ne be sent -#define EPERS_NOTIFY_SIG (-30) - - -/** - * @brief Main dispatching loop - * - * @return 0 - */ -void* dbus_main_dispatching_loop(void* dataPtr); +/// change notification signal could ne be sent +#define EPERS_NOTIFY_SIG (-31) +/// client library has not been initialized +#define EPERS_NOT_INITIALIZED (-32) #ifdef __cplusplus } #endif - +/** \} */ /* End of PERS_GEN_ERROR */ #endif /* PERSISTENCE_CLIENT_LIBRARY_ERROR_DEF_H */ diff --git a/include/persistence_client_library_file.h b/include/persistence_client_library_file.h index f56ccd2..1cdd8a3 100644 --- a/include/persistence_client_library_file.h +++ b/include/persistence_client_library_file.h @@ -17,13 +17,13 @@ * @author Ingo Huerner (XSe) / Guy Sagnes (Continental) * @brief Header of the persistence client library. * Library provides an API to access persistent data - * @see + * @see */ -/** \ingroup SSW_PERS */ -/** \defgroup SSW_PERS_FILE Client: File access +/** \ingroup GEN_PERS */ +/** \defgroup PERS_FILE Client: File access * \{ */ -/** \defgroup SSW_PERS_FILE_INTERFACE API document +/** \defgroup PERS_FILE_INTERFACE API document * \{ */ #ifdef __cplusplus @@ -31,9 +31,13 @@ extern "C" { #endif -#define PERSIST_FILEAPI_INTERFACE_VERSION (0x03000000U) +#define PERSIST_FILEAPI_INTERFACE_VERSION (0x03000000U) +#include "persistence_client_library.h" +/** \defgroup PCL_FILE functions file access + * \{ + */ /** * @brief close the given POSIX file descriptor @@ -168,11 +172,7 @@ int pclFileUnmapData(void* address, long size); */ int pclFileWriteData(int fd, const void * buffer, int buffer_size); - - - - - +/** \} */ #ifdef __cplusplus } @@ -184,4 +184,3 @@ int pclFileWriteData(int fd, const void * buffer, int buffer_size); #endif /* PERSISTENCY_CLIENT_LIBRARY_FILE_H */ - diff --git a/include/persistence_client_library_key.h b/include/persistence_client_library_key.h index ea0b7af..e125bfa 100644 --- a/include/persistence_client_library_key.h +++ b/include/persistence_client_library_key.h @@ -14,16 +14,20 @@ /** * @file persistence_client_library_key.h * @ingroup Persistence client library - * @author Ingo Huerner (XSe) / Guy Sagnes (Continental) + * vauthor Ingo Huerner (XSe) / Guy Sagnes (Continental) * @brief Header of the persistence client library. * Library provides an API to access persistent data - * @see + * @par change history + * Date Author Version + * 27/03/13 Ingo Hürner 4.0.0 - Add registration for callback notification + * 28/05/13 Ingo Hürner 5.0.0 - Add pclInitLibrary(), pcl DeInitLibrary() incl. shutdown notification + * 05/06/13 Oliver Bach 6.0.0 - Rework of Init functions */ -/** \ingroup SSW_PERS */ -/** \defgroup SSW_PERS_KEYVALUE Client: Key-value access +/** \ingroup GEN_PERS */ +/** \defgroup PERS_KEYVALUE Client: Key-value access * \{ */ -/** \defgroup SSW_PERS_KEYVALUE_INTERFACE API document +/** \defgroup PERS_KEYVALUE_INTERFACE API document * \{ */ @@ -31,8 +35,14 @@ extern "C" { #endif +/** \defgroup PCL_DEFINES_KEYVALUE Defines, Struct, Enum + * \{ + */ + +#define PERSIST_KEYVALUEAPI_INTERFACE_VERSION (0x06000000U) + +#include "persistence_client_library.h" -#define PERSIST_KEYVALUEAPI_INTERFACE_VERSION (0x05000000U) /** * status returned in notification structure @@ -60,39 +70,31 @@ typedef struct _pclNotification_s unsigned int seat_no; /// seat id } pclNotification_s; - -/** - * shutdown notification type definitions +/** \defgroup SHUTDOWN_TYPE shutdown notification type definitions * according to Node State Manager component + * \{ */ -enum pclShutdownTypeNotification -{ - NSM_SHUTDOWN_TYPE_FAST = 2, /// Client registered for fast lifecycle shutdown - NSM_SHUTDOWN_TYPE_NORMAL = 1 /// Client registered for normal lifecycle shutdown -}; +#define PCL_SHUTDOWN_TYPE_FAST 2 /// Client registered for fast lifecycle shutdown +#define PCL_SHUTDOWN_TYPE_NORMAL 1 /// Client registered for normal lifecycle shutdown -/// defiinition of the change callback -typedef int(* pclChangeNotifyCallback_t)(pclNotification_s * notifyStruct); +/** \} */ -/** - * @brief itialize client library +/** \} */ + +/** definition of the change callback * - * @param application name - * @param shutdown mode NSM_SHUTDOWN_TYPE_FAST or NSM_SHUTDOWN_TYPE_NORMAL + * @param notifyStruct structure for notifcation * - */ -void pclInitLibrary(const char* appname, int shutdownMode); - + * @return positive value: success; + * On error a negative value will be returned with the following error codes: ::EPERS_LOCKFS +*/ +typedef int(* pclChangeNotifyCallback_t)(pclNotification_s * notifyStruct); -/** - * @brief deinitialize client library - * - * @param shutdown mode NSM_SHUTDOWN_TYPE_FAST or NSM_SHUTDOWN_TYPE_NORMAL +/** \defgroup PCL_KEYVALUE functions Key-Value access + * \{ */ -void pclDeinitLibrary(int shutdownMode); - /** * @brief delete persistent data @@ -102,8 +104,8 @@ void pclDeinitLibrary(int shutdownMode); * @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 * - * @return positive value: success; On error a negative value will be returned with th follwoing error codes: - * EPERS_LOCKFS + * @return positive value: success; On error a negative value will be returned with the following error codes: + * ::EPERS_LOCKFS */ int pclKeyDelete(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no); @@ -117,8 +119,8 @@ int pclKeyDelete(unsigned int ldbid, const char* resource_id, unsigned int user_ * @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 * - * @return positive value: the size; On error a negative value will be returned with th follwoing error codes: - * EPERS_LOCKFS, EPERS_BADPOL, EPERS_NOKEY, EPERS_NOKEYDATA or EPERS_NOPRCTABLE + * @return positive value: the size; On error a negative value will be returned with the following error codes: + * ::EPERS_LOCKFS, ::EPERS_BADPOL, ::EPERS_NOKEY, ::EPERS_NOKEYDATA or ::EPERS_NOPRCTABLE */ int pclKeyGetSize(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no); @@ -127,8 +129,8 @@ int pclKeyGetSize(unsigned int ldbid, const char* resource_id, unsigned int user * * @param key_handle key value handle return by key_handle_open() * - * @return positive value: success; On error a negative value will be returned with th follwoing error codes: - * EPERS_LOCKFS + * @return positive value: success; On error a negative value will be returned with the following error codes: + * ::EPERS_LOCKFS */ int pclKeyHandleClose(int key_handle); @@ -139,7 +141,8 @@ int pclKeyHandleClose(int key_handle); * * @param key_handle key value handle return by key_handle_open() * - * @return positive value: the size; On error a negative value will be returned with th follwoing error codes: + * @return positive value: the size; On error a negative value will be returned with the following error codes: + * ::EPERS_LOCKFS */ int pclKeyHandleGetSize(int key_handle); @@ -154,7 +157,8 @@ int pclKeyHandleGetSize(int key_handle); * @param seat_no the seat number * * @return positive value: the key handle to access the value; - * On error a negative value will be returned with th follwoing error codes: + * On error a negative value will be returned with the following error codes: + * ::EPERS_LOCKFS */ int pclKeyHandleOpen(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no); @@ -167,8 +171,8 @@ int pclKeyHandleOpen(unsigned int ldbid, const char* resource_id, unsigned int u * @param buffer the buffer for persistent data * @param buffer_size size of buffer for reading * - * @return positive value: the bytes read; On error a negative value will be returned with th follwoing error codes: - * + * @return positive value: the bytes read; On error a negative value will be returned with the following error codes: + * ::EPERS_LOCKFS */ int pclKeyHandleReadData(int key_handle, unsigned char* buffer, int buffer_size); @@ -180,7 +184,8 @@ int pclKeyHandleReadData(int key_handle, unsigned char* buffer, int buffer_size) * @param key_handle key value handle return by key_handle_open() * @param callback notification callback * - * @return positive value: registration OK; On error a negative value will be returned with th follwoing error codes: + * @return positive value: registration OK; On error a negative value will be returned with the following error codes: + * ::EPERS_LOCKFS */ int pclKeyHandleRegisterNotifyOnChange(int key_handle, pclChangeNotifyCallback_t callback); @@ -194,7 +199,8 @@ int pclKeyHandleRegisterNotifyOnChange(int key_handle, pclChangeNotifyCallback_t * @param buffer_size the number of bytes to write (default max size is set to 16kB) * use environment variable PERS_MAX_KEY_VAL_DATA_SIZE to modify default size in bytes * - * @return positive value: the bytes written; On error a negative value will be returned with th follwoing error codes: + * @return positive value: the bytes written; On error a negative value will be returned with the following error codes: + * ::EPERS_LOCKFS */ int pclKeyHandleWriteData(int key_handle, unsigned char* buffer, int buffer_size); @@ -211,6 +217,7 @@ int pclKeyHandleWriteData(int key_handle, unsigned char* buffer, int buffer_size * @param buffer_size size of buffer for reading * * @return positive value: the bytes read; On error a negative value will be returned with th follwoing error codes: + * ::EPERS_LOCKFS */ int pclKeyReadData(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no, unsigned char* buffer, int buffer_size); @@ -225,8 +232,8 @@ int pclKeyReadData(unsigned int ldbid, const char* resource_id, unsigned int use * @param seat_no the seat number * @param callback notification callback * - * @return positive value: registration OK; On error a negative value will be returned with th follwoing error codes: - * EPERS_RES_NO_KEY EPERS_NOKEYDATA EPERS_NOPRCTABLE + * @return positive value: registration OK; On error a negative value will be returned with the following error codes: + * ::EPERS_RES_NO_KEY ::EPERS_NOKEYDATA ::EPERS_NOPRCTABLE */ int pclKeyRegisterNotifyOnChange(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no, pclChangeNotifyCallback_t callback); @@ -243,10 +250,12 @@ int pclKeyRegisterNotifyOnChange(unsigned int ldbid, const char* resource_id, un * @param buffer_size the number of bytes to write (default max size is set to 16kB) * use environment variable PERS_MAX_KEY_VAL_DATA_SIZE to modify default size in bytes * - * @return positive value: the bytes written; On error a negative value will be returned with th follwoing error codes: + * @return positive value: the bytes written; On error a negative value will be returned with the following error codes: + * ::EPERS_LOCKFS */ int pclKeyWriteData(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no, unsigned char* buffer, int buffer_size); +/** \} */ #ifdef __cplusplus } @@ -256,4 +265,3 @@ int pclKeyWriteData(unsigned int ldbid, const char* resource_id, unsigned int us /** \} */ /* End of MODULE */ #endif /* PERSISTENCY_CLIENT_LIBRARY_KEY_H */ - diff --git a/include_protected/persistence_client_library_data_organization.h b/include_protected/persistence_client_library_data_organization.h index 56c86d7..01ad010 100644 --- a/include_protected/persistence_client_library_data_organization.h +++ b/include_protected/persistence_client_library_data_organization.h @@ -24,7 +24,7 @@ extern "C" { #endif -#define PERSIST_CLIENT_LIBRARY_DATA_ORGANIZATION_INTERFACE_VERSION (0x01030000U) +#define PERSIST_CLIENT_LIBRARY_DATA_ORGANIZATION_INTERFACE_VERSION (0x01040000U) #include "../include/persistence_client_library_error_def.h" #include "../include/persistence_client_library_key.h" @@ -43,6 +43,9 @@ enum _PersistenceConstantDef ResIsFile = 1, /// flag to identify that resource a file AccessNoLock = 1, /// flag to indicate that access is not locked + PCLnotInitialized = 0, /// + PCLinitialized = 1, /// + FileClosed = 0, FileOpen = 1, @@ -141,9 +144,12 @@ extern char gAppId[MaxAppNameLen]; /// max key value data size extern int gMaxKeyValDataSize; -// the DLT context +/// the DLT context extern DltContext gDLTContext; +/// flag to indicate if client library has been initialized +extern unsigned int gPclInitialized; + /** * @brief definition of change callback function diff --git a/include_protected/persistence_client_library_db_access.h b/include_protected/persistence_client_library_db_access.h index feeb6c1..ca101bd 100644 --- a/include_protected/persistence_client_library_db_access.h +++ b/include_protected/persistence_client_library_db_access.h @@ -24,12 +24,12 @@ extern "C" { #endif -#define PERSIST_DATA_ACCESS_INTERFACE_VERSION (0x04010000U) +#define PERSIST_DATA_ACCESS_INTERFACE_VERSION (0x04020000U) #include "persistence_client_library_data_organization.h" #include "persistence_client_library_rc_table.h" -#include "persistence_client_library_key.h" +#include "../include/persistence_client_library_key.h" @@ -89,7 +89,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* dbKey, PersistenceInfo_s* info); +int pers_db_delete_key(char* dbPath, char* key, PersistenceInfo_s* info); diff --git a/src/persistence_client_library.c b/src/persistence_client_library.c index d11fba4..3fde82c 100644 --- a/src/persistence_client_library.c +++ b/src/persistence_client_library.c @@ -23,7 +23,7 @@ #include "persistence_client_library_dbus_service.h" #include "persistence_client_library_handle.h" #include "persistence_client_library_custom_loader.h" -#include "persistence_client_library_key.h" +#include "persistence_client_library.h" #include <string.h> #include <errno.h> @@ -34,102 +34,186 @@ #include <dbus/dbus.h> +#define USE_DBUS 1 /// debug log and trace (DLT) setup DLT_DECLARE_CONTEXT(gDLTContext); +static int gShutdownMode = 0; +/// loical function declaration +void invalidateCustomPlugin(int idx); -void pclInitLibrary(const char* appName, int shutdownMode) +int pclInitLibrary(const char* appName, int shutdownMode) { int status = 0; - int i = 0; + int i = 0, rval = 0; - DLT_REGISTER_CONTEXT(gDLTContext,"pers","Context for persistence client library logging"); - DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclInit => Initialize Persistence Client Library!!!!")); + if(gPclInitialized == PCLnotInitialized) + { + gPclInitialized++; - /// environment variable for on demand loading of custom libraries - const char *pOnDemandLoad = getenv("PERS_CUSTOM_LIB_LOAD_ON_DEMAND"); + gShutdownMode = shutdownMode; - /// environment variable for max key value data - const char *pDataSize = getenv("PERS_MAX_KEY_VAL_DATA_SIZE"); + DLT_REGISTER_CONTEXT(gDLTContext,"pers","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_STRING("- init counter: "), DLT_INT(gPclInitialized) ); - if(pDataSize != NULL) - { - gMaxKeyValDataSize = atoi(pDataSize); - } + /// environment variable for on demand loading of custom libraries + const char *pOnDemandLoad = getenv("PERS_CUSTOM_LIB_LOAD_ON_DEMAND"); - setup_dbus_mainloop(); + /// environment variable for max key value data + const char *pDataSize = getenv("PERS_MAX_KEY_VAL_DATA_SIZE"); - // register for lifecycle and persistence admin service dbus messages - register_lifecycle(shutdownMode); - register_pers_admin_service(); + if(pDataSize != NULL) + { + gMaxKeyValDataSize = atoi(pDataSize); + } - // clear the open file descriptor array - memset(gOpenFdArray, 0, MaxPersHandle * sizeof(int)); + setup_dbus_mainloop(); - /// get custom library names to load - status = get_custom_libraries(); - if(status < 0) - { - DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclInit => Failed to load custom library config table => error number:"), DLT_INT(status)); - } +#if USE_DBUS + // register for lifecycle and persistence admin service dbus messages + register_lifecycle(shutdownMode); + register_pers_admin_service(); +#endif - // initialize custom library structure - for(i = 0; i<PersCustomLib_LastEntry; i++) - { - gPersCustomFuncs[i].handle = NULL; - gPersCustomFuncs[i].custom_plugin_init = NULL; - gPersCustomFuncs[i].custom_plugin_deinit = NULL; - gPersCustomFuncs[i].custom_plugin_handle_open = NULL; - gPersCustomFuncs[i].custom_plugin_handle_close = NULL; - gPersCustomFuncs[i].custom_plugin_handle_get_data = NULL; - gPersCustomFuncs[i].custom_plugin_handle_set_data = NULL; - gPersCustomFuncs[i].custom_plugin_get_data = NULL; - gPersCustomFuncs[i].custom_plugin_set_data = NULL; - gPersCustomFuncs[i].custom_plugin_delete_data = NULL; - gPersCustomFuncs[i].custom_plugin_get_status_notification_clbk = NULL; - gPersCustomFuncs[i].custom_plugin_handle_get_size = NULL; - gPersCustomFuncs[i].custom_plugin_get_size = NULL; - gPersCustomFuncs[i].custom_plugin_create_backup = NULL; - gPersCustomFuncs[i].custom_plugin_get_backup = NULL; - gPersCustomFuncs[i].custom_plugin_restore_backup = NULL; - } + // clear the open file descriptor array + memset(gOpenFdArray, 0, MaxPersHandle * sizeof(int)); - if(pOnDemandLoad == NULL) // load all available libraries now - { - for(i=0; i < get_num_custom_client_libs(); i++ ) + /// get custom library names to load + status = get_custom_libraries(); + if(status >= 0) { - if(load_custom_library(get_custom_client_position_in_array(i), &gPersCustomFuncs[i] ) == -1) + // initialize custom library structure + for(i = 0; i < PersCustomLib_LastEntry; i++) { - DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclInit => E r r o r could not load plugin: "), DLT_STRING(get_custom_client_lib_name(get_custom_client_position_in_array(i)))); - break; + invalidateCustomPlugin(i); + } + + if(pOnDemandLoad == NULL) // load all available libraries now + { + for(i=0; i < PersCustomLib_LastEntry; i++ ) + { + if(check_valid_idx(i) != -1) + { + if(load_custom_library(i, &gPersCustomFuncs[i] ) == 1) + { + if( (gPersCustomFuncs[i].custom_plugin_init) != NULL) + { + DLT_LOG(gDLTContext, 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_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_STRING(get_custom_client_lib_name(i))); + } + } + else + { + continue; + } + } } - gPersCustomFuncs[i].custom_plugin_init(); } - } + else + { + DLT_LOG(gDLTContext, DLT_LOG_WARN, DLT_STRING("pclInit => Failed to load custom library config table => error number:"), DLT_INT(status)); + } - // assign application name - strncpy(gAppId, appName, MaxAppNameLen); - gAppId[MaxAppNameLen-1] = '\0'; - // destory mutex - pthread_mutex_destroy(&gDbusInitializedMtx); - pthread_cond_destroy(&gDbusInitializedCond); + // assign application name + strncpy(gAppId, appName, MaxAppNameLen); + gAppId[MaxAppNameLen-1] = '\0'; + + // destory mutex + pthread_mutex_destroy(&gDbusInitializedMtx); + pthread_cond_destroy(&gDbusInitializedCond); + + rval = 1; + } + 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_STRING("- ONLY INCREMENT init counter: "), DLT_INT(gPclInitialized) ); + } + + return rval; } -void pclDeinitLibrary(int shutdownMode) +int pclDeinitLibrary(void) { - DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclDeinit -> Deinit client library:"), DLT_STRING(gAppId)); + int i = 0, rval = 1; + + if(gPclInitialized == PCLinitialized) + { + DLT_LOG(gDLTContext, 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 + #if USE_DBUS + unregister_lifecycle(gShutdownMode); + unregister_pers_admin_service(); + #endif - // unregister for lifecycle and persistence admin service dbus messages - unregister_lifecycle(shutdownMode); - unregister_pers_admin_service(); + // unload custom client libraries + for(i=0; i<PersCustomLib_LastEntry; i++) + { + if(gPersCustomFuncs[i].custom_plugin_init != NULL) + { + // deinitialize plugin + gPersCustomFuncs[i].custom_plugin_deinit(); + // close library handle + dlclose(gPersCustomFuncs[i].handle); + + invalidateCustomPlugin(i); + } + } - DLT_UNREGISTER_CONTEXT(gDLTContext); - dlt_free(); + gPclInitialized = PCLnotInitialized; + + DLT_UNREGISTER_CONTEXT(gDLTContext); + } + 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_STRING("- ONLY DECREMENT init counter: "), DLT_INT(gPclInitialized)); + gPclInitialized--; // decrement init counter + } + + return rval; +} + + +void invalidateCustomPlugin(int idx) +{ + gPersCustomFuncs[idx].handle = NULL; + gPersCustomFuncs[idx].custom_plugin_init = NULL; + gPersCustomFuncs[idx].custom_plugin_deinit = NULL; + gPersCustomFuncs[idx].custom_plugin_handle_open = NULL; + gPersCustomFuncs[idx].custom_plugin_handle_close = NULL; + gPersCustomFuncs[idx].custom_plugin_handle_get_data = NULL; + gPersCustomFuncs[idx].custom_plugin_handle_set_data = NULL; + gPersCustomFuncs[idx].custom_plugin_get_data = NULL; + gPersCustomFuncs[idx].custom_plugin_set_data = NULL; + gPersCustomFuncs[idx].custom_plugin_delete_data = NULL; + gPersCustomFuncs[idx].custom_plugin_get_status_notification_clbk = NULL; + gPersCustomFuncs[idx].custom_plugin_handle_get_size = NULL; + gPersCustomFuncs[idx].custom_plugin_get_size = NULL; + gPersCustomFuncs[idx].custom_plugin_create_backup = NULL; + gPersCustomFuncs[idx].custom_plugin_get_backup = NULL; + gPersCustomFuncs[idx].custom_plugin_restore_backup = NULL; } diff --git a/src/persistence_client_library_custom_loader.c b/src/persistence_client_library_custom_loader.c index 6d1dce6..9a8bd7f 100644 --- a/src/persistence_client_library_custom_loader.c +++ b/src/persistence_client_library_custom_loader.c @@ -29,13 +29,17 @@ #include <sys/stat.h> #include <dlfcn.h> -// array containing the id of the custom arrays -static int gCustomLibIdArray[PersCustomLib_LastEntry]; + +/// type definition of persistence custom library information +typedef struct sPersCustomLibInfo +{ + char libname[CustLibMaxLen]; + int valid; +} PersCustomLibInfo; + /// array with custom client library names -static char gCustomLibArray[PersCustomLib_LastEntry][CustLibMaxLen]; -// number of libraries loaded -static int gNumOfCustomLibraries = 0; +static PersCustomLibInfo gCustomLibArray[PersCustomLib_LastEntry]; PersistenceCustomLibs_e custom_client_name_to_id(const char* lib_name, int substring) @@ -109,7 +113,7 @@ PersistenceCustomLibs_e custom_client_name_to_id(const char* lib_name, int subst } else { - printf("custom_libname_to_id - error - id not found for lib: %s \n", lib_name); + DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("custom_libname_to_id - error - id not found for lib:"), DLT_STRING(lib_name)); } } @@ -120,9 +124,7 @@ PersistenceCustomLibs_e custom_client_name_to_id(const char* lib_name, int subst int get_custom_libraries() { - int rval = 0, - fd = 0, - i = 0; + int rval = 0, fd = 0, j = 0; struct stat buffer; char* delimiters = " \n"; // search for blank and end of line @@ -132,9 +134,16 @@ int get_custom_libraries() if(filename == NULL) { - filename = "customLibConfigFile.cfg"; // use default filename + filename = "/etc/pclCustomLibConfigFile.cfg"; // use default filename + } + + for(j=0; j<PersCustomLib_LastEntry; j++) + { + // init pos to -1 + gCustomLibArray[j].valid = -1; } + if(stat(filename, &buffer) != -1) { fd = open(filename, O_RDONLY); @@ -150,9 +159,10 @@ int get_custom_libraries() token = strtok(configFileMap, delimiters); libId = custom_client_name_to_id(token, 0); + if(libId < PersCustomLib_LastEntry) { - gCustomLibIdArray[libId] = i; + gCustomLibArray[libId].valid = 1; } else { @@ -163,9 +173,8 @@ int get_custom_libraries() // get the library name token = strtok (NULL, delimiters); - strncpy(gCustomLibArray[i], token, CustLibMaxLen); - gCustomLibArray[i][CustLibMaxLen-1] = '\0'; // Ensures 0-Termination - i++; + strncpy(gCustomLibArray[libId].libname, token, CustLibMaxLen); + gCustomLibArray[libId].libname[CustLibMaxLen-1] = '\0'; // Ensures 0-Termination while( token != NULL ) { @@ -176,7 +185,7 @@ int get_custom_libraries() libId = custom_client_name_to_id(token, 0); if(libId < PersCustomLib_LastEntry) { - gCustomLibIdArray[libId] = i; + gCustomLibArray[libId].valid = 1; } else { @@ -193,26 +202,23 @@ int get_custom_libraries() token = strtok (NULL, delimiters); if(token != NULL) { - strncpy(gCustomLibArray[i], token, CustLibMaxLen); - gCustomLibArray[i][CustLibMaxLen-1] = '\0'; // Ensures 0-Termination - i++; + strncpy(gCustomLibArray[libId].libname, token, CustLibMaxLen); + gCustomLibArray[libId].libname[CustLibMaxLen-1] = '\0'; // Ensures 0-Termination } else { break; } } - gNumOfCustomLibraries = i; // remember the number of loaded libraries munmap(configFileMap, buffer.st_size); - // debugging only -/* printf("get_custom_libraries - found [ %d ] libraries \n", gNumOfCustomLibraries); - for(i=0; i< gNumOfCustomLibraries; i++) - printf("get_custom_libraries - names: %s\n", gCustomLibArray[i]); - - for(i=0; i<PersCustomLib_LastEntry; i++) - printf("get_custom_libraries - id: %d | pos: %d \n", i, gCustomLibIdArray[i]); */ + #if 0 // debuging + for(j=0; j<PersCustomLib_LastEntry; j++) + { + printf("Custom libraries => Name: %s | valid: %d \n", gCustomLibArray[j].libname, gCustomLibArray[j].valid); + } + #endif } else { @@ -239,13 +245,14 @@ int get_custom_libraries() int load_custom_library(PersistenceCustomLibs_e customLib, Pers_custom_functs_s *customFuncts) { - int rval = 0; + int rval = 1; char *error; if(customLib < PersCustomLib_LastEntry) { - void* handle = dlopen(gCustomLibArray[customLib], RTLD_LAZY); + void* handle = dlopen(gCustomLibArray[customLib].libname, RTLD_LAZY); customFuncts->handle = handle; + if(handle != NULL) { dlerror(); // reset error @@ -348,6 +355,11 @@ int load_custom_library(PersistenceCustomLibs_e customLib, Pers_custom_functs_s rval = EPERS_DLOPENERROR; } } + else + { + DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_library - error: - customLib out of bounds")); + rval = EPERS_DLOPENERROR; + } return rval; } @@ -359,7 +371,7 @@ int load_all_custom_libraries() int rval = 0, i = 0; - for(i=0; i<gNumOfCustomLibraries; i++) + for(i=0; i<PersCustomLib_LastEntry; i++) { rval = load_custom_library(i, &gPersCustomFuncs[i]); if( rval < 0) @@ -376,7 +388,7 @@ char* get_custom_client_lib_name(int idx) { if(idx < PersCustomLib_LastEntry) { - return gCustomLibArray[idx]; + return gCustomLibArray[idx].libname; } else { @@ -384,21 +396,15 @@ char* get_custom_client_lib_name(int idx) } } -int get_custom_client_position_in_array(PersistenceCustomLibs_e customLibId) +//int get_custom_client_position_in_array(int customLibId) +int check_valid_idx(int idx) { - //printf("get_position_in_array - id: %d | position: %d \n", customLibId, gCustomLibIdArray[(int)customLibId]); - if(customLibId < PersCustomLib_LastEntry) - { - return gCustomLibIdArray[(int)customLibId]; - } - else + int rval = -1; + + if(idx < PersCustomLib_LastEntry) { - return -1; + rval = gCustomLibArray[idx].valid; } -} - -int get_num_custom_client_libs() -{ - return gNumOfCustomLibraries; + return rval; } diff --git a/src/persistence_client_library_custom_loader.h b/src/persistence_client_library_custom_loader.h index 7435233..3bd0c12 100644 --- a/src/persistence_client_library_custom_loader.h +++ b/src/persistence_client_library_custom_loader.h @@ -158,16 +158,9 @@ int load_all_custom_libraries(); * * @return the array position or -1 if the position can't be found */ -int get_custom_client_position_in_array(PersistenceCustomLibs_e customLib); +int check_valid_idx(int idx); -/** - * @brief gget the number of available custom client libraries - * - * @return the number of the client libraries - */ -int get_num_custom_client_libs(); - /** * @brief get the custom library name form an index diff --git a/src/persistence_client_library_data_organization.c b/src/persistence_client_library_data_organization.c index c2dcde1..05ba317 100644 --- a/src/persistence_client_library_data_organization.c +++ b/src/persistence_client_library_data_organization.c @@ -79,6 +79,8 @@ char gAppId[MaxAppNameLen]; /// max key value data size [default 16kB] int gMaxKeyValDataSize = defaultMaxKeyValDataSize; +unsigned int gPclInitialized = PCLnotInitialized; + DltContext gDLTContext; diff --git a/src/persistence_client_library_db_access.c b/src/persistence_client_library_db_access.c index 4939cc7..5875069 100644 --- a/src/persistence_client_library_db_access.c +++ b/src/persistence_client_library_db_access.c @@ -91,7 +91,6 @@ itzam_btree* pers_db_open(PersistenceInfo_s* info, const char* dbPath) itzam_comparator_string, error_handler, 0/*recover*/, 0/*read_only*/); if (state != ITZAM_OKAY) { - printf("pers_db_open ==> itzam_btree_open => Itzam problem: %s\n", STATE_MESSAGES[state]); DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_open ==> itzam_btree_open => Itzam problem"), DLT_STRING(STATE_MESSAGES[state])); } gBtreeCreated[arrayIdx][info->configKey.policy] = 1; @@ -101,7 +100,6 @@ itzam_btree* pers_db_open(PersistenceInfo_s* info, const char* dbPath) } else { - printf("pers_db_open ==> invalid storage type\n"); DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_open ==> invalid storage type"), DLT_STRING(dbPath)); } return btree; @@ -119,14 +117,12 @@ void pers_db_close(PersistenceInfo_s* info) state = itzam_btree_close(&gBtree[arrayIdx][info->configKey.policy]); if (state != ITZAM_OKAY) { - printf("pers_db_close ==> Close Itzam problem: %s\n", STATE_MESSAGES[state]); DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_close ==> itzam_btree_close => Itzam problem"), DLT_STRING(STATE_MESSAGES[state])); } gBtreeCreated[arrayIdx][info->configKey.policy] = 0; } else { - printf("pers_db_close ==> invalid storage type\n"); DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_close ==> invalid storage type"), DLT_INT(info->context.ldbid )); } } @@ -146,7 +142,6 @@ void pers_db_close_all() state = itzam_btree_close(&gBtree[i][PersistencePolicy_wc]); if (state != ITZAM_OKAY) { - printf("pers_db_close_all ==> itzam_btree_close => Itzam problem: %s\n", STATE_MESSAGES[state]); DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_close_all ==> itzam_btree_close => Itzam problem:"), DLT_STRING(STATE_MESSAGES[state]) ); } gBtreeCreated[i][PersistencePolicy_wc] = 0; @@ -159,7 +154,6 @@ void pers_db_close_all() state = itzam_btree_close(&gBtree[i][PersistencePolicy_wt]); if (state != ITZAM_OKAY) { - printf("pers_db_close_all ==> itzam_btree_close => Itzam problem: %s\n", STATE_MESSAGES[state]); DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_close_all ==>itzam_btree_close => Itzam problem:"), DLT_STRING(STATE_MESSAGES[state])); } gBtreeCreated[i][PersistencePolicy_wt] = 0; @@ -199,7 +193,6 @@ int pers_db_read_key(char* dbPath, char* key, PersistenceInfo_s* info, unsigned } else { - printf("pers_db_read_key ==> no resource config table %s | %s \n", dbPath, key); 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; } @@ -210,12 +203,18 @@ int pers_db_read_key(char* dbPath, char* key, PersistenceInfo_s* info, unsigned char workaroundPath[128]; // workaround, because /sys/ can not be accessed on host!!!! snprintf(workaroundPath, 128, "%s%s", "/Data", dbPath ); - if( (idx < PersCustomLib_LastEntry) && (*gPersCustomFuncs[idx].custom_plugin_handle_get_data != NULL) ) + if( (idx < PersCustomLib_LastEntry) && (gPersCustomFuncs[idx].custom_plugin_handle_get_data != NULL) ) { if(info->configKey.customID[0] == '\0') // if we have not a customID we use the key - read_size = gPersCustomFuncs[idx].custom_plugin_get_data(key, (char*)buffer, buffer_size); + { + char pathKeyString[128]; + snprintf(pathKeyString, 128, "%s/%s", dbPath, key); + read_size = gPersCustomFuncs[idx].custom_plugin_get_data(pathKeyString, (char*)buffer, buffer_size); + } else + { read_size = gPersCustomFuncs[idx].custom_plugin_get_data(info->configKey.customID, (char*)buffer, buffer_size); + } } else { @@ -273,7 +272,6 @@ int pers_db_write_key(char* dbPath, char* key, PersistenceInfo_s* info, unsigned state = itzam_btree_insert(btree,(const void *)&insert); if (state != ITZAM_OKAY) { - printf("pers_db_write_key ==> itzam_btree_insert => Itzam problem: %s\n", STATE_MESSAGES[state]); 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; } @@ -290,21 +288,18 @@ int pers_db_write_key(char* dbPath, char* key, PersistenceInfo_s* info, unsigned } else { - printf("pers_db_write_key ==> data to long » size %d | maxSize: %d\n", dataSize, DbValueSize); 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; } } else { - printf("pers_db_write_key => key to long » size: %d | maxSize: %d\n", keySize, DbKeySize); 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; } } else { - printf("pers_db_write_key ==> no resource config table: %s | %s\n", dbPath, key); DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_write_key ==> no resource config table"), DLT_STRING(dbPath), DLT_STRING(key)); write_size = EPERS_NOPRCTABLE; } @@ -312,10 +307,14 @@ int pers_db_write_key(char* dbPath, char* key, PersistenceInfo_s* info, unsigned else if(PersistenceStorage_custom == info->configKey.storage) // custom storage implementation via custom library { int idx = custom_client_name_to_id(dbPath, 1); - if((idx < PersCustomLib_LastEntry) && (*gPersCustomFuncs[idx].custom_plugin_handle_set_data != NULL) ) + if((idx < PersCustomLib_LastEntry) && (gPersCustomFuncs[idx].custom_plugin_handle_set_data != NULL) ) { if(info->configKey.customID[0] == '\0') // if we have not a customID we use the key - write_size = gPersCustomFuncs[idx].custom_plugin_set_data(key, (char*)buffer, buffer_size); + { + char pathKeyString[128]; + snprintf(pathKeyString, 128, "%s/%s", dbPath, key); + write_size = gPersCustomFuncs[idx].custom_plugin_set_data(pathKeyString, (char*)buffer, buffer_size); + } else write_size = gPersCustomFuncs[idx].custom_plugin_set_data(info->configKey.customID, (char*)buffer, buffer_size); } @@ -360,14 +359,12 @@ int pers_db_get_key_size(char* dbPath, char* key, PersistenceInfo_s* info) } else { - printf("pers_db_get_key_size => key to long » size: %d | maxSize: %d\n", keySize, DbKeySize); 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 { - printf("pers_db_get_key_size ==> no resource config table: %s | %s\n", dbPath, key); 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; } @@ -375,10 +372,14 @@ int pers_db_get_key_size(char* dbPath, char* key, PersistenceInfo_s* info) else if(PersistenceStorage_custom == info->configKey.storage) // custom storage implementation via custom library { int idx = custom_client_name_to_id(dbPath, 1); - if((idx < PersCustomLib_LastEntry) && (*gPersCustomFuncs[idx].custom_plugin_handle_set_data != NULL) ) + if((idx < PersCustomLib_LastEntry) && (gPersCustomFuncs[idx].custom_plugin_handle_set_data != NULL) ) { if(info->configKey.customID[0] == '\0') // if we have not a customID we use the key - read_size = gPersCustomFuncs[idx].custom_plugin_get_size(key); + { + char pathKeyString[128]; + snprintf(pathKeyString, 128, "%s/%s", dbPath, key); + read_size = gPersCustomFuncs[idx].custom_plugin_get_size(pathKeyString); + } else read_size = gPersCustomFuncs[idx].custom_plugin_get_size(info->configKey.customID); } @@ -392,7 +393,7 @@ int pers_db_get_key_size(char* dbPath, char* key, PersistenceInfo_s* info) -int pers_db_delete_key(char* dbPath, char* dbKey, PersistenceInfo_s* info) +int pers_db_delete_key(char* dbPath, char* key, PersistenceInfo_s* info) { int ret = 0; if(PersistenceStorage_custom != info->configKey.storage) @@ -405,7 +406,7 @@ int pers_db_delete_key(char* dbPath, char* dbKey, PersistenceInfo_s* info) if(btree != NULL) { int keySize = 0; - keySize = (int)strlen((const char*)dbKey); + keySize = (int)strlen((const char*)key); if(keySize < DbKeySize) { // ----------------------------------------------------------------------------- @@ -415,11 +416,10 @@ int pers_db_delete_key(char* dbPath, char* dbKey, PersistenceInfo_s* info) itzam_state state; memset(delete.m_key,0, DbKeySize); - memcpy(delete.m_key, dbKey, keySize); + memcpy(delete.m_key, key, keySize); state = itzam_btree_remove(btree, (const void *)&delete); if (state != ITZAM_OKAY) { - printf("pers_db_delete_key ==> itzam_btree_remove => Itzam problem: %s \n", STATE_MESSAGES[state]); 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; } @@ -429,30 +429,32 @@ int pers_db_delete_key(char* dbPath, char* dbKey, PersistenceInfo_s* info) if(PersistenceStorage_shared == info->configKey.storage) { - pers_send_Notification_Signal(dbKey, &info->context, pclNotifyStatus_changed); + pers_send_Notification_Signal(key, &info->context, pclNotifyStatus_changed); } } else { - printf("pers_db_delete_key => key to long » size: %d | maxSize: %d\n", keySize, DbKeySize); 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; } } else { - printf("pers_db_delete_key ==> no resource config table: %s | %s\n", dbPath, dbKey); - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_delete_key ==> no resource config table"), DLT_STRING(dbPath), DLT_STRING(dbKey)); + DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_delete_key ==> no resource config table"), DLT_STRING(dbPath), DLT_STRING(key)); ret = EPERS_NOPRCTABLE; } } else // custom storage implementation via custom library { int idx = custom_client_name_to_id(dbPath, 1); - if((idx < PersCustomLib_LastEntry) && (*gPersCustomFuncs[idx].custom_plugin_handle_set_data != NULL) ) + if((idx < PersCustomLib_LastEntry) && (gPersCustomFuncs[idx].custom_plugin_handle_set_data != NULL) ) { if(info->configKey.customID[0] == '\0') // if we have not a customID we use the key - ret = gPersCustomFuncs[idx].custom_plugin_delete_data(dbKey); + { + char pathKeyString[128]; + snprintf(pathKeyString, 128, "%s/%s", dbPath, key); + ret = gPersCustomFuncs[idx].custom_plugin_delete_data(pathKeyString); + } else ret = gPersCustomFuncs[idx].custom_plugin_delete_data(info->configKey.customID); } @@ -616,7 +618,6 @@ int get_cursor_handle() } else { - printf("get_cursor_handle => Reached maximum of open handles: %d \n", MaxPersHandle); DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("get_cursor_handle ==> Reached maximum of open handles:"), DLT_INT(MaxPersHandle)); handle = -1; } @@ -654,7 +655,6 @@ int pers_db_cursor_create(char* dbPath) state = itzam_btree_open(&gCursorArray[handle].m_btree, dbPath, itzam_comparator_string, error_handler, 1/*recover*/, 0/*read_only*/); if (state != ITZAM_OKAY) { - printf("pers_db_cursor_create ==> itzam_btree_open: %s\n", STATE_MESSAGES[state]); DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_cursor_create ==> itzam_btree_open"), DLT_STRING(STATE_MESSAGES[state])); } else @@ -699,13 +699,11 @@ int pers_db_cursor_next(unsigned int handlerDB) } else { - printf("pers_db_cursor_next ==> invalid handle: %u \n", handlerDB); DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_cursor_next ==> invalid handle: "), DLT_INT(handlerDB)); } } else { - printf("pers_db_cursor_next ==> handle bigger than max » handleDB: %u | max: : %d \n", handlerDB, MaxPersHandle); DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_cursor_next ==> handle bigger than max:"), DLT_INT(MaxPersHandle)); } return rval; @@ -732,19 +730,16 @@ int pers_db_cursor_get_key(unsigned int handlerDB, char * bufKeyName_out, int bu } else { - printf("pers_db_cursor_get_key ==> buffer to small » keySize: %d | bufSize: %d \n", length, bufSize); DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_cursor_get_key ==> buffer to small » keySize: "), DLT_INT(bufSize)); } } else { - printf("persistence_db_cursor_get_key ==> invalid handle: %u \n", handlerDB); DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("persistence_db_cursor_get_key ==> invalid handle:"), DLT_INT(handlerDB)); } } else { - printf("persistence_db_cursor_get_key ==> handle bigger than max » handleDB: %u | max: : %d \n", handlerDB, MaxPersHandle); DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("persistence_db_cursor_get_key ==> handle bigger than max:"), DLT_INT(MaxPersHandle)); } return rval; @@ -772,19 +767,16 @@ int pers_db_cursor_get_data(unsigned int handlerDB, char * bufData_out, int bufS } else { - printf("pers_db_cursor_get_data ==> buffer to small » keySize: %d | bufSize: %d \n", length, bufSize); DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_cursor_get_data ==> buffer to small » keySize: "), DLT_INT(bufSize)); } } else { - printf("persistence_db_cursor_get_data ==> invalid handle: %u \n", handlerDB); DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("persistence_db_cursor_get_data ==> invalid handle:"), DLT_INT(handlerDB)); } } else { - printf("persistence_db_cursor_get_data ==> handle bigger than max » handleDB: %u | max: : %d \n", handlerDB, MaxPersHandle); DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("persistence_db_cursor_get_data ==> handle bigger than max:"), DLT_INT(MaxPersHandle)); } return rval; @@ -806,13 +798,11 @@ int pers_db_cursor_get_data_size(unsigned int handlerDB) } else { - printf("pers_db_cursor_get_data_size ==> invalid handle: %u \n", handlerDB); DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_cursor_get_data_size ==> invalid handle:"), DLT_INT(handlerDB)); } } else { - printf("persistence_db_cursor_get_data ==> handle bigger than max » handleDB: %u | max: : %d \n", handlerDB, MaxPersHandle); DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("persistence_db_cursor_get_data ==> handle bigger than max:"), DLT_INT(MaxPersHandle)); } return size; @@ -832,7 +822,6 @@ int pers_db_cursor_destroy(unsigned int handlerDB) state = itzam_btree_close(&gCursorArray[handlerDB].m_btree); if (state != ITZAM_OKAY) { - printf("pers_db_cursor_destroy ==> itzam_btree_close: Itzam problem: %s\n", STATE_MESSAGES[state]); DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_cursor_destroy ==> itzam_btree_close: Itzam problem"), DLT_STRING(STATE_MESSAGES[state])); } diff --git a/src/persistence_client_library_file.c b/src/persistence_client_library_file.c index 4469e56..92631a5 100644 --- a/src/persistence_client_library_file.c +++ b/src/persistence_client_library_file.c @@ -55,25 +55,33 @@ int pclBackupNeeded(const char* path); int pclFileClose(int fd) { - int rval = -1; + int rval = EPERS_NOT_INITIALIZED; //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileClose fd: "), DLT_INT(fd)); - if(fd < MaxPersHandle) + if(gPclInitialized >= PCLinitialized) { - // check if a backup and checksum file needs to bel deleted - if( gFileHandleArray[fd].permission != PersistencePermission_ReadOnly) + if(fd < MaxPersHandle) { - // remove backup file - remove(gFileHandleArray[fd].backupPath); // we don't care about return value + // check if a backup and checksum file needs to bel deleted + if( gFileHandleArray[fd].permission != PersistencePermission_ReadOnly) + { + // remove backup file + remove(gFileHandleArray[fd].backupPath); // we don't care about return value - // remove checksum file - remove(gFileHandleArray[fd].csumPath); // we don't care about return value + // remove checksum file + remove(gFileHandleArray[fd].csumPath); // we don't care about return value + } + __sync_fetch_and_sub(&gOpenFdArray[fd], FileClosed); // set closed flag + rval = close(fd); + } + else + { + rval = -1; } - __sync_fetch_and_sub(&gOpenFdArray[fd], FileClosed); // set closed flag - rval = close(fd); } + return rval; } @@ -81,18 +89,22 @@ int pclFileClose(int fd) int pclFileGetSize(int fd) { - int rval = -1; + int rval = EPERS_NOT_INITIALIZED; - struct stat buf; - int ret = 0; - ret = fstat(fd, &buf); + if(gPclInitialized >= PCLinitialized) + { + struct stat buf; + int ret = 0; + ret = fstat(fd, &buf); - //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileGetSize fd: "), DLT_INT(fd)); + //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileGetSize fd: "), DLT_INT(fd)); - if(ret != -1) - { - rval = buf.st_size; + if(ret != -1) + { + rval = buf.st_size; + } } + return rval; } @@ -104,15 +116,19 @@ void* pclFileMapData(void* addr, long size, long offset, int fd) //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileMapData fd: "), DLT_INT(fd)); - if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked + if(gPclInitialized >= PCLinitialized) { - int mapFlag = PROT_WRITE | PROT_READ; - ptr = mmap(addr,size, mapFlag, MAP_SHARED, fd, offset); - } - else - { - ptr = EPERS_MAP_LOCKFS; + if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked + { + int mapFlag = PROT_WRITE | PROT_READ; + ptr = mmap(addr,size, mapFlag, MAP_SHARED, fd, offset); + } + else + { + ptr = EPERS_MAP_LOCKFS; + } } + return ptr; } @@ -120,104 +136,110 @@ void* pclFileMapData(void* addr, long size, long offset, int fd) int pclFileOpen(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no) { - int handle = -1, shared_DB = 0; - PersistenceInfo_s dbContext; + int handle = EPERS_NOT_INITIALIZED; - char dbKey[DbKeyMaxLen]; // database key - char dbPath[DbPathMaxLen]; // database location - char backupPath[DbKeyMaxLen]; // backup file - char csumPath[DbPathMaxLen]; // checksum file + if(gPclInitialized >= PCLinitialized) + { + int shared_DB = 0; + PersistenceInfo_s dbContext; - //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileOpen: "), DLT_INT(ldbid), DLT_STRING(resource_id) ); + char dbKey[DbKeyMaxLen]; // database key + char dbPath[DbPathMaxLen]; // database location + char backupPath[DbKeyMaxLen]; // backup file + char csumPath[DbPathMaxLen]; // checksum file - memset(dbKey, 0, DbKeyMaxLen); - memset(dbPath, 0, DbPathMaxLen); + //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileOpen: "), DLT_INT(ldbid), DLT_STRING(resource_id) ); - dbContext.context.ldbid = ldbid; - dbContext.context.seat_no = seat_no; - dbContext.context.user_no = user_no; + memset(dbKey, 0, DbKeyMaxLen); + memset(dbPath, 0, DbPathMaxLen); - // get database context: database path and database key - shared_DB = get_db_context(&dbContext, resource_id, ResIsFile, dbKey, dbPath); + dbContext.context.ldbid = ldbid; + dbContext.context.seat_no = seat_no; + dbContext.context.user_no = user_no; - if( (shared_DB >= 0) // check valid database context - && (dbContext.configKey.type == PersistenceResourceType_file) ) // check if type matches - { - int flags = dbContext.configKey.permission; + // get database context: database path and database key + shared_DB = get_db_context(&dbContext, resource_id, ResIsFile, dbKey, dbPath); - // file will be opend writable, so check about data consistency - if( dbContext.configKey.permission != PersistencePermission_ReadOnly - && pclBackupNeeded(dbPath) ) + if( (shared_DB >= 0) // check valid database context + && (dbContext.configKey.type == PersistenceResourceType_file) ) // check if type matches { - memset(backupPath, 0, DbKeyMaxLen); - memset(csumPath, 0, DbPathMaxLen); + int flags = dbContext.configKey.permission; - snprintf(backupPath, DbPathMaxLen, "%s%s", dbPath, "~"); - snprintf(csumPath, DbPathMaxLen, "%s%s", dbPath, "~.crc"); - - if((handle = pclVerifyConsistency(dbPath, backupPath, csumPath, flags)) == -1) + // file will be opened writable, so check about data consistency + if( dbContext.configKey.permission != PersistencePermission_ReadOnly + && pclBackupNeeded(dbPath) ) { - printf("pclFileOpen: error => file inconsistent, recovery N O T possible!\n"); - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclFileOpen: error => file inconsistent, recovery N O T possible!")); - return -1; - } - } + memset(backupPath, 0, DbKeyMaxLen); + memset(csumPath, 0, DbPathMaxLen); - if(handle <= 0) // check if open is needed or already done in verifyConsistency - handle = open(dbPath, flags); + snprintf(backupPath, DbPathMaxLen, "%s%s", dbPath, "~"); + snprintf(csumPath, DbPathMaxLen, "%s%s", dbPath, "~.crc"); - if(handle != -1) - { - if(handle < MaxPersHandle) + 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!")); + return -1; + } + } + + if(handle <= 0) // check if open is needed or already done in verifyConsistency { - __sync_fetch_and_add(&gOpenFdArray[handle], FileOpen); // set open flag + handle = open(dbPath, flags); + } - if(dbContext.configKey.permission != PersistencePermission_ReadOnly) + if(handle != -1) + { + if(handle < MaxPersHandle) { - strcpy(gFileHandleArray[handle].backupPath, backupPath); - strcpy(gFileHandleArray[handle].csumPath, csumPath); + __sync_fetch_and_add(&gOpenFdArray[handle], FileOpen); // set open flag - gFileHandleArray[handle].backupCreated = 0; - gFileHandleArray[handle].permission = dbContext.configKey.permission; + 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 + else // file does not exist, create file and folder { - close(handle); - handle = EPERS_MAXHANDLE; + handle = pclCreateFile(dbPath); } } - else // file does not exist, create file and folder + else { + // assemble file string for local cached location + snprintf(dbPath, DbPathMaxLen, gLocalCacheFilePath, gAppId, user_no, seat_no, resource_id); handle = pclCreateFile(dbPath); - } - } - else - { - // assemble file string for local cached location - snprintf(dbPath, DbPathMaxLen, gLocalCacheFilePath, gAppId, user_no, seat_no, resource_id); - handle = pclCreateFile(dbPath); - if(handle != -1) - { - if(handle < MaxPersHandle) + if(handle != -1) { - memset(backupPath, 0, DbKeyMaxLen); - memset(csumPath, 0, DbPathMaxLen); + if(handle < MaxPersHandle) + { + memset(backupPath, 0, DbKeyMaxLen); + memset(csumPath, 0, DbPathMaxLen); - snprintf(backupPath, DbPathMaxLen, "%s%s", dbPath, "~"); - snprintf(csumPath, DbPathMaxLen, "%s%s", dbPath, "~.crc"); + snprintf(backupPath, DbPathMaxLen, "%s%s", dbPath, "~"); + snprintf(csumPath, DbPathMaxLen, "%s%s", dbPath, "~.crc"); - __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; + __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; + } } } } @@ -229,57 +251,66 @@ int pclFileOpen(unsigned int ldbid, const char* resource_id, unsigned int user_n int pclFileReadData(int fd, void * buffer, int buffer_size) { + int readSize = EPERS_NOT_INITIALIZED; + //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileReadData fd: "), DLT_INT(fd)); - return read(fd, buffer, buffer_size); + if(gPclInitialized >= PCLinitialized) + { + readSize = read(fd, buffer, buffer_size); + } + return readSize; } int pclFileRemove(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no) { - int rval = 0; + int rval = EPERS_NOT_INITIALIZED; //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileReadData "), DLT_INT(ldbid), DLT_STRING(resource_id)); - if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked + if(gPclInitialized >= PCLinitialized) { - int shared_DB = 0; - PersistenceInfo_s dbContext; + if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked + { + int shared_DB = 0; + PersistenceInfo_s dbContext; - char dbKey[DbKeyMaxLen]; // database key - char dbPath[DbPathMaxLen]; // database location + char dbKey[DbKeyMaxLen]; // database key + char dbPath[DbPathMaxLen]; // database location - memset(dbKey, 0, DbKeyMaxLen); - memset(dbPath, 0, DbPathMaxLen); + memset(dbKey, 0, DbKeyMaxLen); + memset(dbPath, 0, DbPathMaxLen); - dbContext.context.ldbid = ldbid; - dbContext.context.seat_no = seat_no; - dbContext.context.user_no = user_no; + dbContext.context.ldbid = ldbid; + dbContext.context.seat_no = seat_no; + dbContext.context.user_no = user_no; - // get database context: database path and database key - shared_DB = get_db_context(&dbContext, resource_id, ResIsFile, dbKey, dbPath); + // get database context: database path and database key + shared_DB = get_db_context(&dbContext, resource_id, ResIsFile, dbKey, dbPath); - if( (shared_DB >= 0) // check valid database context - && (dbContext.configKey.type == PersistenceResourceType_file) ) // check if type matches - { - rval = remove(dbPath); - if(rval == -1) + if( (shared_DB >= 0) // check valid database context + && (dbContext.configKey.type == PersistenceResourceType_file) ) // check if type matches { - printf("pclFileRemove => remove ERROR: %s \n", strerror(errno) ); - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclFileRemove => remove ERROR"), DLT_STRING(strerror(errno)) ); + rval = remove(dbPath); + if(rval == -1) + { + printf("pclFileRemove => remove ERROR: %s \n", strerror(errno) ); + DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclFileRemove => remove ERROR"), DLT_STRING(strerror(errno)) ); + } + } + else + { + rval = shared_DB; + printf("pclFileRemove ==> no valid database context or resource not a file\n"); + DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclFileRemove ==> no valid database context or resource not a file")); } } else { - rval = shared_DB; - printf("pclFileRemove ==> no valid database context or resource not a file\n"); - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclFileRemove ==> no valid database context or resource not a file")); + rval = EPERS_LOCKFS; } } - else - { - rval = EPERS_LOCKFS; - } return rval; } @@ -288,17 +319,20 @@ int pclFileRemove(unsigned int ldbid, const char* resource_id, unsigned int user int pclFileSeek(int fd, long int offset, int whence) { - int rval = 0; + int rval = EPERS_NOT_INITIALIZED; //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileSeek fd:"), DLT_INT(fd)); - if(AccessNoLock == isAccessLocked() ) // check if access to persistent data is locked - { - rval = lseek(fd, offset, whence); - } - else + if(gPclInitialized >= PCLinitialized) { - rval = EPERS_LOCKFS; + if(AccessNoLock == isAccessLocked() ) // check if access to persistent data is locked + { + rval = lseek(fd, offset, whence); + } + else + { + rval = EPERS_LOCKFS; + } } return rval; @@ -308,17 +342,20 @@ int pclFileSeek(int fd, long int offset, int whence) int pclFileUnmapData(void* address, long size) { - int rval = 0; + int rval = EPERS_NOT_INITIALIZED; //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileUnmapData")); - if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked - { - rval = munmap(address, size); - } - else + if(gPclInitialized >= PCLinitialized) { - rval = EPERS_LOCKFS; + if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked + { + rval = munmap(address, size); + } + else + { + rval = EPERS_LOCKFS; + } } return rval; @@ -328,36 +365,39 @@ int pclFileUnmapData(void* address, long size) int pclFileWriteData(int fd, const void * buffer, int buffer_size) { - int size = 0; + int size = EPERS_NOT_INITIALIZED; //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileWriteData fd:"), DLT_INT(fd)); - if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked + if(gPclInitialized >= PCLinitialized) { - if(fd < MaxPersHandle) + if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked { - // check if a backup file has to be created - if( gFileHandleArray[fd].permission != PersistencePermission_ReadOnly - && gFileHandleArray[fd].backupCreated == 0) + if(fd < MaxPersHandle) { - char csumBuf[ChecksumBufSize]; - memset(csumBuf, 0, ChecksumBufSize); + // check if a backup file has to be created + if( gFileHandleArray[fd].permission != PersistencePermission_ReadOnly + && gFileHandleArray[fd].backupCreated == 0) + { + char csumBuf[ChecksumBufSize]; + memset(csumBuf, 0, ChecksumBufSize); - // calculate checksum - pclCalcCrc32Csum(fd, csumBuf); + // calculate checksum + pclCalcCrc32Csum(fd, csumBuf); - // create checksum and backup file - pclCreateBackup(gFileHandleArray[fd].backupPath, fd, gFileHandleArray[fd].csumPath, csumBuf); + // create checksum and backup file + pclCreateBackup(gFileHandleArray[fd].backupPath, fd, gFileHandleArray[fd].csumPath, csumBuf); - gFileHandleArray[fd].backupCreated = 1; - } + gFileHandleArray[fd].backupCreated = 1; + } - size = write(fd, buffer, buffer_size); + size = write(fd, buffer, buffer_size); + } + } + else + { + size = EPERS_LOCKFS; } - } - else - { - size = EPERS_LOCKFS; } return size; @@ -453,12 +493,15 @@ int pclVerifyConsistency(const char* origPath, const char* backupPath, const cha backupAvail = access(backupPath, F_OK); csumAvail = access(csumPath, F_OK); + //printf("pclVerifyConsistency => backup path: %s | backupAvail: %d \n", backupPath, backupAvail); + //printf("pclVerifyConsistency => csum path: %s | csumAvail : %d \n", csumPath, csumAvail); + // ************************************************* // there is a backup file and a checksum // ************************************************* if( (backupAvail == 0) && (csumAvail == 0) ) { - printf("pclVerifyConsistency => there is a backup file AND a checksum\n"); + //printf("pclVerifyConsistency => there is a backup file AND a checksum\n"); DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclVerifyConsistency => there is a backup file AND a checksum")); // calculate checksum form backup file fdBackup = open(backupPath, O_RDONLY); @@ -518,7 +561,7 @@ int pclVerifyConsistency(const char* origPath, const char* backupPath, const cha // ************************************************* else if(csumAvail == 0) { - printf("verifyConsistency => there is ONLY a checksum file\n"); + //printf("verifyConsistency => there is ONLY a checksum file\n"); DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclVerifyConsistency => there is ONLY a checksum file")); fdCsum = open(csumPath, O_RDONLY); @@ -527,7 +570,7 @@ int pclVerifyConsistency(const char* origPath, const char* backupPath, const cha readSize = read(fdCsum, csumBuf, ChecksumBufSize); if(readSize <= 0) { - printf("verifyConsistency ==> read checksum: invalid readSize\n"); + //printf("verifyConsistency ==> read checksum: invalid readSize\n"); DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclVerifyConsistency => read checksum: invalid readSize")); } close(fdCsum); @@ -562,7 +605,7 @@ int pclVerifyConsistency(const char* origPath, const char* backupPath, const cha // ************************************************* else if(backupAvail == 0) { - printf("verifyConsistency => there is ONLY a backup file\n"); + //printf("verifyConsistency => there is ONLY a backup file\n"); DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclVerifyConsistency => there is ONLY a backup file")); // calculate checksum form backup file @@ -604,6 +647,7 @@ int pclVerifyConsistency(const char* origPath, const char* backupPath, const cha // if we are in an inconsistent state: delete file, backup and checksum if(handle == -1) { + //printf(" =====> remove\n"); remove(origPath); remove(backupPath); remove(csumPath); diff --git a/src/persistence_client_library_key.c b/src/persistence_client_library_key.c index 43352ec..dd9d16e 100644 --- a/src/persistence_client_library_key.c +++ b/src/persistence_client_library_key.c @@ -37,70 +37,74 @@ int pclKeyHandleOpen(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no) { - int handle = 0; - PersistenceInfo_s dbContext; + int handle = EPERS_NOT_INITIALIZED; - char dbKey[DbKeyMaxLen]; // database key - char dbPath[DbPathMaxLen]; // database location + if(gPclInitialized >= PCLinitialized) + { + PersistenceInfo_s dbContext; + + char dbKey[DbKeyMaxLen]; // database key + char dbPath[DbPathMaxLen]; // database location - //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyHandleOpen: "), DLT_INT(ldbid), DLT_STRING(resource_id) ); + //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyHandleOpen: "), DLT_INT(ldbid), DLT_STRING(resource_id) ); - memset(dbKey, 0, DbKeyMaxLen); - memset(dbPath, 0, DbPathMaxLen); + memset(dbKey, 0, DbKeyMaxLen); + memset(dbPath, 0, DbPathMaxLen); - dbContext.context.ldbid = ldbid; - dbContext.context.seat_no = seat_no; - dbContext.context.user_no = user_no; + dbContext.context.ldbid = ldbid; + dbContext.context.seat_no = seat_no; + dbContext.context.user_no = user_no; - // get database context: database path and database key - handle = get_db_context(&dbContext, resource_id, ResIsNoFile, dbKey, dbPath); - if( (handle >= 0) - && (dbContext.configKey.type == PersistenceResourceType_key) ) // check if type matches - { - if(dbContext.configKey.storage < PersistenceStorage_LastEntry) // check if store policy is valid + // get database context: database path and database key + handle = get_db_context(&dbContext, resource_id, ResIsNoFile, dbKey, dbPath); + if( (handle >= 0) + && (dbContext.configKey.type == PersistenceResourceType_key) ) // check if type matches { - if(PersistenceStorage_custom == dbContext.configKey.storage) + if(dbContext.configKey.storage < PersistenceStorage_LastEntry) // check if store policy is valid { - int idx = custom_client_name_to_id(dbPath, 1); - char workaroundPath[128]; // workaround, because /sys/ can not be accessed on host!!!! - snprintf(workaroundPath, 128, "%s%s", "/Data", dbPath ); - - if( (idx < PersCustomLib_LastEntry) && (gPersCustomFuncs[idx].custom_plugin_handle_open != NULL) ) + if(PersistenceStorage_custom == dbContext.configKey.storage) { - int flag = 0, mode = 0; - handle = gPersCustomFuncs[idx].custom_plugin_handle_open(workaroundPath, flag, mode); + int idx = custom_client_name_to_id(dbPath, 1); + char workaroundPath[128]; // workaround, because /sys/ can not be accessed on host!!!! + snprintf(workaroundPath, 128, "%s%s", "/Data", dbPath ); + + if( (idx < PersCustomLib_LastEntry) && (gPersCustomFuncs[idx].custom_plugin_handle_open != NULL) ) + { + int flag = 0, mode = 0; + handle = gPersCustomFuncs[idx].custom_plugin_handle_open(workaroundPath, flag, mode); + } + else + { + handle = EPERS_NOPLUGINFUNCT; + } } else { - handle = EPERS_NOPLUGINFUNCT; + handle = get_persistence_handle_idx(); } - } - else - { - handle = get_persistence_handle_idx(); - } - if(handle < MaxPersHandle && handle != -1) - { - // remember data in handle array - strncpy(gKeyHandleArray[handle].dbPath, dbPath, DbPathMaxLen); - 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].info = dbContext; - } - else - { - printf("pclKeyHandleOpen: error - handleId out of bounds [%d]\n", handle); - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyHandleOpen: error - handleId out of bounds:"), DLT_INT(handle)); + if(handle < MaxPersHandle && handle != -1) + { + // remember data in handle array + strncpy(gKeyHandleArray[handle].dbPath, dbPath, DbPathMaxLen); + 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].info = dbContext; + } + else + { + printf("pclKeyHandleOpen: error - handleId out of bounds [%d]\n", handle); + DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyHandleOpen: error - handleId out of bounds:"), DLT_INT(handle)); + } } } - } - else - { - printf("pclKeyHandleOpen: error - no database context or resource is not a key \n"); - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyHandleOpen: error - no database context or resource is not a key ")); + else + { + printf("pclKeyHandleOpen: error - no database context or resource is not a key \n"); + DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyHandleOpen: error - no database context or resource is not a key ")); + } } @@ -111,40 +115,42 @@ int pclKeyHandleOpen(unsigned int ldbid, const char* resource_id, unsigned int u int pclKeyHandleClose(int key_handle) { - int rval = 0; + int rval = EPERS_NOT_INITIALIZED; //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyHandleClose: "), // DLT_INT(gKeyHandleArray[key_handle].info.context.ldbid), DLT_STRING(gKeyHandleArray[key_handle].resourceID) ); - - if(key_handle < MaxPersHandle) + if(gPclInitialized >= PCLinitialized) { - if(PersistenceStorage_custom == gKeyHandleArray[key_handle].info.configKey.storage ) + if(key_handle < MaxPersHandle) { - int idx = custom_client_name_to_id(gKeyHandleArray[key_handle].dbPath, 1); - - if( (idx < PersCustomLib_LastEntry) && (gPersCustomFuncs[idx].custom_plugin_handle_close) ) + if(PersistenceStorage_custom == gKeyHandleArray[key_handle].info.configKey.storage ) { - rval = gPersCustomFuncs[idx].custom_plugin_handle_close(key_handle); + int idx = custom_client_name_to_id(gKeyHandleArray[key_handle].dbPath, 1); + + if( (idx < PersCustomLib_LastEntry) && (gPersCustomFuncs[idx].custom_plugin_handle_close != NULL) ) + { + rval = gPersCustomFuncs[idx].custom_plugin_handle_close(key_handle); + } + else + { + rval = EPERS_NOPLUGINFUNCT; + } } else { - rval = EPERS_NOPLUGINFUNCT; + set_persistence_handle_close_idx(key_handle); } + + // invalidate entries + strncpy(gKeyHandleArray[key_handle].dbPath, "", DbPathMaxLen); + strncpy(gKeyHandleArray[key_handle].dbKey ,"", DbKeyMaxLen); + gKeyHandleArray[key_handle].info.configKey.storage = -1; } else { - set_persistence_handle_close_idx(key_handle); + rval = -1; } - - // invalidate entries - strncpy(gKeyHandleArray[key_handle].dbPath, "", DbPathMaxLen); - strncpy(gKeyHandleArray[key_handle].dbKey ,"", DbKeyMaxLen); - gKeyHandleArray[key_handle].info.configKey.storage = -1; - } - else - { - rval = -1; } return rval; @@ -154,31 +160,34 @@ int pclKeyHandleClose(int key_handle) int pclKeyHandleGetSize(int key_handle) { - int size = 0; + int size = EPERS_NOT_INITIALIZED; //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyHandleGetSize: "), // DLT_INT(gKeyHandleArray[key_handle].info.context.ldbid), DLT_STRING(gKeyHandleArray[key_handle].resourceID) ); - if(key_handle < MaxPersHandle) + if(gPclInitialized >= PCLinitialized) { - if(PersistenceStorage_custom == gKeyHandleArray[key_handle].info.configKey.storage) + if(key_handle < MaxPersHandle) { - int idx = custom_client_name_to_id(gKeyHandleArray[key_handle].dbPath, 1); - - if(idx < PersCustomLib_LastEntry && &(gPersCustomFuncs[idx].custom_plugin_get_size) != NULL) + if(PersistenceStorage_custom == gKeyHandleArray[key_handle].info.configKey.storage) { - size = gPersCustomFuncs[idx].custom_plugin_get_size(gKeyHandleArray[key_handle].dbPath); + int idx = custom_client_name_to_id(gKeyHandleArray[key_handle].dbPath, 1); + + if( (idx < PersCustomLib_LastEntry) && (gPersCustomFuncs[idx].custom_plugin_get_size != NULL) ) + { + size = gPersCustomFuncs[idx].custom_plugin_get_size(gKeyHandleArray[key_handle].dbPath); + } + else + { + size = EPERS_NOPLUGINFUNCT; + } } else { - size = EPERS_NOPLUGINFUNCT; + size = pers_db_get_key_size(gKeyHandleArray[key_handle].dbPath, gKeyHandleArray[key_handle].dbKey, + &gKeyHandleArray[key_handle].info); } } - else - { - size = pers_db_get_key_size(gKeyHandleArray[key_handle].dbPath, gKeyHandleArray[key_handle].dbKey, - &gKeyHandleArray[key_handle].info); - } } return size; @@ -188,31 +197,34 @@ int pclKeyHandleGetSize(int key_handle) int pclKeyHandleReadData(int key_handle, unsigned char* buffer, int buffer_size) { - int size = 0; + int size = EPERS_NOT_INITIALIZED; //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyHandleReadData: "), // DLT_INT(gKeyHandleArray[key_handle].info.context.ldbid), DLT_STRING(gKeyHandleArray[key_handle].resourceID) ); - if(key_handle < MaxPersHandle) + if(gPclInitialized >= PCLinitialized) { - if(PersistenceStorage_custom == gKeyHandleArray[key_handle].info.configKey.storage) + if(key_handle < MaxPersHandle) { - int idx = custom_client_name_to_id(gKeyHandleArray[key_handle].dbPath, 1); - - if(idx < PersCustomLib_LastEntry && &(gPersCustomFuncs[idx].custom_plugin_handle_get_data) != NULL) + if(PersistenceStorage_custom == gKeyHandleArray[key_handle].info.configKey.storage) { - size = gPersCustomFuncs[idx].custom_plugin_handle_get_data(key_handle, (char*)buffer, buffer_size-1); + int idx = custom_client_name_to_id(gKeyHandleArray[key_handle].dbPath, 1); + + if( (idx < PersCustomLib_LastEntry) && (gPersCustomFuncs[idx].custom_plugin_handle_get_data != NULL) ) + { + size = gPersCustomFuncs[idx].custom_plugin_handle_get_data(key_handle, (char*)buffer, buffer_size-1); + } + else + { + size = EPERS_NOPLUGINFUNCT; + } } else { - size = EPERS_NOPLUGINFUNCT; + size = pers_db_read_key(gKeyHandleArray[key_handle].dbPath, gKeyHandleArray[key_handle].dbKey, + &gKeyHandleArray[key_handle].info, buffer, buffer_size); } } - else - { - size = pers_db_read_key(gKeyHandleArray[key_handle].dbPath, gKeyHandleArray[key_handle].dbKey, - &gKeyHandleArray[key_handle].info, buffer, buffer_size); - } } return size; @@ -222,17 +234,20 @@ int pclKeyHandleReadData(int key_handle, unsigned char* buffer, int buffer_size) int pclKeyHandleRegisterNotifyOnChange(int key_handle, pclChangeNotifyCallback_t callback) { - int rval = -1; + int rval = EPERS_NOT_INITIALIZED; //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyHandleRegisterNotifyOnChange: "), // DLT_INT(gKeyHandleArray[key_handle].info.context.ldbid), DLT_STRING(gKeyHandleArray[key_handle].resourceID) ); - if(key_handle < MaxPersHandle) + if(gPclInitialized >= PCLinitialized) { - rval = pclKeyRegisterNotifyOnChange(gKeyHandleArray[key_handle].info.context.ldbid, - gKeyHandleArray[key_handle].resourceID, - gKeyHandleArray[key_handle].info.context.user_no, - gKeyHandleArray[key_handle].info.context.seat_no, callback); + if(key_handle < MaxPersHandle) + { + rval = pclKeyRegisterNotifyOnChange(gKeyHandleArray[key_handle].info.context.ldbid, + gKeyHandleArray[key_handle].resourceID, + gKeyHandleArray[key_handle].info.context.user_no, + gKeyHandleArray[key_handle].info.context.seat_no, callback); + } } return rval; @@ -242,51 +257,54 @@ int pclKeyHandleRegisterNotifyOnChange(int key_handle, pclChangeNotifyCallback_t int pclKeyHandleWriteData(int key_handle, unsigned char* buffer, int buffer_size) { - int size = 0; + int size = EPERS_NOT_INITIALIZED; //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyHandleWriteData: "), // DLT_INT(gKeyHandleArray[key_handle].info.context.ldbid), DLT_STRING(gKeyHandleArray[key_handle].resourceID) ); - if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked + if(gPclInitialized >= PCLinitialized) { - if(buffer_size <= gMaxKeyValDataSize) // check data size + if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked { - if(key_handle < MaxPersHandle) + if(buffer_size <= gMaxKeyValDataSize) // check data size { - if(PersistenceStorage_custom == gKeyHandleArray[key_handle].info.configKey.storage) + if(key_handle < MaxPersHandle) { - int idx = custom_client_name_to_id(gKeyHandleArray[key_handle].dbPath, 1); - - if(idx < PersCustomLib_LastEntry && *gPersCustomFuncs[idx].custom_plugin_handle_set_data != NULL) + if(PersistenceStorage_custom == gKeyHandleArray[key_handle].info.configKey.storage) { - size = gPersCustomFuncs[idx].custom_plugin_handle_set_data(key_handle, (char*)buffer, buffer_size-1); + int idx = custom_client_name_to_id(gKeyHandleArray[key_handle].dbPath, 1); + + if( (idx < PersCustomLib_LastEntry) && (gPersCustomFuncs[idx].custom_plugin_handle_set_data != NULL) ) + { + size = gPersCustomFuncs[idx].custom_plugin_handle_set_data(key_handle, (char*)buffer, buffer_size-1); + } + else + { + size = EPERS_NOPLUGINFUNCT; + } } else { - size = EPERS_NOPLUGINFUNCT; + size = pers_db_write_key(gKeyHandleArray[key_handle].dbPath, gKeyHandleArray[key_handle].dbKey, + &gKeyHandleArray[key_handle].info, buffer, buffer_size); } } else { - size = pers_db_write_key(gKeyHandleArray[key_handle].dbPath, gKeyHandleArray[key_handle].dbKey, - &gKeyHandleArray[key_handle].info, buffer, buffer_size); + size = EPERS_MAXHANDLE; } } else { - size = EPERS_MAXHANDLE; + printf("pclKeyHandleWriteData: error - buffer_size to big, limit is [%d] bytes\n", gMaxKeyValDataSize); + DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyHandleWriteData: error - buffer_size to big, limit is [bytes]:"), DLT_INT(gMaxKeyValDataSize)); } } else { - printf("pclKeyHandleWriteData: error - buffer_size to big, limit is [%d] bytes\n", gMaxKeyValDataSize); - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyHandleWriteData: error - buffer_size to big, limit is [bytes]:"), DLT_INT(gMaxKeyValDataSize)); + size = EPERS_LOCKFS; } } - else - { - size = EPERS_LOCKFS; - } return size; } @@ -303,102 +321,59 @@ int pclKeyHandleWriteData(int key_handle, unsigned char* buffer, int buffer_size int pclKeyDelete(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no) { - int rval = 0; + int rval = EPERS_NOT_INITIALIZED; //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyDelete: "), DLT_INT(ldbid), DLT_STRING(resource_id) ); - if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked + if(gPclInitialized >= PCLinitialized) { - PersistenceInfo_s dbContext; + if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked + { + PersistenceInfo_s dbContext; - char dbKey[DbKeyMaxLen]; // database key - char dbPath[DbPathMaxLen]; // database location + char dbKey[DbKeyMaxLen]; // database key + char dbPath[DbPathMaxLen]; // database location - memset(dbKey, 0, DbKeyMaxLen); - memset(dbPath, 0, DbPathMaxLen); + memset(dbKey, 0, DbKeyMaxLen); + memset(dbPath, 0, DbPathMaxLen); - dbContext.context.ldbid = ldbid; - dbContext.context.seat_no = seat_no; - dbContext.context.user_no = user_no; + dbContext.context.ldbid = ldbid; + dbContext.context.seat_no = seat_no; + dbContext.context.user_no = user_no; - // get database context: database path and database key - rval = get_db_context(&dbContext, resource_id, ResIsNoFile, dbKey, dbPath); - if( (rval >= 0) - && (dbContext.configKey.type == PersistenceResourceType_key) ) // check if type is matching - { - if( dbContext.configKey.storage < PersistenceStorage_LastEntry - && dbContext.configKey.storage >= PersistenceStorage_local) // check if store policy is valid + // get database context: database path and database key + rval = get_db_context(&dbContext, resource_id, ResIsNoFile, dbKey, dbPath); + if( (rval >= 0) + && (dbContext.configKey.type == PersistenceResourceType_key) ) // check if type is matching { - rval = pers_db_delete_key(dbPath, dbKey, &dbContext); + 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); + } + else + { + rval = EPERS_BADPOL; + } } - else - { - rval = EPERS_BADPOL; - } - } - } - else - { - rval = EPERS_LOCKFS; - } - - return rval; -} - - - -// status: OK -int pclKeyGetSize(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no) -{ - int data_size = 0; - PersistenceInfo_s dbContext; - - char dbKey[DbKeyMaxLen]; // database key - char dbPath[DbPathMaxLen]; // database location - - memset(dbKey, 0, DbKeyMaxLen); - memset(dbPath, 0, DbPathMaxLen); - - dbContext.context.ldbid = ldbid; - dbContext.context.seat_no = seat_no; - dbContext.context.user_no = user_no; - - //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyGetSize: "), DLT_INT(ldbid), DLT_STRING(resource_id) ); - - // get database context: database path and database key - data_size = get_db_context(&dbContext, resource_id, ResIsNoFile, dbKey, dbPath); - if( (data_size >= 0) - && (dbContext.configKey.type == PersistenceResourceType_key) ) // check if type matches - { - 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); } else { - data_size = EPERS_BADPOL; + rval = EPERS_LOCKFS; } } - else - { - data_size = EPERS_BADPOL; - } - return data_size; + return rval; } // status: OK -int pclKeyReadData(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no, - unsigned char* buffer, int buffer_size) +int pclKeyGetSize(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no) { - int data_size = 0; + int data_size = EPERS_NOT_INITIALIZED; - //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyReadData: "), DLT_INT(ldbid), DLT_STRING(resource_id) ); - - if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked + if(gPclInitialized >= PCLinitialized) { PersistenceInfo_s dbContext; @@ -412,53 +387,48 @@ int pclKeyReadData(unsigned int ldbid, const char* resource_id, unsigned int use dbContext.context.seat_no = seat_no; dbContext.context.user_no = user_no; + //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyGetSize: "), DLT_INT(ldbid), DLT_STRING(resource_id) ); + // get database context: database path and database key data_size = get_db_context(&dbContext, resource_id, ResIsNoFile, dbKey, dbPath); if( (data_size >= 0) - && (dbContext.configKey.type == PersistenceResourceType_key) ) + && (dbContext.configKey.type == PersistenceResourceType_key) ) // check if type matches { - - if( dbContext.configKey.storage < PersistenceStorage_LastEntry + 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 = pers_db_get_key_size(dbPath, dbKey, &dbContext); } else { - data_size = EPERS_BADPOL; + data_size = EPERS_BADPOL; } } else { - printf("pclKeyReadData - error - no database context or resource is not a key\n"); - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyReadData - error - no database context or resource is not a key")); + data_size = EPERS_BADPOL; } } - else - { - data_size = EPERS_LOCKFS; - } return data_size; } -int pclKeyWriteData(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no, - unsigned char* buffer, int buffer_size) +// status: OK +int pclKeyReadData(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no, + unsigned char* buffer, int buffer_size) { - int data_size = 0; + int data_size = EPERS_NOT_INITIALIZED; - //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyWriteData: "), DLT_INT(ldbid), DLT_STRING(resource_id) ); + //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyReadData: "), DLT_INT(ldbid), DLT_STRING(resource_id) ); - if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked + if(gPclInitialized >= PCLinitialized) { - if(buffer_size <= gMaxKeyValDataSize) // check data size + if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked { PersistenceInfo_s dbContext; - unsigned int hash_val_data = 0; - char dbKey[DbKeyMaxLen]; // database key char dbPath[DbPathMaxLen]; // database location @@ -472,16 +442,13 @@ int pclKeyWriteData(unsigned int ldbid, const char* resource_id, unsigned int us // get database context: database path and database key data_size = get_db_context(&dbContext, resource_id, ResIsNoFile, dbKey, dbPath); if( (data_size >= 0) - && (dbContext.configKey.type == PersistenceResourceType_key)) + && (dbContext.configKey.type == PersistenceResourceType_key) ) { - // get hash value of data to verify storing - hash_val_data = crc32(hash_val_data, buffer, buffer_size); - // store data 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 = pers_db_read_key(dbPath, dbKey, &dbContext, buffer, buffer_size); } else { @@ -490,20 +457,84 @@ int pclKeyWriteData(unsigned int ldbid, const char* resource_id, unsigned int us } else { - printf("pclKeyWriteData: error - no database context or resource is not a key\n"); - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyWriteData - error - no database context or resource is not a key")); + printf("pclKeyReadData - error - no database context or resource is not a key\n"); + DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyReadData - error - no database context or resource is not a key")); } } else { - data_size = EPERS_BUFLIMIT; - printf("pclKeyWriteData: error - buffer_size to big, limit is [%d] bytes\n", gMaxKeyValDataSize); - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyWriteData: error - buffer_size to big, limit is [bytes]:"), DLT_INT(gMaxKeyValDataSize)); + data_size = EPERS_LOCKFS; } } - else + + return data_size; +} + + + +int pclKeyWriteData(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no, + unsigned char* buffer, int buffer_size) +{ + int data_size = EPERS_NOT_INITIALIZED; + + //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyWriteData: "), DLT_INT(ldbid), DLT_STRING(resource_id) ); + + if(gPclInitialized >= PCLinitialized) { - data_size = EPERS_LOCKFS; + if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked + { + if(buffer_size <= gMaxKeyValDataSize) // check data size + { + PersistenceInfo_s dbContext; + + unsigned int hash_val_data = 0; + + char dbKey[DbKeyMaxLen]; // database key + char dbPath[DbPathMaxLen]; // database location + + memset(dbKey, 0, DbKeyMaxLen); + memset(dbPath, 0, DbPathMaxLen); + + dbContext.context.ldbid = ldbid; + dbContext.context.seat_no = seat_no; + dbContext.context.user_no = user_no; + + // get database context: database path and database key + data_size = get_db_context(&dbContext, resource_id, ResIsNoFile, dbKey, dbPath); + if( (data_size >= 0) + && (dbContext.configKey.type == PersistenceResourceType_key)) + { + // get hash value of data to verify storing + hash_val_data = crc32(hash_val_data, buffer, buffer_size); + + // store data + 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); + } + else + { + data_size = EPERS_BADPOL; + } + } + else + { + printf("pclKeyWriteData: error - no database context or resource is not a key\n"); + DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyWriteData - error - no database context or resource is not a key")); + } + } + else + { + data_size = EPERS_BUFLIMIT; + printf("pclKeyWriteData: error - buffer_size to big, limit is [%d] bytes\n", gMaxKeyValDataSize); + DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyWriteData: error - buffer_size to big, limit is [bytes]:"), DLT_INT(gMaxKeyValDataSize)); + } + } + else + { + data_size = EPERS_LOCKFS; + } } return data_size; @@ -512,36 +543,40 @@ int pclKeyWriteData(unsigned int ldbid, const char* resource_id, unsigned int us int pclKeyRegisterNotifyOnChange(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no, pclChangeNotifyCallback_t callback) { - int rval = 0; - PersistenceInfo_s dbContext; + int rval = EPERS_NOT_INITIALIZED; - // unsigned int hash_val_data = 0; - char dbKey[DbKeyMaxLen]; // database key - char dbPath[DbPathMaxLen]; // database location + if(gPclInitialized >= PCLinitialized) + { + PersistenceInfo_s dbContext; - memset(dbKey, 0, DbKeyMaxLen); - memset(dbPath, 0, DbPathMaxLen); + // unsigned int hash_val_data = 0; + char dbKey[DbKeyMaxLen]; // database key + char dbPath[DbPathMaxLen]; // database location - //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyRegisterNotifyOnChange: "), DLT_INT(ldbid), DLT_STRING(resource_id) ); + memset(dbKey, 0, DbKeyMaxLen); + memset(dbPath, 0, DbPathMaxLen); - dbContext.context.ldbid = ldbid; - dbContext.context.seat_no = seat_no; - dbContext.context.user_no = user_no; + //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyRegisterNotifyOnChange: "), DLT_INT(ldbid), DLT_STRING(resource_id) ); + + dbContext.context.ldbid = ldbid; + dbContext.context.seat_no = seat_no; + dbContext.context.user_no = user_no; - // get database context: database path and database key - rval = get_db_context(&dbContext, resource_id, ResIsNoFile, dbKey, dbPath); + // get database context: database path and database key + rval = get_db_context(&dbContext, resource_id, ResIsNoFile, dbKey, dbPath); - // registration is only on shared key possible - if( (dbContext.configKey.storage == PersistenceStorage_shared) - && (dbContext.configKey.type == PersistenceResourceType_key) ) - { - rval = persistence_reg_notify_on_change(dbPath, dbKey, ldbid, user_no, seat_no, callback); - } - else - { - printf("pclKeyRegisterNotifyOnChange: error - resource is not a shared resource or resource is not a key\n"); - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyRegisterNotifyOnChange: error - resource is not a shared resource or resource is not a key")); - rval = EPERS_RES_NO_KEY; + // registration is only on shared key possible + if( (dbContext.configKey.storage == PersistenceStorage_shared) + && (dbContext.configKey.type == PersistenceResourceType_key) ) + { + rval = persistence_reg_notify_on_change(dbPath, dbKey, ldbid, user_no, seat_no, callback); + } + else + { + printf("pclKeyRegisterNotifyOnChange: error - resource is not a shared resource or resource is not a key\n"); + DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyRegisterNotifyOnChange: error - resource is not a shared resource or resource is not a key")); + rval = EPERS_RES_NO_KEY; + } } return rval; diff --git a/src/persistence_client_library_lc_interface.c b/src/persistence_client_library_lc_interface.c index 0febffd..987331e 100644 --- a/src/persistence_client_library_lc_interface.c +++ b/src/persistence_client_library_lc_interface.c @@ -225,7 +225,7 @@ int send_lifecycle_request(const char* method, int requestId, int status) if(conn != NULL) { - DBusMessage* message = dbus_message_new_method_call("org.genivi.NodeStateManager.Consumer", // destination + DBusMessage* message = dbus_message_new_method_call("org.genivi.NodeStateManager", // destination "/org/genivi/NodeStateManager/Consumer", // path "org.genivi.NodeStateManager.Consumer", // interface method); // method @@ -327,12 +327,15 @@ void process_prepare_shutdown(unsigned char requestId, unsigned int status) // unload custom client libraries - for(i=0; i<get_num_custom_client_libs(); i++) + for(i=0; i<PersCustomLib_LastEntry; i++) { - // deinitialize plugin - gPersCustomFuncs[i].custom_plugin_deinit(); - // close library handle - dlclose(gPersCustomFuncs[i].handle); + if(gPersCustomFuncs[i].custom_plugin_init != NULL) + { + // deinitialize plugin + gPersCustomFuncs[i].custom_plugin_deinit(); + // close library handle + dlclose(gPersCustomFuncs[i].handle); + } } // notify lifecycle shutdown OK diff --git a/src/persistence_client_library_pas_interface.c b/src/persistence_client_library_pas_interface.c index 31ba221..2b6f000 100644 --- a/src/persistence_client_library_pas_interface.c +++ b/src/persistence_client_library_pas_interface.c @@ -237,55 +237,64 @@ int send_pas_register(const char* method, int notificationFlag) DBusMessage *replyMsg = NULL; DBusConnection* conn = get_dbus_connection(); - const char* objName = "/org/genivi/persistence/adminconsumer"; - const char* busName = dbus_bus_get_unique_name(conn); - - DBusMessage* message = dbus_message_new_method_call("org.genivi.persistence", // destination - "/org/genivi/persistence", // path - "org.genivi.persistence.admin", // interface - method); // method - - if(message != NULL) + if(conn != NULL) { - dbus_message_append_args(message, DBUS_TYPE_STRING, &busName, // bus name - DBUS_TYPE_STRING, &objName, - DBUS_TYPE_INT32, ¬ificationFlag, - DBUS_TYPE_UINT32, &gTimeoutMs, - DBUS_TYPE_INVALID); - if(conn != NULL) + const char* objName = "/org/genivi/persistence/adminconsumer"; + const char* busName = dbus_bus_get_unique_name(conn); + + if(busName != NULL) { - replyMsg = dbus_connection_send_with_reply_and_block(conn, message, gTimeoutMs, &error); + DBusMessage* message = dbus_message_new_method_call("org.genivi.persistence", // destination + "/org/genivi/persistence", // path + "org.genivi.persistence.admin", // interface + method); // method - if(replyMsg != NULL) + if(message != NULL) { - if(dbus_set_error_from_message(&error, replyMsg)) + dbus_message_append_args(message, DBUS_TYPE_STRING, &busName, // bus name + DBUS_TYPE_STRING, &objName, + DBUS_TYPE_INT32, ¬ificationFlag, + DBUS_TYPE_UINT32, &gTimeoutMs, + DBUS_TYPE_INVALID); + + replyMsg = dbus_connection_send_with_reply_and_block(conn, message, gTimeoutMs, &error); + + if(replyMsg != NULL) { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("send_pas_register => Access denied"), DLT_STRING(error.message) ); + if(dbus_set_error_from_message(&error, replyMsg)) + { + DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("send_pas_register => Access denied"), DLT_STRING(error.message) ); + } + else + { + dbus_message_get_args(replyMsg, &error, DBUS_TYPE_INT32, &rval, DBUS_TYPE_INVALID); + } + dbus_message_unref(replyMsg); } else { - dbus_message_get_args(replyMsg, &error, DBUS_TYPE_INT32, &rval, DBUS_TYPE_INVALID); + DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("send_pas_register => reply message is NULL!"), DLT_STRING(error.message) ); } - dbus_message_unref(replyMsg); + + dbus_message_unref(message); } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("send_pas_register => reply message is NULL!"), DLT_STRING(error.message) ); + DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("send_pas_register => ERROR: Invalid message") ); + rval = -1; } } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("send_pas_register => ERROR: Invalid connection") ); + DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("send_pas_register => ERROR: Invalid busname") ); rval = -1; } - dbus_message_unref(message); } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("send_pas_register => ERROR: Invalid message") ); + DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("send_pas_register => ERROR: Invalid connection") ); rval = -1; } - return rval; } diff --git a/src/persistence_client_library_prct_access.c b/src/persistence_client_library_prct_access.c index 0aae822..10c34da 100644 --- a/src/persistence_client_library_prct_access.c +++ b/src/persistence_client_library_prct_access.c @@ -161,21 +161,29 @@ int get_db_context(PersistenceInfo_s* dbContext, const char* resource_id, unsign } else { - // if customer storage, we use the custom name as path + int len = strlen(resource_id); + + // if customer storage, we use the custom name as dbPath strncpy(dbPath, dbContext->configKey.custom_name, strlen(dbContext->configKey.custom_name)); + + if(len > DbKeyMaxLen) + { + len = DbKeyMaxLen; + } + // and the resource_id as dbKey + strncpy(dbKey, resource_id, len); + } resourceFound = 1; } else { - printf("get_db_context - resource_table: no value for key: %s \n", resource_id); DLT_LOG(gDLTContext, DLT_LOG_WARN, DLT_STRING("get_db_context => itzam_btree_open => resource_table: no value for key:"), DLT_STRING(resource_id) ); rval = EPERS_NOKEYDATA; } } // resource table else { - printf("get_db_context - error resource table\n"); DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("get_db_context =>error resource table")); rval = EPERS_NOPRCTABLE; } diff --git a/test/customLibConfigFile.cfg b/test/customLibConfigFile.cfg deleted file mode 100644 index e69de29..0000000 --- a/test/customLibConfigFile.cfg +++ /dev/null diff --git a/test/data/Data.tar.gz b/test/data/Data.tar.gz Binary files differindex 64f0d92..25beebc 100644 --- a/test/data/Data.tar.gz +++ b/test/data/Data.tar.gz diff --git a/test/persistence_client_library_dbus_test.c b/test/persistence_client_library_dbus_test.c index b619cac..bd8957c 100644 --- a/test/persistence_client_library_dbus_test.c +++ b/test/persistence_client_library_dbus_test.c @@ -43,7 +43,7 @@ int myChangeCallback(pclNotification_s * notifyStruct) int main(int argc, char *argv[]) { int ret = 0; - int shutdownReg = NSM_SHUTDOWN_TYPE_FAST | NSM_SHUTDOWN_TYPE_NORMAL; + unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; printf("Dbus interface test application\n"); @@ -62,12 +62,14 @@ int main(int argc, char *argv[]) getchar(); - pclDeinitLibrary(shutdownReg); + pclDeinitLibrary(); // unregister debug log and trace DLT_UNREGISTER_APP(); + dlt_free(); + printf("By\n"); return ret; } diff --git a/test/persistence_client_library_test.c b/test/persistence_client_library_test.c index 75b7a43..4ed33c9 100644 --- a/test/persistence_client_library_test.c +++ b/test/persistence_client_library_test.c @@ -29,9 +29,7 @@ #include <dlt/dlt.h> #include <dlt/dlt_common.h> -#include "../include/persistence_client_library_key.h" -#include "../include/persistence_client_library_file.h" -#include "../include/persistence_client_library_error_def.h" +#include "../include/persistence_client_library.h" // protected header, should be used only be persistence components @@ -59,7 +57,7 @@ char* dayOfWeek[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "F START_TEST (test_GetData) { int ret = 0; - int shutdownReg = NSM_SHUTDOWN_TYPE_FAST | NSM_SHUTDOWN_TYPE_NORMAL; + unsigned int shutdownReg = (PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL); unsigned char buffer[READ_SIZE]; @@ -71,10 +69,10 @@ START_TEST (test_GetData) * Logical DB ID: 0xFF with user 0 and seat 0 * ==> local value accessible by all users (user 0, seat 0) */ - ret = pclKeyReadData(0xFF, "language/country_code", 0, 0, buffer, READ_SIZE); - fail_unless(strncmp((char*)buffer, "Custom plugin -> plugin_get_data_handle", + ret = pclKeyReadData(0xFF, "pos/last_position", 0, 0, buffer, READ_SIZE); + fail_unless(strncmp((char*)buffer, "CACHE_ +48° 10' 38.95\", +8° 44' 39.06\"", strlen((char*)buffer)) == 0, "Buffer not correctly read"); - fail_unless(ret = strlen("Custom plugin -> plugin_get_data_handle")); + fail_unless(ret = strlen("CACHE_ +48° 10' 38.95\", +8° 44' 39.06\"")); memset(buffer, 0, READ_SIZE); @@ -82,13 +80,14 @@ START_TEST (test_GetData) * Logical DB ID: 0xFF with user 0 and seat 0 * ==> local value accessible by all users (user 0, seat 0) */ - ret = pclKeyReadData(0xFF, "pos/last_position", 0, 0, buffer, READ_SIZE); - fail_unless(strncmp((char*)buffer, "CACHE_ +48° 10' 38.95\", +8° 44' 39.06\"", + ret = pclKeyReadData(0xFF, "language/country_code", 0, 0, buffer, READ_SIZE); + fail_unless(strncmp((char*)buffer, "Custom plugin -> plugin_get_data: secure!", strlen((char*)buffer)) == 0, "Buffer not correctly read"); - fail_unless(ret = strlen("CACHE_ +48° 10' 38.95\", +8° 44' 39.06\"")); + fail_unless(ret = strlen("Custom plugin -> plugin_get_data_handle")); memset(buffer, 0, READ_SIZE); + /** * Logical DB ID: 0 with user 3 and seat 0 * ==> public shared user value (user 3, seat 0) @@ -141,7 +140,7 @@ START_TEST (test_GetData) ret = pclKeyReadData(0x84, "links/last_link", 2, 1, buffer, READ_SIZE); fail_unless(strncmp((char*)buffer, "CACHE_ /last_exit/queens", strlen((char*)buffer)) == 0, "Buffer not correctly read"); - pclDeinitLibrary(shutdownReg); + pclDeinitLibrary(); } END_TEST @@ -155,7 +154,7 @@ END_TEST START_TEST (test_GetDataHandle) { int ret = 0, handle = 0, handle2 = 0, handle3 = 0, handle4 = 0, size = 0; - int shutdownReg = NSM_SHUTDOWN_TYPE_FAST | NSM_SHUTDOWN_TYPE_NORMAL; + unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; unsigned char buffer[READ_SIZE]; struct tm *locTime; @@ -182,7 +181,7 @@ START_TEST (test_GetDataHandle) fail_unless(handle >= 0, "Failed to open handle ==> /posHandle/last_position"); ret = pclKeyHandleReadData(handle, buffer, READ_SIZE); - fail_unless(strncmp((char*)buffer, "WT_ H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\"", ret-1) == 0, "Buffer not correctly read"); + fail_unless(strncmp((char*)buffer, "WT_ H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\"", ret-1) == 0, "Buffer not correctly read => 1"); size = pclKeyHandleGetSize(handle); fail_unless(size = strlen("WT_ H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\"")); @@ -214,7 +213,7 @@ START_TEST (test_GetDataHandle) fail_unless(handle4 >= 0, "Failed to open handle /language/country_code"); ret = pclKeyHandleReadData(handle4, buffer, READ_SIZE); - fail_unless(strncmp((char*)buffer, "Custom plugin -> plugin_get_data_handle", -1) == 0, "Buffer not correctly read"); + fail_unless(strncmp((char*)buffer, "Custom plugin -> plugin_get_data_handle: secure!", -1) == 0, "Buffer not correctly read => 2"); size = pclKeyHandleGetSize(handle4); fail_unless(size = strlen("Custom plugin -> plugin_get_data_handle")); @@ -232,7 +231,7 @@ START_TEST (test_GetDataHandle) fail_unless(handle3 >= 0, "Failed to open handle /statusHandle/open_document"); ret = pclKeyHandleReadData(handle3, buffer, READ_SIZE); - fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read"); + fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read => 3"); size = pclKeyHandleGetSize(handle3); fail_unless(size = strlen(sysTimeBuffer)); @@ -244,7 +243,7 @@ START_TEST (test_GetDataHandle) ret = pclKeyHandleClose(handle3); ret = pclKeyHandleClose(handle4); - pclDeinitLibrary(shutdownReg); + pclDeinitLibrary(); } END_TEST @@ -258,7 +257,7 @@ END_TEST START_TEST(test_SetData) { int ret = 0; - int shutdownReg = NSM_SHUTDOWN_TYPE_FAST | NSM_SHUTDOWN_TYPE_NORMAL; + unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; unsigned char buffer[READ_SIZE]; char write1[READ_SIZE]; char write2[READ_SIZE]; @@ -315,7 +314,7 @@ START_TEST(test_SetData) * * ==> used for shared testing */ - printf("Write data to trigger change notification\n"); + //printf("Write data to trigger change notification\n"); ret = pclKeyWriteData(0x84, "links/last_link2", 2, 1, (unsigned char*)"Test notify shared data", strlen("Test notify shared data")); /** @@ -324,7 +323,7 @@ START_TEST(test_SetData) * * ==> used for shared testing */ - printf("Write data to trigger change notification\n"); + //printf("Write data to trigger change notification\n"); ret = pclKeyWriteData(0x84, "links/last_link3", 3, 2, (unsigned char*)"Test notify shared data", strlen("Test notify shared data")); /** @@ -333,7 +332,7 @@ START_TEST(test_SetData) * * ==> used for shared testing */ - printf("Write data to trigger change notification\n"); + //printf("Write data to trigger change notification\n"); ret = pclKeyWriteData(0x84, "links/last_link4", 4, 1, (unsigned char*)"Test notify shared data", strlen("Test notify shared data")); /*******************************************************************************************************************************************/ /*******************************************************************************************************************************************/ @@ -361,7 +360,7 @@ START_TEST(test_SetData) fail_unless(strncmp((char*)buffer, write2, strlen(write2)) == 0, "Buffer not correctly read"); fail_unless(ret == strlen(write2), "Wrong read size"); - pclDeinitLibrary(shutdownReg); + pclDeinitLibrary(); } END_TEST @@ -375,7 +374,7 @@ END_TEST START_TEST(test_SetDataNoPRCT) { int ret = 0; - int shutdownReg = NSM_SHUTDOWN_TYPE_FAST | NSM_SHUTDOWN_TYPE_NORMAL; + unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; unsigned char buffer[READ_SIZE]; struct tm *locTime; @@ -396,7 +395,7 @@ START_TEST(test_SetDataNoPRCT) */ ret = pclKeyWriteData(0xFF, "NoPRCT", 1, 2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer)); fail_unless(ret == strlen(sysTimeBuffer), "Wrong write size"); - printf("Write Buffer : %s\n", sysTimeBuffer); + //printf("Write Buffer : %s\n", sysTimeBuffer); // read data again and and verify datat has been written correctly memset(buffer, 0, READ_SIZE); @@ -404,9 +403,9 @@ START_TEST(test_SetDataNoPRCT) ret = pclKeyReadData(0xFF, "NoPRCT", 1, 2, buffer, READ_SIZE); fail_unless(strncmp((char*)buffer, sysTimeBuffer, strlen(sysTimeBuffer)) == 0, "Buffer not correctly read"); fail_unless(ret == strlen(sysTimeBuffer), "Wrong read size"); - printf("read buffer : %s\n", buffer); + //printf("read buffer : %s\n", buffer); - pclDeinitLibrary(shutdownReg); + pclDeinitLibrary(); } END_TEST @@ -420,7 +419,7 @@ START_TEST(test_GetDataSize) { int size = 0; - int shutdownReg = NSM_SHUTDOWN_TYPE_FAST | NSM_SHUTDOWN_TYPE_NORMAL; + unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; pclInitLibrary(gTheAppId, shutdownReg); @@ -439,7 +438,7 @@ START_TEST(test_GetDataSize) size = pclKeyGetSize(0x84, "links/last_link", 2, 1); fail_unless(size == strlen("CACHE_ /last_exit/queens"), "Invalid size"); - pclDeinitLibrary(shutdownReg); + pclDeinitLibrary(); } END_TEST @@ -453,7 +452,7 @@ START_TEST(test_DeleteData) { int rval = 0; unsigned char buffer[READ_SIZE]; - int shutdownReg = NSM_SHUTDOWN_TYPE_FAST | NSM_SHUTDOWN_TYPE_NORMAL; + unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; pclInitLibrary(gTheAppId, shutdownReg); @@ -483,7 +482,7 @@ START_TEST(test_DeleteData) rval = pclKeyReadData(0xFF, "70", 1, 2, buffer, READ_SIZE); fail_unless(rval == EPERS_NOKEY, "Read form key 70 works, but should fail"); - pclDeinitLibrary(shutdownReg); + pclDeinitLibrary(); } END_TEST @@ -502,7 +501,7 @@ START_TEST(test_DataFile) int fd = 0, i = 0, idx = 0; int size = 0, ret = 0; int writeSize = 16*1024; - int shutdownReg = NSM_SHUTDOWN_TYPE_FAST | NSM_SHUTDOWN_TYPE_NORMAL; + unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; unsigned char buffer[READ_SIZE]; const char* refBuffer = "/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media"; @@ -544,10 +543,10 @@ START_TEST(test_DataFile) fail_unless(strncmp((char*)buffer, refBuffer, strlen(refBuffer)) == 0, "Buffer not correctly read => media/mediaDB.db"); fail_unless(size == (strlen(refBuffer)+1), "Wrong size returned"); // strlen + 1 ==> inlcude cr/lf + ret = pclFileClose(fd); fail_unless(ret == 0, "Failed to close file"); - // open ------------------------------------------------------------ fd = pclFileOpen(0xFF, "media/mediaDBWrite.db", 1, 1); fail_unless(fd != -1, "Could not open file ==> /media/mediaDBWrite.db"); @@ -587,19 +586,20 @@ START_TEST(test_DataFile) free(writeBuffer); - pclDeinitLibrary(shutdownReg); + pclDeinitLibrary(); } END_TEST + START_TEST(test_DataFileRecovery) { int fd_RW = 0, fd_RO = 0; int ret = 0; char* wBuffer = "This is a buffer to write"; - int shutdownReg = NSM_SHUTDOWN_TYPE_FAST | NSM_SHUTDOWN_TYPE_NORMAL; + unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; pclInitLibrary(gTheAppId, shutdownReg); @@ -614,7 +614,7 @@ START_TEST(test_DataFileRecovery) ret = pclFileClose(fd_RW); ret = pclFileClose(fd_RO); - pclDeinitLibrary(shutdownReg); + pclDeinitLibrary(); } END_TEST @@ -625,7 +625,7 @@ START_TEST(test_DataHandle) { int handle1 = 0, handle2 = 0; int ret = 0; - int shutdownReg = NSM_SHUTDOWN_TYPE_FAST | NSM_SHUTDOWN_TYPE_NORMAL; + unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; pclInitLibrary(gTheAppId, shutdownReg); @@ -654,7 +654,7 @@ START_TEST(test_DataHandle) ret = pclKeyHandleClose(1024); fail_unless(ret == -1, "Could close, but should not!!"); - pclDeinitLibrary(shutdownReg); + pclDeinitLibrary(); } END_TEST @@ -667,7 +667,7 @@ END_TEST START_TEST(test_DataHandleOpen) { int hd1 = -2, hd2 = -2, hd3 = -2, hd4 = -2, hd5 = -2, hd6 = -2, hd7 = -2, hd8 = -2, hd9 = -2, ret = 0; - int shutdownReg = NSM_SHUTDOWN_TYPE_FAST | NSM_SHUTDOWN_TYPE_NORMAL; + unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; pclInitLibrary(gTheAppId, shutdownReg); @@ -729,7 +729,7 @@ START_TEST(test_DataHandleOpen) ret = pclKeyHandleClose(hd9); fail_unless(ret != -1, "Failed to close handle!!"); - pclDeinitLibrary(shutdownReg); + pclDeinitLibrary(); } END_TEST @@ -746,7 +746,7 @@ START_TEST(test_Cursor) char bufferDataSrc[READ_SIZE]; char bufferKeyDst[READ_SIZE]; char bufferDataDst[READ_SIZE]; - int shutdownReg = NSM_SHUTDOWN_TYPE_FAST | NSM_SHUTDOWN_TYPE_NORMAL; + unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; pclInitLibrary(gTheAppId, shutdownReg); @@ -758,12 +758,10 @@ START_TEST(test_Cursor) // create cursor handle = pers_db_cursor_create("/Data/mnt-c/lt-persistence_client_library_test/cached.itz"); - fail_unless(handle != -1, "Failed to create cursor!!"); // create cursor - handle1 = pers_db_cursor_create("/Data/mnt-c/lt-persistence_client_library_test/wt.itz"); - + handle1 = pers_db_cursor_create("/Data/mnt-wt/lt-persistence_client_library_test/wt.itz"); fail_unless(handle1 != -1, "Failed to create cursor!!"); do @@ -804,7 +802,47 @@ START_TEST(test_Cursor) rval = pers_db_cursor_destroy(handle1); fail_unless(rval != -1, "Failed to destroy cursor!!"); - pclDeinitLibrary(shutdownReg); + pclDeinitLibrary(); +} +END_TEST + + + +START_TEST(test_Plugin) +{ + int ret = 0; + char buffer[READ_SIZE]; + + unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; + pclInitLibrary(gTheAppId, shutdownReg); + + ret = pclKeyReadData(0xFF, "language/country_code", 0, 0, buffer, READ_SIZE); + //printf("B U F F E R - secure: %s\n", buffer); + fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: secure!", + strlen((char*)buffer)) == 0, "Buffer SECURE not correctly read"); + + + ret = pclKeyReadData(0xFF, "language/country_code_early", 0, 0, buffer, READ_SIZE); + //printf("B U F F E R - early: %s\n", buffer); + fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: early!", + strlen((char*)buffer)) == 0, "Buffer EARLY not correctly read"); + + ret = pclKeyReadData(0xFF, "language/country_code_emergency", 0, 0, buffer, READ_SIZE); + //printf("B U F F E R - emergency: %s\n", buffer); + fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: emergency!", + strlen((char*)buffer)) == 0, "Buffer EMERGENCY not correctly read"); + + ret = pclKeyReadData(0xFF, "language/info", 0, 0, buffer, READ_SIZE); + //printf("B U F F E R - hwinfo: %s\n", buffer); + fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: hwinfo!", + strlen((char*)buffer)) == 0, "Buffer HWINFO not correctly read"); + + ret = pclKeyReadData(0xFF, "language/country_code_custom3", 0, 0, buffer, READ_SIZE); + //printf("B U F F E R - hwinfo: %s\n", buffer); + fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: custom3!", + strlen((char*)buffer)) == 0, "Buffer CUSTOM 3 not correctly read"); + + pclDeinitLibrary(); } END_TEST @@ -847,6 +885,9 @@ static Suite * persistencyClientLib_suite() 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); + suite_add_tcase(s, tc_persGetData); suite_add_tcase(s, tc_persSetData); suite_add_tcase(s, tc_persSetDataNoPRCT); @@ -859,12 +900,12 @@ static Suite * persistencyClientLib_suite() suite_add_tcase(s, tc_persDataFileRecovery); suite_add_tcase(s, tc_Cursor); + suite_add_tcase(s, tc_Plugin); // activate only if the plugins are available + return s; } - - int main(int argc, char *argv[]) { int nr_failed = 0; @@ -873,21 +914,25 @@ int main(int argc, char *argv[]) strncpy(gTheAppId, "lt-persistence_client_library_test", MaxAppNameLen); gTheAppId[MaxAppNameLen-1] = '\0'; - printf("A p p l i c a t i o n n a m e => %s \n", gTheAppId /*program_invocation_short_name*/); - /// debug log and trace (DLT) setup DLT_REGISTER_APP("test","tests the persistence client library"); +#if 1 Suite * s = persistencyClientLib_suite(); SRunner * sr = srunner_create(s); srunner_run_all(sr, CK_VERBOSE); nr_failed = srunner_ntests_failed(sr); srunner_free(sr); +#else + +#endif // unregister debug log and trace DLT_UNREGISTER_APP(); + dlt_free(); + return (0==nr_failed)?EXIT_SUCCESS:EXIT_FAILURE; } |