summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--Makefile.am6
-rw-r--r--configure.ac11
-rw-r--r--data/Data.tar.gzbin2862 -> 0 bytes
-rw-r--r--include/persistence_client_library_file.h12
-rw-r--r--include/persistence_client_library_key.h9
-rw-r--r--persistence_client_library.pc.in2
-rw-r--r--src/Makefile.am18
-rw-r--r--src/persistence_client_library.c35
-rw-r--r--src/persistence_client_library.h6
-rw-r--r--src/persistence_client_library_access_helper.c72
-rw-r--r--src/persistence_client_library_custom_loader.c55
-rw-r--r--src/persistence_client_library_custom_loader.h34
-rw-r--r--src/persistence_client_library_data_access.c17
-rw-r--r--src/persistence_client_library_data_access.h3
-rw-r--r--src/persistence_client_library_dbus_service.c10
-rw-r--r--src/persistence_client_library_dbus_service.h25
-rw-r--r--src/persistence_client_library_file.c8
-rw-r--r--src/persistence_client_library_handle.c5
-rw-r--r--src/persistence_client_library_handle.h1
-rw-r--r--src/persistence_client_library_key.c49
-rw-r--r--src/persistence_client_library_lc_interface.c38
-rw-r--r--src/persistence_client_library_lc_interface.h30
-rw-r--r--src/persistence_client_library_pas_interface.c23
-rw-r--r--src/persistence_client_library_pas_interface.h44
-rw-r--r--test/data/Data.tar.gzbin0 -> 2967 bytes
-rw-r--r--test/persistence_client_library_dbus_test.c4
-rw-r--r--test/persistence_client_library_test.c50
28 files changed, 418 insertions, 157 deletions
diff --git a/ChangeLog b/ChangeLog
index e69de29..4caf5d0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -0,0 +1,8 @@
+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
+- Update after code review; corrected package config; updated tests and test data
+- Now custom client lib functions will be called; Added debug configure switch (debug was by default activated)
+- Added debug version to configure; Now custom client lib functions will be called; stabilized custom library feature; added new test data
diff --git a/Makefile.am b/Makefile.am
index 4d8d24d..580b7a9 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -4,9 +4,9 @@ if WANT_TESTS
SUBDIRS+=test
endif
-#pkgconfigdir=$(libdir)/pkgconfig
-#pkgconfig_DATA=persistence_clientlib.pc
+pkgconfigdir=$(libdir)/pkgconfig
+pkgconfig_DATA=persistence_client_library.pc
MAINTAINERCLEANFILES = \
Makefile.in aclocal.m4 compile config.guess config.h.in config.sub \
- configure depcomp install-sh ltmain.sh persistence_clientlib.pc.in config.h.in~ Makefile missing
+ configure depcomp install-sh ltmain.sh persistence_client_library.pc config.h.in~ Makefile missing
diff --git a/configure.ac b/configure.ac
index eec633d..690ac89 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.1], [not-valid@xse.de])
+AC_INIT([Persistence Client Library], [0.1.4], [not-valid@xse.de])
AC_CONFIG_SRCDIR([Makefile.am])
AM_INIT_AUTOMAKE([dist-bzip2])
AC_GNU_SOURCE()
@@ -50,6 +50,7 @@ PKG_CHECK_MODULES(DEPS,
automotive-dlt
dbus-1
dconf
+ dconf-dbus-1
glib-2.0)
AC_SUBST(DEPS_CFLAGS)
@@ -90,11 +91,9 @@ esac],
AM_CONDITIONAL(DEBUG, test x"$debug" = x"true")
-#AC_CONFIG_FILES([Makefile
-# persistence_client_library.pc
-# src/Makefile
-# test/Makefile])
AC_CONFIG_FILES([Makefile
+ persistence_client_library.pc
src/Makefile
- test/Makefile])
+ test/Makefile])
+
AC_OUTPUT
diff --git a/data/Data.tar.gz b/data/Data.tar.gz
deleted file mode 100644
index 08a2061..0000000
--- a/data/Data.tar.gz
+++ /dev/null
Binary files differ
diff --git a/include/persistence_client_library_file.h b/include/persistence_client_library_file.h
index 0059de6..2d1a6f6 100644
--- a/include/persistence_client_library_file.h
+++ b/include/persistence_client_library_file.h
@@ -33,7 +33,13 @@
* Library provides an API to access persistent data
* @see
*/
-
+/** \ingroup SSW_PERS */
+/** \defgroup SSW_PERS_FILE Client: File access
+ * \{
+ */
+/** \defgroup SSW_PERS_FILE_INTERFACE API document
+ * \{
+ */
#ifdef __cplusplus
extern "C" {
#endif
@@ -174,5 +180,9 @@ int file_write_data(int fd, const void * buffer, unsigned long buffer_size);
#endif
+/** \} */ /* End of API */
+/** \} */ /* End of MODULE */
+
+
#endif /* PERSISTENCY_CLIENT_LIBRARY_FILE_H */
diff --git a/include/persistence_client_library_key.h b/include/persistence_client_library_key.h
index 61550cc..7818916 100644
--- a/include/persistence_client_library_key.h
+++ b/include/persistence_client_library_key.h
@@ -33,6 +33,13 @@
* Library provides an API to access persistent data
* @see
*/
+/** \ingroup SSW_PERS */
+/** \defgroup SSW_PERS_KEYVALUE Client: Key-value access
+ * \{
+ */
+/** \defgroup SSW_PERS_KEYVALUE_INTERFACE API document
+ * \{
+ */
#ifdef __cplusplus
extern "C" {
@@ -193,6 +200,8 @@ int key_write_data(unsigned char ldbid, char* resource_id, unsigned char user_no
}
#endif
+/** \} */ /* End of API */
+/** \} */ /* End of MODULE */
#endif /* PERSISTENCY_CLIENT_LIBRARY_KEY_H */
diff --git a/persistence_client_library.pc.in b/persistence_client_library.pc.in
index 819fc9a..e3d982d 100644
--- a/persistence_client_library.pc.in
+++ b/persistence_client_library.pc.in
@@ -9,5 +9,5 @@ Name: persistence client library
Description: persistence client library
Version: @VERSION@
Requires: automotive-dlt glib-2.0
-Libs: -L${libdir} -lmygvdb -lrt -lglib-2.0 -ldl
+Libs: -L${libdir} -lgvdb -lrt -lglib-2.0 -ldl
Cflags: -I${includedir}
diff --git a/src/Makefile.am b/src/Makefile.am
index 3f59e3f..bf9b0b3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -2,16 +2,16 @@ AUTOMAKE_OPTIONS = foreign
if DEBUG
AM_CFLAGS =$(DEPS_CFLAGS) -g -I../include \
- -I/usr/include/glib-2.0 \
- -I/usr/include/dbus-1.0 \
- -I/usr/include/dconf-dbus-1 \
- -I/usr/lib/glib-2.0/include
+ -Iglib-2.0 \
+ -Idbus-1.0 \
+ -Idconf-dbus-1 \
+ -Iglib-2.0/include
else
AM_CFLAGS =$(DEPS_CFLAGS) -I../include \
- -I/usr/include/glib-2.0 \
- -I/usr/include/dbus-1.0 \
- -I/usr/include/dconf-dbus-1 \
- -I/usr/lib/glib-2.0/include
+ -Iglib-2.0 \
+ -Idbus-1.0 \
+ -Idconf-dbus-1 \
+ -Iglib-2.0/include
endif
@@ -19,7 +19,7 @@ include_HEADERS = ../include/persistence_client_library_key.h ../include/persist
lib_LTLIBRARIES = libpersistence_client_library.la
-libpersistence_client_library_la_LIBADD = $(DEPS_LIBS) -ldconf -ldl -ldconf-dbus-1 -lmygvdb
+libpersistence_client_library_la_LIBADD = $(DEPS_LIBS) -ldconf -ldl -ldconf-dbus-1 -lgvdb
libpersistence_client_library_la_SOURCES = \
persistence_client_library.c \
diff --git a/src/persistence_client_library.c b/src/persistence_client_library.c
index f928cbf..6ae15ac 100644
--- a/src/persistence_client_library.c
+++ b/src/persistence_client_library.c
@@ -48,6 +48,7 @@
#include <dlt/dlt.h>
#include <dlt/dlt_common.h>
+extern char* __progname;
/// debug log and trace (DLT) setup
DLT_DECLARE_CONTEXT(persClientLibCtx);
@@ -100,8 +101,8 @@ const char* gSharedPublicWtPath = "/Data/mnt-wt/shared/public%s";
/// application id
char gAppId[maxAppNameLen];
-/// max key value data size
-int gMaxKeyValDataSize;
+/// max key value data size [default 16kB]
+int gMaxKeyValDataSize = defaultMaxKeyValDataSize;
/// library constructor
@@ -120,7 +121,7 @@ void pers_library_init(void)
DLT_LOG(persClientLibCtx, DLT_LOG_ERROR, DLT_STRING("Initialize Persistence Client Library!!!!"));
/// environment variable for on demand loading of custom libraries
- const char *pOnDemenaLoad = getenv("PERS_CUSTOM_LIB_LOAD_ON_DEMAND");
+ const char *pOnDemandLoad = getenv("PERS_CUSTOM_LIB_LOAD_ON_DEMAND");
/// environment variable for max key value data
const char *pDataSize = getenv("PERS_MAX_KEY_VAL_DATA_SIZE");
@@ -130,9 +131,15 @@ void pers_library_init(void)
gMaxKeyValDataSize = atoi(pDataSize);
}
+ // initialize mutex
+ pthread_mutex_init(&gDbusInitializedMtx, NULL);
+
// setup dbus main dispatching loop
setup_dbus_mainloop();
+ // wain until dbus main loop has been setup and running
+ pthread_mutex_lock(&gDbusInitializedMtx);
+
// register for lifecycle and persistence admin service dbus messages
register_lifecycle();
register_pers_admin_service();
@@ -143,7 +150,7 @@ void pers_library_init(void)
/// get custom library names to load
get_custom_libraries();
- if(pOnDemenaLoad == NULL) // load all available libraries now
+ if(pOnDemandLoad == NULL) // load all available libraries now
{
int i = 0;
@@ -155,7 +162,6 @@ void pers_library_init(void)
break;
}
gPersCustomFuncs[i].custom_plugin_init();
-
}
/// just testing
@@ -163,27 +169,16 @@ void pers_library_init(void)
//gPersCustomFuncs[PersCustomLib_early].custom_plugin_close(17);
}
- printf("A p p l i c a t i o n n a m e : %s \n", program_invocation_short_name); // TODO: only temp solution for application name
- strncpy(gAppId, program_invocation_short_name, maxAppNameLen);
+ printf("A p p l i c a t i o n n a m e => %s \n", __progname /*program_invocation_short_name*/); // TODO: only temp solution for application name
+ strncpy(gAppId, __progname, maxAppNameLen);
}
void pers_library_destroy(void)
{
- int i = 0;
- GvdbTable* resourceTable = NULL;
-
- for(i=0; i< PersistenceRCT_LastEntry; i++)
- {
- resourceTable = get_resource_cfg_table_by_idx(i);
-
- // dereference opend database
- if(resourceTable != NULL)
- {
- gvdb_table_unref(resourceTable);
- }
- }
+ // destory mutex
+ pthread_mutex_destroy(&gDbusInitializedMtx);
// unregister for lifecycle and persistence admin service dbus messages
unregister_lifecycle();
diff --git a/src/persistence_client_library.h b/src/persistence_client_library.h
index a52b082..0e59a2b 100644
--- a/src/persistence_client_library.h
+++ b/src/persistence_client_library.h
@@ -72,7 +72,7 @@ enum _PersistenceConstantDef
};
-/** enumerator used to identify the policy to manage the data */
+/// enumerator used to identify the policy to manage the data
typedef enum _PersistencePolicy_e
{
PersistencePolicy_wc = 0, /**< the data is managed write cached */
@@ -85,7 +85,7 @@ typedef enum _PersistencePolicy_e
} PersistencePolicy_e;
-/** enumerator used to identify the persistence storage to manage the data */
+/// enumerator used to identify the persistence storage to manage the data
typedef enum _PersistenceStorage_e
{
PersistenceStorage_local = 0, /**< the data is managed local: gvdb */
@@ -98,7 +98,7 @@ typedef enum _PersistenceStorage_e
} PersistenceStorage_e;
-/** structure used to manage the persistence configuration for a key */
+/// structure used to manage the persistence configuration for a key
typedef struct _PersistenceConfigurationKey_s
{
PersistencePolicy_e policy; /**< policy */
diff --git a/src/persistence_client_library_access_helper.c b/src/persistence_client_library_access_helper.c
index 50fe60c..0eb47b7 100644
--- a/src/persistence_client_library_access_helper.c
+++ b/src/persistence_client_library_access_helper.c
@@ -84,6 +84,7 @@ GvdbTable* get_resource_cfg_table(PersistenceRCT_e rct, int group)
{
GError* error = NULL;
char filename[dbPathMaxLen];
+ memset(filename, 0, dbPathMaxLen);
switch(rct) // create db name
{
@@ -134,7 +135,7 @@ int de_serialize_data(char* buffer, PersistenceConfigurationKey_s* pc)
{
int rval = 1;
char* token = NULL;
- if(buffer != NULL)
+ if((buffer != NULL) && (pc != NULL))
{
token = strtok(buffer, " "); // policy
if(token != 0)
@@ -189,7 +190,15 @@ int de_serialize_data(char* buffer, PersistenceConfigurationKey_s* pc)
{
int size = strlen(token)+1;
pc->reponsible = malloc(size);
- strncpy(pc->reponsible, token, size);
+
+ if(pc->reponsible != NULL)
+ {
+ strncpy(pc->reponsible, token, size);
+ }
+ else
+ {
+ printf("de_serialize_data - error: can't allocate memory [reponsible] \n");
+ }
//printf(" pc->reponsible %s | 0x%x \n", pc->reponsible, (int)pc->reponsible);
}
else
@@ -203,7 +212,14 @@ int de_serialize_data(char* buffer, PersistenceConfigurationKey_s* pc)
{
int size = strlen(token)+1;
pc->custom_name = malloc(size);
- strncpy(pc->custom_name, token, size);
+ if(pc->custom_name != NULL )
+ {
+ strncpy(pc->custom_name, token, size);
+ }
+ else
+ {
+ printf("de_serialize_data - error: can't allocate memory [custom_name] \n");
+ }
//printf(" pc->custom_name %s | 0x%x \n", pc->custom_name, (int)pc->custom_name);
}
else
@@ -212,12 +228,19 @@ int de_serialize_data(char* buffer, PersistenceConfigurationKey_s* pc)
int size = strlen(na)+1;
// custom name not available => no custom plugin
pc->custom_name = malloc(size);
- strncpy(pc->custom_name, "na", size);
+ if(pc->custom_name != NULL )
+ {
+ strncpy(pc->custom_name, "na", size);
+ }
+ else
+ {
+ printf("de_serialize_data - error: can't allocate memory [custom_name-default] \n");
+ }
}
}
else
{
- printf("de_serialize_data - error: buffer is NULL\n");
+ printf("de_serialize_data - error: buffer or PersistenceConfigurationKey_s is NULL\n");
rval = -1;
}
@@ -284,30 +307,33 @@ int get_db_context(unsigned char ldbid, char* resource_id, unsigned char user_no
if(valuePtr != NULL)
{
char* buffer = malloc(size);
- memcpy(buffer, valuePtr, size);
- de_serialize_data(buffer, &dbEntry);
-
- if(dbEntry.storage != PersistenceStorage_custom )
+ if(buffer != NULL)
{
- // TODO check rval ==> double defined shared/local/custom via ldbid and dbEntry.policy
- rval = get_db_path_and_key(ldbid, resource_id, user_no, seat_no, isFile, dbKey, dbPath, dbEntry.policy);
- if(rval != -1)
+ memcpy(buffer, valuePtr, size);
+ de_serialize_data(buffer, &dbEntry);
+
+ if(dbEntry.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;
+ }
+ }
+ 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;
}
- }
- 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;
+
+ free(buffer);
+ buffer = NULL;
+ free_pers_conf_key(&dbEntry);
+ resourceFound = 1;
}
- free(buffer);
- buffer = NULL;
- free_pers_conf_key(&dbEntry);
- resourceFound = 1;
}
}
else
diff --git a/src/persistence_client_library_custom_loader.c b/src/persistence_client_library_custom_loader.c
index 667fc66..ef6de9d 100644
--- a/src/persistence_client_library_custom_loader.c
+++ b/src/persistence_client_library_custom_loader.c
@@ -163,7 +163,15 @@ int get_custom_libraries()
// get the library identifier (early, secure, emergency, ...)
token = strtok(configFileMap, delimiters);
libId = custom_client_name_to_id(token, 0);
- gCustomLibIdArray[libId] = i;
+
+ if(libId < PersCustomLib_LastEntry)
+ {
+ gCustomLibIdArray[libId] = i;
+ }
+ else
+ {
+ return -1; // out of array bounds
+ }
// get the library name
token = strtok (NULL, delimiters);
@@ -176,7 +184,15 @@ int get_custom_libraries()
if(token != NULL)
{
libId = custom_client_name_to_id(token, 0);
- gCustomLibIdArray[libId] = i;
+ if(libId < PersCustomLib_LastEntry)
+ {
+ gCustomLibIdArray[libId] = i;
+ }
+ else
+ {
+ rval = -1;
+ break;
+ }
}
else
{
@@ -234,6 +250,7 @@ int load_custom_library(PersistenceCustomLibs_e customLib, Pers_custom_functs_s
if(customLib < PersCustomLib_LastEntry)
{
void* handle = dlopen(gCustomLibArray[customLib], RTLD_LAZY);
+ customFuncts->handle = handle;
if(handle != NULL)
{
dlerror(); // reset error
@@ -253,6 +270,13 @@ int load_custom_library(PersistenceCustomLibs_e customLib, Pers_custom_functs_s
return -1;
}
// custom_plugin_get_data
+ *(void **) (&customFuncts->custom_plugin_get_data_handle) = dlsym(handle, "plugin_get_data_handle");
+ if ((error = dlerror()) != NULL)
+ {
+ printf("load_custom_library - error: %s\n", error);
+ return -1;
+ }
+ // custom_plugin_get_data
*(void **) (&customFuncts->custom_plugin_get_data) = dlsym(handle, "plugin_get_data");
if ((error = dlerror()) != NULL)
{
@@ -274,6 +298,13 @@ int load_custom_library(PersistenceCustomLibs_e customLib, Pers_custom_functs_s
return -1;
}
// custom_plugin_set_data
+ *(void **) (&customFuncts->custom_plugin_set_data_handle) = dlsym(handle, "plugin_set_data");
+ if ((error = dlerror()) != NULL)
+ {
+ printf("load_custom_library - error: %s\n", error);
+ return -1;
+ }
+ // custom_plugin_set_data
*(void **) (&customFuncts->custom_plugin_set_data) = dlsym(handle, "plugin_set_data");
if ((error = dlerror()) != NULL)
{
@@ -318,15 +349,29 @@ int load_all_custom_libraries()
}
-char* get_custom_client_lib_name(int id)
+char* get_custom_client_lib_name(int idx)
{
- return gCustomLibArray[id];
+ if(idx < PersCustomLib_LastEntry)
+ {
+ return gCustomLibArray[idx];
+ }
+ else
+ {
+ return NULL;
+ }
}
int get_custom_client_position_in_array(PersistenceCustomLibs_e customLibId)
{
//printf("get_position_in_array - id: %d | position: %d \n", customLibId, gCustomLibIdArray[(int)customLibId]);
- return gCustomLibIdArray[(int)customLibId];
+ if(customLibId < PersCustomLib_LastEntry)
+ {
+ return gCustomLibIdArray[(int)customLibId];
+ }
+ else
+ {
+ return -1;
+ }
}
diff --git a/src/persistence_client_library_custom_loader.h b/src/persistence_client_library_custom_loader.h
index c28bb6d..bb73342 100644
--- a/src/persistence_client_library_custom_loader.h
+++ b/src/persistence_client_library_custom_loader.h
@@ -51,12 +51,15 @@ typedef enum _PersistenceCustomLibs_e
} PersistenceCustomLibs_e;
+
+/// enumerator fo custom library defines
enum _PersCustomLibDefines_e
{
PersCustomPathSize = 12
} PersCustomLibDefines_e;
+
/// callback definition for custom_plugin_get_status_notification_clbk function
typedef int (*plugin_callback_t) (int status, void* dataPtr);
@@ -64,6 +67,9 @@ typedef int (*plugin_callback_t) (int status, void* dataPtr);
/// structure definition for custom library functions
typedef struct _Pers_custom_functs_s
{
+ /// custom library handle
+ void* handle;
+
/// custom library init function
int (*custom_plugin_init)();
@@ -74,10 +80,17 @@ typedef struct _Pers_custom_functs_s
int (*custom_plugin_close)(int handle);
/// custom get data function
- long (*custom_plugin_get_data)(long handle, char* buffer, long size);
+ long (*custom_plugin_get_data_handle)(long handle, char* buffer, long size);
/// custom set data function
- long (*custom_plugin_set_data)(long handle, char* buffer, long size);
+ long (*custom_plugin_set_data_handle)(long handle, char* buffer, long size);
+
+ /// custom get data function
+ long (*custom_plugin_get_data)(char* buffer, long size);
+
+ /// custom set data function
+ long (*custom_plugin_set_data)(char* buffer, long size);
+
/// custom delete function
int (*custom_plugin_delete_data)(const char* path);
@@ -88,12 +101,18 @@ typedef struct _Pers_custom_functs_s
}Pers_custom_functs_s;
-
/// custom library functions array
Pers_custom_functs_s gPersCustomFuncs[PersCustomLib_LastEntry];
-
+/**
+ * @brief Translate a client library name into a id
+ *
+ * @param lib_name the library name
+ * @param substring indicator if a substring search is neccessary
+ *
+ * @return the library id
+ */
PersistenceCustomLibs_e custom_client_name_to_id(const char* lib_name, int substring);
/**
@@ -139,7 +158,12 @@ int get_custom_client_position_in_array(PersistenceCustomLibs_e customLib);
int get_num_custom_client_libs();
-char* get_custom_client_lib_name(int id);
+/**
+ * @brief get the custom library name form an index
+ *
+ * @return the name of the custom library ot NULL if invalid
+ */
+char* get_custom_client_lib_name(int idx);
#endif /* PERSISTENCE_CLIENT_LIBRARY_CUSTOM_LOADER_H */
diff --git a/src/persistence_client_library_data_access.c b/src/persistence_client_library_data_access.c
index b54b9c5..5d7b279 100644
--- a/src/persistence_client_library_data_access.c
+++ b/src/persistence_client_library_data_access.c
@@ -44,13 +44,14 @@
int get_value_from_table(GvdbTable* database, char* key, unsigned char* buffer, unsigned long buffer_size)
{
int read_size = 0;
- gconstpointer valuePtr = NULL;
GVariant* dbValue = NULL;
dbValue = gvdb_table_get_value(database, key);
if(dbValue != NULL)
{
+ gconstpointer valuePtr = NULL;
+
read_size = g_variant_get_size(dbValue);
valuePtr = g_variant_get_data(dbValue); // get the "data" part from GVariant
@@ -116,7 +117,7 @@ int persistence_get_data(char* dbPath, char* key, PersistenceStorage_e storage,
GvdbTable* database = gvdb_table_new(dbPath, TRUE, &error);;
gvdb_table_ref(database);
if(database != NULL)
- {
+ {
read_size = get_value_from_table(database, key, buffer, buffer_size-1);
gvdb_table_unref(database);
}
@@ -137,7 +138,7 @@ int persistence_get_data(char* dbPath, char* key, PersistenceStorage_e storage,
if(idx < PersCustomLib_LastEntry)
{
- gPersCustomFuncs[idx].custom_plugin_get_data(88, (char*)buffer, buffer_size-1);
+ gPersCustomFuncs[idx].custom_plugin_get_data_handle(88, (char*)buffer, buffer_size-1);
}
}
@@ -172,8 +173,14 @@ int persistence_set_data(char* dbPath, char* key, PersistenceStorage_e storage,
if(hash_table != NULL)
{
write_size = set_value_to_table(hash_table, key, buffer, buffer_size);
- gvdb_table_write_contents(hash_table, dbPath, FALSE, &error);
+ gboolean success = gvdb_table_write_contents(hash_table, dbPath, FALSE, &error);
+ if(success != TRUE)
+ {
+ printf("persistence_set_data => error: %s \n", error->message );
+ g_error_free(error);
+ error = NULL;
+ }
}
else
{
@@ -188,7 +195,7 @@ int persistence_set_data(char* dbPath, char* key, PersistenceStorage_e storage,
printf(" C U S T O M D A T A => not implemented yet - path: %s | index: %d \n", dbPath , idx);
if(idx < PersCustomLib_LastEntry)
{
- gPersCustomFuncs[idx].custom_plugin_set_data(88, (char*)buffer, buffer_size);
+ gPersCustomFuncs[idx].custom_plugin_set_data_handle(88, (char*)buffer, buffer_size);
}
}
diff --git a/src/persistence_client_library_data_access.h b/src/persistence_client_library_data_access.h
index e8ad564..725d472 100644
--- a/src/persistence_client_library_data_access.h
+++ b/src/persistence_client_library_data_access.h
@@ -130,7 +130,4 @@ int get_size_from_table(GvdbTable* database, char* key);
-
-
-
#endif /* PERSISTENCY_CLIENT_LIBRARY_DATA_ACCESS_H */
diff --git a/src/persistence_client_library_dbus_service.c b/src/persistence_client_library_dbus_service.c
index dc10017..c05e306 100644
--- a/src/persistence_client_library_dbus_service.c
+++ b/src/persistence_client_library_dbus_service.c
@@ -41,7 +41,6 @@
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
-#include <pthread.h>
/// polling structure
@@ -61,7 +60,7 @@ static tPollInfo gPollInfo;
DBusConnection* gDbusConn = NULL;
-DBusConnection* get_dbus_connection()
+DBusConnection* get_dbus_connection(void)
{
return gDbusConn;
}
@@ -110,6 +109,9 @@ static void unregisterObjectPathFallback(DBusConnection *connection, void *user
void* run_mainloop(void* dataPtr)
{
+ // lock mutex to make sure dbus main loop is running
+ pthread_mutex_lock(&gDbusInitializedMtx);
+
// persistence admin message
static const struct DBusObjectPathVTable vtablePersAdmin
= {unregisterMessageHandler, checkPersAdminMsg, NULL, };
@@ -132,7 +134,7 @@ void* run_mainloop(void* dataPtr)
-int setup_dbus_mainloop()
+int setup_dbus_mainloop(void)
{
int rval = 0;
pthread_t thread;
@@ -291,6 +293,8 @@ int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtable2,
{
char buf[64];
+ // minloop is running now, release mutex
+ pthread_mutex_unlock(&gDbusInitializedMtx);
do
{
bContinue = 0; /* assume error */
diff --git a/src/persistence_client_library_dbus_service.h b/src/persistence_client_library_dbus_service.h
index bb69077..b4def6a 100644
--- a/src/persistence_client_library_dbus_service.h
+++ b/src/persistence_client_library_dbus_service.h
@@ -35,6 +35,11 @@
#include <dbus/dbus.h>
#include <poll.h>
+#include <pthread.h>
+
+/// mutex to make sure main loop is running
+pthread_mutex_t gDbusInitializedMtx;
+
/// command definitions for main loop
typedef enum ECmd
@@ -51,24 +56,32 @@ typedef enum ECmd
int gPipefds[2];
-
-
/// returns the dbus connection
-DBusConnection* get_dbus_connection();
+DBusConnection* get_dbus_connection(void);
/**
- * Main loop to dispatch events and dbus messages
+ * @brief DBus main loop to dispatch events and dbus messages
*
+ * @param vtable the function pointer tables for '/org/genivi/persistence/adminconsumer' messages
+ * @param vtable2 the function pointer tables for '/com/contiautomotive/NodeStateManager/LifecycleConsumer' messages
+ * @param vtableFallback the fallback function pointer tables
+ * @param userData data to pass to the main loop
+ *
+ * @return 0
*/
int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtable2,
DBusObjectPathVTable vtableFallback, void* userData);
-/// dbus main loop
-int setup_dbus_mainloop();
+/**
+ * @brief Setup the dbus main dispatching loop
+ *
+ * @return 0
+ */
+int setup_dbus_mainloop(void);
#endif /* PERSISTENCE_CLIENT_LIBRARY_DBUS_SERVICE_H_ */
diff --git a/src/persistence_client_library_file.c b/src/persistence_client_library_file.c
index 3f6931a..642621e 100644
--- a/src/persistence_client_library_file.c
+++ b/src/persistence_client_library_file.c
@@ -86,10 +86,10 @@ int file_get_size(int fd)
void* file_map_data(void* addr, long size, long offset, int fd)
{
void* ptr = 0;
- int mapFlag = PROT_WRITE | PROT_READ;
if(accessNoLock == isAccessLocked() ) // check if access to persistent data is locked
{
+ int mapFlag = PROT_WRITE | PROT_READ;
ptr = mmap(addr,size, mapFlag, MAP_SHARED, fd, offset);
}
return ptr;
@@ -109,6 +109,9 @@ int file_open(unsigned char ldbid, char* resource_id, unsigned char user_no, uns
char dbKey[dbKeyMaxLen]; // database key
char dbPath[dbPathMaxLen]; // database location
+ memset(dbKey, 0, dbKeyMaxLen);
+ memset(dbPath, 0, dbPathMaxLen);
+
// get database context: database path and database key
shared_DB = get_db_context(ldbid, resource_id, user_no, seat_no, resIsFile, dbKey, dbPath);
@@ -158,6 +161,9 @@ int file_remove(unsigned char ldbid, char* resource_id, unsigned char user_no, u
char dbKey[dbKeyMaxLen]; // database key
char dbPath[dbPathMaxLen]; // database location
+ memset(dbKey, 0, dbKeyMaxLen);
+ memset(dbPath, 0, dbPathMaxLen);
+
// get database context: database path and database key
shared_DB = get_db_context(ldbid, resource_id, user_no, seat_no, resIsFile, dbKey, dbPath);
diff --git a/src/persistence_client_library_handle.c b/src/persistence_client_library_handle.c
index 680ee86..96f799c 100644
--- a/src/persistence_client_library_handle.c
+++ b/src/persistence_client_library_handle.c
@@ -48,7 +48,7 @@ int gOpenFdArray[maxPersHandle];
/// get persistence handle
int get_persistence_handle_idx()
{
- int handle = -1;
+ int handle = 0;
if(gHandleFreeIdx != -1) // check if we have a free spot in the array before the current max
{
@@ -63,7 +63,8 @@ int get_persistence_handle_idx()
}
else
{
- printf("Reached maximum of open handles: %d \n", maxPersHandle);
+ handle = -1;
+ printf("get_persistence_handle_idx => Reached maximum of open handles: %d \n", maxPersHandle);
}
}
diff --git a/src/persistence_client_library_handle.h b/src/persistence_client_library_handle.h
index ef1f5a5..f3aa0a5 100644
--- a/src/persistence_client_library_handle.h
+++ b/src/persistence_client_library_handle.h
@@ -36,6 +36,7 @@
#include "persistence_client_library.h"
+/// handle structure definition
typedef struct _PersistenceHandle_s
{
int shared_DB; /// is a shared resource
diff --git a/src/persistence_client_library_key.c b/src/persistence_client_library_key.c
index 119fb23..798a29d 100644
--- a/src/persistence_client_library_key.c
+++ b/src/persistence_client_library_key.c
@@ -46,7 +46,7 @@
int key_handle_open(unsigned char ldbid, char* resource_id, unsigned char user_no, unsigned char seat_no)
{
- int handle = -1;
+ int handle = 0;
if(accessNoLock == isAccessLocked() ) // check if access to persistent data is locked
{
@@ -55,6 +55,9 @@ int key_handle_open(unsigned char ldbid, char* resource_id, unsigned char user_n
char dbKey[dbKeyMaxLen]; // database key
char dbPath[dbPathMaxLen]; // database location
+ 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);
@@ -70,7 +73,8 @@ int key_handle_open(unsigned char ldbid, char* resource_id, unsigned char user_n
if(idx < PersCustomLib_LastEntry)
{
- int flag = 0, mode = 0;
+ int flag = 0,
+ mode = 0;
handle = gPersCustomFuncs[idx].custom_plugin_open(dbPath, flag, mode);
}
}
@@ -79,10 +83,17 @@ int key_handle_open(unsigned char ldbid, char* resource_id, unsigned char user_n
handle = get_persistence_handle_idx();
}
- // remember data in handle array
- strncpy(gHandleArray[handle].dbPath, dbPath, dbPathMaxLen);
- strncpy(gHandleArray[handle].dbKey, dbKey, dbKeyMaxLen);
- gHandleArray[handle].shared_DB = storePolicy;
+ if(handle < maxPersHandle)
+ {
+ // 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);
+ }
}
}
@@ -140,7 +151,8 @@ int key_handle_get_size(int key_handle)
char workaroundPath[128]; // workaround, because /sys/ can not be accessed on host!!!!
snprintf(workaroundPath, 128, "%s%s", "/tmp", gHandleArray[key_handle].dbPath );
- printf(" C U S T O M D A T A => not implemented yet - path: %s | index: %d \n", gHandleArray[key_handle].dbPath , idx);
+ printf(" C U S T O M D A T A => not implemented yet - path: %s | index: %d \n",
+ gHandleArray[key_handle].dbPath , idx);
if(idx < PersCustomLib_LastEntry)
{
@@ -178,7 +190,7 @@ int key_handle_read_data(int key_handle, unsigned char* buffer, unsigned long bu
if(idx < PersCustomLib_LastEntry)
{
- gPersCustomFuncs[idx].custom_plugin_get_data(key_handle, (char*)buffer, buffer_size-1);
+ gPersCustomFuncs[idx].custom_plugin_get_data_handle(key_handle, (char*)buffer, buffer_size-1);
}
}
else
@@ -223,7 +235,7 @@ int key_handle_write_data(int key_handle, unsigned char* buffer, unsigned long b
if(idx < PersCustomLib_LastEntry)
{
- gPersCustomFuncs[idx].custom_plugin_set_data(key_handle, (char*)buffer, buffer_size-1);
+ gPersCustomFuncs[idx].custom_plugin_set_data_handle(key_handle, (char*)buffer, buffer_size-1);
}
}
else
@@ -255,7 +267,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
{
- // TODO
+ // TODO implement key delete
}
return rval;
}
@@ -274,6 +286,9 @@ int key_get_size(unsigned char ldbid, char* resource_id, unsigned char user_no,
char dbKey[dbKeyMaxLen]; // database key
char dbPath[dbPathMaxLen]; // database location
+ 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);
@@ -306,6 +321,10 @@ int key_read_data(unsigned char ldbid, char* resource_id, unsigned char user_no,
char dbKey[dbKeyMaxLen]; // database key
char dbPath[dbPathMaxLen]; // database location
+ 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);
@@ -333,7 +352,7 @@ int key_write_data(unsigned char ldbid, char* resource_id, unsigned char user_no
{
int data_size = -1;
- if(accessNoLock == isAccessLocked() ) // check if access to persistent data is locked
+ if(accessNoLock != isAccessLocked() ) // check if access to persistent data is locked
{
if(buffer_size <= gMaxKeyValDataSize) // check data size
{
@@ -344,6 +363,9 @@ int key_write_data(unsigned char ldbid, char* resource_id, unsigned char user_no
char dbKey[dbKeyMaxLen]; // database key
char dbPath[dbPathMaxLen]; // database location
+ 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);
@@ -372,7 +394,7 @@ int key_write_data(unsigned char ldbid, char* resource_id, unsigned char user_no
-// status: TODO
+// status: TODO implement register on change
int key_register_notify_on_change(unsigned char ldbid, char* resource_id, unsigned char user_no, unsigned char seat_no)
{
int rval = 0;
@@ -381,6 +403,9 @@ int key_register_notify_on_change(unsigned char ldbid, char* resource_id, unsign
char dbKey[dbKeyMaxLen]; // database key
char dbPath[dbPathMaxLen]; // database location
+ memset(dbKey, 0, dbKeyMaxLen);
+ memset(dbPath, 0, dbPathMaxLen);
+
// registration is only on shared key possible
if(PersistenceStorage_shared == get_db_context(ldbid, resource_id, user_no, seat_no, resIsNoFile, dbKey, dbPath))
{
diff --git a/src/persistence_client_library_lc_interface.c b/src/persistence_client_library_lc_interface.c
index 2ab8951..bc40e89 100644
--- a/src/persistence_client_library_lc_interface.c
+++ b/src/persistence_client_library_lc_interface.c
@@ -30,16 +30,21 @@
* @see
*/
+
#include "persistence_client_library_lc_interface.h"
-#include "persistence_client_library_pas_interface.h"
-#include "persistence_client_library_dbus_service.h"
+
#include "persistence_client_library.h"
#include "persistence_client_library_handle.h"
+#include "persistence_client_library_pas_interface.h"
+#include "persistence_client_library_dbus_service.h"
+#include "persistence_client_library_custom_loader.h"
+#include "persistence_client_library_access_helper.h"
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
+#include <dlfcn.h>
int check_lc_request(int request)
@@ -242,12 +247,14 @@ int send_lifecycle_un_register(const char* method, const char* busname, const ch
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;
@@ -300,8 +307,9 @@ int send_lifecycle_request(const char* method, int requestId, int status)
int register_lifecycle()
{
const char* objName = "objName";
- int shutdownMode = 88;
- int TimeoutMs = 500;
+ 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);
}
@@ -311,7 +319,7 @@ int register_lifecycle()
int unregister_lifecycle()
{
const char* objName = "objName";
- int shutdownMode = 88;
+ int shutdownMode = 88; // TODO send correct mode
return send_lifecycle_un_register("UnRegisterShutdownClient",
dbus_bus_get_unique_name(get_dbus_connection()), objName, shutdownMode);
@@ -320,7 +328,7 @@ int unregister_lifecycle()
int send_prepare_shutdown_complete(int requestId)
{
- int status = 1;
+ int status = 1; // TODO send correct status
return send_lifecycle_request("LifecycleRequestComplete", requestId, status);
}
@@ -331,6 +339,7 @@ int send_prepare_shutdown_complete(int requestId)
void process_prepare_shutdown(unsigned char requestId)
{
int i = 0;
+ GvdbTable* resourceTable = NULL;
// block write
pers_lock_access();
@@ -346,7 +355,22 @@ void process_prepare_shutdown(unsigned char requestId)
}
// close open gvdb and dconf database
- // TODO
+ for(i=0; i< PersistenceRCT_LastEntry; i++)
+ {
+ resourceTable = get_resource_cfg_table_by_idx(i);
+
+ // dereference opend database
+ if(resourceTable != NULL)
+ {
+ gvdb_table_unref(resourceTable);
+ }
+ }
+
+ // unload custom client libraries
+ for(i=0; i<get_num_custom_client_libs(); i++)
+ {
+ dlclose(gPersCustomFuncs[i].handle);
+ }
// notify lifecycle shutdown OK
send_prepare_shutdown_complete((int)requestId);
diff --git a/src/persistence_client_library_lc_interface.h b/src/persistence_client_library_lc_interface.h
index 5f2a4e3..cdc6d90 100644
--- a/src/persistence_client_library_lc_interface.h
+++ b/src/persistence_client_library_lc_interface.h
@@ -35,15 +35,41 @@
#include <dbus/dbus.h>
+
+/**
+ * @brief Check if a com.contiautomotive.NodeStateManager.LifecycleConsumer message has been received
+ *
+ * @param connection the debus connection
+ * @param message the dbus message
+ * @param user_data data handed over to this function
+ *
+ * @return DBUS_HANDLER_RESULT_HANDLED or DBUS_HANDLER_RESULT_NOT_YET_HANDLED
+ */
DBusHandlerResult checkLifecycleMsg(DBusConnection * connection, DBusMessage * message, void * user_data);
+
+/**
+ * @brief send register message 'RegisterShutdownClient' to com.contiautomotive.NodeStateManager.Consumer
+ *
+ * @return 0 on success or -1 on error
+ */
int register_lifecycle();
-int unregister_lifecycle();
-void process_prepare_shutdown(unsigned char requestId);
+/**
+ * @brief send register message 'UnRegisterShutdownClient' to com.contiautomotive.NodeStateManager.Consumer
+ *
+ * @return 0 on success or -1 on error
+ */
+int unregister_lifecycle();
+/**
+ * @brief process a shutdown message (close all open files, open databases, ...
+ *
+ * @param requestId the requestID
+ */
+void process_prepare_shutdown(unsigned char requestId);
diff --git a/src/persistence_client_library_pas_interface.c b/src/persistence_client_library_pas_interface.c
index 04ff758..42c230c 100644
--- a/src/persistence_client_library_pas_interface.c
+++ b/src/persistence_client_library_pas_interface.c
@@ -43,22 +43,22 @@
static int gLockAccess = 0;
-int pers_data_sync()
+int pers_data_sync(void)
{
- return 1;
+ return 1; // TODO implement sync data back
}
-void pers_lock_access()
+void pers_lock_access(void)
{
__sync_fetch_and_add(&gLockAccess,1);
}
-void pers_unlock_access()
+void pers_unlock_access(void)
{
__sync_fetch_and_sub(&gLockAccess,1);
}
-int isAccessLocked()
+int isAccessLocked(void)
{
return gLockAccess;
}
@@ -213,12 +213,14 @@ int send_pas_register(const char* method, const char* appname)
else
{
fprintf(stderr, "send_pers_admin_service ==> ERROR: Invalid connection!! \n");
+ rval = -1;
}
dbus_message_unref(message);
}
else
{
fprintf(stderr, "send_pers_admin_service ==> ERROR: Invalid message!! \n");
+ rval = -1;
}
return rval;
@@ -248,6 +250,7 @@ int send_pas_request(const char* method, int blockStatus)
if(!dbus_connection_send(conn, message, 0))
{
fprintf(stderr, "send_pers_admin_service ==> Access denied: %s \n", error.message);
+ rval = -1;
}
dbus_connection_flush(conn);
@@ -255,12 +258,14 @@ int send_pas_request(const char* method, int blockStatus)
else
{
fprintf(stderr, "send_pers_admin_service ==> ERROR: Invalid connection!! \n");
+ rval = -1;
}
dbus_message_unref(message);
}
else
{
fprintf(stderr, "send_pers_admin_service ==> ERROR: Invalid message!! \n");
+ rval = -1;
}
return rval;
@@ -269,25 +274,25 @@ int send_pas_request(const char* method, int blockStatus)
-int register_pers_admin_service()
+int register_pers_admin_service(void)
{
return send_pas_register("RegisterPersAdminNotification", gAppId);
}
-int unregister_pers_admin_service()
+int unregister_pers_admin_service(void)
{
return send_pas_register("UnRegisterPersAdminNotification", gAppId);
}
-int pers_admin_service_data_sync_complete()
+int pers_admin_service_data_sync_complete(void)
{
return send_pas_request("PersistenceAdminRequestCompleted", 1);
}
-void process_block_and_write_data_back()
+void process_block_and_write_data_back(void)
{
// lock persistence data access
pers_lock_access();
diff --git a/src/persistence_client_library_pas_interface.h b/src/persistence_client_library_pas_interface.h
index 7eabbe2..ad911e1 100644
--- a/src/persistence_client_library_pas_interface.h
+++ b/src/persistence_client_library_pas_interface.h
@@ -37,34 +37,56 @@
#include <dbus/dbus.h>
-
-
+/**
+ * @brief Check if a org.genivi.persistence.admin message has been received
+ *
+ * @param connection the debus connection
+ * @param message the dbus message
+ * @param user_data data handed over to this function
+ *
+ * @return DBUS_HANDLER_RESULT_HANDLED or DBUS_HANDLER_RESULT_NOT_YET_HANDLED
+ */
DBusHandlerResult checkPersAdminMsg(DBusConnection * connection, DBusMessage * message, void * user_data);
+
/// synchronize data back to memory device
-int pers_data_sync();
+int pers_data_sync(void);
+
/// lock access to persistence data
-void pers_lock_access();
+void pers_lock_access(void);
/// unlock access to persistent data
-void pers_unlock_access();
+void pers_unlock_access(void);
-/// check if access to persistent data is locked
-int isAccessLocked();
-
+/**
+ * @brief check if access to persistent data is locked
+ *
+ * @return 1 if access is locked, 0 if access is possible
+ */
+int isAccessLocked(void);
/// block persistence access and write data back to device
-void process_block_and_write_data_back();
+void process_block_and_write_data_back(void);
+/**
+ * @brief send registration message 'RegisterPersAdminNotification' to org.genivi.persistence.admin
+ *
+ * @return 0 on success or -1 on error
+ */
+int register_pers_admin_service(void);
-int register_pers_admin_service();
-int unregister_pers_admin_service();
+/**
+ * @brief send registration message 'UnRegisterPersAdminNotification' to org.genivi.persistence.admin
+ *
+ * @return 0 on success or -1 on error
+ */
+int unregister_pers_admin_service(void);
diff --git a/test/data/Data.tar.gz b/test/data/Data.tar.gz
new file mode 100644
index 0000000..589f643
--- /dev/null
+++ b/test/data/Data.tar.gz
Binary files differ
diff --git a/test/persistence_client_library_dbus_test.c b/test/persistence_client_library_dbus_test.c
index ebd8155..e9bf0ba 100644
--- a/test/persistence_client_library_dbus_test.c
+++ b/test/persistence_client_library_dbus_test.c
@@ -21,11 +21,11 @@ int main(int argc, char *argv[])
printf("Dbus interface test application\n");
- ret = key_read_data(0, "/language/current_language", 3, 0, buffer, 128);
+ ret = key_read_data(0, "/language/current_language", 3, 0, (unsigned char*)buffer, 128);
getchar();
printf("By\n");
- return 1;
+ return ret;
}
diff --git a/test/persistence_client_library_test.c b/test/persistence_client_library_test.c
index 48f79e3..db3926a 100644
--- a/test/persistence_client_library_test.c
+++ b/test/persistence_client_library_test.c
@@ -50,15 +50,17 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define BUF_SIZE 64
#define NUM_OF_FILES 3
-#define READ_SIZE 256
+#define READ_SIZE 1024
char* dayOfWeek[] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };
+
+
START_TEST (test_persGetData)
{
int ret = 0;
unsigned char* buffer = NULL;
- char sysTimeBuffer[128];
+ char sysTimeBuffer[256];
buffer = malloc(READ_SIZE);
struct tm *locTime;
@@ -66,79 +68,89 @@ START_TEST (test_persGetData)
locTime = localtime(&t);
- snprintf(sysTimeBuffer, 128, "\"%s %d.%d.%d - %d:%.2d:%.2d Uhr\"", dayOfWeek[locTime->tm_wday], locTime->tm_mday, locTime->tm_mon, (locTime->tm_year+1900),
+ snprintf(sysTimeBuffer, 256, "\"%s %d.%d.%d - %d:%.2d:%.2d Uhr\"", dayOfWeek[locTime->tm_wday], locTime->tm_mday, locTime->tm_mon, (locTime->tm_year+1900),
locTime->tm_hour, locTime->tm_min, locTime->tm_sec);
printf("\n\n");
printf("<-----------------------------------------------\n");
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"
- printf("T E S T Data - country_code: %s \n", buffer);
+ printf("T E S T Data - country_code: %s | size: %d \n", buffer, ret);
+ fail_unless(strncmp((char*)buffer, "Custom plugin -> plugin_get_data_handle", strlen((char*)buffer)) == 0, "Buffer not correctly read");
+
printf("----------------------------------------------->\n\n");
printf("<-----------------------------------------------\n");
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\"", ret-1) == 0, "Buffer not correctly read");
printf("T E S T Data - last_position: %s \n", buffer);
printf("----------------------------------------------->\n\n");
printf("<-----------------------------------------------\n");
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"
+ 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, "S H A R E D D A T A => not implemented yet", strlen((char*)buffer)) == 0, "Buffer not correctly read");
printf("T E S T Data - current_language: %s \n", buffer);
printf("----------------------------------------------->\n\n");
printf("<-----------------------------------------------\n");
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"
+ 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"
+ printf("T E S T Data - last link: %s \n", buffer);
+ fail_unless(strncmp((char*)buffer, "/var/opt/user_manual_climateControl.pdf", ret-1) == 0, "Buffer not correctly read");
printf("T E S T Data - open_document: %s \n", buffer);
- printf("----------------------------------------------->\n\n");
+ printf("----------------------------------------------->\n\n");
printf("<-----------------------------------------------\n");
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"
+ 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, "S H A R E D D A T A => not implemented yet", strlen((char*)buffer)) == 0, "Buffer not correctly read");
printf("T E S T Data - home_address: %s \n", buffer);
printf("----------------------------------------------->\n\n");
printf("<-----------------------------------------------\n");
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"
+ 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", ret-1) == 0, "Buffer not correctly read");
printf("T E S T Data - last satellites: %s \n", buffer);
printf("----------------------------------------------->\n\n");
printf("<-----------------------------------------------\n");
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"
+ 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", ret-1) == 0, "Buffer not correctly read");
printf("T E S T Data - last link: %s \n", buffer);
printf("----------------------------------------------->\n\n");
printf("<-----------------------------------------------\n");
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"
+ 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", ret-1) == 0, "Buffer not correctly read");
printf("T E S T Data - last link: %s \n", buffer);
printf("----------------------------------------------->\n\n");
-
printf("<-----------------------------------------------\n");
memset(buffer, 0, READ_SIZE);
- ret = key_write_data(0x84, "/links/last link", 2, 1, sysTimeBuffer, READ_SIZE); // "/Data/mnt-wt/Appl-2/wt.gvdb" => "/84/User/2/Seat/1/links/last link"
- printf("T E S T Data: %s \n\n", sysTimeBuffer);
+ //ret = key_write_data(0xFF, "/status/open_document", 1, 2, (unsigned char*)sysTimeBuffer, READ_SIZE); // "/Data/mnt-c/Appl-1/cached.gvdb" => "/User/3/Seat/2/status/open_document"
+ printf("T E S T write data /status/open_document: %s \n", sysTimeBuffer);
printf("----------------------------------------------->\n\n");
printf("<-----------------------------------------------\n");
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/Seat/1/links/last link"
- printf("T E S T Data last link: %s \n", buffer);
- printf("----------------------------------------------->\n\n");
+ ret = key_read_data(0xFF, "/status/open_document", 1, 2, buffer, READ_SIZE); // "/Data/mnt-c/Appl-1/cached.gvdb" => "/User/3/Seat/2/status/open_document"
+ printf("T E S T Data /status/open_document: %s \n", buffer);
+ fail_unless(strncmp((char*)buffer, "empty", strlen(sysTimeBuffer)) == 0, "Buffer not correctly read");
+ printf("----------------------------------------------->\n\n");
free(buffer);
@@ -166,6 +178,7 @@ START_TEST (test_persGetDataHandle)
memset(buffer, 0, READ_SIZE);
handlePos = key_handle_open(0xFF, "/posHandle/last_position", 0, 0);
ret = key_handle_read_data(handlePos, buffer, READ_SIZE);
+ fail_unless(strncmp((char*)buffer, "", ret-1) == 0, "Buffer not correctly read");
printf("T E S T handle: %d | Data: %s \n\n", handlePos, buffer);
memset(buffer, 0, READ_SIZE);
@@ -194,7 +207,6 @@ END_TEST
START_TEST(test_persSetData)
{
- int ret = 0;
unsigned char* buffer = NULL;
buffer = malloc(READ_SIZE);
memset(buffer, 0, READ_SIZE);
@@ -215,6 +227,7 @@ START_TEST(test_persSetSharedData)
memset(buffer, 0, READ_SIZE);
ret = key_write_data(0x20, "/address/home_address", 4, 0, buffer, READ_SIZE);
+ fail_unless(strncmp((char*)buffer, "", ret-1) == 0, "Buffer not correctly read");
printf("T E S T Data: %s \n\n", buffer);
free(buffer);
@@ -233,6 +246,7 @@ START_TEST(test_persGetData_file)
memset(buffer, 0, READ_SIZE);
ret = file_open(0xFF, "/media/mediaDB.db", 1, 1);
+ fail_unless(ret != -1, "Could not open file");
printf("T E S T Data: %s \n\n", buffer);
free(buffer);