From 740b23e7398130a506d6b1a0e7e3e7ae7df0f1d5 Mon Sep 17 00:00:00 2001 From: ihuerner Date: Thu, 27 Sep 2012 09:12:21 +0000 Subject: [PATCH] New release 0.1.4, for changes see ChangeLog --- ChangeLog | 8 +++ Makefile.am | 6 +-- configure.ac | 11 ++-- data/Data.tar.gz | Bin 2862 -> 0 bytes include/persistence_client_library_file.h | 12 ++++- include/persistence_client_library_key.h | 9 ++++ persistence_client_library.pc.in | 2 +- src/Makefile.am | 18 +++---- src/persistence_client_library.c | 35 ++++++------ src/persistence_client_library.h | 6 +-- src/persistence_client_library_access_helper.c | 72 +++++++++++++++++-------- src/persistence_client_library_custom_loader.c | 55 +++++++++++++++++-- src/persistence_client_library_custom_loader.h | 34 ++++++++++-- src/persistence_client_library_data_access.c | 17 ++++-- src/persistence_client_library_data_access.h | 3 -- src/persistence_client_library_dbus_service.c | 10 ++-- src/persistence_client_library_dbus_service.h | 25 ++++++--- src/persistence_client_library_file.c | 8 ++- src/persistence_client_library_handle.c | 5 +- src/persistence_client_library_handle.h | 1 + src/persistence_client_library_key.c | 49 ++++++++++++----- src/persistence_client_library_lc_interface.c | 38 ++++++++++--- src/persistence_client_library_lc_interface.h | 30 ++++++++++- src/persistence_client_library_pas_interface.c | 23 ++++---- src/persistence_client_library_pas_interface.h | 44 +++++++++++---- test/data/Data.tar.gz | Bin 0 -> 2967 bytes test/persistence_client_library_dbus_test.c | 4 +- test/persistence_client_library_test.c | 50 ++++++++++------- 28 files changed, 418 insertions(+), 157 deletions(-) delete mode 100644 data/Data.tar.gz create mode 100644 test/data/Data.tar.gz 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 08a2061439e468f2d18437435b5f7e12c6b1656f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2862 zcmaJ>c|4SB8@42ePG>qOSu*-$R7fQ$+em$sbF7_G#DoqN29+(#OO7msei2S+hzwZ< z<;ZBfS+X0Q$QrT^27@t}?R~ycedjyN@At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LkClkxXP0w!NNF5v{Dao$K1Q@{-%?qO&t-k?Y)cw~%lvFy+<;3h@@m2ol-nug4k z0fGxd+wyXdvv;Hz(8TKQTG&GcsGo?XK~)>&JkloBm64A|x$9<#fFTRQ3#tVL5kK*9 z@63D=FNG0cBU-?LvrzkxY_RWhJX!_>A~~CES5bZETZP50he zr_s86E0@QuUM9Tvu1ayUe{wBCfVT^ZV?THW90h-==y5(VP0+DSAjscM3B*wFN=P)a zNgkqU0iX#2ExumEKq5l0VJQ~Q8GW1qwJj;`E?Qwg60bq_=B`4e51~fv`**a3X`sQeYS9!iA2bqt=NH-jcf&=RmS@H7Fc5bLKbQP<#!Do5j{3 zTO-LK@LewufxyY{F%zIQ^z=vYB$6wjFa~)U#WB4d0)f@mMg|~A4;YG 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 #include +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 #include #include -#include /// 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 #include +#include + +/// 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 #include #include #include +#include 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 + +/** + * @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 - - +/** + * @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 0000000000000000000000000000000000000000..589f6432332f104e85a7afc16b27f9380377c1f6 GIT binary patch literal 2967 zcmZ8fdmxl~7ar2m1)n4&MoMbinj}pOCKTJJ2!(ZNNNy1+<&wO$wp3(l%WaDxxra)| zTE;86RIX)Qnn_dCxQ;O~=K8+BZ_>7x@BQoi&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Time->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); -- 2.7.4