summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog18
-rw-r--r--configure.ac2
-rw-r--r--include/persistence_client_library_error_def.h8
-rw-r--r--src/persistence_client_library.c6
-rw-r--r--src/persistence_client_library.h12
-rw-r--r--src/persistence_client_library_access_helper.c70
-rw-r--r--src/persistence_client_library_access_helper.h9
-rw-r--r--src/persistence_client_library_data_access.c99
-rw-r--r--src/persistence_client_library_data_access.h23
-rw-r--r--src/persistence_client_library_dbus_service.c90
-rw-r--r--src/persistence_client_library_file.c18
-rw-r--r--src/persistence_client_library_handle.h3
-rw-r--r--src/persistence_client_library_key.c204
-rw-r--r--src/persistence_client_library_lc_interface.c77
-rw-r--r--src/persistence_client_library_pas_interface.c175
-rw-r--r--src/persistence_client_library_pas_interface.h4
-rw-r--r--test/data/Data.tar.gzbin121017 -> 121287 bytes
-rw-r--r--test/persistence_client_library_test.c105
18 files changed, 579 insertions, 344 deletions
diff --git a/ChangeLog b/ChangeLog
index 182d015..d0a6914 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,24 +1,30 @@
-Revision 0.2.3 (rev 1793)
+Revision 0.2.4
+- Updated test data
+- Internal data reorganization
+- Fixed a problem with cursor (warning: still not fully working as expected)
+- Fixed a problem with internal database handling
+
+Revision 0.2.3
- Fixed handle problem
- added cursor functions
- key do not need to start with a '/' anymore
- added multi-threading support to dbus mainloop
-Revision 0.2.2 (rev 1759)
+Revision 0.2.2
- Updated test data
- Added shared data support
- Removed error when loading custom plugin function that is not available in the plugin library
(loading just continues with the next function and does not abort anymore)
-Revision 0.2.1 (rev 1748)
+Revision 0.2.1
- Extended tests
- Fixed some minor bugs
- Removed dconf
-Revision 0.2.0 (rev 1709)
+Revision 0.2.0
- Fixed a problem with handle generation
- Updated custom plugin library interface
- Switched to itzam database (gvdb currently commented out)
@@ -27,13 +33,13 @@ Revision 0.2.0 (rev 1709)
- Added itzam database files to Data.tar.gz files
-Revision 0.1.5 (rev 1665)
+Revision 0.1.5
- Fixed problem where no custom lib is available; extended custom lib interface; introduced error codes; removed modules form Makefile.am
- Adjusted license in test files to MIT
- Removed requesting dbus name from dbus main loop
-Revison 0.1.4 (rev 1591)
+Revison 0.1.4
- Update after code review; Extended custom library interface with function without handle
- Removed c++test warnings
- Moved test data to subfolder test
diff --git a/configure.ac b/configure.ac
index 1b5c517..d64f667 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,7 +1,7 @@
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
-AC_INIT([Persistence Client Library], [0.2.1], [not-valid@xse.de])
+AC_INIT([Persistence Client Library], [0.2.4], [not-valid@xse.de])
AC_CONFIG_SRCDIR([Makefile.am])
AM_INIT_AUTOMAKE([dist-bzip2])
AC_GNU_SOURCE()
diff --git a/include/persistence_client_library_error_def.h b/include/persistence_client_library_error_def.h
index dc4cad9..5df6e0f 100644
--- a/include/persistence_client_library_error_def.h
+++ b/include/persistence_client_library_error_def.h
@@ -89,4 +89,12 @@
#define EPERS_LAST_ENTRY_IN_DB (-26)
+/**
+ * @brief Main dispatching loop
+ *
+ * @return 0
+ */
+void* dbus_main_dispatching_loop(void* dataPtr);
+
+
#endif /* PERSISTENCE_CLIENT_LIBRARY_ERROR_DEF_H */
diff --git a/src/persistence_client_library.c b/src/persistence_client_library.c
index 04d26ad..8b939d8 100644
--- a/src/persistence_client_library.c
+++ b/src/persistence_client_library.c
@@ -44,6 +44,7 @@
#include <string.h>
#include <errno.h>
#include <stdlib.h>
+#include <dbus/dbus.h>
#include <dlt/dlt.h>
#include <dlt/dlt_common.h>
@@ -138,6 +139,7 @@ void pers_library_init(void)
{
int status = 0;
int i = 0;
+
//DLT_REGISTER_APP("Persistence Client Library","persClientLib");
//DLT_REGISTER_CONTEXT(persClientLibCtx,"persClientLib","Context for Logging");
@@ -158,10 +160,12 @@ void pers_library_init(void)
pthread_mutex_init(&gDbusInitializedMtx, NULL);
// setup dbus main dispatching loop
+ printf("*** setup dbus main loop\n");
setup_dbus_mainloop();
// wain until dbus main loop has been setup and running
- pthread_mutex_lock(&gDbusInitializedMtx);
+ //pthread_mutex_lock(&gDbusInitializedMtx);
+
// register for lifecycle and persistence admin service dbus messages
register_lifecycle();
diff --git a/src/persistence_client_library.h b/src/persistence_client_library.h
index 13a9903..35904bd 100644
--- a/src/persistence_client_library.h
+++ b/src/persistence_client_library.h
@@ -102,11 +102,20 @@ typedef enum _PersistenceStorage_e
} PersistenceStorage_e;
+/// structure used to manage database context
+typedef struct _PersistenceDbContext_s
+{
+ unsigned char ldbid;
+ unsigned char user_no;
+ unsigned char seat_no;
+} PersistenceDbContext_s;
+
/// structure used to manage the persistence configuration for a key
typedef struct _PersistenceConfigurationKey_s
{
PersistencePolicy_e policy; /**< policy */
PersistenceStorage_e storage; /**< definition of storage to use */
+ PersistenceDbContext_s context; /**< database context*/
unsigned int permission; /**< access right, corresponds to UNIX */
unsigned int max_size; /**< max size expected for the key */
char * reponsible; /**< name of responsible application */
@@ -114,6 +123,9 @@ typedef struct _PersistenceConfigurationKey_s
} PersistenceConfigurationKey_s;
+
+
+
typedef enum _PersistenceRCT_e
{
PersistenceRCT_local = 0,
diff --git a/src/persistence_client_library_access_helper.c b/src/persistence_client_library_access_helper.c
index f7454ee..447a259 100644
--- a/src/persistence_client_library_access_helper.c
+++ b/src/persistence_client_library_access_helper.c
@@ -273,16 +273,13 @@ void free_pers_conf_key(PersistenceConfigurationKey_s* pc)
// status: OK
-int get_db_context(unsigned char ldbid, char* resource_id, unsigned char user_no, unsigned char seat_no,
- unsigned int isFile, char dbKey[], char dbPath[])
+int get_db_context(PersistenceConfigurationKey_s* dbContext, char* resource_id, unsigned int isFile, char dbKey[], char dbPath[])
{
- int rval = 0,
- resourceFound = 0,
- groupId = 0;
+ int rval = 0, resourceFound = 0, groupId = 0;
PersistenceRCT_e rct = PersistenceRCT_LastEntry;
- rct = get_table_id(ldbid, &groupId);
+ rct = get_table_id(dbContext->context.ldbid, &groupId);
// get resource configuration table
GvdbTable* resource_table = get_resource_cfg_table(rct, groupId);
@@ -296,7 +293,6 @@ int get_db_context(unsigned char ldbid, char* resource_id, unsigned char user_no
if(dbValue != NULL)
{
- PersistenceConfigurationKey_s dbEntry;
gconstpointer valuePtr = NULL;
int size = g_variant_get_size(dbValue);
@@ -307,27 +303,22 @@ int get_db_context(unsigned char ldbid, char* resource_id, unsigned char user_no
if(buffer != NULL)
{
memcpy(buffer, valuePtr, size);
- de_serialize_data(buffer, &dbEntry);
+ de_serialize_data(buffer, dbContext);
- if(dbEntry.storage != PersistenceStorage_custom )
+ if(dbContext->storage != PersistenceStorage_custom )
{
- rval = get_db_path_and_key(ldbid, resource_id, user_no, seat_no, isFile, dbKey, dbPath, dbEntry.policy);
- if(rval != -1)
- {
- rval = dbEntry.storage;
- }
+ rval = get_db_path_and_key(dbContext, resource_id, isFile, dbKey, dbPath);
}
else
{
//printf("***************** dbEntry.custom_name %s \n", dbEntry.custom_name);
// if customer storage, we use the custom name as path
- strncpy(dbPath, dbEntry.custom_name, strlen(dbEntry.custom_name));
- rval = dbEntry.storage;
+ strncpy(dbPath, dbContext->custom_name, strlen(dbContext->custom_name));
}
free(buffer);
buffer = NULL;
- free_pers_conf_key(&dbEntry);
+ free_pers_conf_key(dbContext);
resourceFound = 1;
}
}
@@ -357,18 +348,17 @@ int get_db_context(unsigned char ldbid, char* resource_id, unsigned char user_no
// status: OK
-int get_db_path_and_key(unsigned char ldbid, char* resource_id, unsigned char user_no, unsigned char seat_no,
- unsigned int isFile, char dbKey[], char dbPath[], unsigned char cached_resource)
+int get_db_path_and_key(PersistenceConfigurationKey_s* dbContext, char* resource_id, unsigned int isFile, char dbKey[], char dbPath[])
{
int storePolicy = PersistenceStoragePolicy_LastEntry;
//
// create resource database key
//
- if((ldbid < 0x80) || (ldbid == 0xFF) )
+ if((dbContext->context.ldbid < 0x80) || (dbContext->context.ldbid == 0xFF) )
{
// The LDBID is used to find the DBID in the resource table.
- if((user_no == 0) && (seat_no == 0))
+ if((dbContext->context.user_no == 0) && (dbContext->context.seat_no == 0))
{
//
// Node is added in front of the resource ID as the key string.
@@ -380,21 +370,21 @@ int get_db_path_and_key(unsigned char ldbid, char* resource_id, unsigned char us
//
// Node is added in front of the resource ID as the key string.
//
- if(seat_no == 0)
+ if(dbContext->context.seat_no == 0)
{
// /User/<user_no_parameter> is added in front of the resource ID as the key string.
- snprintf(dbKey, dbKeyMaxLen, "%s%d/%s", gUser, user_no, resource_id);
+ snprintf(dbKey, dbKeyMaxLen, "%s%d/%s", gUser, dbContext->context.user_no, resource_id);
}
else
{
// /User/<user_no_parameter>/Seat/<seat_no_parameter> is added in front of the resource ID as the key string.
- snprintf(dbKey, dbKeyMaxLen, "%s%d%s%d/%s", gUser, user_no, gSeat, seat_no, resource_id);
+ snprintf(dbKey, dbKeyMaxLen, "%s%d%s%d/%s", gUser, dbContext->context.user_no, gSeat, dbContext->context.seat_no, resource_id);
}
}
storePolicy = PersistenceStorage_local;
}
- if((ldbid >= 0x80) && ( ldbid != 0xFF))
+ if((dbContext->context.ldbid >= 0x80) && (dbContext->context.ldbid != 0xFF))
{
// 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.
@@ -402,13 +392,13 @@ int get_db_path_and_key(unsigned char ldbid, char* resource_id, unsigned char us
// Rational: Reduction of number of databases -> reduction of maintenance costs
// /User/<user_no_parameter> and /Seat/<seat_no_parameter> are add after /<LDBID parameter> if there are different than 0.
- if(seat_no != 0)
+ if(dbContext->context.seat_no != 0)
{
- snprintf(dbKey, dbKeyMaxLen, "/%x%s%d%s%d/%s", ldbid, gUser, user_no, gSeat, seat_no, resource_id);
+ snprintf(dbKey, dbKeyMaxLen, "/%x%s%d%s%d/%s", dbContext->context.ldbid, gUser, dbContext->context.user_no, gSeat, dbContext->context.seat_no, resource_id);
}
else
{
- snprintf(dbKey, dbKeyMaxLen, "/%x%s%d/%s", ldbid, gUser, user_no, resource_id);
+ snprintf(dbKey, dbKeyMaxLen, "/%x%s%d/%s", dbContext->context.ldbid, gUser, dbContext->context.user_no, resource_id);
}
storePolicy = PersistenceStorage_local;
}
@@ -416,29 +406,29 @@ int get_db_path_and_key(unsigned char ldbid, char* resource_id, unsigned char us
//
// create resource database path
//
- if(ldbid < 0x80)
+ if(dbContext->context.ldbid < 0x80)
{
// S H A R E D database
- if(ldbid != 0)
+ if(dbContext->context.ldbid != 0)
{
// Additionally /GROUP/<LDBID_parameter> shall be added inside of the database path listed in the resource table. (Off target)
//
// shared G R O U P database * * * * * * * * * * * * * * * * * * *
//
- if(PersistencePolicy_wc == cached_resource)
+ if(PersistencePolicy_wc == dbContext->policy)
{
if(isFile == resIsNoFile)
- snprintf(dbPath, dbPathMaxLen, gSharedCachePath, ldbid, gSharedCached);
+ snprintf(dbPath, dbPathMaxLen, gSharedCachePath, dbContext->context.ldbid, gSharedCached);
else
- snprintf(dbPath, dbPathMaxLen, gSharedCachePath, ldbid, dbKey);
+ snprintf(dbPath, dbPathMaxLen, gSharedCachePath, dbContext->context.ldbid, dbKey);
}
- else if(PersistencePolicy_wt == cached_resource)
+ else if(PersistencePolicy_wt == dbContext->policy)
{
if(isFile == resIsNoFile)
- snprintf(dbPath, dbPathMaxLen, gSharedWtPath, ldbid, gSharedWt);
+ snprintf(dbPath, dbPathMaxLen, gSharedWtPath, dbContext->context.ldbid, gSharedWt);
else
- snprintf(dbPath, dbPathMaxLen, gSharedWtPath, ldbid, dbKey);
+ snprintf(dbPath, dbPathMaxLen, gSharedWtPath, dbContext->context.ldbid, dbKey);
}
}
else
@@ -447,14 +437,14 @@ int get_db_path_and_key(unsigned char ldbid, char* resource_id, unsigned char us
//
// shared P U B L I C database * * * * * * * * * * * * * * * * * *
//
- if(PersistencePolicy_wc == cached_resource)
+ if(PersistencePolicy_wc == dbContext->policy)
{
if(isFile == resIsNoFile)
snprintf(dbPath, dbPathMaxLen, gSharedPublicCachePath, gSharedCached);
else
snprintf(dbPath, dbPathMaxLen, gSharedPublicCachePath, dbKey);
}
- else if(PersistencePolicy_wt == cached_resource)
+ else if(PersistencePolicy_wt == dbContext->policy)
{
if(isFile == resIsNoFile)
snprintf(dbPath, dbPathMaxLen, gSharedPublicWtPath, gSharedWt);
@@ -469,14 +459,14 @@ int get_db_path_and_key(unsigned char ldbid, char* resource_id, unsigned char us
{
// L O C A L database
- if(PersistencePolicy_wc == cached_resource)
+ if(PersistencePolicy_wc == dbContext->policy)
{
if(isFile == resIsNoFile)
snprintf(dbPath, dbPathMaxLen, gLocalCachePath, gAppId, gLocalCached);
else
snprintf(dbPath, dbPathMaxLen, gLocalCachePath, gAppId, dbKey);
}
- else if(PersistencePolicy_wt == cached_resource)
+ else if(PersistencePolicy_wt == dbContext->policy)
{
if(isFile == resIsNoFile)
snprintf(dbPath, dbPathMaxLen, gLocalWtPath, gAppId, gLocalWt);
diff --git a/src/persistence_client_library_access_helper.h b/src/persistence_client_library_access_helper.h
index 864646a..842302b 100644
--- a/src/persistence_client_library_access_helper.h
+++ b/src/persistence_client_library_access_helper.h
@@ -51,8 +51,7 @@
* @return 1 if shared database and 0 if local database or PersistenceStoragePolicy_LastEntry
* when no valid database has been found
*/
-int get_db_path_and_key(unsigned char ldbid, char* resource_id, unsigned char user_no, unsigned char seat_no,
- unsigned int isFile, char dbKey[], char dbPath[], unsigned char cached_resource);
+int get_db_path_and_key(PersistenceConfigurationKey_s* dbContext, char* resource_id, unsigned int isFile, char dbKey[], char dbPath[]);
@@ -68,11 +67,9 @@ int get_db_path_and_key(unsigned char ldbid, char* resource_id, unsigned char us
* @param dbPath the array where the database location path will be stored
* @param cached_resource flag to identify if the resource is cached (value 1)or write through (value 0)
*
- * @return the PersistenceStorage_e
- * or a negative value with one of the following errors: EPERS_NOKEY, EPERS_NOKEYDATA or EPERS_NOPRCTABLE
+ * @return 0 or a negative value with one of the following errors: EPERS_NOKEY, EPERS_NOKEYDATA or EPERS_NOPRCTABLE
*/
-int get_db_context(unsigned char ldbid, char* resource_id, unsigned char user_no, unsigned char seat_no,
- unsigned int isFile, char dbKey[], char dbPath[]);
+int get_db_context(PersistenceConfigurationKey_s* dbContext, char* resource_id, unsigned int isFile, char dbKey[], char dbPath[]);
diff --git a/src/persistence_client_library_data_access.c b/src/persistence_client_library_data_access.c
index cce0ac0..7837e4a 100644
--- a/src/persistence_client_library_data_access.c
+++ b/src/persistence_client_library_data_access.c
@@ -40,7 +40,7 @@
#include <stdlib.h>
#include <itzam.h>
-
+// definition of a key-value pair
typedef struct _KeyValuePair_s
{
char m_key[KeySize];
@@ -49,15 +49,17 @@ typedef struct _KeyValuePair_s
KeyValuePair_s;
-
+// definition of a cursor entry
typedef struct _CursorEntry_s
{
itzam_btree_cursor m_cursor;
+ PersistenceStorage_e storage;
+ PersistencePolicy_e policy;
int m_empty;
}
CursorEntry_s;
-
+// cursor array handle
CursorEntry_s gCursorArray[maxPersHandle];
/// handle index
@@ -67,15 +69,20 @@ static int gInitialized = 0;
/// free handle array
int gFreeCursorHandleArray[maxPersHandle];
-
+// free head index
int gFreeCursorHandleIdxHead = 0;
+// mutex
pthread_mutex_t gMtx;
/// btree array
-static itzam_btree gBtree[2];
-static int gBtreeCreated[] = { 0, 0 };
+static itzam_btree gBtree[PersistenceStoragePolicy_LastEntry][PersistencePolicy_LastEntry];
+static int gBtreeCreated[PersistenceStoragePolicy_LastEntry][PersistencePolicy_LastEntry] =
+{ {0, 0, 0 },
+ {0, 0, 0 },
+ {0, 0, 0 }
+};
void error_handler(const char * function_name, itzam_error error)
@@ -85,24 +92,24 @@ void error_handler(const char * function_name, itzam_error error)
-itzam_btree* database_get(PersistenceStorage_e storage, const char* dbPath)
+itzam_btree* database_get(PersistenceStorage_e storage, PersistencePolicy_e policy, const char* dbPath)
{
itzam_btree* btree = NULL;
if( (storage >= PersistenceStorage_local)
&& (storage <= PersistenceStorage_shared) )
{
- if(gBtreeCreated[storage] == 0)
+ if(gBtreeCreated[storage][policy] == 0)
{
itzam_state state = ITZAM_FAILED;
- state = itzam_btree_open(&gBtree[storage], dbPath, itzam_comparator_string, error_handler, 0/*recover*/, 0/*read_only*/);
+ state = itzam_btree_open(&gBtree[storage][policy], dbPath, itzam_comparator_string, error_handler, 0/*recover*/, 0/*read_only*/);
if (state != ITZAM_OKAY)
{
fprintf(stderr, "Open Itzam problem: %s\n", STATE_MESSAGES[state]);
}
- gBtreeCreated[storage] = 1;
+ gBtreeCreated[storage][policy] = 1;
}
// return tree
- btree = &gBtree[storage];
+ btree = &gBtree[storage][policy];
}
else
{
@@ -113,18 +120,18 @@ itzam_btree* database_get(PersistenceStorage_e storage, const char* dbPath)
}
-void database_close(PersistenceStorage_e storage)
+void database_close(PersistenceStorage_e storage, PersistencePolicy_e policy)
{
if( (storage >= PersistenceStorage_local)
&& (storage <= PersistenceStorage_shared) )
{
itzam_state state = ITZAM_FAILED;
- state = itzam_btree_close(&gBtree[storage]);
+ state = itzam_btree_close(&gBtree[storage][policy]);
if (state != ITZAM_OKAY)
{
fprintf(stderr, "Close Itzam problem: %s\n", STATE_MESSAGES[state]);
}
- gBtreeCreated[storage] = 0;
+ gBtreeCreated[storage][policy] = 0;
}
else
{
@@ -136,7 +143,7 @@ void database_close(PersistenceStorage_e storage)
-int persistence_get_data(char* dbPath, char* key, PersistenceStorage_e storage, unsigned char* buffer, unsigned long buffer_size)
+int persistence_get_data(char* dbPath, char* key, PersistenceStorage_e storage, PersistencePolicy_e policy, unsigned char* buffer, unsigned long buffer_size)
{
int read_size = -1;
@@ -146,7 +153,7 @@ int persistence_get_data(char* dbPath, char* key, PersistenceStorage_e storage,
itzam_state state = ITZAM_FAILED;
KeyValuePair_s search;
- btree = database_get(storage, dbPath);
+ btree = database_get(storage, policy, dbPath);
if(btree != NULL)
{
if(itzam_true == itzam_btree_find(btree, key, &search))
@@ -166,7 +173,7 @@ int persistence_get_data(char* dbPath, char* key, PersistenceStorage_e storage,
//
// workaround till lifecycle is working correctly
//
- database_close(storage);
+ database_close(storage, policy);
}
else
{
@@ -194,7 +201,7 @@ int persistence_get_data(char* dbPath, char* key, PersistenceStorage_e storage,
-int persistence_set_data(char* dbPath, char* key, PersistenceStorage_e storage, unsigned char* buffer, unsigned long buffer_size)
+int persistence_set_data(char* dbPath, char* key, PersistenceStorage_e storage, PersistencePolicy_e policy, unsigned char* buffer, unsigned long buffer_size)
{
int write_size = -1;
@@ -205,7 +212,7 @@ int persistence_set_data(char* dbPath, char* key, PersistenceStorage_e storage,
itzam_state state = ITZAM_FAILED;
KeyValuePair_s insert;
- btree = database_get(storage, dbPath);
+ btree = database_get(storage, policy, dbPath);
if(btree != NULL)
{
int keySize = 0;
@@ -239,7 +246,7 @@ int persistence_set_data(char* dbPath, char* key, PersistenceStorage_e storage,
//
// workaround till lifecycle is working correctly
//
- database_close(storage);
+ database_close(storage, policy);
}
else
{
@@ -269,7 +276,7 @@ int persistence_set_data(char* dbPath, char* key, PersistenceStorage_e storage,
-int persistence_get_data_size(char* dbPath, char* key, PersistenceStorage_e storage)
+int persistence_get_data_size(char* dbPath, char* key, PersistenceStorage_e storage, PersistencePolicy_e policy)
{
int read_size = -1;
@@ -280,7 +287,7 @@ int persistence_get_data_size(char* dbPath, char* key, PersistenceStorage_e stor
itzam_state state = ITZAM_FAILED;
KeyValuePair_s search;
- btree = database_get(storage, dbPath);
+ btree = database_get(storage, policy, dbPath);
if(btree != NULL)
{
keySize = (int)strlen((const char*)key);
@@ -300,7 +307,7 @@ int persistence_get_data_size(char* dbPath, char* key, PersistenceStorage_e stor
//
// workaround till lifecycle is working correctly
//
- database_close(storage);
+ database_close(storage, policy);
}
else
{
@@ -325,7 +332,7 @@ int persistence_get_data_size(char* dbPath, char* key, PersistenceStorage_e stor
-int persistence_delete_data(char* dbPath, char* dbKey, PersistenceStorage_e storage)
+int persistence_delete_data(char* dbPath, char* dbKey, PersistenceStorage_e storage, PersistencePolicy_e policy)
{
int ret = 0;
if(PersistenceStorage_custom != storage)
@@ -334,7 +341,7 @@ int persistence_delete_data(char* dbPath, char* dbKey, PersistenceStorage_e stor
KeyValuePair_s delete;
//printf("delete_key_from_table_itzam => Path: \"%s\" | key: \"%s\" \n", dbPath, key);
- btree = database_get(storage, dbPath);
+ btree = database_get(storage, policy, dbPath);
if(btree != NULL)
{
int keySize = 0;
@@ -358,7 +365,7 @@ int persistence_delete_data(char* dbPath, char* dbKey, PersistenceStorage_e stor
//
// workaround till lifecycle is working correctly
//
- database_close(storage);
+ database_close(storage, policy);
}
else
{
@@ -441,28 +448,35 @@ void close_cursor_handle(int handlerDB)
}
-int persistence_db_cursor_create(char* dbPath, PersistenceStorage_e storage)
+int persistence_db_cursor_create(char* dbPath, PersistenceStorage_e storage, PersistencePolicy_e policy)
{
int handle = -1;
itzam_btree* btree = NULL;
- btree = database_get(storage, dbPath);
+ printf("CREATE-Cursor: %d | path: %s \n", (int)storage, dbPath);
+ btree = database_get(storage, policy, dbPath);
if(btree != NULL)
{
itzam_state state;
handle = get_cursor_handle();
- state = itzam_btree_cursor_create(&gCursorArray[handle].m_cursor, btree);
- if(state == ITZAM_OKAY)
+ if(handle < maxPersHandle && handle >= 0)
{
- gCursorArray[handle].m_empty = 0;
- }
- else
- {
- gCursorArray[handle].m_empty = 1;
+ state = itzam_btree_cursor_create(&gCursorArray[handle].m_cursor, btree);
+ if(state == ITZAM_OKAY)
+ {
+ gCursorArray[handle].m_empty = 0;
+ gCursorArray[handle].storage = storage;
+ gCursorArray[handle].policy = policy;
+ }
+ else
+ {
+ gCursorArray[handle].m_empty = 1;
+ gCursorArray[handle].storage = PersistenceStoragePolicy_LastEntry;
+ gCursorArray[handle].policy = PersistencePolicy_LastEntry;
+ }
}
}
-
return handle;
}
@@ -471,7 +485,7 @@ int persistence_db_cursor_create(char* dbPath, PersistenceStorage_e storage)
int persistence_db_cursor_next(int handlerDB)
{
int rval = -1;
- if(handlerDB < maxPersHandle)
+ if(handlerDB < maxPersHandle && handlerDB >= 0)
{
if(gCursorArray[handlerDB].m_empty != 1)
{
@@ -507,7 +521,7 @@ int persistence_db_cursor_get_key(int handlerDB, char * bufKeyName_out, int bufS
int rval = -1;
KeyValuePair_s search;
- if(handlerDB < maxPersHandle)
+ if(handlerDB < maxPersHandle && handlerDB >= 0)
{
if(gCursorArray[handlerDB].m_empty != 1)
{
@@ -544,7 +558,7 @@ int persistence_db_cursor_get_data(int handlerDB, char * bufData_out, int bufSiz
int rval = -1;
KeyValuePair_s search;
- if(handlerDB < maxPersHandle)
+ if(handlerDB < maxPersHandle && handlerDB >= 0)
{
if(gCursorArray[handlerDB].m_empty != 1)
{
@@ -582,7 +596,7 @@ int persistence_db_cursor_get_data_size(int handlerDB)
int size = -1;
KeyValuePair_s search;
- if(handlerDB < maxPersHandle)
+ if(handlerDB < maxPersHandle && handlerDB >= 0)
{
if(gCursorArray[handlerDB].m_empty != 1)
{
@@ -613,7 +627,12 @@ int persistence_db_cursor_destroy(int handlerDB)
if (state == ITZAM_OKAY)
{
rval = 0;
+ database_close(gCursorArray[handlerDB].storage, gCursorArray[handlerDB].policy);
+
gCursorArray[handlerDB].m_empty = 1;
+ gCursorArray[handlerDB].storage = PersistenceStoragePolicy_LastEntry;
+ gCursorArray[handlerDB].policy = PersistencePolicy_LastEntry;
+
close_cursor_handle(handlerDB);
}
diff --git a/src/persistence_client_library_data_access.h b/src/persistence_client_library_data_access.h
index ca547de..5e4e5ff 100644
--- a/src/persistence_client_library_data_access.h
+++ b/src/persistence_client_library_data_access.h
@@ -34,7 +34,7 @@
* @see
*/
-#define PERSIST_DATA_ACCESS_INTERFACE_VERSION (0x01000000U)
+#define PERSIST_DATA_ACCESS_INTERFACE_VERSION (0x02000000U)
#include "persistence_client_library.h"
@@ -52,7 +52,8 @@
* @return the number of bytes written or a negative value if an error occured with the following error codes:
* EPERS_SETDTAFAILED EPERS_NOPRCTABLE EPERS_NOKEYDATA EPERS_NOKEY
*/
-int persistence_set_data(char* dbPath, char* key, PersistenceStorage_e storage, unsigned char* buffer, unsigned long buffer_size);
+int persistence_set_data(char* dbPath, char* key, PersistenceStorage_e storage, PersistencePolicy_e policy,
+ unsigned char* buffer, unsigned long buffer_size);
@@ -66,7 +67,8 @@ int persistence_set_data(char* dbPath, char* key, PersistenceStorage_e storage,
* @return the number of bytes read or a negative value if an error occured with the following error codes:
* EPERS_NOPRCTABLE EPERS_NOKEYDATA EPERS_NOKEY
*/
-int persistence_get_data(char* dbPath, char* key, PersistenceStorage_e storage, unsigned char* buffer, unsigned long buffer_size);
+int persistence_get_data(char* dbPath, char* key, PersistenceStorage_e storage, PersistencePolicy_e policy,
+ unsigned char* buffer, unsigned long buffer_size);
@@ -80,7 +82,7 @@ int persistence_get_data(char* dbPath, char* key, PersistenceStorage_e storage,
* @return size of data in bytes read from the key or on error a negative value with the following error codes:
* EPERS_NOPRCTABLE or EPERS_NOKEY
*/
-int persistence_get_data_size(char* dbPath, char* key, PersistenceStorage_e storage);
+int persistence_get_data_size(char* dbPath, char* key, PersistenceStorage_e storage, PersistencePolicy_e policy);
@@ -98,17 +100,22 @@ int persistence_reg_notify_on_change(char* dbPath, char* key);
/**
* @brief delete data
*/
-int persistence_delete_data(char* dbPath, char* dbKey, PersistenceStorage_e storePolicy);
+int persistence_delete_data(char* dbPath, char* dbKey, PersistenceStorage_e storage, PersistencePolicy_e policy);
/**
* @brief close the database for the given storage type
*
* @param storage the storage type of the database to close
*/
-void database_close(PersistenceStorage_e storage);
+void database_close(PersistenceStorage_e storage, PersistencePolicy_e policy);
+
+//---------------------------------------------------------------------------------------------
+// C U R S O R F U N C T I O N S
+//---------------------------------------------------------------------------------------------
+
/**
* @brief create a cursor to a DB ; if success, the cursor points to (-1)
* to access the first entry in DB, call persistence_db_cursor_next
@@ -118,7 +125,7 @@ void database_close(PersistenceStorage_e storage);
*
* @return handler to the DB (to be used in successive calls) or error code (< 0)
*/
-int persistence_db_cursor_create(char* dbPath, PersistenceStorage_e storage);
+int persistence_db_cursor_create(char* dbPath, PersistenceStorage_e storage, PersistencePolicy_e policy);
/**
* @brief move cursor to the next position
@@ -127,7 +134,7 @@ int persistence_db_cursor_create(char* dbPath, PersistenceStorage_e storage);
*
* @return 0 for success, negative value in case of error (check against EPERS_LAST_ENTRY_IN_DB)
*/
-int persistence_db_cursor_next(int handlerDB) ;
+int persistence_db_cursor_next(int handlerDB);
/**
* @brief get the name of the key pointed by the cursor associated with the database
diff --git a/src/persistence_client_library_dbus_service.c b/src/persistence_client_library_dbus_service.c
index 0311f1c..145b1e2 100644
--- a/src/persistence_client_library_dbus_service.c
+++ b/src/persistence_client_library_dbus_service.c
@@ -77,9 +77,6 @@ void sigHandler(int signo)
}
//------------------------------------------------------------------------
-//const char* gPersDbusAdminInterface = "org.genivi.persistence.admin";
-//const char* gPersDbusAdminPath = "/org/genivi/persistence/admin";
-
#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
@@ -94,8 +91,70 @@ static void unregisterMessageHandler(DBusConnection *connection, void *user_data
/* catches messages not directed to any registered object path ("garbage collector") */
static DBusHandlerResult handleObjectPathMessageFallback(DBusConnection * connection, DBusMessage * message, void * user_data)
{
- printf("handleObjectPathMessageFallback '%s' -> '%s'\n", dbus_message_get_interface(message), dbus_message_get_member(message) );
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ DBusHandlerResult result = DBUS_HANDLER_RESULT_HANDLED;
+
+ printf("handleObjectPathMessageFallback Object: '%s' -> Interface: '%s' -> Message: '%s'\n",
+ dbus_message_get_sender(message), dbus_message_get_interface(message), dbus_message_get_member(message) );
+
+ // org.genivi.persistence.admin S I G N A L
+ if((0==strcmp("org.genivi.persistence.admin", dbus_message_get_interface(message))))
+ {
+ // printf("checkPersAdminSignalInterface '%s' -> '%s'\n", dbus_message_get_interface(message), dbus_message_get_member(message));
+ if(dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_SIGNAL)
+ {
+ printf(" checkPersAdminSignal signal\n");
+ if((0==strcmp("PersistenceModeChanged", dbus_message_get_member(message))))
+ {
+ printf(" checkPersAdminSignal message\n");
+ // to do handle signal
+ result = signal_persModeChange(connection, message);
+ }
+ else
+ {
+ printf("handleObjectPathMessageFallback -> unknown signal '%s'\n", dbus_message_get_interface(message));
+ }
+ }
+ }
+
+ // org.genivi.persistence.admin P R O P E R T Y
+ else if((0==strcmp("org.freedesktop.DBus.Properties", dbus_message_get_interface(message))))
+ {
+ if(dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_SIGNAL)
+ {
+ if((0==strcmp("EggDBusChanged", dbus_message_get_member(message))))
+ {
+ DBusMessageIter array;
+ DBusMessageIter dict;
+ DBusMessageIter variant;
+
+ char* dictString = NULL;
+ int value = 0;
+
+ dbus_message_iter_open_container(&array, DBUS_TYPE_DICT_ENTRY, 0, &dict);
+ dbus_message_iter_get_basic(&dict, &dictString);
+
+ dbus_message_iter_open_container(&dict,DBUS_TYPE_VARIANT, NULL, &variant);
+ dbus_message_iter_get_basic(&dict, &value);
+
+ dbus_message_iter_close_container(&dict, &variant);
+ dbus_message_iter_close_container(&array, &dict);
+
+ printf("handleObjectPathMessageFallback ==> value: %d \n", value);
+ // to do handle signal
+ result = DBUS_HANDLER_RESULT_HANDLED;
+ }
+ else
+ {
+ printf("handleObjectPathMessageFallback -> unknown property '%s'\n", dbus_message_get_interface(message));
+ }
+ }
+ else
+ {
+ printf("handleObjectPathMessageFallback -> not a signal '%s'\n", dbus_message_get_member(message));
+ }
+ }
+
+ return result;
}
@@ -109,8 +168,10 @@ static void unregisterObjectPathFallback(DBusConnection *connection, void *user
void* run_mainloop(void* dataPtr)
{
+ printf(" *** run_mainloop ==> pthread_mutex_lock => \n");
// lock mutex to make sure dbus main loop is running
- pthread_mutex_lock(&gDbusInitializedMtx);
+ //pthread_mutex_lock(&gDbusInitializedMtx);
+ printf(" *** run_mainloop ==> pthread_mutex_lock <= \n");
// persistence admin message
static const struct DBusObjectPathVTable vtablePersAdmin
@@ -125,6 +186,7 @@ void* run_mainloop(void* dataPtr)
= {unregisterObjectPathFallback, handleObjectPathMessageFallback, NULL, };
// setup the dbus
+ printf(" *** run_mainloop ==> mainLoop\n");
mainLoop(vtablePersAdmin, vtableLifecycle, vtableFallback, dataPtr);
printf("Exit dbus main loop!!!!\n");
@@ -176,6 +238,7 @@ int setup_dbus_mainloop(void)
gDbusConn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
}
+ printf(" *** setup_dbus_mainloop ==> pthread_create\n");
// create here the dbus connection and pass to main loop
rval = pthread_create(&thread, NULL, run_mainloop, gDbusConn);
@@ -261,9 +324,7 @@ int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtable2,
else if (NULL != conn)
{
dbus_connection_set_exit_on_disconnect (conn, FALSE);
-
printf("connected as '%s'\n", dbus_bus_get_unique_name(conn));
-
if (0!=pipe(gPipefds))
{
printf("pipe() failed w/ errno %d\n", errno);
@@ -278,10 +339,15 @@ int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtable2,
gPollInfo.fds[0].fd = gPipefds[0];
gPollInfo.fds[0].events = POLLIN;
+// dbus_bus_add_match(conn, "type='signal', sender='org.genivi.persistence.admin',interface='org.genivi.persistence.admin',member='PersistenceModeChanged',path='/org/genivi/persistence/admin'", &err);
+// dbus_connection_add_filter(conn, checkPersAdminSignal, NULL, NULL);
+
+ // register for messages
if ( (TRUE==dbus_connection_register_object_path(conn, "/org/genivi/persistence/adminconsumer", &vtable, userData))
&& (TRUE==dbus_connection_register_object_path(conn, "/com/contiautomotive/NodeStateManager/LifecycleConsumer", &vtable2, userData))
&& (TRUE==dbus_connection_register_fallback(conn, "/", &vtableFallback, userData)) )
{
+ printf("* * * * mainLoop ==> success: dbus_connection_register_object_path \n");
if (TRUE!=dbus_connection_set_watch_functions(conn, addWatch, removeWatch, watchToggled, NULL, NULL))
{
printf("dbus_connection_set_watch_functions() failed\n");
@@ -289,9 +355,8 @@ int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtable2,
else
{
char buf[64];
-
- // minloop is running now, release mutex
- pthread_mutex_unlock(&gDbusInitializedMtx);
+ // mainloop is running now, release mutex
+ //pthread_mutex_unlock(&gDbusInitializedMtx);
do
{
bContinue = 0; /* assume error */
@@ -378,9 +443,10 @@ int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtable2,
while (0!=bContinue);
}
dbus_connection_unregister_object_path(conn, "/org/genivi/persistence/adminconsumer");
- //dbus_connection_unregister_object_path(conn, "/com/");
+ dbus_connection_unregister_object_path(conn, "/com/contiautomotive/NodeStateManager/LifecycleConsumer");
dbus_connection_unregister_object_path(conn, "/");
}
+ printf("* * * * mainLoop ==> error: dbus_connection_register_object_path\n");
close(gPipefds[1]);
close(gPipefds[0]);
}
diff --git a/src/persistence_client_library_file.c b/src/persistence_client_library_file.c
index 9ae5357..d965f10 100644
--- a/src/persistence_client_library_file.c
+++ b/src/persistence_client_library_file.c
@@ -100,10 +100,9 @@ void* file_map_data(void* addr, long size, long offset, int fd)
int file_open(unsigned char ldbid, char* resource_id, unsigned char user_no, unsigned char seat_no)
{
- int handle = -1;
+ int handle = -1, shared_DB = 0, flags = O_RDWR;
- int shared_DB = 0,
- flags = O_RDWR;
+ PersistenceConfigurationKey_s dbContext;
char dbKey[dbKeyMaxLen]; // database key
char dbPath[dbPathMaxLen]; // database location
@@ -111,8 +110,12 @@ int file_open(unsigned char ldbid, char* resource_id, unsigned char user_no, uns
memset(dbKey, 0, dbKeyMaxLen);
memset(dbPath, 0, dbPathMaxLen);
+ dbContext.context.ldbid = ldbid;
+ dbContext.context.seat_no = seat_no;
+ dbContext.context.user_no = user_no;
+
// get database context: database path and database key
- shared_DB = get_db_context(ldbid, resource_id, user_no, seat_no, resIsFile, dbKey, dbPath);
+ shared_DB = get_db_context(&dbContext, resource_id, resIsFile, dbKey, dbPath);
if(shared_DB != -1) // check valid database context
{
@@ -154,6 +157,7 @@ int file_remove(unsigned char ldbid, char* resource_id, unsigned char user_no, u
if(accessNoLock != isAccessLocked() ) // check if access to persistent data is locked
{
int shared_DB = 0;
+ PersistenceConfigurationKey_s dbContext;
char dbKey[dbKeyMaxLen]; // database key
char dbPath[dbPathMaxLen]; // database location
@@ -161,8 +165,12 @@ int file_remove(unsigned char ldbid, char* resource_id, unsigned char user_no, u
memset(dbKey, 0, dbKeyMaxLen);
memset(dbPath, 0, dbPathMaxLen);
+ dbContext.context.ldbid = ldbid;
+ dbContext.context.seat_no = seat_no;
+ dbContext.context.user_no = user_no;
+
// get database context: database path and database key
- shared_DB = get_db_context(ldbid, resource_id, user_no, seat_no, resIsFile, dbKey, dbPath);
+ shared_DB = get_db_context(&dbContext, resource_id, resIsFile, dbKey, dbPath);
if(shared_DB != -1) // check valid database context
{
diff --git a/src/persistence_client_library_handle.h b/src/persistence_client_library_handle.h
index da83c0a..0df6185 100644
--- a/src/persistence_client_library_handle.h
+++ b/src/persistence_client_library_handle.h
@@ -39,7 +39,8 @@
/// handle structure definition
typedef struct _PersistenceHandle_s
{
- int shared_DB; /// is a shared resource
+ int storage; /// storage type
+ int policy; /// write policy
char dbPath[dbPathMaxLen]; /// path to the database
char dbKey[dbKeyMaxLen]; /// database key
}
diff --git a/src/persistence_client_library_key.c b/src/persistence_client_library_key.c
index 39b8d15..9a79117 100644
--- a/src/persistence_client_library_key.c
+++ b/src/persistence_client_library_key.c
@@ -50,8 +50,7 @@
int key_handle_open(unsigned char ldbid, char* resource_id, unsigned char user_no, unsigned char seat_no)
{
int handle = 0;
-
- int storePolicy = 0;
+ PersistenceConfigurationKey_s dbContext;
char dbKey[dbKeyMaxLen]; // database key
char dbPath[dbPathMaxLen]; // database location
@@ -59,49 +58,52 @@ int key_handle_open(unsigned char ldbid, char* resource_id, unsigned char user_n
memset(dbKey, 0, dbKeyMaxLen);
memset(dbPath, 0, dbPathMaxLen);
- // get database context: database path and database key
- storePolicy = get_db_context(ldbid, resource_id, user_no, seat_no, resIsNoFile, dbKey, dbPath);
+ dbContext.context.ldbid = ldbid;
+ dbContext.context.seat_no = seat_no;
+ dbContext.context.user_no = user_no;
- if( storePolicy >= PersistenceStorage_local
- && storePolicy < PersistenceStoragePolicy_LastEntry) // check if store policy is valid
+ // get database context: database path and database key
+ handle = get_db_context(&dbContext, resource_id, resIsNoFile, dbKey, dbPath);
+ if(handle >= 0)
{
- if(PersistenceStorage_custom == storePolicy)
+ if( dbContext.storage >= PersistenceStorage_local
+ && dbContext.storage < PersistenceStoragePolicy_LastEntry) // check if store policy is valid
{
- 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) )
+ if(PersistenceStorage_custom == dbContext.storage)
{
- int flag = 0, mode = 0;
- handle = gPersCustomFuncs[idx].custom_plugin_handle_open(workaroundPath, flag, mode);
+ 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;
+ handle = gPersCustomFuncs[idx].custom_plugin_handle_open(workaroundPath, flag, mode);
+ }
+ else
+ {
+ handle = EPERS_NOPLUGINFUNCT;
+ }
}
else
{
- handle = EPERS_NOPLUGINFUNCT;
+ handle = get_persistence_handle_idx();
}
- }
- else
- {
- handle = get_persistence_handle_idx();
- }
- if(handle < maxPersHandle && handle != -1)
- {
- // remember data in handle array
- strncpy(gHandleArray[handle].dbPath, dbPath, dbPathMaxLen);
- strncpy(gHandleArray[handle].dbKey, dbKey, dbKeyMaxLen);
- gHandleArray[handle].shared_DB = storePolicy;
- }
- else
- {
- printf("key_handle_open: error - handleId out of bounds [%d]\n", handle);
+ if(handle < maxPersHandle && handle != -1)
+ {
+ // remember data in handle array
+ strncpy(gHandleArray[handle].dbPath, dbPath, dbPathMaxLen);
+ strncpy(gHandleArray[handle].dbKey, dbKey, dbKeyMaxLen);
+ gHandleArray[handle].storage = dbContext.storage;
+ gHandleArray[handle].policy = dbContext.policy;
+ }
+ else
+ {
+ printf("key_handle_open: error - handleId out of bounds [%d]\n", handle);
+ }
}
}
- else
- {
- handle = storePolicy;
- }
return handle;
@@ -115,7 +117,7 @@ int key_handle_close(int key_handle)
if(key_handle < maxPersHandle)
{
- if(PersistenceStorage_custom == gHandleArray[key_handle].shared_DB )
+ if(PersistenceStorage_custom == gHandleArray[key_handle].storage )
{
int idx = custom_client_name_to_id(gHandleArray[key_handle].dbPath, 1);
@@ -136,7 +138,7 @@ int key_handle_close(int key_handle)
// invalidate entries
strncpy(gHandleArray[key_handle].dbPath, "", dbPathMaxLen);
strncpy(gHandleArray[key_handle].dbKey ,"", dbKeyMaxLen);
- gHandleArray[key_handle].shared_DB = -1;
+ gHandleArray[key_handle].storage = -1;
}
else
{
@@ -154,7 +156,7 @@ int key_handle_get_size(int key_handle)
if(key_handle < maxPersHandle)
{
- if(PersistenceStorage_custom == gHandleArray[key_handle].shared_DB)
+ if(PersistenceStorage_custom == gHandleArray[key_handle].storage)
{
int idx = custom_client_name_to_id(gHandleArray[key_handle].dbPath, 1);
@@ -170,7 +172,7 @@ int key_handle_get_size(int key_handle)
else
{
size = persistence_get_data_size(gHandleArray[key_handle].dbPath, gHandleArray[key_handle].dbKey,
- gHandleArray[key_handle].shared_DB);
+ gHandleArray[key_handle].storage, gHandleArray[key_handle].policy);
}
}
@@ -184,7 +186,7 @@ int key_handle_read_data(int key_handle, unsigned char* buffer, unsigned long bu
int size = 0;
if(key_handle < maxPersHandle)
{
- if(PersistenceStorage_custom == gHandleArray[key_handle].shared_DB)
+ if(PersistenceStorage_custom == gHandleArray[key_handle].storage)
{
int idx = custom_client_name_to_id(gHandleArray[key_handle].dbPath, 1);
@@ -200,7 +202,7 @@ int key_handle_read_data(int key_handle, unsigned char* buffer, unsigned long bu
else
{
size = persistence_get_data(gHandleArray[key_handle].dbPath, gHandleArray[key_handle].dbKey,
- gHandleArray[key_handle].shared_DB, buffer, buffer_size);
+ gHandleArray[key_handle].storage, gHandleArray[key_handle].policy, buffer, buffer_size);
}
}
@@ -228,7 +230,7 @@ int key_handle_write_data(int key_handle, unsigned char* buffer, unsigned long b
{
if(key_handle < maxPersHandle)
{
- if(PersistenceStorage_custom == gHandleArray[key_handle].shared_DB)
+ if(PersistenceStorage_custom == gHandleArray[key_handle].storage)
{
int idx = custom_client_name_to_id(gHandleArray[key_handle].dbPath, 1);
@@ -244,7 +246,7 @@ int key_handle_write_data(int key_handle, unsigned char* buffer, unsigned long b
else
{
size = persistence_set_data(gHandleArray[key_handle].dbPath, gHandleArray[key_handle].dbKey,
- gHandleArray[key_handle].shared_DB, buffer, buffer_size);
+ gHandleArray[key_handle].storage, gHandleArray[key_handle].policy, buffer, buffer_size);
}
}
else
@@ -281,7 +283,7 @@ int key_delete(unsigned char ldbid, char* resource_id, unsigned char user_no, un
if(accessNoLock != isAccessLocked() ) // check if access to persistent data is locked
{
- int storePolicy = 0;
+ PersistenceConfigurationKey_s dbContext;
char dbKey[dbKeyMaxLen]; // database key
char dbPath[dbPathMaxLen]; // database location
@@ -289,17 +291,23 @@ int key_delete(unsigned char ldbid, char* resource_id, unsigned char user_no, un
memset(dbKey, 0, dbKeyMaxLen);
memset(dbPath, 0, dbPathMaxLen);
- // get database context: database path and database key
- storePolicy = get_db_context(ldbid, resource_id, user_no, seat_no, resIsNoFile, dbKey, dbPath);
+ dbContext.context.ldbid = ldbid;
+ dbContext.context.seat_no = seat_no;
+ dbContext.context.user_no = user_no;
- if( storePolicy < PersistenceStoragePolicy_LastEntry
- && storePolicy >= PersistenceStorage_local) // check if store policy is valid
- {
- rval = persistence_delete_data(dbPath, dbKey, storePolicy);
- }
- else
+ // get database context: database path and database key
+ rval = get_db_context(&dbContext, resource_id, resIsNoFile, dbKey, dbPath);
+ if(rval >= 0)
{
- rval = EPERS_BADPOL;
+ if( dbContext.storage < PersistenceStoragePolicy_LastEntry
+ && dbContext.storage >= PersistenceStorage_local) // check if store policy is valid
+ {
+ rval = persistence_delete_data(dbPath, dbKey, dbContext.storage, dbContext.policy);
+ }
+ else
+ {
+ rval = EPERS_BADPOL;
+ }
}
}
else
@@ -316,7 +324,7 @@ int key_delete(unsigned char ldbid, char* resource_id, unsigned char user_no, un
int key_get_size(unsigned char ldbid, char* resource_id, unsigned char user_no, unsigned char seat_no)
{
int data_size = 0;
- int storePolicy = 0;
+ PersistenceConfigurationKey_s dbContext;
char dbKey[dbKeyMaxLen]; // database key
char dbPath[dbPathMaxLen]; // database location
@@ -324,13 +332,23 @@ int key_get_size(unsigned char ldbid, char* resource_id, unsigned char user_no,
memset(dbKey, 0, dbKeyMaxLen);
memset(dbPath, 0, dbPathMaxLen);
- // get database context: database path and database key
- storePolicy = get_db_context(ldbid, resource_id, user_no, seat_no, resIsNoFile, dbKey, dbPath);
+ dbContext.context.ldbid = ldbid;
+ dbContext.context.seat_no = seat_no;
+ dbContext.context.user_no = user_no;
- if( storePolicy < PersistenceStoragePolicy_LastEntry
- && storePolicy >= PersistenceStorage_local) // check if store policy is valid
+ // get database context: database path and database key
+ data_size = get_db_context(&dbContext, resource_id, resIsNoFile, dbKey, dbPath);
+ if(data_size >= 0)
{
- data_size = persistence_get_data_size(dbPath, dbKey, storePolicy);
+ if( dbContext.storage < PersistenceStoragePolicy_LastEntry
+ && dbContext.storage >= PersistenceStorage_local) // check if store policy is valid
+ {
+ data_size = persistence_get_data_size(dbPath, dbKey, dbContext.storage, dbContext.policy);
+ }
+ else
+ {
+ data_size = EPERS_BADPOL;
+ }
}
else
{
@@ -350,7 +368,7 @@ int key_read_data(unsigned char ldbid, char* resource_id, unsigned char user_no,
if(accessNoLock != isAccessLocked() ) // check if access to persistent data is locked
{
- int storePolicy = 0;
+ PersistenceConfigurationKey_s dbContext;
char dbKey[dbKeyMaxLen]; // database key
char dbPath[dbPathMaxLen]; // database location
@@ -358,18 +376,24 @@ int key_read_data(unsigned char ldbid, char* resource_id, unsigned char user_no,
memset(dbKey, 0, dbKeyMaxLen);
memset(dbPath, 0, dbPathMaxLen);
+ dbContext.context.ldbid = ldbid;
+ dbContext.context.seat_no = seat_no;
+ dbContext.context.user_no = user_no;
// get database context: database path and database key
- storePolicy = get_db_context(ldbid, resource_id, user_no, seat_no, resIsNoFile, dbKey, dbPath);
-
- if( storePolicy < PersistenceStoragePolicy_LastEntry
- && storePolicy >= PersistenceStorage_local) // check if store policy is valid
- {
- data_size = persistence_get_data(dbPath, dbKey, storePolicy, buffer, buffer_size);
- }
- else
+ data_size = get_db_context(&dbContext, resource_id, resIsNoFile, dbKey, dbPath);
+ if(data_size >= 0)
{
- data_size = EPERS_BADPOL;
+
+ if( dbContext.storage < PersistenceStoragePolicy_LastEntry
+ && dbContext.storage >= PersistenceStorage_local) // check if store policy is valid
+ {
+ data_size = persistence_get_data(dbPath, dbKey, dbContext.storage, dbContext.policy, buffer, buffer_size);
+ }
+ else
+ {
+ data_size = EPERS_BADPOL;
+ }
}
}
else
@@ -391,7 +415,7 @@ int key_write_data(unsigned char ldbid, char* resource_id, unsigned char user_no
{
if(buffer_size <= gMaxKeyValDataSize) // check data size
{
- int storePolicy = 0;
+ PersistenceConfigurationKey_s dbContext;
unsigned int hash_val_data = 0;
@@ -401,21 +425,27 @@ int key_write_data(unsigned char ldbid, char* resource_id, unsigned char user_no
memset(dbKey, 0, dbKeyMaxLen);
memset(dbPath, 0, dbPathMaxLen);
- // get database context: database path and database key
- storePolicy = get_db_context(ldbid, resource_id, user_no, seat_no, resIsNoFile, dbKey, dbPath);
-
- // get hash value of data to verify storing
- hash_val_data = crc32(hash_val_data, buffer, buffer_size);
+ dbContext.context.ldbid = ldbid;
+ dbContext.context.seat_no = seat_no;
+ dbContext.context.user_no = user_no;
- // store data
- if( storePolicy < PersistenceStoragePolicy_LastEntry
- && storePolicy >= PersistenceStorage_local) // check if store policy is valid
- {
- data_size = persistence_set_data(dbPath, dbKey, storePolicy, buffer, buffer_size);
- }
- else
+ // get database context: database path and database key
+ data_size = get_db_context(&dbContext, resource_id, resIsNoFile, dbKey, dbPath);
+ if(data_size >= 0)
{
- data_size = EPERS_BADPOL;
+ // get hash value of data to verify storing
+ hash_val_data = crc32(hash_val_data, buffer, buffer_size);
+
+ // store data
+ if( dbContext.storage < PersistenceStoragePolicy_LastEntry
+ && dbContext.storage >= PersistenceStorage_local) // check if store policy is valid
+ {
+ data_size = persistence_set_data(dbPath, dbKey, dbContext.storage, dbContext.policy, buffer, buffer_size);
+ }
+ else
+ {
+ data_size = EPERS_BADPOL;
+ }
}
}
else
@@ -438,6 +468,7 @@ int key_write_data(unsigned char ldbid, char* resource_id, unsigned char user_no
int key_register_notify_on_change(unsigned char ldbid, char* resource_id, unsigned char user_no, unsigned char seat_no)
{
int rval = 0;
+ PersistenceConfigurationKey_s dbContext;
// unsigned int hash_val_data = 0;
char dbKey[dbKeyMaxLen]; // database key
@@ -446,8 +477,15 @@ int key_register_notify_on_change(unsigned char ldbid, char* resource_id, unsign
memset(dbKey, 0, dbKeyMaxLen);
memset(dbPath, 0, dbPathMaxLen);
+ dbContext.context.ldbid = ldbid;
+ dbContext.context.seat_no = seat_no;
+ dbContext.context.user_no = user_no;
+
+ // get database context: database path and database key
+ rval = get_db_context(&dbContext, resource_id, resIsNoFile, dbKey, dbPath);
+
// registration is only on shared key possible
- if(PersistenceStorage_shared == get_db_context(ldbid, resource_id, user_no, seat_no, resIsNoFile, dbKey, dbPath))
+ if(PersistenceStorage_shared == rval)
{
rval = persistence_reg_notify_on_change(dbPath, dbKey);
}
diff --git a/src/persistence_client_library_lc_interface.c b/src/persistence_client_library_lc_interface.c
index e48992f..69ce19a 100644
--- a/src/persistence_client_library_lc_interface.c
+++ b/src/persistence_client_library_lc_interface.c
@@ -47,6 +47,7 @@
#include <unistd.h>
#include <dlfcn.h>
+static int gTimeoutMs = 500;
int check_lc_request(int request)
{
@@ -152,7 +153,7 @@ DBusHandlerResult checkLifecycleMsg(DBusConnection * connection, DBusMessage * m
//printf("handleObjectPathMessage '%s' -> '%s'\n", dbus_message_get_interface(message), dbus_message_get_member(message));
if((0==strncmp("com.contiautomotive.NodeStateManager.LifecycleConsumer", dbus_message_get_interface(message), 20)))
{
- if((0==strncmp("LifecycleRequest", dbus_message_get_member(message), 18)))
+ if((0==strncmp("NSMLifecycleRequest", dbus_message_get_member(message), 18)))
{
result = msg_lifecycleRequest(connection, message);
}
@@ -166,29 +167,27 @@ DBusHandlerResult checkLifecycleMsg(DBusConnection * connection, DBusMessage * m
-
-
-
-int send_lifecycle_register(const char* method, const char* busname, const char* objName,
- int shutdownMode, int TimeoutMs)
+int send_lifecycle_register(const char* method, int shutdownMode)
{
int rval = 0;
DBusError error;
dbus_error_init (&error);
-
DBusConnection* conn = get_dbus_connection();
+ const char* objName = "/com/contiautomotive/NodeStateManager/LifecycleConsumer";
+ const char* busName = dbus_bus_get_unique_name(conn);
+
DBusMessage* message = dbus_message_new_method_call("com.contiautomotive.NodeStateManager.Consumer", // destination
"/com/contiautomotive/NodeStateManager/Consumer", // path
"com.contiautomotive.NodeStateManager.Consumer", // interface
method); // method
if(message != NULL)
{
- dbus_message_append_args(message, DBUS_TYPE_STRING, &busname,
+ dbus_message_append_args(message, DBUS_TYPE_STRING, &busName,
DBUS_TYPE_STRING, &objName,
DBUS_TYPE_INT32, &shutdownMode,
- DBUS_TYPE_INT32, &TimeoutMs,
+ DBUS_TYPE_INT32, &gTimeoutMs,
DBUS_TYPE_INVALID);
if(conn != NULL)
@@ -216,51 +215,6 @@ int send_lifecycle_register(const char* method, const char* busname, const char*
-int send_lifecycle_un_register(const char* method, const char* busname, const char* objName, int shutdownMode)
-{
- int rval = 0;
-
- DBusError error;
- dbus_error_init (&error);
-
- DBusConnection* conn = get_dbus_connection();
-
- DBusMessage* message = dbus_message_new_method_call("com.contiautomotive.NodeStateManager.Consumer", // destination
- "/com/contiautomotive/NodeStateManager/Consumer", // path
- "com.contiautomotive.NodeStateManager.Consumer", // interface
- method); // method
- if(message != NULL)
- {
- dbus_message_append_args(message, DBUS_TYPE_STRING, &busname,
- DBUS_TYPE_STRING, &objName,
- DBUS_TYPE_INT32, &shutdownMode,
- DBUS_TYPE_INVALID);
-
- if(conn != NULL)
- {
- if(!dbus_connection_send(conn, message, 0))
- {
- fprintf(stderr, "send_lifecycle ==> Access denied: %s \n", error.message);
- }
-
- dbus_connection_flush(conn);
- }
- else
- {
- fprintf(stderr, "send_lifecycle ==> ERROR: Invalid connection!! \n");
- rval = -1;
- }
- dbus_message_unref(message);
- }
- else
- {
- fprintf(stderr, "send_lifecycle ==> ERROR: Invalid message!! \n");
- rval = -1;
- }
-
- return rval;
-}
-
int send_lifecycle_request(const char* method, int requestId, int status)
{
int rval = 0;
@@ -307,23 +261,18 @@ int send_lifecycle_request(const char* method, int requestId, int status)
int register_lifecycle()
{
- const char* objName = "objName";
int shutdownMode = 88; // TODO send correct mode
- int TimeoutMs = 500; // TODO send timeout
- return send_lifecycle_register("RegisterShutdownClient",
- dbus_bus_get_unique_name(get_dbus_connection()), objName, shutdownMode, TimeoutMs);
+ return send_lifecycle_register("RegisterShutdownClient", shutdownMode);
}
int unregister_lifecycle()
{
- const char* objName = "objName";
int shutdownMode = 88; // TODO send correct mode
- return send_lifecycle_un_register("UnRegisterShutdownClient",
- dbus_bus_get_unique_name(get_dbus_connection()), objName, shutdownMode);
+ return send_lifecycle_register("UnRegisterShutdownClient", shutdownMode);
}
@@ -367,8 +316,10 @@ void process_prepare_shutdown(unsigned char requestId)
}
//close opend database
- database_close(PersistenceStorage_local);
- database_close(PersistenceStorage_shared);
+ database_close(PersistenceStorage_local, PersistencePolicy_wc);
+ database_close(PersistenceStorage_local, PersistencePolicy_wt);
+ database_close(PersistenceStorage_shared, PersistencePolicy_wc);
+ database_close(PersistenceStorage_shared, PersistencePolicy_wt);
// unload custom client libraries
diff --git a/src/persistence_client_library_pas_interface.c b/src/persistence_client_library_pas_interface.c
index 72b1923..f04730c 100644
--- a/src/persistence_client_library_pas_interface.c
+++ b/src/persistence_client_library_pas_interface.c
@@ -39,6 +39,8 @@
#include <unistd.h>
+static int gTimeoutMs = 500;
+
/// flag if access is locked
static int gLockAccess = 0;
@@ -64,7 +66,7 @@ int isAccessLocked(void)
}
-int check_pas_request(int request)
+int check_pas_request(unsigned int request, unsigned int requestID)
{
int rval = 0;
@@ -101,20 +103,25 @@ int check_pas_request(int request)
}
-int msg_persAdminRequest(DBusConnection *connection, DBusMessage *message)
+
+
+
+DBusHandlerResult msg_persAdminRequest(DBusConnection *connection, DBusMessage *message)
{
- int request = 0,
- msgReturn = 0;
+ int request = 0, requestID = 0;
+ int errorCode = 0;
DBusMessage *reply;
DBusError error;
dbus_error_init (&error);
- if (!dbus_message_get_args (message, &error, DBUS_TYPE_INT32 , &request, DBUS_TYPE_INVALID))
+ if (!dbus_message_get_args (message, &error, DBUS_TYPE_INT32 , &request,
+ DBUS_TYPE_INT32 , &requestID,
+ DBUS_TYPE_INVALID))
{
reply = dbus_message_new_error(message, error.name, error.message);
- if (reply == 0)
+ if(reply == 0)
{
//DLT_LOG(mgrContext, DLT_LOG_ERROR, DLT_STRING("DBus No memory"));
printf("DBus No memory\n");
@@ -131,7 +138,64 @@ int msg_persAdminRequest(DBusConnection *connection, DBusMessage *message)
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
- msgReturn = check_pas_request(request);
+ errorCode = check_pas_request(request, requestID);
+
+ reply = dbus_message_new_method_return(message);
+
+ if (reply == 0)
+ {
+ //DLT_LOG(mgrContext, DLT_LOG_ERROR, DLT_STRING("DBus No memory"));
+ printf("DBus No memory\n");
+ }
+
+ if (!dbus_message_append_args(reply, DBUS_TYPE_INT32, &errorCode, DBUS_TYPE_INVALID))
+ {
+ //DLT_LOG(mgrContext, DLT_LOG_ERROR, DLT_STRING("DBus No memory"));
+ printf("DBus No memory\n");
+ }
+
+ if (!dbus_connection_send(connection, reply, 0))
+ {
+ //DLT_LOG(mgrContext, DLT_LOG_ERROR, DLT_STRING("DBus No memory"));
+ printf("DBus No memory\n");
+ }
+
+ dbus_connection_flush(connection);
+ dbus_message_unref(reply);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+int signal_persModeChange(DBusConnection *connection, DBusMessage *message)
+{
+ int persistenceMode = 0;
+ int errorCode = 0;
+
+ DBusMessage *reply;
+ DBusError error;
+ dbus_error_init (&error);
+
+ if (!dbus_message_get_args (message, &error, DBUS_TYPE_INT32 , &persistenceMode,
+ DBUS_TYPE_INVALID))
+ {
+ reply = dbus_message_new_error(message, error.name, error.message);
+
+ if(reply == 0)
+ {
+ //DLT_LOG(mgrContext, DLT_LOG_ERROR, DLT_STRING("DBus No memory"));
+ printf("DBus No memory\n");
+ }
+
+ if (!dbus_connection_send(connection, reply, 0))
+ {
+ //DLT_LOG(mgrContext, DLT_LOG_ERROR, DLT_STRING("DBus No memory"));
+ printf("DBus No memory\n");
+ }
+
+ dbus_message_unref (reply);
+
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
reply = dbus_message_new_method_return(message);
@@ -141,7 +205,7 @@ int msg_persAdminRequest(DBusConnection *connection, DBusMessage *message)
printf("DBus No memory\n");
}
- if (!dbus_message_append_args(reply, DBUS_TYPE_INT32, &msgReturn, DBUS_TYPE_INVALID))
+ if (!dbus_message_append_args(reply, DBUS_TYPE_INT32, &errorCode, DBUS_TYPE_INVALID))
{
//DLT_LOG(mgrContext, DLT_LOG_ERROR, DLT_STRING("DBus No memory"));
printf("DBus No memory\n");
@@ -159,24 +223,50 @@ int msg_persAdminRequest(DBusConnection *connection, DBusMessage *message)
return DBUS_HANDLER_RESULT_HANDLED;
}
+/*
+DBusHandlerResult checkPersAdminSignal(DBusConnection *connection, DBusMessage *message, void *user_data)
+{
+ DBusHandlerResult result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ printf("checkPersAdminSignalInterface '%s' -> '%s'\n", dbus_message_get_interface(message), dbus_message_get_member(message));
+
+ if((0==strcmp("org.genivi.persistence.admin", dbus_message_get_interface(message))))
+ {
+ if(dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_SIGNAL)
+ {
+ printf("checkPersAdminSignal signal\n");
+ if((0==strcmp("PersistenceModeChanged", dbus_message_get_member(message))))
+ {
+ printf("checkPersAdminSignal signal\n");
+ // to do handle signal
+ result = signal_persModeChange(connection, message);
+ }
+ else
+ {
+ printf("checkPersAdminMsg -> unknown signal '%s'\n", dbus_message_get_interface(message));
+ }
+ }
+ }
+ return result;
+}
+*/
DBusHandlerResult checkPersAdminMsg(DBusConnection * connection, DBusMessage * message, void * user_data)
{
DBusHandlerResult result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- //printf("handleObjectPathMessage '%s' -> '%s'\n", dbus_message_get_interface(message), dbus_message_get_member(message));
- if((0==strncmp("org.genivi.persistence.admin", dbus_message_get_interface(message), 20)))
+ //printf("checkPersAdminMsg '%s' -> '%s'\n", dbus_message_get_interface(message), dbus_message_get_member(message));
+ if((0==strcmp("org.genivi.persistence.adminconsumer", dbus_message_get_interface(message))))
{
- if((0==strncmp("PersistenceAdminRequest", dbus_message_get_member(message), 14)))
+ if((0==strcmp("PersistenceAdminRequest", dbus_message_get_member(message))))
{
result = msg_persAdminRequest(connection, message);
}
else
{
- printf("checkPersAdminMsg -> unknown message '%s'\n", dbus_message_get_interface(message));
+ printf("checkPersAdminMsg -> unknown message '%s'\n", dbus_message_get_interface(message));
}
}
return result;
@@ -184,31 +274,43 @@ DBusHandlerResult checkPersAdminMsg(DBusConnection * connection, DBusMessage * m
-
-int send_pas_register(const char* method, const char* appname)
+int send_pas_register(const char* method, int notificationFlag)
{
int rval = 0;
DBusError error;
dbus_error_init (&error);
+ DBusMessage *replyMsg = NULL;
DBusConnection* conn = get_dbus_connection();
+ const char* objName = "/org/genivi/persistence/adminconsumer";
+ const char* busName = dbus_bus_get_unique_name(conn);
+
DBusMessage* message = dbus_message_new_method_call("org.genivi.persistence.admin", // destination
"/org/genivi/persistence/admin", // path
"org.genivi.persistence.admin", // interface
method); // method
if(message != NULL)
{
- dbus_message_append_args(message, DBUS_TYPE_STRING, &appname, DBUS_TYPE_INVALID);
+ dbus_message_append_args(message, DBUS_TYPE_STRING, &busName, // bus name
+ DBUS_TYPE_STRING, &objName,
+ DBUS_TYPE_INT32, &notificationFlag,
+ DBUS_TYPE_INT32, &gTimeoutMs,
+ DBUS_TYPE_INVALID);
if(conn != NULL)
{
- if(!dbus_connection_send(conn, message, 0))
+ replyMsg = dbus_connection_send_with_reply_and_block(conn, message, gTimeoutMs, &error);
+ if(dbus_set_error_from_message(&error, replyMsg))
{
- fprintf(stderr, "send_pers_admin_service ==> Access denied: %s \n", error.message);
+ fprintf(stderr, "sendDBusMessage ==> Access denied: %s \n", error.message);
+ }
+ else
+ {
+ dbus_message_get_args(replyMsg, &error, DBUS_TYPE_INT32, &rval, DBUS_TYPE_INVALID);
}
- dbus_connection_flush(conn);
+ dbus_message_unref(message);
}
else
{
@@ -228,12 +330,13 @@ int send_pas_register(const char* method, const char* appname)
-int send_pas_request(const char* method, int blockStatus)
+int send_pas_request(const char* method, unsigned int requestID, int status)
{
int rval = 0;
DBusError error;
dbus_error_init (&error);
+ DBusMessage *replyMsg = NULL;
DBusConnection* conn = get_dbus_connection();
DBusMessage* message = dbus_message_new_method_call("org.genivi.persistence.admin", // destination
@@ -242,18 +345,23 @@ int send_pas_request(const char* method, int blockStatus)
method); // method
if(message != NULL)
{
- dbus_message_append_args(message, DBUS_TYPE_UINT32, &blockStatus, DBUS_TYPE_INVALID);
-
+ dbus_message_append_args(message, DBUS_TYPE_UINT32, &requestID,
+ DBUS_TYPE_INT32, &status,
+ DBUS_TYPE_INVALID);
if(conn != NULL)
{
- if(!dbus_connection_send(conn, message, 0))
+ replyMsg = dbus_connection_send_with_reply_and_block(conn, message, gTimeoutMs, &error);
+ if(dbus_set_error_from_message(&error, replyMsg))
{
- fprintf(stderr, "send_pers_admin_service ==> Access denied: %s \n", error.message);
- rval = -1;
+ fprintf(stderr, "sendDBusMessage ==> Access denied: %s \n", error.message);
+ }
+ else
+ {
+ dbus_message_get_args(replyMsg, &error, DBUS_TYPE_INT32, &rval, DBUS_TYPE_INVALID);
}
- dbus_connection_flush(conn);
+ dbus_message_unref(message);
}
else
{
@@ -273,25 +381,34 @@ int send_pas_request(const char* method, int blockStatus)
-
int register_pers_admin_service(void)
{
- return send_pas_register("RegisterPersAdminNotification", gAppId);
+ int notificationFlag = 88; // TODO send correct notification flag
+
+ return send_pas_register("RegisterPersAdminNotification", notificationFlag);
}
+
int unregister_pers_admin_service(void)
{
- return send_pas_register("UnRegisterPersAdminNotification", gAppId);
+ int notificationFlag = 88; // TODO send correct notification flag
+
+ return send_pas_register("UnRegisterPersAdminNotification", notificationFlag);
}
+
int pers_admin_service_data_sync_complete(void)
{
- return send_pas_request("PersistenceAdminRequestCompleted", 1);
+ unsigned int requestID = 0;
+ int status = 0;
+
+ return send_pas_request("PersistenceAdminRequestCompleted", requestID, status);
}
+
void process_block_and_write_data_back(void)
{
// lock persistence data access
diff --git a/src/persistence_client_library_pas_interface.h b/src/persistence_client_library_pas_interface.h
index ad911e1..e5ac3df 100644
--- a/src/persistence_client_library_pas_interface.h
+++ b/src/persistence_client_library_pas_interface.h
@@ -48,6 +48,10 @@
*/
DBusHandlerResult checkPersAdminMsg(DBusConnection * connection, DBusMessage * message, void * user_data);
+//DBusHandlerResult checkPersAdminSignal(DBusConnection * connection, DBusMessage * message, void * user_data);
+
+
+int signal_persModeChange(DBusConnection *connection, DBusMessage *message);
/// synchronize data back to memory device
int pers_data_sync(void);
diff --git a/test/data/Data.tar.gz b/test/data/Data.tar.gz
index beaf27a..f906a35 100644
--- a/test/data/Data.tar.gz
+++ b/test/data/Data.tar.gz
Binary files differ
diff --git a/test/persistence_client_library_test.c b/test/persistence_client_library_test.c
index 2d4784a..54b7009 100644
--- a/test/persistence_client_library_test.c
+++ b/test/persistence_client_library_test.c
@@ -64,38 +64,41 @@ START_TEST (test_GetData)
unsigned char buffer[READ_SIZE];
memset(buffer, 0, READ_SIZE);
- ret = key_read_data(0xFF, "language/country_code", 0, 0, buffer, READ_SIZE); // "/Data/mnt-c/Appl-1/cached.gvdb" => "/Node/pos/last position"
- fail_unless(strncmp((char*)buffer, "Custom plugin -> plugin_get_data_handle", strlen((char*)buffer)) == 0, "Buffer not correctly read");
+ ret = key_read_data(0xFF, "language/country_code", 0, 0, buffer, READ_SIZE);
+ fail_unless(strncmp((char*)buffer, "Custom plugin -> plugin_get_data_handle",
+ strlen((char*)buffer)) == 0, "Buffer not correctly read");
fail_unless(ret = strlen("Custom plugin -> plugin_get_data_handle"));
memset(buffer, 0, READ_SIZE);
- ret = key_read_data(0xFF, "pos/last_position", 0, 0, buffer, READ_SIZE); // "/Data/mnt-c/Appl-1/cached.gvdb" => "/Node/pos/last position"
- fail_unless(strncmp((char*)buffer, "+48° 10' 38.95\", +8° 44' 39.06\"", strlen((char*)buffer)) == 0, "Buffer not correctly read");
- fail_unless(ret = strlen("+48° 10' 38.95\", +8° 44' 39.06\""));
+ ret = key_read_data(0xFF, "pos/last_position", 0, 0, buffer, READ_SIZE);
+ fail_unless(strncmp((char*)buffer, "CACHE_ +48° 10' 38.95\", +8° 44' 39.06\"",
+ strlen((char*)buffer)) == 0, "Buffer not correctly read");
+ fail_unless(ret = strlen("CACHE_ +48° 10' 38.95\", +8° 44' 39.06\""));
memset(buffer, 0, READ_SIZE);
- ret = key_read_data(0, "language/current_language", 3, 0, buffer, READ_SIZE); // "/Data/mnt-wt/Shared/Public/wt.dconf" => "/User/3/language/current_language"
- fail_unless(strncmp((char*)buffer, "Kisuaheli", strlen((char*)buffer)) == 0, "Buffer not correctly read");
+ ret = key_read_data(0, "language/current_language", 3, 0, buffer, READ_SIZE);
+ printf("Buffer: %s \n", buffer);
+ fail_unless(strncmp((char*)buffer, "CACHE_ Kisuaheli", strlen((char*)buffer)) == 0, "Buffer not correctly read");
memset(buffer, 0, READ_SIZE);
- ret = key_read_data(0xFF, "status/open_document", 3, 2, buffer, READ_SIZE); // "/Data/mnt-c/Appl-1/cached.gvdb" => "/User/3/Seat/2/status/open_document"
- fail_unless(strncmp((char*)buffer, "/var/opt/user_manual_climateControl.pdf", strlen((char*)buffer)) == 0, "Buffer not correctly read");
+ ret = key_read_data(0xFF, "status/open_document", 3, 2, buffer, READ_SIZE);
+ fail_unless(strncmp((char*)buffer, "WT_ /var/opt/user_manual_climateControl.pdf", strlen((char*)buffer)) == 0, "Buffer not correctly read");
memset(buffer, 0, READ_SIZE);
- ret = key_read_data(0x20, "address/home_address", 4, 0, buffer, READ_SIZE); // "/Data/mnt-c/Shared/Group/20/cached.dconf" => "/User/4/address/home_address"
- fail_unless(strncmp((char*)buffer, "55327 Heimatstadt, Wohnstrasse 31", strlen((char*)buffer)) == 0, "Buffer not correctly read");
+ ret = key_read_data(0x20, "address/home_address", 4, 0, buffer, READ_SIZE);
+ fail_unless(strncmp((char*)buffer, "WT_ 55327 Heimatstadt, Wohnstrasse 31", strlen((char*)buffer)) == 0, "Buffer not correctly read");
memset(buffer, 0, READ_SIZE);
- ret = key_read_data(0xFF, "pos/last_satellites", 0, 0, buffer, READ_SIZE); // "/Data/mnt-wt/Appl-1/wt.gvdb" => "/Node/pos/last satellites"
- fail_unless(strncmp((char*)buffer, "17", strlen((char*)buffer)) == 0, "Buffer not correctly read");
+ ret = key_read_data(0xFF, "pos/last_satellites", 0, 0, buffer, READ_SIZE);
+ fail_unless(strncmp((char*)buffer, "WT_ 17", strlen((char*)buffer)) == 0, "Buffer not correctly read");
memset(buffer, 0, READ_SIZE);
- ret = key_read_data(0x84, "links/last_link", 2, 0, buffer, READ_SIZE); // "/Data/mnt-wt/Appl-2/wt.gvdb" => "/84/User/2/links/last link"
- fail_unless(strncmp((char*)buffer, "/last_exit/brooklyn", strlen((char*)buffer)) == 0, "Buffer not correctly read");
+ ret = key_read_data(0x84, "links/last_link", 2, 0, buffer, READ_SIZE);
+ fail_unless(strncmp((char*)buffer, "CACHE_ /last_exit/brooklyn", strlen((char*)buffer)) == 0, "Buffer not correctly read");
memset(buffer, 0, READ_SIZE);
- ret = key_read_data(0x84, "links/last_link", 2, 1, buffer, READ_SIZE); // "/Data/mnt-wt/Appl-2/wt.gvdb" => "/84/User/2/links/last link"
- fail_unless(strncmp((char*)buffer, "/last_exit/queens", strlen((char*)buffer)) == 0, "Buffer not correctly read");
+ ret = key_read_data(0x84, "links/last_link", 2, 1, buffer, READ_SIZE);
+ fail_unless(strncmp((char*)buffer, "CACHE_ /last_exit/queens", strlen((char*)buffer)) == 0, "Buffer not correctly read");
}
END_TEST
@@ -120,10 +123,10 @@ START_TEST (test_GetDataHandle)
fail_unless(handle >= 0, "Failed to open handle ==> /posHandle/last position");
ret = key_handle_read_data(handle, buffer, READ_SIZE);
- fail_unless(strncmp((char*)buffer, "H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\"", ret-1) == 0, "Buffer not correctly read");
+ fail_unless(strncmp((char*)buffer, "WT_ H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\"", ret-1) == 0, "Buffer not correctly read");
size = key_handle_get_size(handle);
- fail_unless(size = strlen("H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\""));
+ fail_unless(size = strlen("WT_ H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\""));
// open handle ---------------------------------------------------
@@ -227,10 +230,10 @@ START_TEST(test_GetDataSize)
int size = 0;
size = key_get_size(0xFF, "status/open_document", 3, 2);
- fail_unless(size == strlen("/var/opt/user_manual_climateControl.pdf"), "Invalid size");
+ fail_unless(size == strlen("WT_ /var/opt/user_manual_climateControl.pdf"), "Invalid size");
size = key_get_size(0x84, "links/last_link", 2, 1);
- fail_unless(size == strlen("/last_exit/queens"), "Invalid size");
+ fail_unless(size == strlen("CACHE_ /last_exit/queens"), "Invalid size");
}
END_TEST
@@ -446,55 +449,59 @@ END_TEST
START_TEST(test_Cursor)
{
int handle = -1, rval = 0, size = 0, handle1 = 0;
- char bufferKey[READ_SIZE];
- char bufferData[READ_SIZE];
- memset(bufferKey, 0, READ_SIZE);
- memset(bufferData, 0, READ_SIZE);
+ char bufferKeySrc[READ_SIZE];
+ char bufferDataSrc[READ_SIZE];
+ char bufferKeyDst[READ_SIZE];
+ char bufferDataDst[READ_SIZE];
+
+ memset(bufferKeySrc, 0, READ_SIZE);
+ memset(bufferDataSrc, 0, READ_SIZE);
+
+ memset(bufferKeyDst, 0, READ_SIZE);
+ memset(bufferDataDst, 0, READ_SIZE);
// create cursor
- handle = persistence_db_cursor_create("/Data/mnt-c/lt-persistence_client_library_test/cached.itz", PersistenceStorage_local);
+ handle = persistence_db_cursor_create("/Data/mnt-c/lt-persistence_client_library_test/cached.itz",
+ PersistenceStorage_local, PersistencePolicy_wc);
+ printf("Handle : %d \n", handle);
fail_unless(handle != -1, "Failed to create cursor!!");
+
+ // create cursor
+ handle1 = persistence_db_cursor_create("/Data/mnt-c/lt-persistence_client_library_test/wt.itz",
+ PersistenceStorage_local, PersistencePolicy_wt);
+ printf("Handle1 : %d \n", handle1);
+ fail_unless(handle1 != -1, "Failed to create cursor!!");
+
do
{
- memset(bufferKey, 0, READ_SIZE);
- memset(bufferData, 0, READ_SIZE);
+ memset(bufferKeySrc, 0, READ_SIZE);
+ memset(bufferDataSrc, 0, READ_SIZE);
+ memset(bufferKeyDst, 0, READ_SIZE);
+ memset(bufferDataDst, 0, READ_SIZE);
+
// get key
- rval = persistence_db_cursor_get_key(handle, bufferKey, 128);
+ rval = persistence_db_cursor_get_key(handle, bufferKeySrc, 128);
fail_unless(rval != -1, "Cursor failed to get key!!");
// get data
- rval = persistence_db_cursor_get_data(handle, bufferData, 128);
+ rval = persistence_db_cursor_get_data(handle, bufferDataSrc, 128);
fail_unless(rval != -1, "Cursor failed to get data!!");
// get size
size = persistence_db_cursor_get_data_size(handle);
fail_unless(size != -1, "Cursor failed to get size!!");
+ //printf("1. Key: %s | Data: %s » Size: %d \n", bufferKeySrc, bufferDataSrc, size);
- //printf("Key: %s | Data: %s » Size: %d \n", bufferKey, bufferData, size);
- }
- while(persistence_db_cursor_next(handle) == 0); // next cursor
-
- // create cursor
- handle1 = persistence_db_cursor_create("/Data/mnt-c/lt-persistence_client_library_test/wt.itz", PersistenceStorage_local);
- printf("Handle1: %d \n", handle1);
- fail_unless(handle1 != -1, "Failed to create cursor!!");
- do
- {
- memset(bufferKey, 0, READ_SIZE);
- memset(bufferData, 0, READ_SIZE);
// get key
- rval = persistence_db_cursor_get_key(handle1, bufferKey, 128);
+ rval = persistence_db_cursor_get_key(handle1, bufferKeyDst, 128);
fail_unless(rval != -1, "Cursor failed to get key!!");
// get data
- rval = persistence_db_cursor_get_data(handle1, bufferData, 128);
+ rval = persistence_db_cursor_get_data(handle1, bufferDataDst, 128);
fail_unless(rval != -1, "Cursor failed to get data!!");
// get size
size = persistence_db_cursor_get_data_size(handle1);
fail_unless(size != -1, "Cursor failed to get size!!");
-
- //printf("Key: %s | Data: %s » Size: %d \n", bufferKey, bufferData, size);
+ //printf(" 2. Key: %s | Data: %s » Size: %d \n", bufferKeyDst, bufferDataDst, size);
}
- while(persistence_db_cursor_next(handle1) == 0); // next cursor
-
-
+ while( (persistence_db_cursor_next(handle) == 0) && (persistence_db_cursor_next(handle1) == 0) ); // next cursor
// destory cursor
rval = persistence_db_cursor_destroy(handle);