*/
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
/**
+ * @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
#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
/**
- * @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);
if(gPclInitialized == PCLnotInitialized)
{
- gPclInitialized++;
-
gShutdownMode = shutdownMode;
DLT_REGISTER_CONTEXT(gDLTContext,"pers","Context for persistence client library logging");
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));
}
// destory mutex
pthread_mutex_destroy(&gDbusInitializedMtx);
pthread_cond_destroy(&gDbusInitializedCond);
+
+ gPclInitialized++;
}
else if(gPclInitialized >= PCLinitialized)
{
// 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++)
}
-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;
}
+++ /dev/null
-/******************************************************************************
- * 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
-
-
-
-
+++ /dev/null
-#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 */
}
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;
}
{
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)
}
+
+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)
// 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
{
-
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);
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();