summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIngo Huerner <ingo.huerner@xse.de>2013-11-04 15:25:14 +0100
committerIngo Huerner <ingo.huerner@xse.de>2013-11-04 15:25:14 +0100
commitfa0479cd9409770ebdc843b420e1beab778397aa (patch)
tree9e424bb49ab34581768508d3a78649bc03e089cf
parent91f3912f7c66844b76ea8dfeadd766d5318ae017 (diff)
downloadpersistence-client-library-fa0479cd9409770ebdc843b420e1beab778397aa.tar.gz
corrected initcounter; added unregister notify functions
-rw-r--r--include/persistence_client_library_key.h25
-rw-r--r--include_protected/persistence_client_library_db_access.h18
-rw-r--r--src/persistence_client_library.c9
-rw-r--r--src/persistence_client_library_db_access.c36
-rw-r--r--src/persistence_client_library_db_access_ll.c29
-rw-r--r--src/persistence_client_library_db_access_ll.h34
-rw-r--r--src/persistence_client_library_dbus_service.c2
-rw-r--r--src/persistence_client_library_key.c57
-rw-r--r--test/persistence_client_library_dbus_test.c18
9 files changed, 132 insertions, 96 deletions
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
@@ -238,6 +247,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
*
* @param ldbid logical database 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<PersCustomLib_LastEntry; i++)
diff --git a/src/persistence_client_library_db_access.c b/src/persistence_client_library_db_access.c
index 4912a5a..eceacc4 100644
--- a/src/persistence_client_library_db_access.c
+++ b/src/persistence_client_library_db_access.c
@@ -579,34 +579,44 @@ int pers_db_delete_key(char* dbPath, char* key, PersistenceInfo_s* info)
}
-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)
{
int rval = 0;
DBusError error;
dbus_error_init (&error);
char ruleChanged[DbusMatchRuleSize];
char ruleDeleted[DbusMatchRuleSize];
-
- // assign callback
- gChangeNotifyCallback = callback;
+ char ruleCreated[DbusMatchRuleSize];
// add match for c h a n g e
snprintf(ruleChanged, DbusMatchRuleSize, "type='signal',interface='org.genivi.persistence.adminconsumer',member='PersistenceResChange',path='/org/genivi/persistence/adminconsumer',arg0='%s',arg1='%u',arg2='%u',arg3='%u'",
key, ldbid, user_no, seat_no);
- dbus_bus_add_match(get_dbus_connection(), ruleChanged, &error);
-
-
// add match for d e l e t e
snprintf(ruleDeleted, DbusMatchRuleSize, "type='signal',interface='org.genivi.persistence.adminconsumer',member='PersistenceResDelete',path='/org/genivi/persistence/adminconsumer',arg0='%s',arg1='%u',arg2='%u',arg3='%u'",
key, ldbid, user_no, seat_no);
- dbus_bus_add_match(get_dbus_connection(), ruleDeleted, &error);
-
-
// add match for c r e a t e
- snprintf(ruleDeleted, DbusMatchRuleSize, "type='signal',interface='org.genivi.persistence.adminconsumer',member='PersistenceResCreate',path='/org/genivi/persistence/adminconsumer',arg0='%s',arg1='%u',arg2='%u',arg3='%u'",
+ snprintf(ruleCreated, DbusMatchRuleSize, "type='signal',interface='org.genivi.persistence.adminconsumer',member='PersistenceResCreate',path='/org/genivi/persistence/adminconsumer',arg0='%s',arg1='%u',arg2='%u',arg3='%u'",
key, ldbid, user_no, seat_no);
- dbus_bus_add_match(get_dbus_connection(), ruleDeleted, &error);
+
+ if(regPolicy == Notify_register)
+ {
+ // assign callback
+ gChangeNotifyCallback = callback;
+
+ dbus_bus_add_match(get_dbus_connection(), ruleChanged, &error);
+ dbus_bus_add_match(get_dbus_connection(), ruleDeleted, &error);
+ dbus_bus_add_match(get_dbus_connection(), ruleCreated, &error);
+ }
+ else if(regPolicy == Notify_unregister)
+ {
+ // remove callback
+ gChangeNotifyCallback = NULL;
+
+ dbus_bus_remove_match(get_dbus_connection(), ruleChanged, &error);
+ dbus_bus_remove_match(get_dbus_connection(), ruleDeleted, &error);
+ dbus_bus_remove_match(get_dbus_connection(), ruleCreated, &error);
+ }
return rval;
}
diff --git a/src/persistence_client_library_db_access_ll.c b/src/persistence_client_library_db_access_ll.c
deleted file mode 100644
index 234191f..0000000
--- a/src/persistence_client_library_db_access_ll.c
+++ /dev/null
@@ -1,29 +0,0 @@
-/******************************************************************************
- * 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_ll.c
- * @ingroup Persistence client library
- * @author Ingo Huerner
- * @brief Implementation of persistence database low level access
- * @see
- */
-
-#include "persistence_client_library_db_access_ll.h"
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-// 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,8 +562,24 @@ 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;
if(gPclInitialized >= PCLinitialized)
@@ -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();