From fa0479cd9409770ebdc843b420e1beab778397aa Mon Sep 17 00:00:00 2001 From: Ingo Huerner Date: Mon, 4 Nov 2013 15:25:14 +0100 Subject: corrected initcounter; added unregister notify functions --- include/persistence_client_library_key.h | 25 +++++++++- .../persistence_client_library_db_access.h | 18 +++++-- src/persistence_client_library.c | 9 ++-- src/persistence_client_library_db_access.c | 36 +++++++++----- src/persistence_client_library_db_access_ll.c | 29 ----------- src/persistence_client_library_db_access_ll.h | 34 ------------- src/persistence_client_library_dbus_service.c | 2 +- src/persistence_client_library_key.c | 57 +++++++++++++++++++--- test/persistence_client_library_dbus_test.c | 18 ++++++- 9 files changed, 132 insertions(+), 96 deletions(-) delete mode 100644 src/persistence_client_library_db_access_ll.c delete mode 100644 src/persistence_client_library_db_access_ll.h diff --git a/include/persistence_client_library_key.h b/include/persistence_client_library_key.h index 3a1c6b0..8474f32 100644 --- a/include/persistence_client_library_key.h +++ b/include/persistence_client_library_key.h @@ -187,7 +187,16 @@ int pclKeyHandleReadData(int key_handle, unsigned char* buffer, int buffer_size) */ int pclKeyHandleRegisterNotifyOnChange(int key_handle, pclChangeNotifyCallback_t callback); - +/** + * @brief unregister a change notification for persistent data + * + * @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 the following error codes: + * ::EPERS_LOCKFS + */ +int pclKeyHandleUnRegisterNotifyOnChange(int key_handle, pclChangeNotifyCallback_t callback); /** * @brief writes persistent data identified by key handle @@ -237,6 +246,20 @@ int pclKeyRegisterNotifyOnChange(unsigned int ldbid, const char* resource_id, un +/** + * @brief unregister a change notification for persistent data + * + * @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 seat_no the seat number + * @param callback notification callback + * + * @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 pclKeyUnRegisterNotifyOnChange( unsigned int ldbid, const char * resource_id, unsigned int user_no, unsigned int seat_no, pclChangeNotifyCallback_t callback); + /** * @brief writes persistent data identified by ldbid and resource_id * diff --git a/include_protected/persistence_client_library_db_access.h b/include_protected/persistence_client_library_db_access.h index ca101bd..b070dcd 100644 --- a/include_protected/persistence_client_library_db_access.h +++ b/include_protected/persistence_client_library_db_access.h @@ -32,6 +32,13 @@ extern "C" { #include "../include/persistence_client_library_key.h" +/// enumerator used to identify the policy to manage the data +typedef enum _PersistenceNotifyRegPolicy_e +{ + Notify_register = 0, /**< register to change notifications*/ + Notify_unregister = 1, /**< unregister for change notifications */ +}PersistenceNotifyRegPolicy_e; + /** * @brief write data to a key @@ -110,15 +117,20 @@ void pers_db_close_all(); /** - * @brief register for change notifications of a key + * @brief register or unregister for change notifications of a key * * @param dbPath the path to the database where the key is in * @param key the database key to register on + * @param ldbid logical database ID of the resource to monitor + * @param user_no the user ID; user_no=0 can not be used as user-ID beacause ‘0’ is defined as System/node + * @param seat_no the seat number + * @param callback the function callback to be called + * @param regPolic ::Notify_register to register; ::Notify_unregister to unregister * * @return 0 of registration was successfull; -1 if registration failes */ -int persistence_reg_notify_on_change(char* dbPath, char* key, unsigned int ldbid, unsigned int user_no, unsigned int seat_no, - pclChangeNotifyCallback_t callback); +int persistence_notify_on_change(char* dbPath, char* key, unsigned int ldbid, unsigned int user_no, unsigned int seat_no, + pclChangeNotifyCallback_t callback, PersistenceNotifyRegPolicy_e regPolicy); diff --git a/src/persistence_client_library.c b/src/persistence_client_library.c index a841728..f3479db 100644 --- a/src/persistence_client_library.c +++ b/src/persistence_client_library.c @@ -55,8 +55,6 @@ int pclInitLibrary(const char* appName, int shutdownMode) if(gPclInitialized == PCLnotInitialized) { - gPclInitialized++; - gShutdownMode = shutdownMode; DLT_REGISTER_CONTEXT(gDLTContext,"pers","Context for persistence client library logging"); @@ -82,8 +80,7 @@ int pclInitLibrary(const char* appName, int shutdownMode) pBlacklistPath = "/etc/pclBackupBlacklist.txt"; // default path } - rval = readBlacklistConfigFile(pBlacklistPath); - if(rval == -1) + if(readBlacklistConfigFile(pBlacklistPath) == -1) { DLT_LOG(gDLTContext, DLT_LOG_WARN, DLT_STRING("pclInitLibrary -> failed to access blacklist:"), DLT_STRING(pBlacklistPath)); } @@ -162,6 +159,8 @@ int pclInitLibrary(const char* appName, int shutdownMode) // destory mutex pthread_mutex_destroy(&gDbusInitializedMtx); pthread_cond_destroy(&gDbusInitializedCond); + + gPclInitialized++; } else if(gPclInitialized >= PCLinitialized) { @@ -186,7 +185,7 @@ int pclDeinitLibrary(void) // unregister for lifecycle and persistence admin service dbus messages rval = unregister_lifecycle(gShutdownMode); - //rval = unregister_pers_admin_service(); + rval = unregister_pers_admin_service(); // unload custom client libraries for(i=0; i -#include -#include - -// TODO: put here low level database access function - - - - diff --git a/src/persistence_client_library_db_access_ll.h b/src/persistence_client_library_db_access_ll.h deleted file mode 100644 index 5609db7..0000000 --- a/src/persistence_client_library_db_access_ll.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef PERSISTENCE_CLIENT_LIBRARY_DB_ACCESS_LL_H -#define PERSISTENCE_CLIENT_LIBRARY_DB_ACCESS_LL_H - -/****************************************************************************** - * Project Persistency - * (c) copyright 2012 - * Company XS Embedded GmbH - *****************************************************************************/ -/****************************************************************************** - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed - * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -******************************************************************************/ - /** - * @file persistence_client_library_data_access.h - * @ingroup Persistence client library - * @author Ingo Huerner - * @brief Header of the persistence client library database low level access. - * @see - */ - -#ifdef __cplusplus -extern "C" { -#endif - -#define PERSIST_DATA_LL_ACCESS_INTERFACE_VERSION (0x01000000U) - -// TODO: put here low level database access function - -#ifdef __cplusplus -} -#endif - -#endif /* PERSISTENCY_CLIENT_LIBRARY_DB_ACCESS_LL_H */ diff --git a/src/persistence_client_library_dbus_service.c b/src/persistence_client_library_dbus_service.c index 5768254..f5362a5 100644 --- a/src/persistence_client_library_dbus_service.c +++ b/src/persistence_client_library_dbus_service.c @@ -277,7 +277,7 @@ int setup_dbus_mainloop(void) } else { - DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("dbus_connection_open() Error :"), DLT_STRING(err.message) ); + DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("dbus_connection_open_private() Error :"), DLT_STRING(err.message) ); dbus_error_free(&err); return -1; } diff --git a/src/persistence_client_library_key.c b/src/persistence_client_library_key.c index 0185f28..0616ace 100644 --- a/src/persistence_client_library_key.c +++ b/src/persistence_client_library_key.c @@ -249,20 +249,46 @@ int pclKeyHandleRegisterNotifyOnChange(int key_handle, pclChangeNotifyCallback_t { 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); + 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, + Notify_register); } else { rval = EPERS_MAXHANDLE; } } - return rval; } +int pclKeyHandleUnRegisterNotifyOnChange(int key_handle, pclChangeNotifyCallback_t callback) +{ + 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(gPclInitialized >= PCLinitialized) + { + if(key_handle < MaxPersHandle) + { + 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, + Notify_unregister); + } + else + { + rval = EPERS_MAXHANDLE; + } + } + return rval; +} int pclKeyHandleWriteData(int key_handle, unsigned char* buffer, int buffer_size) @@ -536,7 +562,23 @@ 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) +{ + 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) +{ + + return regNotifyOnChange(ldbid, resource_id, user_no, seat_no, callback, Notify_register); +} + + + + +int regNotifyOnChange(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no, pclChangeNotifyCallback_t callback, PersistenceNotifyRegPolicy_e regPolicy) { int rval = EPERS_NOT_INITIALIZED; @@ -559,9 +601,9 @@ int pclKeyRegisterNotifyOnChange(unsigned int ldbid, const char* resource_id, un // registration is only on shared key possible if( (dbContext.configKey.storage == PersistenceStorage_shared) - && (dbContext.configKey.type == PersistenceResourceType_key) ) + && (dbContext.configKey.type == PersistenceResourceType_key) ) { - rval = persistence_reg_notify_on_change(dbPath, dbKey, ldbid, user_no, seat_no, callback); + rval = persistence_notify_on_change(dbPath, dbKey, ldbid, user_no, seat_no, callback, regPolicy); } else { @@ -579,4 +621,3 @@ int pclKeyRegisterNotifyOnChange(unsigned int ldbid, const char* resource_id, un - diff --git a/test/persistence_client_library_dbus_test.c b/test/persistence_client_library_dbus_test.c index 7b2612e..cd4d7c6 100644 --- a/test/persistence_client_library_dbus_test.c +++ b/test/persistence_client_library_dbus_test.c @@ -52,7 +52,6 @@ int main(int argc, char *argv[]) ret = pclInitLibrary("lt-persistence_client_library_dbus_test", shutdownReg); printf("pclInitLibrary: %d\n", ret); -#if 0 printf("Press a key to end application\n"); ret = pclKeyHandleOpen(0xFF, "posHandle/last_position", 0, 0); @@ -61,8 +60,23 @@ int main(int argc, char *argv[]) ret = pclKeyRegisterNotifyOnChange(0x84, "links/last_link3", 3/*user_no*/, 2/*seat_no*/, &myChangeCallback); ret = pclKeyRegisterNotifyOnChange(0x84, "links/last_link4", 4/*user_no*/, 1/*seat_no*/, &myChangeCallback); + printf("Press enter to unregister to notifications\n"); getchar(); -#endif + + ret = pclKeyUnRegisterNotifyOnChange(0x84, "links/last_link2", 2/*user_no*/, 1/*seat_no*/, &myChangeCallback); + ret = pclKeyUnRegisterNotifyOnChange(0x84, "links/last_link3", 3/*user_no*/, 2/*seat_no*/, &myChangeCallback); + ret = pclKeyUnRegisterNotifyOnChange(0x84, "links/last_link4", 4/*user_no*/, 1/*seat_no*/, &myChangeCallback); + + printf("Press enter to register to notifications\n"); + getchar(); + + ret = pclKeyRegisterNotifyOnChange(0x84, "links/last_link2", 2/*user_no*/, 1/*seat_no*/, &myChangeCallback); + ret = pclKeyRegisterNotifyOnChange(0x84, "links/last_link3", 3/*user_no*/, 2/*seat_no*/, &myChangeCallback); + ret = pclKeyRegisterNotifyOnChange(0x84, "links/last_link4", 4/*user_no*/, 1/*seat_no*/, &myChangeCallback); + + printf("Press enter to end\n"); + getchar(); + sleep(2); pclDeinitLibrary(); -- cgit v1.2.1