summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include_protected/persistence_client_library_db_access.h6
-rw-r--r--src/persistence_client_library.c2
-rw-r--r--src/persistence_client_library_db_access.c19
-rw-r--r--src/persistence_client_library_key.c48
-rw-r--r--test/persistence_client_library_test.c31
5 files changed, 52 insertions, 54 deletions
diff --git a/include_protected/persistence_client_library_db_access.h b/include_protected/persistence_client_library_db_access.h
index b070dcd..185ebe9 100644
--- a/include_protected/persistence_client_library_db_access.h
+++ b/include_protected/persistence_client_library_db_access.h
@@ -33,11 +33,11 @@ extern "C" {
/// enumerator used to identify the policy to manage the data
-typedef enum _PersistenceNotifyRegPolicy_e
+typedef enum _PersNotifyRegPolicy_e
{
Notify_register = 0, /**< register to change notifications*/
Notify_unregister = 1, /**< unregister for change notifications */
-}PersistenceNotifyRegPolicy_e;
+} PersNotifyRegPolicy_e;
/**
@@ -130,7 +130,7 @@ void pers_db_close_all();
* @return 0 of registration was successfull; -1 if registration failes
*/
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);
+ pclChangeNotifyCallback_t callback, PersNotifyRegPolicy_e regPolicy);
diff --git a/src/persistence_client_library.c b/src/persistence_client_library.c
index f3479db..c162a0d 100644
--- a/src/persistence_client_library.c
+++ b/src/persistence_client_library.c
@@ -86,7 +86,7 @@ int pclInitLibrary(const char* appName, int shutdownMode)
}
- if( setup_dbus_mainloop() == -1)
+ if(setup_dbus_mainloop() == -1)
{
DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclInitLibrary => Failed to setup main loop"));
return EPERS_DBUS_MAINLOOP;
diff --git a/src/persistence_client_library_db_access.c b/src/persistence_client_library_db_access.c
index eceacc4..589fdb3 100644
--- a/src/persistence_client_library_db_access.c
+++ b/src/persistence_client_library_db_access.c
@@ -580,14 +580,13 @@ int pers_db_delete_key(char* dbPath, char* key, PersistenceInfo_s* info)
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)
+ pclChangeNotifyCallback_t callback, PersNotifyRegPolicy_e regPolicy)
{
int rval = 0;
- DBusError error;
- dbus_error_init (&error);
char ruleChanged[DbusMatchRuleSize];
char ruleDeleted[DbusMatchRuleSize];
char ruleCreated[DbusMatchRuleSize];
+ DBusConnection* conn = get_dbus_connection();
// 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'",
@@ -604,20 +603,22 @@ int persistence_notify_on_change(char* dbPath, char* key, unsigned int ldbid, un
// 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);
+ dbus_bus_add_match(conn, ruleChanged, NULL);
+ dbus_bus_add_match(conn, ruleDeleted, NULL);
+ dbus_bus_add_match(conn, ruleCreated, NULL);
}
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);
+ dbus_bus_remove_match(conn, ruleChanged, NULL);
+ dbus_bus_remove_match(conn, ruleDeleted, NULL);
+ dbus_bus_remove_match(conn, ruleCreated, NULL);
}
+ dbus_connection_flush(conn); // flush the connection to add the match
+
return rval;
}
diff --git a/src/persistence_client_library_key.c b/src/persistence_client_library_key.c
index 0616ace..4986bef 100644
--- a/src/persistence_client_library_key.c
+++ b/src/persistence_client_library_key.c
@@ -240,36 +240,25 @@ int pclKeyHandleReadData(int key_handle, unsigned char* buffer, int buffer_size)
int pclKeyHandleRegisterNotifyOnChange(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) );
+ 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_register);
- }
- else
- {
- rval = EPERS_MAXHANDLE;
- }
- }
- return rval;
+ return handleRegNotifyOnChange(key_handle, callback, Notify_register);
}
int pclKeyHandleUnRegisterNotifyOnChange(int key_handle, pclChangeNotifyCallback_t callback)
{
- int rval = EPERS_NOT_INITIALIZED;
+ 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);
+}
- //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyHandleRegisterNotifyOnChange: "),
- // DLT_INT(gKeyHandleArray[key_handle].info.context.ldbid), DLT_STRING(gKeyHandleArray[key_handle].resourceID) );
+
+
+int handleRegNotifyOnChange(int key_handle, pclChangeNotifyCallback_t callback, PersNotifyRegPolicy_e regPolicy)
+{
+ int rval = EPERS_NOT_INITIALIZED;
if(gPclInitialized >= PCLinitialized)
{
@@ -280,7 +269,7 @@ int pclKeyHandleUnRegisterNotifyOnChange(int key_handle, pclChangeNotifyCallback
gKeyHandleArray[key_handle].info.context.user_no,
gKeyHandleArray[key_handle].info.context.seat_no,
callback,
- Notify_unregister);
+ regPolicy);
}
else
{
@@ -291,6 +280,7 @@ int pclKeyHandleUnRegisterNotifyOnChange(int key_handle, pclChangeNotifyCallback
}
+
int pclKeyHandleWriteData(int key_handle, unsigned char* buffer, int buffer_size)
{
int size = EPERS_NOT_INITIALIZED;
@@ -565,20 +555,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)
{
+ 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);
}
-int regNotifyOnChange(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no, pclChangeNotifyCallback_t callback, PersistenceNotifyRegPolicy_e regPolicy)
+int regNotifyOnChange(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no, pclChangeNotifyCallback_t callback, PersNotifyRegPolicy_e regPolicy)
{
int rval = EPERS_NOT_INITIALIZED;
diff --git a/test/persistence_client_library_test.c b/test/persistence_client_library_test.c
index 6b378ed..c4c7d04 100644
--- a/test/persistence_client_library_test.c
+++ b/test/persistence_client_library_test.c
@@ -64,7 +64,7 @@ START_TEST (test_GetData)
unsigned char buffer[READ_SIZE] = {0};
ret = pclInitLibrary(gTheAppId, shutdownReg);
- fail_unless(ret < 0, "Failed to init PCL");
+ fail_unless(ret <= 1, "Failed to init PCL");
/**
* Logical DB ID: 0xFF with user 0 and seat 0
@@ -163,7 +163,7 @@ START_TEST (test_GetDataHandle)
char sysTimeBuffer[128];
ret = pclInitLibrary(gTheAppId, shutdownReg);
- fail_unless(ret < 0, "Failed to init PCL");
+ fail_unless(ret <= 1, "Failed to init PCL");
time_t t = time(0);
@@ -209,8 +209,10 @@ START_TEST (test_GetDataHandle)
* Logical DB ID: 0xFF with user 0 and seat 0
* ==> local value accessible by ALL USERS (user 0, seat 0)
*/
+#if 0 // plugin test case
memset(buffer, 0, READ_SIZE);
handle4 = pclKeyHandleOpen(0xFF, "language/country_code", 0, 0);
+ printf("H A N D L E: %d\n", handle4);
fail_unless(handle4 >= 0, "Failed to open handle /language/country_code");
ret = pclKeyHandleReadData(handle4, buffer, READ_SIZE);
@@ -220,6 +222,7 @@ START_TEST (test_GetDataHandle)
fail_unless(size = strlen("Custom plugin -> plugin_get_data_handle"));
ret = pclKeyHandleWriteData(handle4, (unsigned char*)"Only dummy implementation behind custom library", READ_SIZE);
+#endif
// ---------------------------------------------------------------------------------------------
@@ -267,7 +270,7 @@ START_TEST(test_SetData)
struct tm *locTime;
ret = pclInitLibrary(gTheAppId, shutdownReg);
- fail_unless(ret < 0, "Failed to init PCL");
+ fail_unless(ret <= 1, "Failed to init PCL");
time_t t = time(0);
@@ -378,7 +381,7 @@ START_TEST(test_SetDataNoPRCT)
struct tm *locTime;
ret = pclInitLibrary(gTheAppId, shutdownReg);
- fail_unless(ret < 0, "Failed to init PCL");
+ fail_unless(ret <= 1, "Failed to init PCL");
time_t t = time(0);
@@ -422,7 +425,7 @@ START_TEST(test_GetDataSize)
unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
ret = pclInitLibrary(gTheAppId, shutdownReg);
- fail_unless(ret < 0, "Failed to init PCL");
+ fail_unless(ret <= 1, "Failed to init PCL");
/**
* Logical DB ID: 0xFF with user 3 and seat 2
@@ -456,7 +459,7 @@ START_TEST(test_DeleteData)
unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
rval = pclInitLibrary(gTheAppId, shutdownReg);
- fail_unless(rval < 0, "Failed to init PCL");
+ fail_unless(rval <= 1, "Failed to init PCL");
// read data from key
rval = pclKeyReadData(0xFF, "key_70", 1, 2, buffer, READ_SIZE);
@@ -511,7 +514,7 @@ START_TEST(test_DataFile)
char* fileMap = NULL;
ret = pclInitLibrary(gTheAppId, shutdownReg);
- fail_unless(ret < 0, "Failed to init PCL");
+ fail_unless(ret <= 1, "Failed to init PCL");
writeBuffer = malloc(writeSize);
@@ -603,7 +606,7 @@ START_TEST(test_DataFileRecovery)
unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
ret = pclInitLibrary(gTheAppId, shutdownReg);
- fail_unless(ret < 0, "Failed to init PCL");
+ fail_unless(ret <= 1, "Failed to init PCL");
// test backup creation --------------------------------------------
fd_RO = pclFileOpen(0xFF, "media/mediaDB_ReadOnly.db", 1, 1);
@@ -634,7 +637,7 @@ START_TEST(test_DataHandle)
unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
ret = pclInitLibrary(gTheAppId, shutdownReg);
- fail_unless(ret < 0, "Failed to init PCL");
+ fail_unless(ret <= 1, "Failed to init PCL");
// test file handles
handle1 = pclFileOpen(0xFF, "media/mediaDB.db", 1, 1);
@@ -678,7 +681,7 @@ START_TEST(test_DataHandleOpen)
unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
ret = pclInitLibrary(gTheAppId, shutdownReg);
- fail_unless(ret < 0, "Failed to init PCL");
+ fail_unless(ret <= 1, "Failed to init PCL");
// open handles ----------------------------------------------------
hd1 = pclKeyHandleOpen(0xFF, "posHandle/last_position1", 0, 0);
@@ -758,7 +761,7 @@ START_TEST(test_Cursor)
unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
rval = pclInitLibrary(gTheAppId, shutdownReg);
- fail_unless(rval < 0, "Failed to init PCL");
+ fail_unless(rval <= 1, "Failed to init PCL");
// create cursor
handle = pers_db_cursor_create("/Data/mnt-c/lt-persistence_client_library_test/cached.itz");
@@ -820,7 +823,7 @@ START_TEST(test_Plugin)
unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
ret = pclInitLibrary(gTheAppId, shutdownReg);
- fail_unless(ret < 0, "Failed to init PCL");
+ fail_unless(ret <= 1, "Failed to init PCL");
ret = pclKeyReadData(0xFF, "language/country_code", 0, 0, buffer, READ_SIZE);
fail_unless(ret != EPERS_NOT_INITIALIZED);
@@ -868,7 +871,7 @@ START_TEST(test_ReadDefault)
unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
ret = pclInitLibrary(gTheAppId, shutdownReg);
- fail_unless(ret < 0, "Failed to init PCL");
+ fail_unless(ret <= 1, "Failed to init PCL");
ret = pclKeyReadData(0xFF, "statusHandle/default01", 3, 2, buffer, READ_SIZE);
fail_unless(ret != EPERS_NOT_INITIALIZED);
@@ -894,7 +897,7 @@ START_TEST(test_ReadConfDefault)
unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
ret = pclInitLibrary(gTheAppId, shutdownReg);
- fail_unless(ret < 0, "Failed to init PCL");
+ fail_unless(ret <= 1, "Failed to init PCL");
ret = pclKeyReadData(0xFF, "statusHandle/confdefault01", 3, 2, buffer, READ_SIZE);
fail_unless(ret != EPERS_NOT_INITIALIZED);