diff options
-rw-r--r-- | data/Data.tar.gz | bin | 2026 -> 2862 bytes | |||
-rw-r--r-- | include/persistence_client_library_key.h | 6 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/persistence_client_library.c | 240 | ||||
-rw-r--r-- | src/persistence_client_library.h | 78 | ||||
-rw-r--r-- | src/persistence_client_library_access_helper.c | 472 | ||||
-rw-r--r-- | src/persistence_client_library_access_helper.h | 106 | ||||
-rw-r--r-- | src/persistence_client_library_custom_loader.c | 291 | ||||
-rw-r--r-- | src/persistence_client_library_custom_loader.h | 126 | ||||
-rw-r--r-- | src/persistence_client_library_data_access.c | 57 | ||||
-rw-r--r-- | src/persistence_client_library_data_access.h | 19 | ||||
-rw-r--r-- | src/persistence_client_library_dbus_service.c | 4 | ||||
-rw-r--r-- | src/persistence_client_library_file.c | 19 | ||||
-rw-r--r-- | src/persistence_client_library_key.c | 126 | ||||
-rw-r--r-- | src/persistence_client_library_lc_interface.c | 9 | ||||
-rw-r--r-- | src/persistence_client_library_pas_interface.c | 4 | ||||
-rw-r--r-- | test/customLibConfigFile.cfg | 7 | ||||
-rw-r--r-- | test/persistence_client_library_test.c | 60 |
18 files changed, 1266 insertions, 360 deletions
diff --git a/data/Data.tar.gz b/data/Data.tar.gz Binary files differindex c8d11a2..9f60a57 100644 --- a/data/Data.tar.gz +++ b/data/Data.tar.gz diff --git a/include/persistence_client_library_key.h b/include/persistence_client_library_key.h index febe623..61550cc 100644 --- a/include/persistence_client_library_key.h +++ b/include/persistence_client_library_key.h @@ -134,7 +134,8 @@ int key_handle_register_notify_on_change(int key_handle); * * @param key_handle key value handle return by key_handle_open() * @param buffer the buffer containing the persistent data to write - * @param buffer_size the number of bytes to write + * @param buffer_size the number of bytes to write (default max size is set to 16kB) + * use environment variable PERS_MAX_KEY_VAL_DATA_SIZE to modify default size in bytes * * @return positive value: the bytes written; negative value: error code */ @@ -180,7 +181,8 @@ int key_register_notify_on_change(unsigned char ldbid, char* resource_id, unsign * @param user_no the user ID * @param seat_no the seat number (seat 0 to 3) * @param buffer the buffer containing the persistent data to write - * @param buffer_size the number of bytes to write + * @param buffer_size the number of bytes to write (default max size is set to 16kB) + * use environment variable PERS_MAX_KEY_VAL_DATA_SIZE to modify default size in bytes * * @return positive value: the bytes written; negative value: error code */ diff --git a/src/Makefile.am b/src/Makefile.am index 64c21a1..0e43191 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -23,6 +23,8 @@ libpersistence_client_library_la_SOURCES = \ persistence_client_library_lc_interface.c \ persistence_client_library_pas_interface.c \ persistence_client_library_dbus_service.c \ + persistence_client_library_custom_loader.c \ + persistence_client_library_access_helper.c \ crc32.c libpersistence_client_library_la_LDFLAGS = -module -export-dynamic $(LDFLAGS) diff --git a/src/persistence_client_library.c b/src/persistence_client_library.c index a732ae6..623ef5a 100644 --- a/src/persistence_client_library.c +++ b/src/persistence_client_library.c @@ -37,31 +37,29 @@ #include "persistence_client_library_pas_interface.h" #include "persistence_client_library_dbus_service.h" #include "persistence_client_library_handle.h" +#include "persistence_client_library_data_access.h" +#include "persistence_client_library_custom_loader.h" #include <string.h> #include <errno.h> -#include <dlfcn.h> #include <stdlib.h> #include <dlt/dlt.h> #include <dlt/dlt_common.h> -/// pointer to resource table database -static GvdbTable* gResource_table = NULL; - /// debug log and trace (DLT) setup DLT_DECLARE_CONTEXT(persClientLibCtx); + /// library constructor void pers_library_init(void) __attribute__((constructor)); + /// library deconstructor void pers_library_destroy(void) __attribute__((destructor)); - - void pers_library_init(void) { DLT_REGISTER_APP("Persistence Client Library","persClientLib"); @@ -69,223 +67,75 @@ void pers_library_init(void) DLT_LOG(persClientLibCtx, DLT_LOG_ERROR, DLT_STRING("Initialize Persistence Client Library!!!!")); - setup_dbus_mainloop(); - - // register for lifecycle and persistence admin service dbus messages - register_lifecycle(); - register_pers_admin_service(); - - // clear the open file descriptor array - memset(gOpenFdArray, maxPersHandle, sizeof(int)); - - 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); -} + /// environment variable for on demand loading of custom libraries + const char *pOnDemenaLoad = getenv("PERS_CUSTOM_LIB_LOAD_ON_DEMAND"); + /// environment variable for max key value data + const char *pDataSize = getenv("PERS_MAX_KEY_VAL_DATA_SIZE"); - -void pers_library_destroy(void) -{ - // dereference opend database - if(gResource_table != NULL) + if(pDataSize != NULL) { - gvdb_table_unref(gResource_table); + gMaxKeyValDataSize = atoi(pDataSize); } - // unregister for lifecycle and persistence admin service dbus messages - unregister_lifecycle(); - unregister_pers_admin_service(); - + // setup dbus main dispatching loop + //setup_dbus_mainloop(); - DLT_UNREGISTER_CONTEXT(persClientLibCtx); - DLT_UNREGISTER_APP(); - dlt_free(); -} + // register for lifecycle and persistence admin service dbus messages + //register_lifecycle(); + //register_pers_admin_service(); + // clear the open file descriptor array + memset(gOpenFdArray, maxPersHandle, sizeof(int)); + /// get custom library names to load + get_custom_libraries(); -// status: OK -int get_db_context(unsigned char ldbid, char* resource_id, unsigned char user_no, unsigned char seat_no, - unsigned int isFile, char dbKey[], char dbPath[]) -{ - unsigned char cached = 0; - GVariant* dbValue = NULL; - // get resource configuration table - GvdbTable* resource_table = get_resource_cfg_table(); - - // check if resouce id is in write through table - dbValue = gvdb_table_get_value(resource_table, resource_id); - if(dbValue != NULL) + if(pOnDemenaLoad == NULL) // load all available libraries now { - cached = storeWt; // it's a write through value - } - else - { - cached = storeCached; // must be a cached value - } - return get_db_path_and_key(ldbid, resource_id, user_no, seat_no, isFile, dbKey, dbPath, cached); -} - + int i = 0; + for(i=0; i < get_num_custom_client_libs(); i++ ) + load_custom_library(get_position_in_array(i), &gPersCustomFuncs[i] ); -// status: OK -int get_db_path_and_key(unsigned char ldbid, char* resource_id, unsigned char user_no, unsigned char seat_no, - unsigned int isFile, char dbKey[], char dbPath[], unsigned char cached_resource) -{ - int rval = -1; - - // - // create resource database key - // - if((ldbid < 0x80) || (ldbid == 0xFF) ) - { - // The LDBID is used to find the DBID in the resource table. - if((user_no == 0) && (seat_no == 0)) - { - // Node is added in front of the resource ID as the key string. - snprintf(dbKey, dbKeyMaxLen, "%s%s", gNode, resource_id); - rval = 0; - } - else - { - if(seat_no == 0) - { - // /User/<user_no_parameter> is added in front of the resource ID as the key string. - snprintf(dbKey, dbKeyMaxLen, "%s%d%s", gUser, user_no, resource_id); - rval = 0; - } - else - { - // /User/<user_no_parameter>/Seat/<seat_no_parameter> is added in front of the resource ID as the key string. - snprintf(dbKey, dbKeyMaxLen, "%s%d%s%d%s", gUser, user_no, gSeat, seat_no, resource_id); - rval = 0; - } - } + /// just testing + //gPersCustomFuncs[PersCustomLib_early].custom_plugin_open("Hallo", 88, 99); + //gPersCustomFuncs[PersCustomLib_early].custom_plugin_close(17); } - - if((ldbid >= 0x80) && ( ldbid != 0xFF)) - { - // The LDBID is used to find the DBID in the resource table. - // /<LDBID parameter> is added in front of the resource ID as the key string. - // Rational: Creates a namespace within one data base. - // Rational: Reduction of number of databases -> reduction of maintenance costs - // /User/<user_no_parameter> and /Seat/<seat_no_parameter> are add after /<LDBID parameter> if there are different than 0. - if(seat_no != 0) - { - snprintf(dbKey, dbKeyMaxLen, "/%x%s%d%s%d%s", ldbid, gUser, user_no, gSeat, seat_no, resource_id); - } - else - { - snprintf(dbKey, dbKeyMaxLen, "/%x%s%d%s", ldbid, gUser, user_no, resource_id); - } - rval = 0; - } + 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); +} - // - // create resource database path - // - if(ldbid < 0x80) - { - // ------------------------------------- - // shared database - // ------------------------------------- - if(ldbid != 0) - { - // Additionally /GROUP/<LDBID_parameter> shall be added inside of the database path listed in the resource table. (Off target) - // Rational: To ensure data separation using the Linux user right policy (different data base files in different locations). - - if(storeCached == cached_resource) - { - if(isFile == resIsNoFile) - snprintf(dbPath, dbPathMaxLen, gSharedCachePath, ldbid, gSharedCached); - else - snprintf(dbPath, dbPathMaxLen, gSharedCachePath, ldbid, dbKey); - } - else if(storeWt == cached_resource) - { - if(isFile == resIsNoFile) - snprintf(dbPath, dbPathMaxLen, gSharedWtPath, ldbid, gSharedWt); - else - snprintf(dbPath, dbPathMaxLen, gSharedWtPath, ldbid, dbKey); - } - } - else - { - // Additionally /Shared/Public shall be added inside of the database path listed in the resource table. (Off target) - - if(storeCached == cached_resource) - { - if(isFile == resIsNoFile) - snprintf(dbPath, dbPathMaxLen, gSharedPublicCachePath, gSharedCached); - else - snprintf(dbPath, dbPathMaxLen, gSharedPublicCachePath, dbKey); - } - else if(storeWt == cached_resource) - { - if(isFile == resIsNoFile) - snprintf(dbPath, dbPathMaxLen, gSharedPublicWtPath, gSharedWt); - else - snprintf(dbPath, dbPathMaxLen, gSharedPublicWtPath, dbKey); - } - } +void pers_library_destroy(void) +{ + int i = 0; + GvdbTable* resourceTable = NULL; - rval = dbShared; // we have a shared database - } - else + for(i=0; i< PersistenceRCT_LastEntry; i++) { - // ------------------------------------- - // local database - // ------------------------------------- + resourceTable = get_resource_cfg_table_by_idx(i); - if(storeCached == cached_resource) + // dereference opend database + if(resourceTable != NULL) { - if(isFile == resIsNoFile) - snprintf(dbPath, dbPathMaxLen, gLocalCachePath, gAppId, gLocalCached); - else - snprintf(dbPath, dbPathMaxLen, gLocalCachePath, gAppId, dbKey); + gvdb_table_unref(resourceTable); } - else if(storeWt == cached_resource) - { - if(isFile == resIsNoFile) - snprintf(dbPath, dbPathMaxLen, gLocalWtPath, gAppId, gLocalWt); - else - snprintf(dbPath, dbPathMaxLen, gLocalWtPath, gAppId, dbKey); - } - - rval = dbLocal; // we have a local database } - printf("dbKey : [key ]: %s \n", dbKey); - printf("dbPath : [path]: %s\n\n", dbPath); - - return rval; -} - - -// status: OK -GvdbTable* get_resource_cfg_table() -{ - if(gResource_table == NULL) // check if database is already open - { - GError* error = NULL; - char filename[dbPathMaxLen]; - snprintf(filename, dbPathMaxLen, gLocalWtPath, gAppId, gResTableCfg); - gResource_table = gvdb_table_new(filename, TRUE, &error); + // unregister for lifecycle and persistence admin service dbus messages + //unregister_lifecycle(); + //unregister_pers_admin_service(); - if(gResource_table == NULL) - { - printf("Database error: %s\n", error->message); - g_error_free(error); - error = NULL; - } - } - return gResource_table; + DLT_UNREGISTER_CONTEXT(persClientLibCtx); + DLT_UNREGISTER_APP(); + dlt_free(); } + diff --git a/src/persistence_client_library.h b/src/persistence_client_library.h index 6f9ce91..94ceb0f 100644 --- a/src/persistence_client_library.h +++ b/src/persistence_client_library.h @@ -43,16 +43,11 @@ /// constant definitions -enum persClientLibConstantDef +enum _PersistenceConstantDef { - - storeWt = 0, /// flag for write through storage policy - dbLocal = 0, /// flag for local storage location resIsNoFile = 0, /// flag to identify that resource a not file - storeCached = 1, /// flag for cached storage policy - dbShared = 1, /// flag for shared storage location resIsFile = 1, /// flag to identify that resource a file - accessLocked = 1, /// flag to indicate that access is locked + accessNoLock = 1, /// flag to indicate that access is not locked FileClosed = 0, FileOpen = 1, @@ -68,10 +63,13 @@ enum persClientLibConstantDef PasErrorStatus_OK = 100, /// persistence administration service msg return status PasErrorStatus_FAIL = -1, /// persistence administration service msg return status + CustLibMaxLen = 128, /// max length of the custom library name and path dbKeyMaxLen = 128, /// max database key length dbPathMaxLen = 128, /// max database path length maxAppNameLen = 128, /// max application name - maxPersHandle = 256 /// max number of parallel open persistence handles + maxPersHandle = 256, /// max number of parallel open persistence handles + + defaultMaxKeyValDataSize = 16384 /// default limit the key-value data size to 16kB }; /// resource configuration table name @@ -109,17 +107,17 @@ static const char* gLocalCachePath = "/Data/mnt-c/%s%s"; /// path prefic for local write through database /Data/mnt_wt/<appId>/<database_name> static const char* gLocalWtPath = "/Data/mnt-wt/%s%s"; /// path prefic for shared cached database: /Data/mnt_c/Shared/Group/<group_no>/<database_name> -static const char* gSharedCachePath = "/Data/mnt-c/Shared/Group/%x%s"; +static const char* gSharedCachePath = "/Data/mnt-c/shared/group/%x%s"; /// path prefic for shared write through database: /Data/mnt_wt/Shared/Group/<group_no>/<database_name> -static const char* gSharedWtPath = "/Data/mnt-wt/Shared/Group/%x%s"; +static const char* gSharedWtPath = "/Data/mnt-wt/shared/group/%x%s"; /// path prefic for shared public cached database: /Data/mnt_c/Shared/Public//<database_name> -static const char* gSharedPublicCachePath = "/Data/mnt-c/Shared/Public%s"; +static const char* gSharedPublicCachePath = "/Data/mnt-c/shared/public%s"; /// path prefic for shared public write through database: /Data/mnt_wt/Shared/Public/<database_name> -static const char* gSharedPublicWtPath = "/Data/mnt-wt/Shared/Public%s"; +static const char* gSharedPublicWtPath = "/Data/mnt-wt/shared/public%s"; /// application id -static char gAppId[maxAppNameLen]; +char gAppId[maxAppNameLen]; /** enumerator used to identify the policy to manage the data */ @@ -154,57 +152,27 @@ typedef struct _PersistenceConfigurationKey_s PersistencePolicy_e policy; /**< policy */ PersistenceStorage_e storage; /**< definition of storage to use */ unsigned int permission; /**< access right, corresponds to UNIX */ - long max_size; /**< max size expected for the key */ + unsigned int max_size; /**< max size expected for the key */ char * reponsible; /**< name of responsible application */ char * custom_name; /**< name of the customer plugin */ } PersistenceConfigurationKey_s; +typedef enum _PersistenceRCT_e +{ + PersistenceRCT_local = 0, + PersistenceRCT_shared_public = 1, + PersistenceRCT_shared_group = 2, -/** - * @brief Create database search key and database location path - * - * @param ldbid logical database id - * @param resource_id the resource id - * @param user_no user identification - * @param seat_no seat identifier - * @param isFile identifier if this resource is a file - * @param dbKey the array where the database key will be stored - * @param dbPath the array where the database location path will be stored - * @param cached_resource flag to identify if the resource is cached (value 1)or write through (value 0) - * - * @return -1 if error : 1 if shared database and 0 if local database - */ -int get_db_path_and_key(unsigned char ldbid, char* resource_id, unsigned char user_no, unsigned char seat_no, - unsigned int isFile, char dbKey[], char dbPath[], unsigned char cached_resource); - - - -/** - * Create database search key and database location path - * - * @param ldbid logical database id - * @param resource_id the resource id - * @param user_no user identification - * @param seat_no seat identifier - * @param isFile identifier if this resource is a file - * @param dbKey the array where the database key will be stored - * @param dbPath the array where the database location path will be stored - * @param cached_resource flag to identify if the resource is cached (value 1)or write through (value 0) - * - * @return -1 if error : 1 if shared database and 0 if local database - */ -int get_db_context(unsigned char ldbid, char* resource_id, unsigned char user_no, unsigned char seat_no, - unsigned int isFile, char dbKey[], char dbPath[]); + PersistenceRCT_LastEntry // last Entry +} PersistenceRCT_e; + + +/// max key value data size +static int gMaxKeyValDataSize = defaultMaxKeyValDataSize; -/** - * @brief get the resource configuration table gvbd database - * - * @return pointer to the gvdb database table - */ -GvdbTable* get_resource_cfg_table(); diff --git a/src/persistence_client_library_access_helper.c b/src/persistence_client_library_access_helper.c new file mode 100644 index 0000000..a19fb58 --- /dev/null +++ b/src/persistence_client_library_access_helper.c @@ -0,0 +1,472 @@ +/****************************************************************************** + * Project Persistency + * (c) copyright 2012 + * Company XS Embedded GmbH + *****************************************************************************/ +/****************************************************************************** + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE + OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +******************************************************************************/ + /** + * @file persistence_client_library_access_helper.c + * @ingroup Persistence client library + * @author Ingo Huerner + * @brief Implementation of persistence access helper functions + * @see + */ + + +#include "persistence_client_library_access_helper.h" + +#include "gvdb-builder.h" + +#include <stdlib.h> + + +/// pointer to resource table database +GvdbTable* gResource_table[] = { NULL, NULL, NULL, NULL }; + + + +PersistenceRCT_e get_table_id(int ldbid, int* groupId) +{ + PersistenceRCT_e rctType = PersistenceRCT_LastEntry; + if(ldbid < 0x80) + { + // S H A R E D database + if(ldbid != 0) + { + // shared G R O U P database * * * * * * * * * * * * * * * * * * * + *groupId = ldbid; // assign group ID + rctType = PersistenceRCT_shared_group; + } + else + { + // shared P U B L I C database * * * * * * * * * * * * * * * * * * + *groupId = 0; // no group ID for public data + rctType = PersistenceRCT_shared_public; + } + } + else + { + // L O C A L database + *groupId = 0; // no group ID for local data + rctType = PersistenceStorage_local; // we have a local database + } + return rctType; +} + + +GvdbTable* get_resource_cfg_table_by_idx(int i) +{ + return gResource_table[i]; +} + + +// status: OK +GvdbTable* get_resource_cfg_table(PersistenceRCT_e rct, int group) +{ + if(gResource_table[rct] == NULL) // check if database is already open + { + GError* error = NULL; + char filename[dbPathMaxLen]; + + switch(rct) // create db name + { + case PersistenceRCT_local: + snprintf(filename, dbPathMaxLen, gLocalWtPath, gAppId, gResTableCfg); + break; + case PersistenceRCT_shared_public: + snprintf(filename, dbPathMaxLen, gSharedPublicWtPath, gResTableCfg); + break; + case PersistenceRCT_shared_group: + snprintf(filename, dbPathMaxLen, gSharedWtPath, group, gResTableCfg); + break; + default: + printf("get_resource_cfg_table - error: no valid PersistenceRCT_e\n"); + break; + } + + gResource_table[rct] = gvdb_table_new(filename, TRUE, &error); + printf("get_resource_cfg_table - group %d | db filename: %s \n", group, filename); + + if(gResource_table[rct] == NULL) + { + printf("get_resource_cfg_table - Database error: %s\n", error->message); + g_error_free(error); + error = NULL; + } + } + + return gResource_table[rct]; +} + + + +int serialize_data(PersistenceConfigurationKey_s pc, char* buffer) +{ + int rval = 0; + rval = snprintf(buffer, gMaxKeyValDataSize, "%d %d %u %d %s %s", + pc.policy, pc.storage, pc.permission, pc.max_size, + pc.reponsible, pc.custom_name); + + printf("serialize_data: %s \n", buffer); + return rval; +} + + + +int de_serialize_data(char* buffer, PersistenceConfigurationKey_s* pc) +{ + int rval = 1; + char* token = NULL; + if(buffer != NULL) + { + token = strtok(buffer, " "); // policy + if(token != 0) + { + pc->policy = strtol(token, 0, 10); + //printf("pc->policy %d \n", pc->policy); + } + else + { + printf("de_serialize_data - error: can't get [policy] \n"); + rval = -1; + } + + token = strtok (NULL, " "); // storage + if(token != 0) + { + pc->storage = strtol(token, 0, 10); + //printf("pc->storage %d \n", pc->storage); + } + else + { + printf("de_serialize_data - error: can't get [storage] \n"); + rval = -1; + } + + token = strtok (NULL, " "); // permission + if(token != 0) + { + pc->permission = strtol(token, 0, 10); + //printf("pc->permission %d \n", pc->permission); + } + else + { + printf("de_serialize_data - error: can't get [permission] \n"); + rval = -1; + } + + token = strtok (NULL, " "); // max_size + if(token != 0) + { + pc->max_size = strtol(token, 0, 10); + //printf("pc->max_size %d \n", pc->max_size); + } + else + { + printf("de_serialize_data - error: can't get [max_size] \n"); + rval = -1; + } + + token = strtok (NULL, " "); // reponsible + if(token != 0) + { + int size = strlen(token)+1; + pc->reponsible = malloc(size); + strncpy(pc->reponsible, token, size); + //printf(" pc->reponsible %s | 0x%x \n", pc->reponsible, (int)pc->reponsible); + } + else + { + printf("de_serialize_data - error: can't get [reponsible] \n"); + rval = -1; + } + + token = strtok (NULL, " "); // custom_name + if(token != 0) + { + int size = strlen(token)+1; + pc->custom_name = malloc(size); + strncpy(pc->custom_name, token, size); + //printf(" pc->custom_name %s | 0x%x \n", pc->custom_name, (int)pc->custom_name); + } + else + { + char* na = "na"; + int size = strlen(na)+1; + // custom name not available => no custom plugin + pc->custom_name = malloc(size); + strncpy(pc->custom_name, "na", size); + } + } + else + { + printf("de_serialize_data - error: buffer is NULL\n"); + rval = -1; + } + + return rval; +} + + + +int free_pers_conf_key(PersistenceConfigurationKey_s* pc) +{ + int rval = 1; + + if(pc != NULL) + { + if(pc->reponsible != NULL) + { + free(pc->reponsible); + pc->reponsible = NULL; + //printf("free_pers_conf_key => free(pc->reponsible);"); + } + + if(pc->custom_name != NULL) + { + free(pc->custom_name); + pc->custom_name = NULL; + //printf("free_pers_conf_key => free(pc->reponsible);"); + } + } + + return rval; +} + + + +// status: OK +int get_db_context(unsigned char ldbid, char* resource_id, unsigned char user_no, unsigned char seat_no, + unsigned int isFile, char dbKey[], char dbPath[]) +{ + int rval = 0, + resourceFound = 0, + groupId = 0; + + PersistenceRCT_e rct = PersistenceRCT_LastEntry; + + rct = get_table_id(ldbid, &groupId); + + // get resource configuration table + GvdbTable* resource_table = get_resource_cfg_table(rct, groupId); + + if(resource_table != NULL) + { + GVariant* dbValue = NULL; + + // check if resouce id is in write through table + dbValue = gvdb_table_get_value(resource_table, resource_id); + + if(dbValue != NULL) + { + PersistenceConfigurationKey_s dbEntry; + + gconstpointer valuePtr = NULL; + int size = g_variant_get_size(dbValue); + valuePtr = g_variant_get_data(dbValue); + if(valuePtr != NULL) + { + char* buffer = malloc(size); + memcpy(buffer, valuePtr, size); + de_serialize_data(buffer, &dbEntry); + + if(dbEntry.storage != PersistenceStorage_custom ) + { + // 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) + { + 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; + } + } + else + { + printf("get_db_context - resource_table: no value for key: %s \n", resource_id); + rval = -1; + } + } // resource table + + + if(resourceFound == 0) + { + printf("get_db_context - error resource not found %s \n", resource_id); + } + + return rval; +} + + + +// status: OK +int get_db_path_and_key(unsigned char ldbid, char* resource_id, unsigned char user_no, unsigned char seat_no, + unsigned int isFile, char dbKey[], char dbPath[], unsigned char cached_resource) +{ + int storePolicy = PersistenceStoragePolicy_LastEntry; + + // + // create resource database key + // + if((ldbid < 0x80) || (ldbid == 0xFF) ) + { + // The LDBID is used to find the DBID in the resource table. + if((user_no == 0) && (seat_no == 0)) + { + // + // Node is added in front of the resource ID as the key string. + // + snprintf(dbKey, dbKeyMaxLen, "%s%s", gNode, resource_id); + } + else + { + // + // Node is added in front of the resource ID as the key string. + // + if(seat_no == 0) + { + // /User/<user_no_parameter> is added in front of the resource ID as the key string. + snprintf(dbKey, dbKeyMaxLen, "%s%d%s", gUser, user_no, resource_id); + } + else + { + // /User/<user_no_parameter>/Seat/<seat_no_parameter> is added in front of the resource ID as the key string. + snprintf(dbKey, dbKeyMaxLen, "%s%d%s%d%s", gUser, user_no, gSeat, seat_no, resource_id); + } + } + storePolicy = PersistenceStorage_local; + } + + if((ldbid >= 0x80) && ( ldbid != 0xFF)) + { + // The LDBID is used to find the DBID in the resource table. + // /<LDBID parameter> is added in front of the resource ID as the key string. + // Rational: Creates a namespace within one data base. + // Rational: Reduction of number of databases -> reduction of maintenance costs + // /User/<user_no_parameter> and /Seat/<seat_no_parameter> are add after /<LDBID parameter> if there are different than 0. + + if(seat_no != 0) + { + snprintf(dbKey, dbKeyMaxLen, "/%x%s%d%s%d%s", ldbid, gUser, user_no, gSeat, seat_no, resource_id); + } + else + { + snprintf(dbKey, dbKeyMaxLen, "/%x%s%d%s", ldbid, gUser, user_no, resource_id); + } + storePolicy = PersistenceStorage_local; + } + + // + // create resource database path + // + if(ldbid < 0x80) + { + // S H A R E D database + + if(ldbid != 0) + { + // Additionally /GROUP/<LDBID_parameter> shall be added inside of the database path listed in the resource table. (Off target) + // + // shared G R O U P database * * * * * * * * * * * * * * * * * * * + // + if(PersistencePolicy_wc == cached_resource) + { + if(isFile == resIsNoFile) + snprintf(dbPath, dbPathMaxLen, gSharedCachePath, ldbid, gSharedCached); + else + snprintf(dbPath, dbPathMaxLen, gSharedCachePath, ldbid, dbKey); + } + else if(PersistencePolicy_wt == cached_resource) + { + if(isFile == resIsNoFile) + snprintf(dbPath, dbPathMaxLen, gSharedWtPath, ldbid, gSharedWt); + else + snprintf(dbPath, dbPathMaxLen, gSharedWtPath, ldbid, dbKey); + } + } + else + { + // Additionally /Shared/Public shall be added inside of the database path listed in the resource table. (Off target) + // + // shared P U B L I C database * * * * * * * * * * * * * * * * * * + // + if(PersistencePolicy_wc == cached_resource) + { + if(isFile == resIsNoFile) + snprintf(dbPath, dbPathMaxLen, gSharedPublicCachePath, gSharedCached); + else + snprintf(dbPath, dbPathMaxLen, gSharedPublicCachePath, dbKey); + } + else if(PersistencePolicy_wt == cached_resource) + { + if(isFile == resIsNoFile) + snprintf(dbPath, dbPathMaxLen, gSharedPublicWtPath, gSharedWt); + else + snprintf(dbPath, dbPathMaxLen, gSharedPublicWtPath, dbKey); + } + } + + storePolicy = PersistenceStorage_shared; // we have a shared database + } + else + { + // L O C A L database + + if(PersistencePolicy_wc == cached_resource) + { + if(isFile == resIsNoFile) + snprintf(dbPath, dbPathMaxLen, gLocalCachePath, gAppId, gLocalCached); + else + snprintf(dbPath, dbPathMaxLen, gLocalCachePath, gAppId, dbKey); + } + else if(PersistencePolicy_wt == cached_resource) + { + if(isFile == resIsNoFile) + snprintf(dbPath, dbPathMaxLen, gLocalWtPath, gAppId, gLocalWt); + else + snprintf(dbPath, dbPathMaxLen, gLocalWtPath, gAppId, dbKey); + } + + storePolicy = PersistenceStorage_local; // we have a local database + } + + //printf("get_db_path_and_key - dbKey : [key ]: %s \n", dbKey); + //printf("get_db_path_and_key - dbPath : [path]: %s\n\n", dbPath); + return storePolicy; +} + + + + + + diff --git a/src/persistence_client_library_access_helper.h b/src/persistence_client_library_access_helper.h new file mode 100644 index 0000000..dc09b55 --- /dev/null +++ b/src/persistence_client_library_access_helper.h @@ -0,0 +1,106 @@ +#ifndef PERSISTENCE_CLIENT_LIBRARY_ACCESS_HELPER_H +#define PERSISTENCE_CLIENT_LIBRARY_ACCESS_HELPER_H + +/****************************************************************************** + * Project Persistency + * (c) copyright 2012 + * Company XS Embedded GmbH + *****************************************************************************/ +/****************************************************************************** + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE + OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +******************************************************************************/ + /** + * @file persistence_client_library_access_helper.h + * @ingroup Persistence client library + * @author Ingo Huerner + * @brief Header of the persistence client library access helper. + * @see + */ + +#include "persistence_client_library.h" + + +/** + * @brief Create database search key and database location path + * + * @param ldbid logical database id + * @param resource_id the resource id + * @param user_no user identification + * @param seat_no seat identifier + * @param isFile identifier if this resource is a file + * @param dbKey the array where the database key will be stored + * @param dbPath the array where the database location path will be stored + * @param cached_resource flag to identify if the resource is cached (value 1)or write through (value 0) + * + * @return -1 if error : 1 if shared database and 0 if local database + */ +int get_db_path_and_key(unsigned char ldbid, char* resource_id, unsigned char user_no, unsigned char seat_no, + unsigned int isFile, char dbKey[], char dbPath[], unsigned char cached_resource); + + + +/** + * Create database search key and database location path + * + * @param ldbid logical database id + * @param resource_id the resource id + * @param user_no user identification + * @param seat_no seat identifier + * @param isFile identifier if this resource is a file + * @param dbKey the array where the database key will be stored + * @param dbPath the array where the database location path will be stored + * @param cached_resource flag to identify if the resource is cached (value 1)or write through (value 0) + * + * @return -1 if error : or PersistenceStorage_e + */ +int get_db_context(unsigned char ldbid, char* resource_id, unsigned char user_no, unsigned char seat_no, + unsigned int isFile, char dbKey[], char dbPath[]); + + + +/** + * @brief get the resource configuration table gvbd database by id + * + * @return pointer to the gvdb database table + */ +GvdbTable* get_resource_cfg_table_by_idx(int i); + + +/** + * @brief serialize data to store to database + */ +int serialize_data(PersistenceConfigurationKey_s pc, char* buffer); + + +/** + * @brief deserialize data read from database + */ +int de_serialize_data(char* buffer, PersistenceConfigurationKey_s* pc); + + +/** + * @brief free allocated data of a persistence configuration key + * + * @param pc the configuration key + */ +int free_pers_conf_key(PersistenceConfigurationKey_s* pc); + + + +#endif /* PERSISTENCE_CLIENT_LIBRARY_ACCESS_HELPER_H */ diff --git a/src/persistence_client_library_custom_loader.c b/src/persistence_client_library_custom_loader.c new file mode 100644 index 0000000..1fefd8e --- /dev/null +++ b/src/persistence_client_library_custom_loader.c @@ -0,0 +1,291 @@ +/****************************************************************************** + * Project Persistency + * (c) copyright 2012 + * Company XS Embedded GmbH + *****************************************************************************/ +/****************************************************************************** + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE + OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +******************************************************************************/ + /** + * @file persistence_client_library_custom_loader.c + * @ingroup Persistence client library + * @author Ingo Huerner + * @brief Implementation of persistence custom loadedr + * @see + */ + +#include "persistence_client_library_custom_loader.h" +#include "persistence_client_library.h" + +#include <stdio.h> +#include <errno.h> +#include <fcntl.h> +#include <sys/mman.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <sys/stat.h> +#include <dlfcn.h> + +// array containing the id of the custom arrays +static int gCustomLibIdArray[PersCustomLib_LastEntry]; + +/// array with custom client library names +static char gCustomLibArray[PersCustomLib_LastEntry][CustLibMaxLen]; +// number of libraries loaded +static int gNumOfCustomLibraries = 0; + + +PersistenceCustomLibs_e custom_libname_to_id(const char* lib_name) +{ + PersistenceCustomLibs_e libId = PersCustomLib_LastEntry; + + if(0 == strcmp(lib_name, "early") ) + { + libId = PersCustomLib_early; + } + else if (0 == strcmp(lib_name, "secure") ) + { + libId = PersCustomLib_secure; + } + else if (0 == strcmp(lib_name, "emergency") ) + { + libId = PersCustomLib_emergency; + } + else if (0 == strcmp(lib_name, "hwinfo") ) + { + libId = PersCustomLib_HWinfo; + } + else if (0 == strcmp(lib_name, "custom1") ) + { + libId = PersCustomLib_Custom1; + } + else if (0 == strcmp(lib_name, "custom2") ) + { + libId = PersCustomLib_Custom2; + } + else if (0 == strcmp(lib_name, "custom3") ) + { + libId = PersCustomLib_Custom3; + } + return libId; +} + + + +int get_custom_libraries() +{ + int rval = 0, + fd = 0, + i = 0; + + struct stat buffer; + char* delimiters = " \n"; // search for blank and end of line + char* configFileMap = 0; + char* token = 0; + const char *filename = getenv("PERS_CLIENT_LIB_CUSTOM_LOAD"); + + if(filename == NULL) + { + filename = "customLibConfigFile.cfg"; // use default filename + } + + if(stat(filename, &buffer) != -1) + { + fd = open(filename, O_RDONLY); + if (fd != -1) + { + configFileMap = (char*)mmap(0, buffer.st_size, PROT_WRITE, MAP_PRIVATE, fd, 0); + + if(configFileMap != MAP_FAILED) + { + int libId = 0; + + // get the library identifier (early, secure, emergency, ...) + token = strtok(configFileMap, delimiters); + libId = custom_libname_to_id(token); + gCustomLibIdArray[libId] = i; + + // get the library name + token = strtok (NULL, delimiters); + strncpy(gCustomLibArray[i++], token, CustLibMaxLen); + + while( token != NULL ) + { + // get the library identifier (early, secure, emergency, ...) + token = strtok(NULL, delimiters); + if(token != NULL) + { + libId = custom_libname_to_id(token); + gCustomLibIdArray[libId] = i; + } + else + { + break; + } + + // get the library name + token = strtok (NULL, delimiters); + if(token != NULL) + { + strncpy(gCustomLibArray[i++], token, CustLibMaxLen); + } + else + { + break; + } + } + gNumOfCustomLibraries = i; // remember the number of loaded libraries +/* + printf("get_custom_libraries - found [ %d ] libraries \n", gNumOfCustomLibraries); + for(i=0; i< gNumOfCustomLibraries; i++) + printf("get_custom_libraries - names: %s\n", gCustomLibArray[i]); + + for(i=0; i<PersCustomLib_LastEntry; i++) + printf("get_custom_libraries - id: %d | pos: %d \n", i, gCustomLibIdArray[i]); +*/ + munmap(configFileMap, buffer.st_size); + close(fd); + } + else + { + printf("load config file error - mapping of file failed"); + } + } + else + { + printf("load config file error - filename: %s | error: %s \n", filename, strerror(errno) ); + + // load default librarys + // TODO + } + } + else + { + printf("load config file error - can't stat config file: %s | %s \n", filename, strerror(errno)); + } + return rval; +} + + + +int load_custom_library(PersistenceCustomLibs_e customLib, Pers_custom_functs_s *customFuncts) +{ + int rval = 0; + char *error; + + if(customLib < PersCustomLib_LastEntry) + { + void* handle = dlopen(gCustomLibArray[customLib], RTLD_LAZY); + if(handle != NULL) + { + dlerror(); // reset error + + // plugin_close + *(void **) (&customFuncts->custom_plugin_close) = dlsym(handle, "plugin_close"); + if ((error = dlerror()) != NULL) + { + printf("load_custom_library - error: %s\n", error); + return -1; + } + // custom_plugin_delete_data + *(void **) (&customFuncts->custom_plugin_delete_data) = dlsym(handle, "plugin_delete_data"); + 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) + { + printf("load_custom_library - error: %s\n", error); + return -1; + } + // custom_plugin_init + *(void **) (&customFuncts->custom_plugin_init) = dlsym(handle, "plugin_init"); + if ((error = dlerror()) != NULL) + { + printf("load_custom_library - error: %s\n", error); + return -1; + } + // custom_plugin_open + *(void **) (&customFuncts->custom_plugin_open) = dlsym(handle, "plugin_open"); + 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) + { + printf("load_custom_library - error: %s\n", error); + return -1; + } + // custom_plugin_get_status_notification_clbk + *(void **) (&customFuncts->custom_plugin_get_status_notification_clbk) = dlsym(handle, "plugin_get_status_notification_clbk"); + if ((error = dlerror()) != NULL) + { + printf("load_custom_library - error: %s\n", error); + return -1; + } + } + else + { + //printf("load_custom_library - error: %s\n", dlerror()); + rval = -1; + } + } + + return rval; +} + + + +int load_all_custom_libraries() +{ + int rval = 0, + i = 0; + + for(i=0; i<gNumOfCustomLibraries; i++) + { + if( load_custom_library(i, &gPersCustomFuncs[i] ) == -1) + { + // printf("load_all_custom_libraries - error loading library number [%d] \n", i); + rval = -1; + break; + } + } + return rval; +} + + + +int get_position_in_array(PersistenceCustomLibs_e customLibId) +{ + //printf("get_position_in_array - id: %d | position: %d \n", customLibId, gCustomLibIdArray[(int)customLibId]); + return gCustomLibIdArray[(int)customLibId]; +} + + +int get_num_custom_client_libs() +{ + return gNumOfCustomLibraries; +} diff --git a/src/persistence_client_library_custom_loader.h b/src/persistence_client_library_custom_loader.h new file mode 100644 index 0000000..3c30829 --- /dev/null +++ b/src/persistence_client_library_custom_loader.h @@ -0,0 +1,126 @@ +#ifndef PERSISTENCE_CLIENT_LIBRARY_CUSTOM_LOADER_H +#define PERSISTENCE_CLIENT_LIBRARY_CUSTOM_LOADER_H + +/****************************************************************************** + * Project Persistency + * (c) copyright 2012 + * Company XS Embedded GmbH + *****************************************************************************/ +/****************************************************************************** + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE + OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +******************************************************************************/ + /** + * @file persistence_client_library_custom_loader.h + * @ingroup Persistence client library + * @author Ingo Huerner + * @brief Header of the persistence client library custom library_loader. + * @see + */ + + +/// enumerator used to identify the policy to manage the data +typedef enum _PersistenceCustomLibs_e +{ + PersCustomLib_early = 0, /// predefined custom library for early persistence + PersCustomLib_secure = 1, /// predefined custom library for secure persistence + PersCustomLib_emergency = 2, /// predefined custom library for emengency persistence + PersCustomLib_HWinfo = 3, /// predefined custom library for hw information + PersCustomLib_Custom1 = 4, /// custom library 1 + PersCustomLib_Custom2 = 5, /// custom library 2 + PersCustomLib_Custom3 = 6, /// custom library 3 + + // insert new entries here ... + + PersCustomLib_LastEntry /// last entry + +} PersistenceCustomLibs_e; + + + +/// callback definition for custom_plugin_get_status_notification_clbk function +typedef int (*plugin_callback_t) (int status, void* dataPtr); + + +/// structure definition for custom library functions +typedef struct _Pers_custom_functs_s +{ + /// custom library init function + int (*custom_plugin_init)(); + + /// custom open function + long (*custom_plugin_open)(char* path, int flag, int mode); + + /// custom close function + int (*custom_plugin_close)(int handle); + + /// custom get data function + long (*custom_plugin_get_data)(long handle, char* buffer, long size); + + /// custom set data function + long (*custom_plugin_set_data)(long handle, char* buffer, long size); + + /// custom delete function + int (*custom_plugin_delete_data)(const char* path); + + /// custom status notification function + int (*custom_plugin_get_status_notification_clbk)(plugin_callback_t pFunct); + +}Pers_custom_functs_s; + + + +/// custom library functions array +Pers_custom_functs_s gPersCustomFuncs[PersCustomLib_LastEntry]; + + +/** + * @brief get the names of the custom libraries to load + * + * @return 0 for success or -1 if an error occurred + */ +int get_custom_libraries(); + + + +/** + * @brief get the names of the custom libraries to load + * + * @return 0 for success or -1 if an error occurred + */ +int load_custom_library(PersistenceCustomLibs_e customLib, Pers_custom_functs_s *customFuncts); + + + +/** + * @brief get the names of the custom libraries to load + * + * @return 0 for success or -1 if an error occurred + */ +int load_all_custom_libraries(); + + +/// get the position in the array +int get_position_in_array(PersistenceCustomLibs_e customLib); + + +int get_num_custom_client_libs(); + + + +#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 9d8eac6..9530f73 100644 --- a/src/persistence_client_library_data_access.c +++ b/src/persistence_client_library_data_access.c @@ -35,11 +35,11 @@ #include <string.h> #include <stdio.h> +#include <stdlib.h> #include <dconf-dbus-1.h> - int get_value_from_table(GvdbTable* database, char* key, unsigned char* buffer, unsigned long buffer_size) { int read_size = 0; @@ -95,23 +95,22 @@ int get_size_from_table(GvdbTable* database, char* key) -int persistence_get_data(char* dbPath, char* key, int shared, unsigned char* buffer, unsigned long buffer_size) +int persistence_get_data(char* dbPath, char* key, PersistenceStorage_e storage, unsigned char* buffer, unsigned long buffer_size) { int read_size = -1; - printf("key : %s \n", key); - printf("path: %s \n", dbPath); - if(dbShared == shared) // check if shared data (dconf) + if(PersistenceStorage_shared == storage) // check if shared data (dconf) { printf(" S H A R E D D A T A => not implemented yet\n"); //DConfClient* dconf_client_new(const gchar *profile, DConfWatchFunc watch_func, gpointer user_data, GDestroyNotify notify); //GVariant* dconf_client_read(DConfClient *client, const gchar *key); - - + strncpy(buffer, "S H A R E D D A T A => not implemented yet", buffer_size-1); } - else if(dbLocal == shared) // it is local data (gvdb) + else if(PersistenceStorage_local == storage) // it is local data (gvdb) { + printf(" L O C A L D A T A - path: %s \n", dbPath); + GError *error = NULL; GvdbTable* database = gvdb_table_new(dbPath, TRUE, &error);; gvdb_table_ref(database); @@ -122,23 +121,27 @@ int persistence_get_data(char* dbPath, char* key, int shared, unsigned char* buf } else { - printf("Database E R R O R: %s\n", error->message); + printf("persistence_get_data - Database E R R O R: %s\n", error->message); g_error_free(error); error = NULL; } } + else if(PersistenceStorage_custom == storage) // custom storage implementation via custom library + { + printf(" C U S T O M D A T A => not implemented yet - path: %s \n", dbPath); + strncpy(buffer, "C U S T O M D A T A => not implemented yet", buffer_size-1); + } + return read_size; } -int persistence_set_data(char* dbPath, char* key, int shared, unsigned char* buffer, unsigned long buffer_size) +int persistence_set_data(char* dbPath, char* key, PersistenceStorage_e storage, unsigned char* buffer, unsigned long buffer_size) { int write_size = -1; - printf("key : %s \n", key); - printf("path: %s \n", dbPath); - if(dbShared == shared) // check if shared data (dconf) + if(PersistenceStorage_shared == storage) // check if shared data (dconf) { //GVariant *value = NULL; //gboolean ok = FALSE; @@ -148,7 +151,7 @@ int persistence_set_data(char* dbPath, char* key, int shared, unsigned char* buf //ok = dconf_dbus_client_write(dcdbc, key, value); } - else if(dbLocal == shared) // it is local data (gvdb) + else if(PersistenceStorage_local == storage) // it is local data (gvdb) { GError *error = NULL; GHashTable* parent = NULL; @@ -161,28 +164,34 @@ int persistence_set_data(char* dbPath, char* key, int shared, unsigned char* buf { write_size = set_value_to_table(hash_table, key, buffer, buffer_size); gvdb_table_write_contents(hash_table, dbPath, FALSE, &error); + } else { - printf("Database E R R O R: %s\n", error->message); + printf("persistence_set_data - Database E R R O R: %s\n", error->message); g_error_free(error); error = NULL; } } + else if(PersistenceStorage_custom == storage) // custom storage implementation via custom library + { + printf(" C U S T O M D A T A => NOW IMPLEMENTING implemented yet\n"); + } + return write_size; } -int persistence_get_data_size(char* dbPath, char* key, int shared) +int persistence_get_data_size(char* dbPath, char* key, PersistenceStorage_e storage) { int read_size = -1; - if(dbShared == shared) // check if shared data (dconf) + if(PersistenceStorage_shared == storage) // check if shared data (dconf) { printf("S H A R E D D A T A => not implemented yet\n"); } - else if(dbLocal == shared) // it is local data (gvdb) + else if(PersistenceStorage_local == storage) // it is local data (gvdb) { GError *error = NULL; GvdbTable* database = gvdb_table_new(dbPath, TRUE, &error);; @@ -194,11 +203,16 @@ int persistence_get_data_size(char* dbPath, char* key, int shared) } else { - printf("Database E R R O R: %s\n", error->message); + printf("persistence_get_data_size - Database E R R O R: %s\n", error->message); g_error_free(error); error = NULL; } } + else if(PersistenceStorage_custom == storage) // custom storage implementation via custom library + { + printf(" C U S T O M D A T A => NOW IMPLEMENTING implemented yet\n"); + } + return read_size; } @@ -206,7 +220,7 @@ int persistence_get_data_size(char* dbPath, char* key, int shared) int set_value_to_table(GHashTable* database, char* key, unsigned char* buffer, unsigned long buffer_size) { - int size_written = -1; + int size_written = buffer_size; gvdb_hash_table_insert_string(database, key, (const gchar*)buffer); return size_written; } @@ -224,6 +238,3 @@ int persistence_reg_notify_on_change(char* dbPath, char* key) - - - diff --git a/src/persistence_client_library_data_access.h b/src/persistence_client_library_data_access.h index 536a38c..e8ad564 100644 --- a/src/persistence_client_library_data_access.h +++ b/src/persistence_client_library_data_access.h @@ -38,17 +38,16 @@ #include "gvdb-builder.h" - /** * @brief write data to a key * * @param dbPath the path to the database where the key is in * @param key the database key - * @param shared flag if key is a shared key + * @param storage the storage identifier (local, shared or custom) * (use dbShared for shared key or dbLocal if the key is local) * @return */ -int persistence_set_data(char* dbPath, char* key, int shared, unsigned char* buffer, unsigned long buffer_size); +int persistence_set_data(char* dbPath, char* key, PersistenceStorage_e storage, unsigned char* buffer, unsigned long buffer_size); @@ -57,12 +56,11 @@ int persistence_set_data(char* dbPath, char* key, int shared, unsigned char* buf * * @param dbPath the path to the database where the key is in * @param key the database key - * @param shared flag if key is a shared key - * (use dbShared for shared key or dbLocal if the key is local) + * @param storage the storage identifier (local, shared or custom) * * @return */ -int persistence_get_data(char* dbPath, char* key, int shared, unsigned char* buffer, unsigned long buffer_size); +int persistence_get_data(char* dbPath, char* key, PersistenceStorage_e storage, unsigned char* buffer, unsigned long buffer_size); @@ -71,12 +69,11 @@ int persistence_get_data(char* dbPath, char* key, int shared, unsigned char* buf * * @param dbPath the path to the database where the key is in * @param key the database key - * @param shared flag if key is a shared key - * (use dbShared for shared key or dbLocal if the key is local) + * @param storage the storage identifier (local, shared or custom) * * @return size of data in bytes read from the key */ -int persistence_get_data_size(char* dbPath, char* key, int shared); +int persistence_get_data_size(char* dbPath, char* key, PersistenceStorage_e storage); @@ -132,4 +129,8 @@ 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 ff1b03e..dc10017 100644 --- a/src/persistence_client_library_dbus_service.c +++ b/src/persistence_client_library_dbus_service.c @@ -330,14 +330,14 @@ int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtable2, if(DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != dbus_bus_request_name(conn, "org.genivi.persistence.adminconsumer", DBUS_NAME_FLAG_DO_NOT_QUEUE, &err)) { - printf("*** Cannot acquire name '%s' (%s). Bailing out!\n", "org.genivi.persistence.admin", err.message); + printf("*** Cannot acquire name '%s' (%s). Bailing out!\n", "org.genivi.persistence.admin\n", err.message); dbus_error_free(&err); bContinue = FALSE; } if(DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != dbus_bus_request_name(conn, "com.contiautomotive.NodeStateManager.LifecycleConsumer", DBUS_NAME_FLAG_DO_NOT_QUEUE, &err)) { - printf("*** Cannot acquire name '%s' (%s). Bailing out!\n", "com.contiautomotive.NodeStateManager.LifecycleConsumer", err.message); + printf("*** Cannot acquire name '%s' (%s). Bailing out!\n", "com.contiautomotive.NodeStateManager.LifecycleConsumer\n", err.message); dbus_error_free(&err); bContinue = FALSE; } diff --git a/src/persistence_client_library_file.c b/src/persistence_client_library_file.c index d8b6b50..3f6931a 100644 --- a/src/persistence_client_library_file.c +++ b/src/persistence_client_library_file.c @@ -36,6 +36,7 @@ #include "persistence_client_library_data_access.h" #include "persistence_client_library_pas_interface.h" #include "persistence_client_library_handle.h" +#include "persistence_client_library_access_helper.h" #include <fcntl.h> // for open flags #include <errno.h> @@ -49,7 +50,7 @@ int file_close(int fd) { int rval = -1; - if(accessLocked == isAccessLocked() ) // check if access to persistent data is locked + if(accessNoLock == isAccessLocked() ) // check if access to persistent data is locked { rval = close(fd); if(fd < maxPersHandle) @@ -66,7 +67,7 @@ int file_get_size(int fd) { int rval = 0; - if(accessLocked == isAccessLocked() ) // check if access to persistent data is locked + if(accessNoLock == isAccessLocked() ) // check if access to persistent data is locked { struct stat buf; int ret = 0; @@ -87,7 +88,7 @@ void* file_map_data(void* addr, long size, long offset, int fd) void* ptr = 0; int mapFlag = PROT_WRITE | PROT_READ; - if(accessLocked == isAccessLocked() ) // check if access to persistent data is locked + if(accessNoLock == isAccessLocked() ) // check if access to persistent data is locked { ptr = mmap(addr,size, mapFlag, MAP_SHARED, fd, offset); } @@ -100,7 +101,7 @@ int file_open(unsigned char ldbid, char* resource_id, unsigned char user_no, uns { int handle = -1; - if(accessLocked == isAccessLocked() ) // check if access to persistent data is locked + if(accessNoLock == isAccessLocked() ) // check if access to persistent data is locked { int shared_DB = 0, flags = O_RDWR; @@ -137,7 +138,7 @@ int file_open(unsigned char ldbid, char* resource_id, unsigned char user_no, uns int file_read_data(int fd, void * buffer, unsigned long buffer_size) { int size = -1; - if(accessLocked == isAccessLocked() ) // check if access to persistent data is locked + if(accessNoLock == isAccessLocked() ) // check if access to persistent data is locked { size = read(fd, buffer, buffer_size); } @@ -150,7 +151,7 @@ int file_remove(unsigned char ldbid, char* resource_id, unsigned char user_no, u { int rval = 0; - if(accessLocked == isAccessLocked() ) // check if access to persistent data is locked + if(accessNoLock == isAccessLocked() ) // check if access to persistent data is locked { int shared_DB = 0; @@ -177,7 +178,7 @@ int file_seek(int fd, long int offset, int whence) { int rval = 0; - if(accessLocked == isAccessLocked() ) // check if access to persistent data is locked + if(accessNoLock == isAccessLocked() ) // check if access to persistent data is locked { rval = lseek(fd, offset, whence); } @@ -190,7 +191,7 @@ int file_unmap_data(void* address, long size) { int rval = 0; - if(accessLocked == isAccessLocked() ) // check if access to persistent data is locked + if(accessNoLock == isAccessLocked() ) // check if access to persistent data is locked { rval = munmap(address, size); } @@ -203,7 +204,7 @@ int file_write_data(int fd, const void * buffer, unsigned long buffer_size) { int size = 0; - if(accessLocked == isAccessLocked() ) // check if access to persistent data is locked + if(accessNoLock == isAccessLocked() ) // check if access to persistent data is locked { size = write(fd, buffer, buffer_size); } diff --git a/src/persistence_client_library_key.c b/src/persistence_client_library_key.c index 1a563b4..509cc00 100644 --- a/src/persistence_client_library_key.c +++ b/src/persistence_client_library_key.c @@ -31,13 +31,12 @@ * @see */ - #include "persistence_client_library_key.h" #include "persistence_client_library.h" #include "persistence_client_library_handle.h" #include "persistence_client_library_data_access.h" #include "persistence_client_library_pas_interface.h" - +#include "persistence_client_library_access_helper.h" @@ -49,24 +48,24 @@ int key_handle_open(unsigned char ldbid, char* resource_id, unsigned char user_n { int handle = -1; - if(accessLocked == isAccessLocked() ) // check if access to persistent data is locked + if(accessNoLock == isAccessLocked() ) // check if access to persistent data is locked { - int shared_DB = 0; + int storePolicy = 0; char dbKey[dbKeyMaxLen]; // database key char dbPath[dbPathMaxLen]; // database location // get database context: database path and database key - shared_DB = get_db_context(ldbid, resource_id, user_no, seat_no, resIsNoFile, dbKey, dbPath); + storePolicy = get_db_context(ldbid, resource_id, user_no, seat_no, resIsNoFile, dbKey, dbPath); - if(shared_DB != -1) // check valid database context + if(storePolicy < PersistenceStoragePolicy_LastEntry) // check if store policy is valid { 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 = shared_DB; + gHandleArray[handle].shared_DB = storePolicy; } } @@ -79,7 +78,7 @@ int key_handle_close(int key_handle) { int rval = 0; - if(accessLocked == isAccessLocked() ) // check if access to persistent data is locked + if(accessNoLock == isAccessLocked() ) // check if access to persistent data is locked { // invalidate entries strncpy(gHandleArray[key_handle].dbPath, "", dbPathMaxLen); @@ -98,10 +97,11 @@ int key_handle_get_size(int key_handle) { int size = -1; - if(accessLocked == isAccessLocked() ) // check if access to persistent data is locked + if(accessNoLock == isAccessLocked() ) // check if access to persistent data is locked { if(key_handle < maxPersHandle) - size = persistence_get_data_size(gHandleArray[key_handle].dbPath, gHandleArray[key_handle].dbKey, gHandleArray[key_handle].shared_DB); + size = persistence_get_data_size(gHandleArray[key_handle].dbPath, gHandleArray[key_handle].dbKey, + gHandleArray[key_handle].shared_DB); } return size; @@ -113,10 +113,11 @@ int key_handle_read_data(int key_handle, unsigned char* buffer, unsigned long bu { int size = -1; - if(accessLocked == isAccessLocked() ) // check if access to persistent data is locked + if(accessNoLock == isAccessLocked() ) // check if access to persistent data is locked { if(key_handle < maxPersHandle) - size = persistence_get_data(gHandleArray[key_handle].dbPath, gHandleArray[key_handle].dbKey, gHandleArray[key_handle].shared_DB, buffer, buffer_size); + size = persistence_get_data(gHandleArray[key_handle].dbPath, gHandleArray[key_handle].dbKey, + gHandleArray[key_handle].shared_DB, buffer, buffer_size); } return size; @@ -137,10 +138,18 @@ int key_handle_write_data(int key_handle, unsigned char* buffer, unsigned long b { int size = -1; - if(accessLocked == isAccessLocked() ) // check if access to persistent data is locked + if(accessNoLock == isAccessLocked() ) // check if access to persistent data is locked { - if(key_handle < maxPersHandle) - size = persistence_set_data(gHandleArray[key_handle].dbPath, gHandleArray[key_handle].dbKey, gHandleArray[key_handle].shared_DB, buffer, buffer_size); + if(buffer_size <= gMaxKeyValDataSize) // check data size + { + if(key_handle < maxPersHandle) + size = persistence_set_data(gHandleArray[key_handle].dbPath, gHandleArray[key_handle].dbKey, + gHandleArray[key_handle].shared_DB, buffer, buffer_size); + } + else + { + printf("key_handle_write_data: error - buffer_size to big, limit is [%d] bytes\n", gMaxKeyValDataSize); + } } return size; @@ -157,11 +166,10 @@ int key_delete(unsigned char ldbid, char* resource_id, unsigned char user_no, un { int rval = 0; - if(accessLocked == isAccessLocked() ) // check if access to persistent data is locked + if(accessNoLock == isAccessLocked() ) // check if access to persistent data is locked { // TODO } - return rval; } @@ -172,19 +180,24 @@ int key_get_size(unsigned char ldbid, char* resource_id, unsigned char user_no, { int data_size = -1; - if(accessLocked == isAccessLocked() ) // check if access to persistent data is locked + if(accessNoLock == isAccessLocked() ) // check if access to persistent data is locked { - int shared_DB = 0; + int storePolicy = 0; char dbKey[dbKeyMaxLen]; // database key char dbPath[dbPathMaxLen]; // database location // get database context: database path and database key - shared_DB = get_db_context(ldbid, resource_id, user_no, seat_no, resIsNoFile, dbKey, dbPath); + storePolicy = get_db_context(ldbid, resource_id, user_no, seat_no, resIsNoFile, dbKey, dbPath); - if(shared_DB != -1) // check if database context is valid + if( storePolicy < PersistenceStoragePolicy_LastEntry + && storePolicy >= PersistenceStorage_local) // check if store policy is valid { - data_size = persistence_get_data_size(dbPath, dbKey, shared_DB); + data_size = persistence_get_data_size(dbPath, dbKey, storePolicy); + } + else + { + printf("key_read_data: error - storage policy does not exist \n"); } } @@ -194,57 +207,79 @@ int key_get_size(unsigned char ldbid, char* resource_id, unsigned char user_no, // status: OK -int key_read_data(unsigned char ldbid, char* resource_id, unsigned char user_no, unsigned char seat_no, unsigned char* buffer, unsigned long buffer_size) +int key_read_data(unsigned char ldbid, char* resource_id, unsigned char user_no, unsigned char seat_no, + unsigned char* buffer, unsigned long buffer_size) { int data_size = -1; - if(accessLocked == isAccessLocked() ) // check if access to persistent data is locked + if(accessNoLock != isAccessLocked() ) // check if access to persistent data is locked { - int shared_DB = 0; + int storePolicy = 0; char dbKey[dbKeyMaxLen]; // database key char dbPath[dbPathMaxLen]; // database location // get database context: database path and database key - shared_DB = get_db_context(ldbid, resource_id, user_no, seat_no, resIsNoFile, dbKey, dbPath); + storePolicy = get_db_context(ldbid, resource_id, user_no, seat_no, resIsNoFile, dbKey, dbPath); - if(shared_DB != -1) // check if database context is valid + if( storePolicy < PersistenceStoragePolicy_LastEntry + && storePolicy >= PersistenceStorage_local) // check if store policy is valid + { + data_size = persistence_get_data(dbPath, dbKey, storePolicy, buffer, buffer_size); + } + else { - data_size = persistence_get_data(dbPath, dbKey, shared_DB, buffer, buffer_size); + printf("key_read_data: error - storage policy does not exist \n"); } } + else + { + printf("key_read_data - accessLocked\n"); + } return data_size; } -// status: TODO -int key_write_data(unsigned char ldbid, char* resource_id, unsigned char user_no, unsigned char seat_no, unsigned char* buffer, unsigned long buffer_size) +int key_write_data(unsigned char ldbid, char* resource_id, unsigned char user_no, unsigned char seat_no, + unsigned char* buffer, unsigned long buffer_size) { int data_size = -1; - if(accessLocked == isAccessLocked() ) // check if access to persistent data is locked + if(accessNoLock == isAccessLocked() ) // check if access to persistent data is locked { - int shared_DB = 0; - unsigned int hash_val_data = 0; + if(buffer_size <= gMaxKeyValDataSize) // check data size + { + int storePolicy = 0; - char dbKey[dbKeyMaxLen]; // database key - char dbPath[dbPathMaxLen]; // database location + unsigned int hash_val_data = 0; - // get database context: database path and database key - shared_DB = get_db_context(ldbid, resource_id, user_no, seat_no, resIsNoFile, dbKey, dbPath); + char dbKey[dbKeyMaxLen]; // database key + char dbPath[dbPathMaxLen]; // database location + + // get database context: database path and database key + storePolicy = get_db_context(ldbid, resource_id, user_no, seat_no, resIsNoFile, dbKey, dbPath); - // get hash value of data to verify storing - hash_val_data = crc32(hash_val_data, buffer, buffer_size); + // get hash value of data to verify storing + hash_val_data = crc32(hash_val_data, buffer, buffer_size); - // store data - if(shared_DB != -1) // check if database context is valid + // store data + if( storePolicy < PersistenceStoragePolicy_LastEntry + && storePolicy >= PersistenceStorage_local) // check if store policy is valid + { + data_size = persistence_set_data(dbPath, dbKey, storePolicy, buffer, buffer_size); + } + else + { + printf("key_write_data: error - storage policy does not exist \n"); + } + } + else { - data_size = persistence_set_data(dbPath, dbKey, shared_DB, buffer, buffer_size); + printf("key_write_data: error - buffer_size to big, limit is [%d] bytes\n", gMaxKeyValDataSize); } } - return data_size; } @@ -255,13 +290,12 @@ int key_register_notify_on_change(unsigned char ldbid, char* resource_id, unsign { int rval = 0; -// unsigned int hash_val_data = 0; - + // unsigned int hash_val_data = 0; char dbKey[dbKeyMaxLen]; // database key char dbPath[dbPathMaxLen]; // database location // registration is only on shared key possible - if(dbShared == get_db_context(ldbid, resource_id, user_no, seat_no, resIsNoFile, dbKey, dbPath)) + if(PersistenceStorage_shared == get_db_context(ldbid, resource_id, user_no, seat_no, resIsNoFile, dbKey, dbPath)) { rval = persistence_reg_notify_on_change(dbPath, dbKey); } diff --git a/src/persistence_client_library_lc_interface.c b/src/persistence_client_library_lc_interface.c index 3be07da..2ab8951 100644 --- a/src/persistence_client_library_lc_interface.c +++ b/src/persistence_client_library_lc_interface.c @@ -62,10 +62,13 @@ int check_lc_request(int request) { rval = NsmErrorStatus_OK; } + break; + } + default: + { + printf("Unknown lifecycle message!\n"); + break; } - break; - default: - printf("Unknown lifecycle message!\n"); } return rval; diff --git a/src/persistence_client_library_pas_interface.c b/src/persistence_client_library_pas_interface.c index cd6614e..04ff758 100644 --- a/src/persistence_client_library_pas_interface.c +++ b/src/persistence_client_library_pas_interface.c @@ -92,7 +92,10 @@ int check_pas_request(int request) break; } default: + { rval = PasErrorStatus_FAIL; + break; + } } return rval; } @@ -198,7 +201,6 @@ int send_pas_register(const char* method, const char* appname) { dbus_message_append_args(message, DBUS_TYPE_STRING, &appname, DBUS_TYPE_INVALID); - if(conn != NULL) { if(!dbus_connection_send(conn, message, 0)) diff --git a/test/customLibConfigFile.cfg b/test/customLibConfigFile.cfg new file mode 100644 index 0000000..dd82d8f --- /dev/null +++ b/test/customLibConfigFile.cfg @@ -0,0 +1,7 @@ +secure /usr/local/lib/libsecurePersCustom.so +early /usr/local/lib/libearlyperscustom.so +custom2 /usr/local/lib/libcustom2PersCustom.so +hwinfo /usr/local/lib/libHWinfoPersCustom.so +custom1 /usr/local/lib/libcustom1PersCustom.so +emergency /usr/local/lib/libemergencyPersCustom.so +custom3 /usr/local/lib/libcustom3PersCustom.so
\ No newline at end of file diff --git a/test/persistence_client_library_test.c b/test/persistence_client_library_test.c index e0f2bcd..48f79e3 100644 --- a/test/persistence_client_library_test.c +++ b/test/persistence_client_library_test.c @@ -70,41 +70,74 @@ START_TEST (test_persGetData) locTime->tm_hour, locTime->tm_min, locTime->tm_sec); 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" - printf("T E S T Data: %s \n\n", buffer); + 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("----------------------------------------------->\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" + 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" - printf("T E S T Data: %s \n\n", buffer); + 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" - printf("T E S T Data: %s \n\n", buffer); + printf("T E S T Data - open_document: %s \n", buffer); + 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" - printf("T E S T Data: %s \n\n", buffer); + 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" - printf("T E S T Data: %s \n\n", buffer); + 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" - printf("T E S T Data: %s \n\n", buffer); + 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" - printf("T E S T Data: %s \n\n", buffer); + 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); + printf("----------------------------------------------->\n\n"); + - memset(buffer, 0, READ_SIZE); + 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: %s \n\n", buffer); + printf("T E S T Data last link: %s \n", buffer); + printf("----------------------------------------------->\n\n"); @@ -229,11 +262,11 @@ static Suite * persistencyClientLib_suite() tcase_add_test(tc_persGetData_file, test_persGetData_file); suite_add_tcase(s, tc_persGetData); - suite_add_tcase(s, tc_persGetDataHandle); + /*suite_add_tcase(s, tc_persGetDataHandle); suite_add_tcase(s, tc_persSetData); suite_add_tcase(s, tc_persSetSharedData); suite_add_tcase(s, tc_persGetData_file); - +*/ return s; } @@ -250,9 +283,6 @@ int main(int argc, char *argv[]) nr_failed = srunner_ntests_failed(sr); srunner_free(sr); - - getchar(); - return (0==nr_failed)?EXIT_SUCCESS:EXIT_FAILURE; } |