diff options
author | Ingo Huerner <ingo.huerner@xse.de> | 2014-05-09 05:19:48 +0200 |
---|---|---|
committer | Ingo Huerner <ingo.huerner@xse.de> | 2014-05-09 05:19:48 +0200 |
commit | b5c52f74865d8e95db66a36fae4acb23ed22f16f (patch) | |
tree | 762f0ab543e280f68c982c7791db2029cabaff29 | |
parent | 5d04ae9d019b1072612e935eb13e198834a23b0f (diff) | |
download | persistence-client-library-b5c52f74865d8e95db66a36fae4acb23ed22f16f.tar.gz |
Code cleanup and optimisation
-rw-r--r-- | include/persistence_client_library.h | 2 | ||||
-rw-r--r-- | include/persistence_client_library_error_def.h | 2 | ||||
-rw-r--r-- | include/persistence_client_library_key.h | 16 | ||||
-rw-r--r-- | src/persistence_client_library.c | 31 | ||||
-rw-r--r-- | src/persistence_client_library_custom_loader.h | 4 | ||||
-rw-r--r-- | src/persistence_client_library_data_organization.c | 29 | ||||
-rw-r--r-- | src/persistence_client_library_data_organization.h | 16 | ||||
-rw-r--r-- | src/persistence_client_library_db_access.c | 74 | ||||
-rw-r--r-- | src/persistence_client_library_db_access.h | 5 | ||||
-rw-r--r-- | src/persistence_client_library_dbus_cmd.c | 9 | ||||
-rw-r--r-- | src/persistence_client_library_dbus_cmd.h | 35 | ||||
-rw-r--r-- | src/persistence_client_library_file.c | 89 | ||||
-rw-r--r-- | src/persistence_client_library_handle.h | 8 | ||||
-rw-r--r-- | src/persistence_client_library_key.c | 253 | ||||
-rw-r--r-- | src/persistence_client_library_prct_access.c | 14 |
15 files changed, 254 insertions, 333 deletions
diff --git a/include/persistence_client_library.h b/include/persistence_client_library.h index 1e6b085..9328712 100644 --- a/include/persistence_client_library.h +++ b/include/persistence_client_library.h @@ -24,7 +24,7 @@ * */ /** \ingroup GEN_PERS */ -/** \defgroup PERS_CLIENT Client: initialization access +/** \defgroup PERS_CLIENT Client: initialisation access * \{ */ /** \defgroup PERS_CLIENT_INTERFACE API document diff --git a/include/persistence_client_library_error_def.h b/include/persistence_client_library_error_def.h index e88efa5..f8e184b 100644 --- a/include/persistence_client_library_error_def.h +++ b/include/persistence_client_library_error_def.h @@ -116,6 +116,8 @@ extern "C" { #define EPERS_SHUTDOWN_MAX_CANCEL (-40) /// not permitted to use this function #define EPERS_SHUTDOWN_NO_PERMIT (-42) +/// requested handle is not valid. \since PCL v7.0.3 +#define EPERS_INVALID_HANDLE (-1000) #ifdef __cplusplus } diff --git a/include/persistence_client_library_key.h b/include/persistence_client_library_key.h index 46d0e8c..4111fe3 100644 --- a/include/persistence_client_library_key.h +++ b/include/persistence_client_library_key.h @@ -78,7 +78,7 @@ typedef struct _pclNotification_s /** definition of the change callback * - * @param notifyStruct structure for notifcation + * @param notifyStruct structure for notification * * @return positive value (0 or greater): success; * On error a negative value will be returned with the following error codes: ::EPERS_LOCKFS @@ -95,7 +95,7 @@ typedef int(* pclChangeNotifyCallback_t)(pclNotification_s * notifyStruct); * * @param ldbid logical database ID * @param resource_id the resource ID - * @param user_no the user ID; user_no=0 can not be used as user-ID beacause ‘0’ is defined as System/node + * @param user_no the user ID; user_no=0 can not be used as user-ID because ‘0’ is defined as System/node * @param seat_no the seat number * * @return positive value (0 or greater) : success; @@ -111,7 +111,7 @@ int pclKeyDelete(unsigned int ldbid, const char* resource_id, unsigned int user_ * * @param ldbid logical database ID * @param resource_id the resource ID - * @param user_no the user ID; user_no=0 can not be used as user-ID beacause ‘0’ is defined as System/node + * @param user_no the user ID; user_no=0 can not be used as user-ID because ‘0’ is defined as System/node * @param seat_no the seat number * * @return positive value (0 or greater): the size; @@ -153,7 +153,7 @@ int pclKeyHandleGetSize(int key_handle); * * @param ldbid logical database ID * @param resource_id the resource ID - * @param user_no the user ID; user_no=0 can not be used as user-ID beacause ‘0’ is defined as System/node + * @param user_no the user ID; user_no=0 can not be used as user-ID because ‘0’ is defined as System/node * @param seat_no the seat number * * @return positive value (0 or greater): the key handle to access the value; @@ -229,7 +229,7 @@ int pclKeyHandleWriteData(int key_handle, unsigned char* buffer, int buffer_size * * @param ldbid logical database ID * @param resource_id the resource ID - * @param user_no the user ID; user_no=0 can not be used as user-ID beacause ‘0’ is defined as System/node + * @param user_no the user ID; user_no=0 can not be used as user-ID because ‘0’ is defined as System/node * @param seat_no the seat number * @param buffer the buffer to read the persistent data * @param buffer_size size of buffer for reading @@ -247,7 +247,7 @@ int pclKeyReadData(unsigned int ldbid, const char* resource_id, unsigned int use * * @param ldbid logical database ID of the resource to monitor * @param resource_id the resource ID - * @param user_no the user ID; user_no=0 can not be used as user-ID beacause ‘0’ is defined as System/node + * @param user_no the user ID; user_no=0 can not be used as user-ID because ‘0’ is defined as System/node * @param seat_no the seat number * @param callback notification callback * @@ -264,7 +264,7 @@ int pclKeyRegisterNotifyOnChange(unsigned int ldbid, const char* resource_id, un * * @param ldbid logical database ID of the resource to monitor * @param resource_id the resource ID - * @param user_no the user ID; user_no=0 can not be used as user-ID beacause ‘0’ is defined as System/node + * @param user_no the user ID; user_no=0 can not be used as user-ID because ‘0’ is defined as System/node * @param seat_no the seat number * @param callback notification callback * @@ -281,7 +281,7 @@ int pclKeyUnRegisterNotifyOnChange( unsigned int ldbid, const char * resource_ * * @param ldbid logical database ID * @param resource_id the resource ID - * @param user_no the user ID; user_no=0 can not be used as user-ID beacause ‘0’ is defined as System/node + * @param user_no the user ID; user_no=0 can not be used as user-ID because ‘0’ is defined as System/node * @param seat_no the seat number * @param buffer the buffer containing the persistent data to write * @param buffer_size the number of bytes to write (default max size is set to 16kB) diff --git a/src/persistence_client_library.c b/src/persistence_client_library.c index c439976..e9387cd 100644 --- a/src/persistence_client_library.c +++ b/src/persistence_client_library.c @@ -55,8 +55,8 @@ int pclInitLibrary(const char* appName, int shutdownMode) gShutdownMode = shutdownMode; DLT_REGISTER_CONTEXT(gPclDLTContext,"PCL","Context for persistence client library logging"); - DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclInitLibrary => I N I T Persistence Client Library - "), DLT_STRING(gAppId), - DLT_STRING("- init counter: "), DLT_INT(gPclInitialized) ); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclInitLibrary => I N I T Persistence Client Library - "), DLT_STRING(appName), + DLT_STRING("- init counter: "), DLT_INT(gPclInitialized) ); /// environment variable for on demand loading of custom libraries const char *pOnDemandLoad = getenv("PERS_CUSTOM_LIB_LOAD_ON_DEMAND"); @@ -70,14 +70,6 @@ int pclInitLibrary(const char* appName, int shutdownMode) pfcInitCache(appName); #endif - -#if USE_PASINTERFACE == 1 - DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("PAS interface is enabled!!")); -#else - DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("PAS interface is not enabled, enable with \"./configure --enable-pasinterface\"")); -#endif - - pthread_mutex_lock(&gDbusPendingRegMtx); // block until pending received if(pDataSize != NULL) @@ -105,7 +97,7 @@ int pclInitLibrary(const char* appName, int shutdownMode) if(gShutdownMode != PCL_SHUTDOWN_TYPE_NONE) { - // register for lifecycle and persistence admin service dbus messages + // register for lifecycle dbus messages if(register_lifecycle(shutdownMode) == -1) { DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclInitLibrary => Failed to register to lifecycle dbus interface")); @@ -114,12 +106,19 @@ int pclInitLibrary(const char* appName, int shutdownMode) } } #if USE_PASINTERFACE == 1 + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("PAS interface is enabled!!")); if(register_pers_admin_service() == -1) { DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclInitLibrary => Failed to register to pers admin dbus interface")); pthread_mutex_unlock(&gDbusPendingRegMtx); return EPERS_REGISTER_ADMIN; } + else + { + DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclInitLibrary => Successfully established IPC protocol for PCL.")); + } +#else + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("PAS interface is not enabled, enable with \"./configure --enable-pasinterface\"")); #endif /// get custom library names to load @@ -202,12 +201,20 @@ int pclDeinitLibrary(void) DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclDeinitLibrary -> D E I N I T client library - "), DLT_STRING(gAppId), DLT_STRING("- init counter: "), DLT_INT(gPclInitialized)); - // unregister for lifecycle and persistence admin service dbus messages + // unregister for lifecycle dbus messages if(gShutdownMode != PCL_SHUTDOWN_TYPE_NONE) rval = unregister_lifecycle(gShutdownMode); #if USE_PASINTERFACE == 1 rval = unregister_pers_admin_service(); + if(0 != rval) + { + DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclDeinitLibrary => Failed to de-initialize IPC protocol for PCL.")); + } + else + { + DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclDeinitLibrary => Successfully de-initialized IPC protocol for PCL.")); + } #endif // unload custom client libraries diff --git a/src/persistence_client_library_custom_loader.h b/src/persistence_client_library_custom_loader.h index 0d2a2ed..82ccadc 100644 --- a/src/persistence_client_library_custom_loader.h +++ b/src/persistence_client_library_custom_loader.h @@ -167,7 +167,7 @@ int load_all_custom_libraries(); * * @return the array position or -1 if the position can't be found */ -inline int check_valid_idx(int idx); +int check_valid_idx(int idx); @@ -176,7 +176,7 @@ inline int check_valid_idx(int idx); * * @return the name of the custom library ot NULL if invalid */ -inline char* get_custom_client_lib_name(int idx); +char* get_custom_client_lib_name(int idx); /** diff --git a/src/persistence_client_library_data_organization.c b/src/persistence_client_library_data_organization.c index 683a7d2..24bf993 100644 --- a/src/persistence_client_library_data_organization.c +++ b/src/persistence_client_library_data_organization.c @@ -22,42 +22,37 @@ #include <stdio.h> #include <stdlib.h> -// rrsource configuration database name -const char* gResTableCfg = "/resource-table-cfg.itz"; - /// configurable default database name const char* gConfigDefault = "/configurable-default-data.itz"; - /// default database name const char* gDefault = "/default-data.itz"; - /// write through database name const char* gWt = "/wt.itz"; /// cached database name const char* gCached = "/cached.itz"; - -/// directory structure node name definition -const char* gNode = "/node"; -/// directory structure user name definition -const char* gUser = "/user/"; -/// directory structure seat name definition -const char* gSeat = "/seat/"; -/// default data folder name definition const char* gDefDataFolder = "/defaultData/"; + +// define PERS_ORG_ROOT_PATH comes form persistence common object + /// cached path location -#define CACHEPREFIX "/Data/mnt-c/" +#define CACHEPREFIX PERS_ORG_ROOT_PATH "/mnt-c/" /// write through path location -#define WTPREFIX "/Data/mnt-wt/" +#define WTPREFIX PERS_ORG_ROOT_PATH "/mnt-wt/" +/// path for the backup location +const char* gBackupPrefix = PERS_ORG_ROOT_PATH "/mnt-backup/"; /// size of cached path string const int gCPathPrefixSize = sizeof(CACHEPREFIX)-1; /// size of write through string const int gWTPathPrefixSize = sizeof(WTPREFIX)-1; -/// path for the backup location -const char* gBackupPrefix = "/Data/mnt-backup/"; + +/// backup filename postfix +const char* gBackupPostfix = "~"; +/// backup checksum filename postfix +const char* gBackupCsPostfix = "~.crc"; /// path prefix for local cached database: /Data/mnt_c/<appId>/ (<database_name> const char* gLocalCachePath = CACHEPREFIX "%s"; diff --git a/src/persistence_client_library_data_organization.h b/src/persistence_client_library_data_organization.h index 64aee36..48e8ced 100644 --- a/src/persistence_client_library_data_organization.h +++ b/src/persistence_client_library_data_organization.h @@ -147,10 +147,6 @@ enum _PersistenceConstantDef defaultMaxKeyValDataSize = PERS_DB_MAX_SIZE_KEY_DATA /// default limit the key-value data size to 16kB }; - -/// resource configuration table name -extern const char* gResTableCfg; - /// configurable default database name extern const char* gConfigDefault; @@ -164,19 +160,15 @@ extern const char* gCached; /// write through database name extern const char* gWt; - -/// directory structure node name definition -extern const char* gNode; -/// directory structure user name definition -extern const char* gUser; -/// directory structure seat name definition -extern const char* gSeat; - /// default data folder name definition extern const char* gDefDataFolder; /// path for the backup location extern const char* gBackupPrefix; +/// backup filename postfix +extern const char* gBackupPostfix; +/// backup checksum filename postfix +extern const char* gBackupCsPostfix; /// size of cached prefix string extern const int gCPathPrefixSize; diff --git a/src/persistence_client_library_db_access.c b/src/persistence_client_library_db_access.c index a792ba5..e4d634c 100644 --- a/src/persistence_client_library_db_access.c +++ b/src/persistence_client_library_db_access.c @@ -101,6 +101,7 @@ int pers_get_defaults(char* dbPath, char* key, unsigned char* buffer, unsigned i PersDefaultType_e i = PersDefaultType_Configurable; int handleDefaultDB = -1; int read_size = EPERS_NOKEY; + char dltMessage[DbPathMaxLen] = {0}; key = pers_get_raw_key(key); /* We need only the raw key without a prefixed '/node/' or '/user/1/seat/0' etc... */ @@ -130,42 +131,39 @@ int pers_get_defaults(char* dbPath, char* key, unsigned char* buffer, unsigned i if(read_size < 0) // check read_size { - if (PersDefaultType_Configurable == i) - { - DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("Key '"), - DLT_STRING(key), - DLT_STRING("' not found in "), - DLT_STRING(dbPath), - DLT_STRING(gLocalConfigurableDefault)); - } - else if (PersDefaultType_Factory == i) - { - DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("Key '"), - DLT_STRING(key), - DLT_STRING("' not found in "), - DLT_STRING(dbPath), - DLT_STRING(gLocalFactoryDefault)); - } - else - { - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_get_defaults ==> unknown PersDefaultType: "), - DLT_INT(i)); - } - if(PERS_COM_ERR_NOT_FOUND == read_size) { read_size = EPERS_NOKEY; } } - else + else /* read_size >= 0 --> default value found */ { + if (PersDefaultType_Configurable == i) + { + snprintf(dltMessage, DbPathMaxLen, "%s%s", dbPath, gLocalConfigurableDefault); + } + if (PersDefaultType_Factory == i) + { + snprintf(dltMessage, DbPathMaxLen, "%s%s", dbPath, gLocalFactoryDefault); + } + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("Default data will be used for Key"), + DLT_STRING(key), + DLT_STRING("from"), + DLT_STRING(dltMessage)); break; } } } - return read_size; + if (read_size < 0) + { + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("Default data not available for Key"), + DLT_STRING(key), + DLT_STRING("Path:"), + DLT_STRING(dbPath)); + } + return read_size; } @@ -334,13 +332,12 @@ int persistence_get_data(char* dbPath, char* key, PersistenceInfo_s* info, unsig read_size = EPERS_NOPLUGINFUNCT; } - if (1 > read_size) + if (1 > read_size) /* Try to get default values */ { info->configKey.policy = PersistencePolicy_wc; /* Set the policy */ info->configKey.type = PersistenceResourceType_key; /* Set the type */ (void)get_db_path_and_key(info, key, NULL, dbPath); - DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("Custom Key not available. Try to get default keys from:"), - DLT_STRING(dbPath), + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("Plugin data not available. Try to get default data of key:"), DLT_STRING(key)); ret_defaults = pers_get_defaults(dbPath, key, buffer, buffer_size, PersGetDefault_Data); if (0 < ret_defaults) @@ -372,14 +369,16 @@ int persistence_set_data(char* dbPath, char* key, PersistenceInfo_s* info, unsig { DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("persistence_set_data ==> persComDbWriteKey() failure")); } - - if(PersistenceStorage_shared == info->configKey.storage) + else { - int rval = pers_send_Notification_Signal(key, &info->context, pclNotifyStatus_changed); - if(rval <= 0) + if(PersistenceStorage_shared == info->configKey.storage) { - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("persistence_set_data ==> failed to send notification signal")); - write_size = rval; + int rval = pers_send_Notification_Signal(key, &info->context, pclNotifyStatus_changed); + if(rval <= 0) + { + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("persistence_set_data ==> failed to send notification signal")); + write_size = rval; + } } } @@ -406,7 +405,7 @@ int persistence_set_data(char* dbPath, char* key, PersistenceInfo_s* info, unsig } write_size = gPersCustomFuncs[idx].custom_plugin_set_data(pathKeyString, (char*)buffer, buffer_size); - if (write_size == buffer_size) /* Check return value and send notification if OK */ + if ((0 < write_size) && ((unsigned int)write_size == buffer_size)) /* Check return value and send notification if OK */ { int rval = pers_send_Notification_Signal(key, &info->context, pclNotifyStatus_changed); if(rval <= 0) @@ -470,8 +469,7 @@ int persistence_get_data_size(char* dbPath, char* key, PersistenceInfo_s* info) info->configKey.policy = PersistencePolicy_wc; /* Set the policy */ info->configKey.type = PersistenceResourceType_key; /* Set the type */ (void)get_db_path_and_key(info, key, NULL, dbPath); - DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("Custom Key not available. Try to get default keys from:"), - DLT_STRING(dbPath), + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("Plugin data not available. Try to get size of default data for key:"), DLT_STRING(key)); ret_defaults = pers_get_defaults(dbPath, key, NULL, 0, PersGetDefault_Size); if (0 < ret_defaults) @@ -622,12 +620,12 @@ void pers_rct_close_all() { int i = 0; - // close open persistence resource configuration table + // close all open persistence resource configuration tables for(i=0; i< PrctDbTableSize; i++) { if(gResource_table[i] != -1) { - if(persComRctClose(i) == -1) + if(persComRctClose(i) != 0) { DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("process_prepare_shutdown => failed to close db => index:"), DLT_INT(i)); } diff --git a/src/persistence_client_library_db_access.h b/src/persistence_client_library_db_access.h index 2cb7076..e7185d0 100644 --- a/src/persistence_client_library_db_access.h +++ b/src/persistence_client_library_db_access.h @@ -180,7 +180,10 @@ int persistence_notify_on_change(char* key, unsigned int ldbid, unsigned int use */ int pers_send_Notification_Signal(const char* key, PersistenceDbContext_s* context, pclNotifyStatus_e reason); - +/** + * @brief close all open persistence resource configuration tables + * + */ void pers_rct_close_all(); #ifdef __cplusplus diff --git a/src/persistence_client_library_dbus_cmd.c b/src/persistence_client_library_dbus_cmd.c index 45b7a8f..296f8d9 100644 --- a/src/persistence_client_library_dbus_cmd.c +++ b/src/persistence_client_library_dbus_cmd.c @@ -16,18 +16,17 @@ * @see */ +#include <errno.h> +#include <dlfcn.h> /* For dlclose() */ #include "persistence_client_library_dbus_cmd.h" #include "persistence_client_library_handle.h" #include "persistence_client_library_custom_loader.h" +#include "persistence_client_library_prct_access.h" #include "persistence_client_library_pas_interface.h" - #include "persistence_client_library_data_organization.h" #include "persistence_client_library_db_access.h" -#include <dlfcn.h> -#include <errno.h> - // function prototype void msg_pending_func(DBusPendingCall *call, void *data); @@ -60,12 +59,14 @@ void process_reg_notification_signal(DBusConnection* conn) dbus_bus_add_match(conn, ruleChanged, NULL); dbus_bus_add_match(conn, ruleDeleted, NULL); dbus_bus_add_match(conn, ruleCreated, NULL); + DLT_LOG(gPclDLTContext, DLT_LOG_VERBOSE, DLT_STRING("Registered for change notifications:"), DLT_STRING(ruleChanged)); } else if(gNotifyPolicy == Notify_unregister) { dbus_bus_remove_match(conn, ruleChanged, NULL); dbus_bus_remove_match(conn, ruleDeleted, NULL); dbus_bus_remove_match(conn, ruleCreated, NULL); + DLT_LOG(gPclDLTContext, DLT_LOG_VERBOSE, DLT_STRING("Unregistered for change notifications:"), DLT_STRING(ruleChanged)); } dbus_connection_flush(conn); // flush the connection to add the match diff --git a/src/persistence_client_library_dbus_cmd.h b/src/persistence_client_library_dbus_cmd.h index 99d2be6..ca7f978 100644 --- a/src/persistence_client_library_dbus_cmd.h +++ b/src/persistence_client_library_dbus_cmd.h @@ -25,17 +25,10 @@ /** * @brief process a shutdown message (close all open files, open databases, ... - */ -void process_prepare_shutdown(int complete); - - -/** - * @brief block persistence access and write data back to device * - * @param requestId the requestID - * @param status the status + * @param complete The mode: Shutdown_Partial=0; Shutdown_Full=1 */ -void process_block_and_write_data_back(unsigned int requestID, unsigned int status); +void process_prepare_shutdown(int complete); /** @@ -54,6 +47,22 @@ void process_send_notification_signal(DBusConnection* conn); void process_reg_notification_signal(DBusConnection* conn); +void process_send_lifecycle_request(DBusConnection* conn, int requestId, int status); + + +void process_send_lifecycle_register(DBusConnection* conn, int regType, int shutdownMode); + + + +/** + * @brief block persistence access and write data back to device + * + * @param requestId the requestID + * @param status the status + */ +void process_block_and_write_data_back(unsigned int requestID, unsigned int status); + + /** * @brief process a request of the persistence admin service @@ -64,6 +73,7 @@ void process_reg_notification_signal(DBusConnection* conn); void process_send_pas_request(DBusConnection* conn, unsigned int requestID, int status); + /** * @brief process a request of the persistence admin service * @@ -74,11 +84,4 @@ void process_send_pas_register(DBusConnection* conn, int regType, int notificati -void process_send_lifecycle_request(DBusConnection* conn, int requestId, int status); - - -void process_send_lifecycle_register(DBusConnection* conn, int regType, int shutdownMode); - - - #endif /* PERSISTENCE_CLIENT_LIBRARY_DBUS_CMD_H_ */ diff --git a/src/persistence_client_library_file.c b/src/persistence_client_library_file.c index d1ab60b..ed0b46d 100644 --- a/src/persistence_client_library_file.c +++ b/src/persistence_client_library_file.c @@ -178,8 +178,8 @@ int pclFileOpen(unsigned int ldbid, const char* resource_id, unsigned int user_n } strncpy(fileSubPath, dbPath+length, DbPathMaxLen); - snprintf(backupPath, DbPathMaxLen-1, "%s%s", gBackupPrefix, fileSubPath); - snprintf(csumPath, DbPathMaxLen-1, "%s%s%s", gBackupPrefix, fileSubPath, ".crc"); + snprintf(backupPath, DbPathMaxLen-1, "%s%s%s", gBackupPrefix, fileSubPath, gBackupPostfix); + snprintf(csumPath, DbPathMaxLen-1, "%s%s%s", gBackupPrefix, fileSubPath, gBackupCsPostfix); if(shared_DB >= 0) // check valid database context { @@ -255,19 +255,22 @@ int pclFileOpen(unsigned int ldbid, const char* resource_id, unsigned int user_n snprintf(dbPath, DbPathMaxLen, gLocalCacheFilePath, gAppId, user_no, seat_no, resource_id); handle = pclCreateFile(dbPath); - if(handle < MaxPersHandle && handle > 0) - { - __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 + if(handle != -1) { - close(handle); - handle = EPERS_MAXHANDLE; + if(handle < MaxPersHandle) + { + __sync_fetch_and_add(&gOpenFdArray[handle], FileOpen); // set open flag + + strcpy(gFileHandleArray[handle].backupPath, backupPath); + strcpy(gFileHandleArray[handle].csumPath, csumPath); + gFileHandleArray[handle].backupCreated = 0; + gFileHandleArray[handle].permission = PersistencePermission_ReadWrite; // make it writable + } + else + { + close(handle); + handle = EPERS_MAXHANDLE; + } } } } @@ -481,8 +484,8 @@ int pclFileCreatePath(unsigned int ldbid, const char* resource_id, unsigned int if( dbContext.configKey.permission != PersistencePermission_ReadOnly && pclBackupNeeded(dbPath) ) { - snprintf(backupPath, DbPathMaxLen-1, "%s%s", dbPath, "~"); - snprintf(csumPath, DbPathMaxLen-1, "%s%s", dbPath, "~.crc"); + snprintf(backupPath, DbPathMaxLen-1, "%s%s", dbPath, gBackupPostfix); + snprintf(csumPath, DbPathMaxLen-1, "%s%s", dbPath, gBackupCsPostfix); if((handle = pclVerifyConsistency(dbPath, backupPath, csumPath, flags)) == -1) { @@ -513,33 +516,47 @@ int pclFileCreatePath(unsigned int ldbid, const char* resource_id, unsigned int *size = strlen(dbPath); *path = malloc((*size)+1); // allocate 1 byte for the string termination - memcpy(*path, dbPath, (*size)); - (*path)[(*size)] = '\0'; // terminate string - gOssHandleArray[handle].filePath = *path; - if(access(*path, F_OK) == -1) + /* Check if malloc was successful */ + if(NULL != (*path)) { - // file does not exist, create it. - int handle = 0; - if((handle = pclCreateFile(*path)) == -1) - { - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclFileCreatePath: error => failed to create file: "), DLT_STRING(*path)); - } - else + memcpy(*path, dbPath, (*size)); + (*path)[(*size)] = '\0'; // terminate string + gOssHandleArray[handle].filePath = *path; + + if(access(*path, F_OK) == -1) { - if(pclFileGetDefaultData(handle, resource_id, dbContext.configKey.policy) == -1) // try to get default data + // file does not exist, create it. + int handle = 0; + if((handle = pclCreateFile(*path)) == -1) + { + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclFileCreatePath: error => failed to create file: "), DLT_STRING(*path)); + } + else { - DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclFileCreatePath => no default data available: "), DLT_STRING(resource_id)); + if(pclFileGetDefaultData(handle, resource_id, dbContext.configKey.policy) == -1) // try to get default data + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclFileCreatePath => no default data available: "), DLT_STRING(resource_id)); + } + close(handle); // don't need the open file } } - close(handle); // don't need the open file + } + else + { + handle = EPERS_DESER_ALLOCMEM; + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, + DLT_STRING("pclFileCreatePath: malloc() failed for path:"), + DLT_STRING(dbPath), + DLT_STRING("With the size:"), + DLT_UINT(*size)); } } else - { - set_persistence_handle_close_idx(handle); - handle = EPERS_MAXHANDLE; - } + { + set_persistence_handle_close_idx(handle); + handle = EPERS_MAXHANDLE; + } } } else // requested resource is not in the RCT, so create resource as local/cached. @@ -552,8 +569,8 @@ int pclFileCreatePath(unsigned int ldbid, const char* resource_id, unsigned int { if(handle < MaxPersHandle) { - snprintf(backupPath, DbPathMaxLen, "%s%s", dbPath, "~"); - snprintf(csumPath, DbPathMaxLen, "%s%s", dbPath, "~.crc"); + snprintf(backupPath, DbPathMaxLen, "%s%s", dbPath, gBackupPostfix); + snprintf(csumPath, DbPathMaxLen, "%s%s", dbPath, gBackupCsPostfix); __sync_fetch_and_add(&gOpenHandleArray[handle], FileOpen); // set open flag strncpy(gOssHandleArray[handle].backupPath, backupPath, DbPathMaxLen); diff --git a/src/persistence_client_library_handle.h b/src/persistence_client_library_handle.h index 369884b..c7ff995 100644 --- a/src/persistence_client_library_handle.h +++ b/src/persistence_client_library_handle.h @@ -67,7 +67,7 @@ extern int gOpenHandleArray[MaxPersHandle]; /** * @brief get persistence handle * - * @return a new handle or 0 if an error occured + * @return a new handle or 0 if an error occured or EPERS_MAXHANDLE if max no of handles is reached */ int get_persistence_handle_idx(); @@ -80,10 +80,12 @@ int get_persistence_handle_idx(); void set_persistence_handle_close_idx(int handle); +/** + * @brief close open key handles + * + */ void close_all_persistence_handle(); - - #endif /* PERSISTENCY_CLIENT_LIBRARY_HANDLE_H */ diff --git a/src/persistence_client_library_key.c b/src/persistence_client_library_key.c index 0d7c0ee..9c1cbf8 100644 --- a/src/persistence_client_library_key.c +++ b/src/persistence_client_library_key.c @@ -51,39 +51,20 @@ int pclKeyHandleOpen(unsigned int ldbid, const char* resource_id, unsigned int u char dbKey[DbKeyMaxLen] = {0}; // database key char dbPath[DbPathMaxLen] = {0}; // database location - //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyHandleOpen: "), 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 handle = get_db_context(&dbContext, resource_id, ResIsNoFile, dbKey, dbPath); - if( (handle >= 0) - && (dbContext.configKey.type == PersistenceResourceType_key) ) // check if type matches + if( (handle >= 0) && (dbContext.configKey.type == PersistenceResourceType_key) ) // check if type matches { if(dbContext.configKey.storage < PersistenceStorage_LastEntry) // check if store policy is valid { - if(PersistenceStorage_custom == dbContext.configKey.storage) - { - 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; - gPersCustomFuncs[idx].custom_plugin_handle_open(workaroundPath, flag, mode); - } - else - { - handle = EPERS_NOPLUGINFUNCT; - } - } - // generate handle for custom and for normal key handle = get_persistence_handle_idx(); - if((handle < MaxPersHandle) && (0 <= handle)) + if((handle < MaxPersHandle) && (0 < handle)) { // remember data in handle array strncpy(gKeyHandleArray[handle].dbPath, dbPath, DbPathMaxLen); @@ -98,6 +79,10 @@ int pclKeyHandleOpen(unsigned int ldbid, const char* resource_id, unsigned int u DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyHandleOpen: error - handleId out of bounds:"), DLT_INT(handle)); } } + else + { + handle = EPERS_BADPOL; + } } else { @@ -105,7 +90,6 @@ int pclKeyHandleOpen(unsigned int ldbid, const char* resource_id, unsigned int u } } - return handle; } @@ -115,36 +99,20 @@ int pclKeyHandleClose(int key_handle) { 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(gPclInitialized >= PCLinitialized) { - if(key_handle < MaxPersHandle && key_handle > 0) + if((key_handle < MaxPersHandle) && (key_handle > 0)) { - if(PersistenceStorage_custom == gKeyHandleArray[key_handle].info.configKey.storage ) + if ('\0' != gKeyHandleArray[key_handle].resourceID[0]) { - 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; - } + /* Invalidate key handle data */ + set_persistence_handle_close_idx(key_handle); + memset(&gKeyHandleArray[key_handle], 0, sizeof(gKeyHandleArray[key_handle])); + rval = 1; } - - if(rval != EPERS_NOPLUGINFUNCT) + else { - set_persistence_handle_close_idx(key_handle); - rval = 1; - - // invalidate entries - memset(gKeyHandleArray[key_handle].dbPath, 0, DbPathMaxLen); - memset(gKeyHandleArray[key_handle].dbKey ,0, DbKeyMaxLen); - gKeyHandleArray[key_handle].info.configKey.storage = -1; + rval = EPERS_INVALID_HANDLE; } } else @@ -162,30 +130,20 @@ int pclKeyHandleGetSize(int key_handle) { 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(gPclInitialized >= PCLinitialized) { - if(key_handle < MaxPersHandle && key_handle > 0) + if((key_handle < MaxPersHandle) && (key_handle > 0)) { - if(PersistenceStorage_custom == gKeyHandleArray[key_handle].info.configKey.storage) + if ('\0' != gKeyHandleArray[key_handle].resourceID[0]) { - 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; - } + size = pclKeyGetSize(gKeyHandleArray[key_handle].info.context.ldbid, + gKeyHandleArray[key_handle].resourceID, + gKeyHandleArray[key_handle].info.context.user_no, + gKeyHandleArray[key_handle].info.context.seat_no); } else { - size = persistence_get_data_size(gKeyHandleArray[key_handle].dbPath, gKeyHandleArray[key_handle].dbKey, - &gKeyHandleArray[key_handle].info); + size = EPERS_INVALID_HANDLE; } } else @@ -203,30 +161,22 @@ int pclKeyHandleReadData(int key_handle, unsigned char* buffer, int buffer_size) { 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(gPclInitialized >= PCLinitialized) { - if(key_handle < MaxPersHandle && key_handle > 0) + if((key_handle < MaxPersHandle) && (key_handle > 0)) { - if(PersistenceStorage_custom == gKeyHandleArray[key_handle].info.configKey.storage) + if ('\0' != gKeyHandleArray[key_handle].resourceID[0]) { - 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; - } + size = pclKeyReadData(gKeyHandleArray[key_handle].info.context.ldbid, + gKeyHandleArray[key_handle].resourceID, + gKeyHandleArray[key_handle].info.context.user_no, + gKeyHandleArray[key_handle].info.context.seat_no, + buffer, + buffer_size); } else { - size = persistence_get_data(gKeyHandleArray[key_handle].dbPath, gKeyHandleArray[key_handle].dbKey, - &gKeyHandleArray[key_handle].info, buffer, buffer_size); + size = EPERS_INVALID_HANDLE; } } else @@ -242,17 +192,11 @@ int pclKeyHandleReadData(int key_handle, unsigned char* buffer, int buffer_size) int pclKeyHandleRegisterNotifyOnChange(int key_handle, pclChangeNotifyCallback_t callback) { - //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyHandleRegisterNotifyOnChange: "), - // DLT_INT(gKeyHandleArray[key_handle].info.context.ldbid), DLT_STRING(gKeyHandleArray[key_handle].resourceID) ); - return handleRegNotifyOnChange(key_handle, callback, Notify_register); } int pclKeyHandleUnRegisterNotifyOnChange(int key_handle, pclChangeNotifyCallback_t callback) { - //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyHandleUnRegisterNotifyOnChange: "), - // DLT_INT(gKeyHandleArray[key_handle].info.context.ldbid), DLT_STRING(gKeyHandleArray[key_handle].resourceID) ); - return handleRegNotifyOnChange(key_handle, callback, Notify_unregister); } @@ -264,14 +208,21 @@ int handleRegNotifyOnChange(int key_handle, pclChangeNotifyCallback_t callback, if(gPclInitialized >= PCLinitialized) { - if(key_handle < MaxPersHandle && key_handle > 0) + if((key_handle < MaxPersHandle) && (key_handle > 0)) { - rval = regNotifyOnChange(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, - regPolicy); + if ('\0' != gKeyHandleArray[key_handle].resourceID[0]) + { + rval = regNotifyOnChange(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, + regPolicy); + } + else + { + rval = EPERS_INVALID_HANDLE; + } } else { @@ -287,70 +238,27 @@ int pclKeyHandleWriteData(int key_handle, unsigned char* buffer, int buffer_size { 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(gPclInitialized >= PCLinitialized) { - if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked + if((key_handle < MaxPersHandle) && (key_handle > 0)) { - if(buffer_size <= gMaxKeyValDataSize) // check data size + if ('\0' != gKeyHandleArray[key_handle].resourceID[0]) { - if(key_handle < MaxPersHandle && key_handle > 0) - { - if(gKeyHandleArray[key_handle].info.configKey.permission != PersistencePermission_ReadOnly) // don't write to a read only resource - { - if(PersistenceStorage_custom == gKeyHandleArray[key_handle].info.configKey.storage) - { - 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); - - if(size >= 0) // success ==> send change notification - { - int rval = pers_send_Notification_Signal(gKeyHandleArray[key_handle].dbKey, - &(gKeyHandleArray[key_handle].info.context), pclNotifyStatus_changed); - - if(rval <= 0) - { - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyHandleWriteData: error - failed to send notification")); - size = rval; - } - } - } - else - { - size = EPERS_NOPLUGINFUNCT; - } - } - else - { - size = persistence_set_data(gKeyHandleArray[key_handle].dbPath, gKeyHandleArray[key_handle].dbKey, - &gKeyHandleArray[key_handle].info, buffer, buffer_size); - } - } - else - { - size = EPERS_RESOURCE_READ_ONLY; - } - - } - else - { - size = EPERS_MAXHANDLE; - } + size = pclKeyWriteData(gKeyHandleArray[key_handle].info.context.ldbid, + gKeyHandleArray[key_handle].resourceID, + gKeyHandleArray[key_handle].info.context.user_no, + gKeyHandleArray[key_handle].info.context.seat_no, + buffer, + buffer_size); } else { - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyHandleWriteData: error - buffer_size to big, limit is [bytes]:"), DLT_INT(gMaxKeyValDataSize)); - size = EPERS_MAX_BUFF_SIZE; + size = EPERS_INVALID_HANDLE; } } else { - size = EPERS_LOCKFS; + size = EPERS_MAXHANDLE; } } @@ -371,8 +279,6 @@ int pclKeyDelete(unsigned int ldbid, const char* resource_id, unsigned int user_ { int rval = EPERS_NOT_INITIALIZED; - //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyDelete: "), DLT_INT(ldbid), DLT_STRING(resource_id) ); - if(gPclInitialized >= PCLinitialized) { if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked @@ -391,8 +297,7 @@ int pclKeyDelete(unsigned int ldbid, const char* resource_id, unsigned int user_ 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 + if( dbContext.configKey.storage < PersistenceStorage_LastEntry) // check if store policy is valid { rval = persistence_delete_data(dbPath, dbKey, &dbContext); } @@ -429,15 +334,12 @@ int pclKeyGetSize(unsigned int ldbid, const char* resource_id, unsigned int user 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 + if( dbContext.configKey.storage < PersistenceStorage_LastEntry) // check if store policy is valid { data_size = persistence_get_data_size(dbPath, dbKey, &dbContext); } @@ -463,8 +365,6 @@ int pclKeyReadData(unsigned int ldbid, const char* resource_id, unsigned int use { int data_size = EPERS_NOT_INITIALIZED; - //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyReadData: "), DLT_INT(ldbid), DLT_STRING(resource_id) ); - if(gPclInitialized >= PCLinitialized) { if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked @@ -484,8 +384,7 @@ int pclKeyReadData(unsigned int ldbid, const char* resource_id, unsigned int use && (dbContext.configKey.type == PersistenceResourceType_key) ) { - if( dbContext.configKey.storage < PersistenceStorage_LastEntry - && dbContext.configKey.storage >= PersistenceStorage_local) // check if store policy is valid + if( dbContext.configKey.storage < PersistenceStorage_LastEntry) // check if store policy is valid { data_size = persistence_get_data(dbPath, dbKey, &dbContext, buffer, buffer_size); } @@ -515,8 +414,6 @@ int pclKeyWriteData(unsigned int ldbid, const char* resource_id, unsigned int us { 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) { if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked @@ -545,8 +442,7 @@ int pclKeyWriteData(unsigned int ldbid, const char* resource_id, unsigned int us hash_val_data = pclCrc32(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 + if( dbContext.configKey.storage < PersistenceStorage_LastEntry) // check if store policy is valid { data_size = persistence_set_data(dbPath, dbKey, &dbContext, buffer, buffer_size); } @@ -583,18 +479,12 @@ int pclKeyWriteData(unsigned int ldbid, const char* resource_id, unsigned int us int pclKeyUnRegisterNotifyOnChange( unsigned int ldbid, const char * resource_id, unsigned int user_no, unsigned int seat_no, pclChangeNotifyCallback_t callback) { - //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyUnRegisterNotifyOnChange: "), - // DLT_INT(ldbid), DLT_STRING(resource_id) ); - return regNotifyOnChange(ldbid, resource_id, user_no, seat_no, callback, Notify_unregister); } int pclKeyRegisterNotifyOnChange(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no, pclChangeNotifyCallback_t callback) { - //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyRegisterNotifyOnChange: "), - // DLT_INT(ldbid), DLT_STRING(resource_id) ); - return regNotifyOnChange(ldbid, resource_id, user_no, seat_no, callback, Notify_register); } @@ -613,8 +503,6 @@ int regNotifyOnChange(unsigned int ldbid, const char* resource_id, unsigned int char dbKey[DbKeyMaxLen] = {0}; // database key char dbPath[DbPathMaxLen] = {0}; // database location - //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; @@ -622,16 +510,27 @@ int regNotifyOnChange(unsigned int ldbid, const char* resource_id, unsigned int // get database context: database path and database key rval = get_db_context(&dbContext, resource_id, ResIsNoFile, dbKey, dbPath); - // registration is only on shared and custom keys possible - if( (dbContext.configKey.storage != PersistenceStorage_local) - && (dbContext.configKey.type == PersistenceResourceType_key) ) - { - rval = persistence_notify_on_change(dbKey, ldbid, user_no, seat_no, callback, regPolicy); + if (rval==0) // no error, key found + { + // registration is only on shared and custom keys possible + if( (dbContext.configKey.storage != PersistenceStorage_local) + && (dbContext.configKey.type == PersistenceResourceType_key) ) + { + rval = persistence_notify_on_change(dbKey, ldbid, user_no, seat_no, callback, regPolicy); + } + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, + DLT_STRING("regNotifyOnChange: Not allowed! Resource is local or it is a file:"), + DLT_STRING(resource_id)); + rval = EPERS_NOTIFY_NOT_ALLOWED; + } } else { - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyRegisterNotifyOnChange: error - resource is not a shared resource or resource is not a key")); - rval = EPERS_NOTIFY_NOT_ALLOWED; + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, + DLT_STRING("regNotifyOnChange: Not possible! get_db_context() returned:"), + DLT_INT(rval)); } } diff --git a/src/persistence_client_library_prct_access.c b/src/persistence_client_library_prct_access.c index a44d229..eb3f8c2 100644 --- a/src/persistence_client_library_prct_access.c +++ b/src/persistence_client_library_prct_access.c @@ -188,7 +188,6 @@ int get_db_context(PersistenceInfo_s* dbContext, const char* resource_id, unsign if((resourceFound == 0) && (dbContext->context.ldbid == 0xFF) ) // create only when the resource is local data { - DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("get_db_context => resource in rct table not found: "), DLT_STRING(resource_id) ); // // resource NOT found in resource table ==> default is local cached key // @@ -211,11 +210,14 @@ int get_db_context(PersistenceInfo_s* dbContext, const char* resource_id, unsign DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("get_db_context => create resource not in PRCT => key:"), DLT_STRING(resource_id) ); - // send create notification - rval = pers_send_Notification_Signal(dbKey, &dbContext->context, pclNotifyStatus_created); - rval = get_db_path_and_key(dbContext, resource_id, dbKey, dbPath); } + /* rval contains the return value of function get_db_path_and_key() if positive structure content 'dbContext' is valid. + * rval can be 0,1 or 2 but get_db_context should only return '0' for success. */ + if (0 < rval) + { + rval = 0; + } return rval; } @@ -230,7 +232,7 @@ int get_db_path_and_key(PersistenceInfo_s* dbContext, const char* resource_id, c // // create resource database key // - if((dbContext->context.ldbid < 0x80) || (dbContext->context.ldbid == 0xFF) ) + if(((dbContext->context.ldbid < 0x80) || (dbContext->context.ldbid == 0xFF)) && (NULL != dbKey)) { // The LDBID is used to find the DBID in the resource table. if((dbContext->context.user_no == 0) && (dbContext->context.seat_no == 0)) @@ -259,7 +261,7 @@ int get_db_path_and_key(PersistenceInfo_s* dbContext, const char* resource_id, c storePolicy = PersistenceStorage_local; } - if((dbContext->context.ldbid >= 0x80) && (dbContext->context.ldbid != 0xFF)) + if((dbContext->context.ldbid >= 0x80) && (dbContext->context.ldbid != 0xFF) && (NULL != dbKey)) { // The LDBID is used to find the DBID in the resource table. // /<LDBID parameter> is added in front of the resource ID as the key string. |