summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorihuerner <ihuerner@b9707d8c-442e-47db-affb-152dabb2260b>2012-10-15 09:07:50 +0000
committerihuerner <ihuerner@b9707d8c-442e-47db-affb-152dabb2260b>2012-10-15 09:07:50 +0000
commitcaedd57d02b5922376db6b7b9c32aef927158287 (patch)
tree96b342a44098a03d7a2d63f54816c4d52b8b5f82
parent2c0f7bd744873bbc674b7bc37744497a513c47b8 (diff)
downloadpersistence-client-library-caedd57d02b5922376db6b7b9c32aef927158287.tar.gz
Updated client library with version 0.1.5 (rev. 1665), for changes see change log
-rw-r--r--ChangeLog7
-rw-r--r--include/persistence_client_library_error_def.h89
-rw-r--r--include/persistence_client_library_file.h34
-rw-r--r--include/persistence_client_library_key.h27
-rw-r--r--src/Makefile.am8
-rw-r--r--src/persistence_client_library.c30
-rw-r--r--src/persistence_client_library.h3
-rw-r--r--src/persistence_client_library_access_helper.c34
-rw-r--r--src/persistence_client_library_access_helper.h19
-rw-r--r--src/persistence_client_library_custom_loader.c68
-rw-r--r--src/persistence_client_library_custom_loader.h36
-rw-r--r--src/persistence_client_library_data_access.c27
-rw-r--r--src/persistence_client_library_data_access.h16
-rw-r--r--src/persistence_client_library_dbus_service.c22
-rw-r--r--src/persistence_client_library_dbus_service.h1
-rw-r--r--src/persistence_client_library_file.c44
-rw-r--r--src/persistence_client_library_key.c103
-rw-r--r--src/persistence_client_library_lc_interface.c5
-rw-r--r--test/persistence_client_library_dbus_test.c37
-rw-r--r--test/persistence_client_library_test.c40
20 files changed, 494 insertions, 156 deletions
diff --git a/ChangeLog b/ChangeLog
index ee20768..2b71fde 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Revison 0.1.5 (rev 1665)
+- Fixed problem where no custom lib is available; extended custom lib interface; introduced error codes; removed modules form Makefile.am
+- Adjusted license in test files to MIT
+- Removed requesting dbus name from dbus main loop
+
+
+
Revison 0.1.4 (rev 1591)
- Update after code review; Extended custom library interface with function without handle
diff --git a/include/persistence_client_library_error_def.h b/include/persistence_client_library_error_def.h
new file mode 100644
index 0000000..3bfaaa9
--- /dev/null
+++ b/include/persistence_client_library_error_def.h
@@ -0,0 +1,89 @@
+#ifndef PERSISTENCE_CLIENT_LIBRARY_ERROR_DEF_H
+#define PERSISTENCE_CLIENT_LIBRARY_ERROR_DEF_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_error_def.h
+ * @ingroup Persistence client library
+ * @author Ingo Huerner
+ * @brief Error definition header
+ * @see
+ */
+
+// common error, for this error errno will be set
+#define EPERS_COMMON -1
+/// file system is locked
+#define EPERS_LOCKFS -2
+/// filesystem is currently locked
+#define EPERS_MAP_LOCKFS ((void *) -2)
+/// bad storage policy
+#define EPERS_BADPOL -3
+/// open handle limit reached
+#define EPERS_MAXHANDLE -4
+/// max buffer limit for persistence data
+#define EPERS_BUFLIMIT -5
+/// persistence resource configuration table not found
+#define EPERS_NOPRCTABLE -6
+/// key not found
+#define EPERS_NOKEY -7
+/// no data for key
+#define EPERS_NOKEYDATA -8
+/// write of data failed
+#define EPERS_SETDTAFAILED -9
+/// failed to open file
+#define EPERS_OPENFILE -10
+/// invalid buffer or key
+#define EPERS_DESER_BUFORKEY -11
+/// can't allocat memory for deserialization of keyvalue
+#define EPERS_DESER_ALLOCMEM -12
+/// no ploicy avaliable in data to serialize
+#define EPERS_DESER_POLICY -13
+/// no store type avaliable in data to serialize
+#define EPERS_DESER_STORE -14
+/// no permission avaliable in data to serialize
+#define EPERS_DESER_PERM -15
+/// no max size avaliable in data to serialize
+#define EPERS_DESER_MAXSIZE -16
+/// no responsibility avaliable in data to serialize
+#define EPERS_DESER_RESP -17
+/// out of array bounds
+#define EPERS_OUTOFBOUNDS -18
+/// failed to map config file
+#define EPERS_CONFIGMAPFAILED -19
+/// config file if not available
+#define EPERS_CONFIGNOTAVAILABLE -20
+/// can't stat config file
+#define EPERS_CONFIGNOSTAT -21
+/// plugin functin not found
+#define EPERS_NOPLUGINFCNT -22
+/// dlopen error
+#define EPERS_DLOPENERROR -23
+/// plugin function not loaded
+#define EPERS_NOPLUGINFUNCT -24
+
+
+
+#endif /* PERSISTENCE_CLIENT_LIBRARY_ERROR_DEF_H */
diff --git a/include/persistence_client_library_file.h b/include/persistence_client_library_file.h
index 2d1a6f6..26f4ac8 100644
--- a/include/persistence_client_library_file.h
+++ b/include/persistence_client_library_file.h
@@ -54,7 +54,8 @@ extern "C" {
*
* @param fd the file descriptor to close
*
- * @return zero on success. On error, -1 is returned, and errno is set appropriately
+ * @return zero on success. On error a negative value will be returned with th follwoing error codes:
+ * EPERS_LOCKFS
*/
int file_close(int fd);
@@ -65,7 +66,8 @@ int file_close(int fd);
*
* @param fd the POSIX file descriptor
*
- * @return positive value. On error, -1 is returned, and errno is set appropriately
+ * @return positive value. On error a negative value will be returned with th follwoing error codes:
+ * EPERS_LOCKFS
*/
int file_get_size(int fd);
@@ -79,7 +81,8 @@ int file_get_size(int fd);
* @param offset in the file to map
* @param fd the POSIX file descriptor of the file to map
*
- * @return a pointer to the mapped area, or on error the value MAP_FAILED
+ * @return a pointer to the mapped area, or on error the value MAP_FAILED or
+ * EPERS_MAP_FAILEDLOCK if filesystem is currrently locked
*/
void* file_map_data(void* addr, long size, long offset, int fd);
@@ -93,7 +96,9 @@ void* file_map_data(void* addr, long size, long offset, int fd);
* @param user_no the user ID
* @param seat_no the seat number (seat 0 to 3)
*
- * @return positive value: the POSIX file descriptor; negative value: Error code
+ * @return positive value: the POSIX file descriptor;
+ * On error a negative value will be returned with th follwoing error codes:
+ * EPERS_LOCKFS, EPERS_MAXHANDLE, EPERS_NOKEY, EPERS_NOKEYDATA, EPERS_NOPRCTABLE or EPERS_COMMON,
*/
int file_open(unsigned char ldbid, char* resource_id, unsigned char user_no, unsigned char seat_no);
@@ -106,7 +111,9 @@ int file_open(unsigned char ldbid, char* resource_id, unsigned char user_no, uns
* @param buffer buffer to read the data
* @param buffer_size the size buffer for reading
*
- * @return positive value: the size read; negative value: error code
+ * @return positive value: the size read;
+ * On error a negative value will be returned with th follwoing error codes:
+ * EPERS_LOCKFS or EPERS_COMMON
*/
int file_read_data(int fd, void * buffer, unsigned long buffer_size);
@@ -120,8 +127,9 @@ int file_read_data(int fd, void * buffer, unsigned long buffer_size);
* @param user_no the user ID
* @param seat_no the seat number (seat 0 to 3)
*
- * @return positive value: success; negative value: error code
- *
+ * @return positive value: success;
+ * On error a negative value will be returned with th follwoing error codes:
+ * EPERS_LOCKFS or EPERS_COMMON
*/
int file_remove(unsigned char ldbid, char* resource_id, unsigned char user_no, unsigned char seat_no);
@@ -140,7 +148,9 @@ int file_remove(unsigned char ldbid, char* resource_id, unsigned char user_no, u
SEEK_END
The offset is set to the size of the file plus offset bytes.
*
- * @return positive value: resulting offset location; negative value: error code
+ * @return positive value: resulting offset location;
+ * On error a negative value will be returned with th follwoing error codes:
+ * EPERS_LOCKFS or EPERS_COMMON
*/
int file_seek(int fd, long int offset, int whence);
@@ -152,7 +162,9 @@ int file_seek(int fd, long int offset, int whence);
* @param address the address to unmap
* @param size the size in bytes to unmap
*
- * @return on success 0; negative value: error code
+ * @return on success 0;
+ * On error a negative value will be returned with th follwoing error codes:
+ * EPERS_LOCKFS or EPERS_COMMON
*/
int file_unmap_data(void* address, long size);
@@ -165,7 +177,9 @@ int file_unmap_data(void* address, long size);
* @param buffer the buffer to write
* @param buffer_size the size of the buffer to write in bytes
*
-* @return positive value: bytes written; negative value: error code
+ * @return positive value: bytes written;
+ * On error a negative value will be returned with th follwoing error codes:
+ * EPERS_LOCKFS or EPERS_COMMON
*/
int file_write_data(int fd, const void * buffer, unsigned long buffer_size);
diff --git a/include/persistence_client_library_key.h b/include/persistence_client_library_key.h
index 7818916..23cc01e 100644
--- a/include/persistence_client_library_key.h
+++ b/include/persistence_client_library_key.h
@@ -58,7 +58,8 @@ extern "C" {
* @param user_no the user ID
* @param seat_no the seat number (seat 0 to 3)
*
- * @return positive value: success; negative value: error code
+ * @return positive value: success; On error a negative value will be returned with th follwoing error codes:
+ * EPERS_LOCKFS
*/
int key_delete(unsigned char ldbid, char* resource_id, unsigned char user_no, unsigned char seat_no);
@@ -72,7 +73,8 @@ int key_delete(unsigned char ldbid, char* resource_id, unsigned char user_no, un
* @param user_no the user ID
* @param seat_no the seat number (seat 0 to 3)
*
- * @return positive value: the size; negative value: error code
+ * @return positive value: the size; On error a negative value will be returned with th follwoing error codes:
+ * EPERS_LOCKFS, EPERS_BADPOL, EPERS_NOKEY, EPERS_NOKEYDATA or EPERS_NOPRCTABLE
*/
int key_get_size(unsigned char ldbid, char* resource_id, unsigned char user_no, unsigned char seat_no);
@@ -81,7 +83,8 @@ int key_get_size(unsigned char ldbid, char* resource_id, unsigned char user_no,
*
* @param key_handle key value handle return by key_handle_open()
*
- * @return positive value: success; negative value: error code
+ * @return positive value: success; On error a negative value will be returned with th follwoing error codes:
+ * EPERS_LOCKFS
*/
int key_handle_close(int key_handle);
@@ -92,7 +95,7 @@ int key_handle_close(int key_handle);
*
* @param key_handle key value handle return by key_handle_open()
*
- * @return positive value: the size; negative value: error code
+ * @return positive value: the size; On error a negative value will be returned with th follwoing error codes:
*/
int key_handle_get_size(int key_handle);
@@ -106,7 +109,8 @@ int key_handle_get_size(int key_handle);
* @param user_no the user ID
* @param seat_no the seat number (seat 0 to 3)
*
- * @return positive value: the key handle to access the value; negative value: Error code
+ * @return positive value: the key handle to access the value;
+ * On error a negative value will be returned with th follwoing error codes:
*/
int key_handle_open(unsigned char ldbid, char* resource_id, unsigned char user_no, unsigned char seat_no);
@@ -119,7 +123,8 @@ int key_handle_open(unsigned char ldbid, char* resource_id, unsigned char user_n
* @param buffer the buffer for persistent data
* @param buffer_size size of buffer for reading
*
- * @return positive value: the bytes read; negative value: error code
+ * @return positive value: the bytes read; On error a negative value will be returned with th follwoing error codes:
+ *
*/
int key_handle_read_data(int key_handle, unsigned char* buffer, unsigned long buffer_size);
@@ -130,7 +135,7 @@ int key_handle_read_data(int key_handle, unsigned char* buffer, unsigned long bu
*
* @param key_handle key value handle return by key_handle_open()
*
- * @return positive value: registration OK; negative value: error code
+ * @return positive value: registration OK; On error a negative value will be returned with th follwoing error codes:
*/
int key_handle_register_notify_on_change(int key_handle);
@@ -144,7 +149,7 @@ int key_handle_register_notify_on_change(int key_handle);
* @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
+ * @return positive value: the bytes written; On error a negative value will be returned with th follwoing error codes:
*/
int key_handle_write_data(int key_handle, unsigned char* buffer, unsigned long buffer_size);
@@ -160,7 +165,7 @@ int key_handle_write_data(int key_handle, unsigned char* buffer, unsigned long b
* @param buffer the buffer to read the persistent data
* @param buffer_size size of buffer for reading
*
- * @return positive value: the bytes read; negative value: error code
+ * @return positive value: the bytes read; On error a negative value will be returned with th follwoing error codes:
*/
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);
@@ -174,7 +179,7 @@ int key_read_data(unsigned char ldbid, char* resource_id, unsigned char user_no,
* @param user_no the user ID
* @param seat_no the seat number (seat 0 to 3)
*
- * @return positive value: registration OK; negative value: error code
+ * @return positive value: registration OK; On error a negative value will be returned with th follwoing error codes:
*/
int key_register_notify_on_change(unsigned char ldbid, char* resource_id, unsigned char user_no, unsigned char seat_no);
@@ -191,7 +196,7 @@ int key_register_notify_on_change(unsigned char ldbid, char* resource_id, unsign
* @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
+ * @return positive value: the bytes written; On error a negative value will be returned with th follwoing error codes:
*/
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);
diff --git a/src/Makefile.am b/src/Makefile.am
index bf9b0b3..ee2e002 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -15,12 +15,16 @@ AM_CFLAGS =$(DEPS_CFLAGS) -I../include \
endif
-include_HEADERS = ../include/persistence_client_library_key.h ../include/persistence_client_library_file.h
+include_HEADERS = ../include/persistence_client_library_key.h \
+ ../include/persistence_client_library_file.h \
+ ../include/persistence_client_library_error_def.h
+
lib_LTLIBRARIES = libpersistence_client_library.la
libpersistence_client_library_la_LIBADD = $(DEPS_LIBS) -ldconf -ldl -ldconf-dbus-1 -lgvdb
+
libpersistence_client_library_la_SOURCES = \
persistence_client_library.c \
persistence_client_library_key.c \
@@ -34,6 +38,6 @@ libpersistence_client_library_la_SOURCES = \
persistence_client_library_access_helper.c \
crc32.c
-libpersistence_client_library_la_LDFLAGS = -module -export-dynamic $(LDFLAGS)
+libpersistence_client_library_la_LDFLAGS = -export-dynamic $(LDFLAGS)
diff --git a/src/persistence_client_library.c b/src/persistence_client_library.c
index 6ae15ac..ce475d8 100644
--- a/src/persistence_client_library.c
+++ b/src/persistence_client_library.c
@@ -115,6 +115,8 @@ void pers_library_destroy(void) __attribute__((destructor));
void pers_library_init(void)
{
+ int status = 0;
+ int i = 0;
DLT_REGISTER_APP("Persistence Client Library","persClientLib");
DLT_REGISTER_CONTEXT(persClientLibCtx,"persClientLib","Context for Logging");
@@ -148,12 +150,34 @@ void pers_library_init(void)
memset(gOpenFdArray, maxPersHandle, sizeof(int));
/// get custom library names to load
- get_custom_libraries();
+ status = get_custom_libraries();
+ if(status < 0)
+ {
+ printf("Failed to load custom library config table => error number %d\n", status );
+ }
- if(pOnDemandLoad == NULL) // load all available libraries now
+ // initialize custom library structure
+ for(i = 0; i<PersCustomLib_LastEntry; i++)
{
- int i = 0;
+ gPersCustomFuncs[i].handle = NULL;
+ gPersCustomFuncs[i].custom_plugin_init = NULL;
+ gPersCustomFuncs[i].custom_plugin_deinit = NULL;
+ gPersCustomFuncs[i].custom_plugin_open = NULL;
+ gPersCustomFuncs[i].custom_plugin_close = NULL;
+ gPersCustomFuncs[i].custom_plugin_get_data_handle = NULL;
+ gPersCustomFuncs[i].custom_plugin_set_data_handle = NULL;
+ gPersCustomFuncs[i].custom_plugin_get_data = NULL;
+ gPersCustomFuncs[i].custom_plugin_set_data = NULL;
+ gPersCustomFuncs[i].custom_plugin_delete_data = NULL;
+ gPersCustomFuncs[i].custom_plugin_get_status_notification_clbk = NULL;
+ gPersCustomFuncs[i].custom_plugin_get_size_handle = NULL;
+ gPersCustomFuncs[i].custom_plugin_get_size = NULL;
+ gPersCustomFuncs[i].custom_plugin_backup_create = NULL;
+ gPersCustomFuncs[i].custom_plugin_backup_restore = NULL;
+ }
+ if(pOnDemandLoad == NULL) // load all available libraries now
+ {
for(i=0; i < get_num_custom_client_libs(); i++ )
{
if(load_custom_library(get_custom_client_position_in_array(i), &gPersCustomFuncs[i] ) == -1)
diff --git a/src/persistence_client_library.h b/src/persistence_client_library.h
index 0e59a2b..b786950 100644
--- a/src/persistence_client_library.h
+++ b/src/persistence_client_library.h
@@ -35,6 +35,7 @@
*/
#include "persistence_client_library_lc_interface.h"
+#include "../include/persistence_client_library_error_def.h"
#include <gvdb-reader.h>
#include "crc32.h"
@@ -122,7 +123,7 @@ typedef enum _PersistenceRCT_e
/// resource configuration table name
-extern const char* gResTableCfg;;
+extern const char* gResTableCfg;
/// shared cached default database
extern const char* gSharedCachedDefault;
diff --git a/src/persistence_client_library_access_helper.c b/src/persistence_client_library_access_helper.c
index 0eb47b7..034cc7d 100644
--- a/src/persistence_client_library_access_helper.c
+++ b/src/persistence_client_library_access_helper.c
@@ -124,8 +124,6 @@ int serialize_data(PersistenceConfigurationKey_s pc, char* buffer)
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;
}
@@ -146,7 +144,7 @@ int de_serialize_data(char* buffer, PersistenceConfigurationKey_s* pc)
else
{
printf("de_serialize_data - error: can't get [policy] \n");
- rval = -1;
+ rval = EPERS_DESER_POLICY;
}
token = strtok (NULL, " "); // storage
@@ -158,7 +156,7 @@ int de_serialize_data(char* buffer, PersistenceConfigurationKey_s* pc)
else
{
printf("de_serialize_data - error: can't get [storage] \n");
- rval = -1;
+ rval = EPERS_DESER_STORE;
}
token = strtok (NULL, " "); // permission
@@ -170,7 +168,7 @@ int de_serialize_data(char* buffer, PersistenceConfigurationKey_s* pc)
else
{
printf("de_serialize_data - error: can't get [permission] \n");
- rval = -1;
+ rval = EPERS_DESER_PERM;
}
token = strtok (NULL, " "); // max_size
@@ -182,7 +180,7 @@ int de_serialize_data(char* buffer, PersistenceConfigurationKey_s* pc)
else
{
printf("de_serialize_data - error: can't get [max_size] \n");
- rval = -1;
+ rval = EPERS_DESER_MAXSIZE;
}
token = strtok (NULL, " "); // reponsible
@@ -194,17 +192,18 @@ int de_serialize_data(char* buffer, PersistenceConfigurationKey_s* pc)
if(pc->reponsible != NULL)
{
strncpy(pc->reponsible, token, size);
+ //printf(" pc->reponsible %s | 0x%x \n", pc->reponsible, (int)pc->reponsible);
}
else
{
+ rval = EPERS_DESER_ALLOCMEM;
printf("de_serialize_data - error: can't allocate memory [reponsible] \n");
}
- //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;
+ rval = EPERS_DESER_RESP;
}
token = strtok (NULL, " "); // custom_name
@@ -218,6 +217,7 @@ int de_serialize_data(char* buffer, PersistenceConfigurationKey_s* pc)
}
else
{
+ rval = EPERS_DESER_ALLOCMEM;
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);
@@ -234,6 +234,7 @@ int de_serialize_data(char* buffer, PersistenceConfigurationKey_s* pc)
}
else
{
+ rval = EPERS_DESER_ALLOCMEM;
printf("de_serialize_data - error: can't allocate memory [custom_name-default] \n");
}
}
@@ -241,7 +242,7 @@ int de_serialize_data(char* buffer, PersistenceConfigurationKey_s* pc)
else
{
printf("de_serialize_data - error: buffer or PersistenceConfigurationKey_s is NULL\n");
- rval = -1;
+ rval = EPERS_DESER_BUFORKEY;
}
return rval;
@@ -249,10 +250,8 @@ int de_serialize_data(char* buffer, PersistenceConfigurationKey_s* pc)
-int free_pers_conf_key(PersistenceConfigurationKey_s* pc)
+void free_pers_conf_key(PersistenceConfigurationKey_s* pc)
{
- int rval = 1;
-
if(pc != NULL)
{
if(pc->reponsible != NULL)
@@ -269,8 +268,6 @@ int free_pers_conf_key(PersistenceConfigurationKey_s* pc)
//printf("free_pers_conf_key => free(pc->reponsible);");
}
}
-
- return rval;
}
@@ -333,20 +330,25 @@ int get_db_context(unsigned char ldbid, char* resource_id, unsigned char user_no
free_pers_conf_key(&dbEntry);
resourceFound = 1;
}
-
}
}
else
{
printf("get_db_context - resource_table: no value for key: %s \n", resource_id);
- rval = -1;
+ rval = EPERS_NOKEYDATA;
}
} // resource table
+ else
+ {
+ printf("get_db_context - error resource table\n");
+ rval = EPERS_NOPRCTABLE;
+ }
if(resourceFound == 0)
{
printf("get_db_context - error resource not found %s \n", resource_id);
+ rval = EPERS_NOKEY;
}
return rval;
diff --git a/src/persistence_client_library_access_helper.h b/src/persistence_client_library_access_helper.h
index 8289ce1..864646a 100644
--- a/src/persistence_client_library_access_helper.h
+++ b/src/persistence_client_library_access_helper.h
@@ -48,7 +48,8 @@
* @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
+ * @return 1 if shared database and 0 if local database or PersistenceStoragePolicy_LastEntry
+ * when no valid database has been found
*/
int get_db_path_and_key(unsigned char ldbid, char* resource_id, unsigned char user_no, unsigned char seat_no,
unsigned int isFile, char dbKey[], char dbPath[], unsigned char cached_resource);
@@ -67,7 +68,8 @@ int get_db_path_and_key(unsigned char ldbid, char* resource_id, unsigned char us
* @param dbPath the array where the database location path will be stored
* @param cached_resource flag to identify if the resource is cached (value 1)or write through (value 0)
*
- * @return -1 if error : or PersistenceStorage_e
+ * @return the PersistenceStorage_e
+ * or a negative value with one of the following errors: EPERS_NOKEY, EPERS_NOKEYDATA or EPERS_NOPRCTABLE
*/
int get_db_context(unsigned char ldbid, char* resource_id, unsigned char user_no, unsigned char seat_no,
unsigned int isFile, char dbKey[], char dbPath[]);
@@ -77,28 +79,33 @@ int get_db_context(unsigned char ldbid, char* resource_id, unsigned char user_no
/**
* @brief get the resource configuration table gvbd database by id
*
- * @return pointer to the gvdb database table
+ * @return pointer to the gvdb database table or NULL if no valid database has been found
*/
GvdbTable* get_resource_cfg_table_by_idx(int i);
+
/**
* @brief serialize data to store to database
+ *
+ * @return the number of bytes serialized of a negative value on error and errno is set
*/
int serialize_data(PersistenceConfigurationKey_s pc, char* buffer);
/**
* @brief deserialize data read from database
+ *
+ * @return 1 of correct deserialization or on of the following error codes:
+ * EPERS_DESER_BUFORKEY, EPERS_DESER_ALLOCMEM, EPERS_DESER_POLICY, EPERS_DESER_STORE,
+ * EPERS_DESER_PERM, EPERS_DESER_MAXSIZE or EPERS_DESER_RESP
*/
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);
+void free_pers_conf_key(PersistenceConfigurationKey_s* pc);
diff --git a/src/persistence_client_library_custom_loader.c b/src/persistence_client_library_custom_loader.c
index ef6de9d..d619968 100644
--- a/src/persistence_client_library_custom_loader.c
+++ b/src/persistence_client_library_custom_loader.c
@@ -170,7 +170,7 @@ int get_custom_libraries()
}
else
{
- return -1; // out of array bounds
+ return EPERS_OUTOFBOUNDS; // out of array bounds
}
// get the library name
@@ -190,7 +190,7 @@ int get_custom_libraries()
}
else
{
- rval = -1;
+ rval = EPERS_OUTOFBOUNDS;
break;
}
}
@@ -225,16 +225,19 @@ int get_custom_libraries()
}
else
{
+ rval = EPERS_CONFIGMAPFAILED;
printf("load config file error - mapping of file failed");
}
}
else
{
+ rval = EPERS_CONFIGNOTAVAILABLE;
printf("load config file error - no file with plugins available -> filename: %s | error: %s \n", filename, strerror(errno) );
}
}
else
{
+ rval = EPERS_CONFIGNOSTAT;
printf("load config file error - can't stat config file: %s | %s \n", filename, strerror(errno));
}
return rval;
@@ -260,49 +263,56 @@ int load_custom_library(PersistenceCustomLibs_e customLib, Pers_custom_functs_s
if ((error = dlerror()) != NULL)
{
printf("load_custom_library - error: %s\n", error);
- return -1;
+ return EPERS_NOPLUGINFCNT;
}
// 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;
+ return EPERS_NOPLUGINFCNT;
}
// 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;
+ return EPERS_NOPLUGINFCNT;
}
// 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;
+ return EPERS_NOPLUGINFCNT;
}
// 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;
+ return EPERS_NOPLUGINFCNT;
+ }
+ // custom_plugin_deinit
+ *(void **) (&customFuncts->custom_plugin_deinit) = dlsym(handle, "plugin_deinit");
+ if ((error = dlerror()) != NULL)
+ {
+ printf("load_custom_library - error: %s\n", error);
+ return EPERS_NOPLUGINFCNT;
}
// 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;
+ return EPERS_NOPLUGINFCNT;
}
// 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;
+ return EPERS_NOPLUGINFCNT;
}
// custom_plugin_set_data
*(void **) (&customFuncts->custom_plugin_set_data) = dlsym(handle, "plugin_set_data");
@@ -310,19 +320,49 @@ int load_custom_library(PersistenceCustomLibs_e customLib, Pers_custom_functs_s
{
printf("load_custom_library - error: %s\n", error);
return -1;
- }
+ }
+ // custom_plugin_get_size_handle
+ *(void **) (&customFuncts->custom_plugin_get_size_handle) = dlsym(handle, "plugin_get_size_handle");
+ if ((error = dlerror()) != NULL)
+ {
+ printf("load_custom_library - error: %s\n", error);
+ return -1;
+ }
+ // custom_plugin_get_size
+ *(void **) (&customFuncts->custom_plugin_get_size) = dlsym(handle, "plugin_get_size");
+ if ((error = dlerror()) != NULL)
+ {
+ printf("load_custom_library - error: %s\n", error);
+ return -1;
+ }
+ // create backup
+ *(void **) (&customFuncts->custom_plugin_backup_create) = dlsym(handle, "plugin_backup_create");
+ if ((error = dlerror()) != NULL)
+ {
+ printf("load_custom_library - error: %s\n", error);
+ return -1;
+ }
+ // restore backup
+ *(void **) (&customFuncts->custom_plugin_backup_restore) = dlsym(handle, "plugin_backup_restore");
+ 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;
+ return EPERS_NOPLUGINFCNT;
}
}
else
{
printf("load_custom_library - error: %s\n", dlerror());
- rval = -1;
+ rval = EPERS_DLOPENERROR;
}
}
@@ -338,10 +378,10 @@ int load_all_custom_libraries()
for(i=0; i<gNumOfCustomLibraries; i++)
{
- if( load_custom_library(i, &gPersCustomFuncs[i] ) == -1)
+ rval = load_custom_library(i, &gPersCustomFuncs[i]);
+ if( rval < 0)
{
// printf("load_all_custom_libraries - error loading library number [%d] \n", i);
- rval = -1;
break;
}
}
diff --git a/src/persistence_client_library_custom_loader.h b/src/persistence_client_library_custom_loader.h
index bb73342..87b3aca 100644
--- a/src/persistence_client_library_custom_loader.h
+++ b/src/persistence_client_library_custom_loader.h
@@ -73,6 +73,9 @@ typedef struct _Pers_custom_functs_s
/// custom library init function
int (*custom_plugin_init)();
+ /// custom library deinit function
+ int (*custom_plugin_deinit)();
+
/// custom open function
long (*custom_plugin_open)(char* path, int flag, int mode);
@@ -91,10 +94,21 @@ typedef struct _Pers_custom_functs_s
/// custom set data function
long (*custom_plugin_set_data)(char* buffer, long size);
-
/// custom delete function
int (*custom_plugin_delete_data)(const char* path);
+ // get the size
+ int (*custom_plugin_get_size_handle)(int key_handle);
+
+ // get the size
+ int (*custom_plugin_get_size)(const char* path);
+
+ /// create backup
+ int (*custom_plugin_backup_create)(const char* src, const char* dst);
+
+ /// restore backup
+ int (*custom_plugin_backup_restore)(const char* srt, const char* dst);
+
/// custom status notification function
int (*custom_plugin_get_status_notification_clbk)(plugin_callback_t pFunct);
@@ -111,14 +125,15 @@ Pers_custom_functs_s gPersCustomFuncs[PersCustomLib_LastEntry];
* @param lib_name the library name
* @param substring indicator if a substring search is neccessary
*
- * @return the library id
+ * @return the library id or PersCustomLib_LastEntry if nothing found
*/
PersistenceCustomLibs_e custom_client_name_to_id(const char* lib_name, int substring);
/**
* @brief get the names of the custom libraries to load
*
- * @return 0 for success or -1 if an error occurred
+ * @return 0 for success or a negative value with the following errors:
+ * EPERS_OUTOFBOUNDS
*/
int get_custom_libraries();
@@ -130,7 +145,9 @@ int get_custom_libraries();
* @param customLib the enumerator id identifying the custom library
* @param customFuncts function pointer array of loaded custom library functions
*
- * @return 0 for success or -1 if an error occurred
+ * @return 0 for success or a negative value with one of the following errors:
+ * EPERS_NOPLUGINFCNT EPERS_DLOPENERROR
+ *
*/
int load_custom_library(PersistenceCustomLibs_e customLib, Pers_custom_functs_s *customFuncts);
@@ -139,7 +156,8 @@ int load_custom_library(PersistenceCustomLibs_e customLib, Pers_custom_functs_s
/**
* @brief get the names of the custom libraries to load
*
- * @return 0 for success or -1 if an error occurred
+ * @return 0 for success orr a negative value with one of the following errors:
+ * EPERS_NOPLUGINFCNT EPERS_DLOPENERROR
*/
int load_all_custom_libraries();
@@ -149,12 +167,16 @@ int load_all_custom_libraries();
*
* @param customLib the enumerator id identifying the custom library
*
- * @return the array position
+ * @return the array position or -1 if the position can't be found
*/
int get_custom_client_position_in_array(PersistenceCustomLibs_e customLib);
-/// get the number of available custom client libraries
+/**
+ * @brief gget the number of available custom client libraries
+ *
+ * @return the number of the client libraries
+ */
int get_num_custom_client_libs();
diff --git a/src/persistence_client_library_data_access.c b/src/persistence_client_library_data_access.c
index 5d7b279..0f32359 100644
--- a/src/persistence_client_library_data_access.c
+++ b/src/persistence_client_library_data_access.c
@@ -37,8 +37,6 @@
#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)
@@ -65,11 +63,13 @@ int get_value_from_table(GvdbTable* database, char* key, unsigned char* buffer,
}
else
{
+ read_size = EPERS_NOKEYDATA;
printf("get_value_from_table: E R R O R getting size and/or data for key: %s \n", key);
}
}
else
{
+ read_size = EPERS_NOKEY;
printf("get_value_from_table: E R R O R getting value for key: %s \n", key);
}
@@ -89,6 +89,7 @@ int get_size_from_table(GvdbTable* database, char* key)
}
else
{
+ read_size = EPERS_NOKEY;
printf("get_size_from_table: E R R O R getting value for key: %s \n", key);
}
@@ -123,6 +124,7 @@ int persistence_get_data(char* dbPath, char* key, PersistenceStorage_e storage,
}
else
{
+ read_size = EPERS_NOPRCTABLE;
printf("persistence_get_data - Database E R R O R: %s\n", error->message);
g_error_free(error);
error = NULL;
@@ -134,12 +136,16 @@ int persistence_get_data(char* dbPath, char* key, PersistenceStorage_e storage,
char workaroundPath[128]; // workaround, because /sys/ can not be accessed on host!!!!
snprintf(workaroundPath, 128, "%s%s", "/tmp", dbPath );
- printf(" C U S T O M D A T A => not implemented yet - path: %s | index: %d \n", dbPath , idx);
+ printf(" get C U S T O M D A T A => not implemented yet - path: %s | index: %d \n", dbPath , idx);
- if(idx < PersCustomLib_LastEntry)
+ if( (idx < PersCustomLib_LastEntry) && (gPersCustomFuncs[idx].custom_plugin_get_data_handle != NULL) )
{
gPersCustomFuncs[idx].custom_plugin_get_data_handle(88, (char*)buffer, buffer_size-1);
}
+ else
+ {
+ read_size = EPERS_NOPLUGINFUNCT;
+ }
}
return read_size;
@@ -180,11 +186,13 @@ int persistence_set_data(char* dbPath, char* key, PersistenceStorage_e storage,
printf("persistence_set_data => error: %s \n", error->message );
g_error_free(error);
error = NULL;
+ write_size = EPERS_SETDTAFAILED;
}
}
else
{
printf("persistence_set_data - Database E R R O R: %s\n", error->message);
+ write_size = EPERS_NOPRCTABLE;
g_error_free(error);
error = NULL;
}
@@ -192,11 +200,15 @@ int persistence_set_data(char* dbPath, char* key, PersistenceStorage_e storage,
else if(PersistenceStorage_custom == storage) // custom storage implementation via custom library
{
int idx = custom_client_name_to_id(dbPath, 1);
- 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)
+ printf(" set 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_handle) )
{
gPersCustomFuncs[idx].custom_plugin_set_data_handle(88, (char*)buffer, buffer_size);
}
+ else
+ {
+ write_size = EPERS_NOPLUGINFUNCT;
+ }
}
return write_size;
@@ -224,6 +236,7 @@ int persistence_get_data_size(char* dbPath, char* key, PersistenceStorage_e stor
}
else
{
+ read_size = EPERS_NOPRCTABLE;
printf("persistence_get_data_size - Database E R R O R: %s\n", error->message);
g_error_free(error);
error = NULL;
@@ -231,7 +244,7 @@ int persistence_get_data_size(char* dbPath, char* key, PersistenceStorage_e stor
}
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");
+ printf(" get C U S T O M D A T A => NOW IMPLEMENTING implemented yet\n");
}
return read_size;
diff --git a/src/persistence_client_library_data_access.h b/src/persistence_client_library_data_access.h
index 725d472..16c80ce 100644
--- a/src/persistence_client_library_data_access.h
+++ b/src/persistence_client_library_data_access.h
@@ -45,7 +45,9 @@
* @param key the database key
* @param storage the storage identifier (local, shared or custom)
* (use dbShared for shared key or dbLocal if the key is local)
- * @return
+ *
+ * @return the number of bytes written or a negative value if an error occured with the following error codes:
+ * EPERS_SETDTAFAILED EPERS_NOPRCTABLE EPERS_NOKEYDATA EPERS_NOKEY
*/
int persistence_set_data(char* dbPath, char* key, PersistenceStorage_e storage, unsigned char* buffer, unsigned long buffer_size);
@@ -58,7 +60,8 @@ int persistence_set_data(char* dbPath, char* key, PersistenceStorage_e storage,
* @param key the database key
* @param storage the storage identifier (local, shared or custom)
*
- * @return
+ * @return the number of bytes read or a negative value if an error occured with the following error codes:
+ * EPERS_NOPRCTABLE EPERS_NOKEYDATA EPERS_NOKEY
*/
int persistence_get_data(char* dbPath, char* key, PersistenceStorage_e storage, unsigned char* buffer, unsigned long buffer_size);
@@ -71,7 +74,8 @@ int persistence_get_data(char* dbPath, char* key, PersistenceStorage_e storage,
* @param key the database key
* @param storage the storage identifier (local, shared or custom)
*
- * @return size of data in bytes read from the key
+ * @return size of data in bytes read from the key or on error a negative value with the following error codes:
+ * EPERS_NOPRCTABLE or EPERS_NOKEY
*/
int persistence_get_data_size(char* dbPath, char* key, PersistenceStorage_e storage);
@@ -97,7 +101,8 @@ int persistence_reg_notify_on_change(char* dbPath, char* key);
* @param buffer the data
* @param buffer_size the size of the buffer in bytes
*
- * @return size of data in bytes read from the key
+ * @return size of data in bytes read from the key or a negative value on error with the following error codes:
+ * EPERS_NOKEYDATA EPERS_NOKEY
*/
int get_value_from_table(GvdbTable* database, char* key, unsigned char* buffer, unsigned long buffer_size);
@@ -123,7 +128,8 @@ int set_value_to_table(GHashTable* database, char* key, unsigned char* buffer, u
* @param database pointer to the database
* @param key the database key to get the size form
*
- * @return size of data
+ * @return size of data or a negative value on error with the following errors codes:
+ * EPERS_NOKEY
*/
int get_size_from_table(GvdbTable* database, char* key);
diff --git a/src/persistence_client_library_dbus_service.c b/src/persistence_client_library_dbus_service.c
index c05e306..263d2b3 100644
--- a/src/persistence_client_library_dbus_service.c
+++ b/src/persistence_client_library_dbus_service.c
@@ -213,12 +213,6 @@ static dbus_bool_t addWatch(DBusWatch *watch, void *data)
}
++gPollInfo.nfds;
-
- static const int cmd = CMD_REQUEST_NAME;
- if (sizeof(int)!=write(gPipefds[1], &cmd, sizeof(int)))
- {
- printf("write failed w/ errno %d\n", errno);
- }
}
result = TRUE;
@@ -330,22 +324,6 @@ int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtable2,
{
switch (buf[0])
{
- case CMD_REQUEST_NAME:
- 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\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\n", err.message);
- dbus_error_free(&err);
- bContinue = FALSE;
- }
- break;
case CMD_PAS_BLOCK_AND_WRITE_BACK:
process_block_and_write_data_back();
break;
diff --git a/src/persistence_client_library_dbus_service.h b/src/persistence_client_library_dbus_service.h
index b4def6a..b209ce5 100644
--- a/src/persistence_client_library_dbus_service.h
+++ b/src/persistence_client_library_dbus_service.h
@@ -45,7 +45,6 @@ pthread_mutex_t gDbusInitializedMtx;
typedef enum ECmd
{
CMD_NONE = 0, /// command none
- CMD_REQUEST_NAME, /// command request dbus name
CMD_PAS_BLOCK_AND_WRITE_BACK, /// command block access and write data back
CMD_LC_PREPARE_SHUTDOWN, /// command to prepare shutdown
CMD_QUIT /// quit command
diff --git a/src/persistence_client_library_file.c b/src/persistence_client_library_file.c
index 642621e..07183ff 100644
--- a/src/persistence_client_library_file.c
+++ b/src/persistence_client_library_file.c
@@ -58,6 +58,10 @@ int file_close(int fd)
__sync_fetch_and_sub(&gOpenFdArray[fd], FileClosed); // set closed flag
}
}
+ else
+ {
+ rval = EPERS_LOCKFS;
+ }
return rval;
}
@@ -78,6 +82,10 @@ int file_get_size(int fd)
rval = buf.st_size;
}
}
+ else
+ {
+ rval = EPERS_LOCKFS;
+ }
return rval;
}
@@ -92,6 +100,10 @@ void* file_map_data(void* addr, long size, long offset, int fd)
int mapFlag = PROT_WRITE | PROT_READ;
ptr = mmap(addr,size, mapFlag, MAP_SHARED, fd, offset);
}
+ else
+ {
+ ptr = EPERS_MAP_LOCKFS;
+ }
return ptr;
}
@@ -129,9 +141,18 @@ int file_open(unsigned char ldbid, char* resource_id, unsigned char user_no, uns
{
__sync_fetch_and_add(&gOpenFdArray[handle], FileOpen); // set open flag
}
+ else
+ {
+ handle = EPERS_MAXHANDLE;
+ }
}
}
}
+ else
+ {
+ handle = EPERS_LOCKFS;
+ }
+
return handle;
}
@@ -145,6 +166,10 @@ int file_read_data(int fd, void * buffer, unsigned long buffer_size)
{
size = read(fd, buffer, buffer_size);
}
+ else
+ {
+ size = EPERS_LOCKFS;
+ }
return size;
}
@@ -174,6 +199,10 @@ int file_remove(unsigned char ldbid, char* resource_id, unsigned char user_no, u
printf("file_remove ERROR: %s \n", strerror(errno) );
}
}
+ else
+ {
+ rval = EPERS_LOCKFS;
+ }
return rval;
}
@@ -188,6 +217,11 @@ int file_seek(int fd, long int offset, int whence)
{
rval = lseek(fd, offset, whence);
}
+ else
+ {
+ rval = EPERS_LOCKFS;
+ }
+
return rval;
}
@@ -201,6 +235,11 @@ int file_unmap_data(void* address, long size)
{
rval = munmap(address, size);
}
+ else
+ {
+ rval = EPERS_LOCKFS;
+ }
+
return rval;
}
@@ -214,6 +253,11 @@ int file_write_data(int fd, const void * buffer, unsigned long buffer_size)
{
size = write(fd, buffer, buffer_size);
}
+ else
+ {
+ size = EPERS_LOCKFS;
+ }
+
return size;
}
diff --git a/src/persistence_client_library_key.c b/src/persistence_client_library_key.c
index 798a29d..867e14e 100644
--- a/src/persistence_client_library_key.c
+++ b/src/persistence_client_library_key.c
@@ -69,14 +69,18 @@ int key_handle_open(unsigned char ldbid, char* resource_id, unsigned char user_n
char workaroundPath[128]; // workaround, because /sys/ can not be accessed on host!!!!
snprintf(workaroundPath, 128, "%s%s", "/tmp", dbPath );
- printf(" C U S T O M D A T A => not implemented yet - path: %s | index: %d \n", dbPath , idx);
+ printf(" open C U S T O M D A T A => not implemented yet - path: %s | index: %d \n", dbPath , idx);
- if(idx < PersCustomLib_LastEntry)
+ if( (idx < PersCustomLib_LastEntry) && (gPersCustomFuncs[idx].custom_plugin_open != NULL) )
{
int flag = 0,
mode = 0;
handle = gPersCustomFuncs[idx].custom_plugin_open(dbPath, flag, mode);
}
+ else
+ {
+ handle = EPERS_NOPLUGINFUNCT;
+ }
}
else
{
@@ -95,6 +99,14 @@ int key_handle_open(unsigned char ldbid, char* resource_id, unsigned char user_n
printf("key_handle_open: error - handleId out of bounds [%d]\n", handle);
}
}
+ else
+ {
+ handle = EPERS_BADPOL;
+ }
+ }
+ else
+ {
+ handle = EPERS_LOCKFS;
}
return handle;
@@ -114,12 +126,16 @@ int key_handle_close(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(" close 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)
+ if( (idx < PersCustomLib_LastEntry) && (gPersCustomFuncs[idx].custom_plugin_close) )
{
gPersCustomFuncs[idx].custom_plugin_close(key_handle);
}
+ else
+ {
+ rval = EPERS_NOPLUGINFUNCT;
+ }
}
else
{
@@ -131,6 +147,10 @@ int key_handle_close(int key_handle)
strncpy(gHandleArray[key_handle].dbKey ,"", dbKeyMaxLen);
gHandleArray[key_handle].shared_DB = -1;
}
+ else
+ {
+ rval = EPERS_LOCKFS;
+ }
return rval;
}
@@ -139,7 +159,7 @@ int key_handle_close(int key_handle)
int key_handle_get_size(int key_handle)
{
- int size = -1;
+ int size = 0;
if(accessNoLock == isAccessLocked() ) // check if access to persistent data is locked
{
@@ -151,12 +171,16 @@ 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",
+ printf(" get size 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)
{
- //gPersCustomFuncs[idx].
+ //gPersCustomFuncs[idx].custom_plugin_get_size()
+ }
+ else
+ {
+ size = EPERS_NOPLUGINFUNCT;
}
}
else
@@ -166,6 +190,10 @@ int key_handle_get_size(int key_handle)
}
}
}
+ else
+ {
+ size = EPERS_LOCKFS;
+ }
return size;
}
@@ -174,7 +202,7 @@ int key_handle_get_size(int key_handle)
int key_handle_read_data(int key_handle, unsigned char* buffer, unsigned long buffer_size)
{
- int size = -1;
+ int size = 0;
if(accessNoLock == isAccessLocked() ) // check if access to persistent data is locked
{
@@ -186,12 +214,16 @@ int key_handle_read_data(int key_handle, unsigned char* buffer, unsigned long bu
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(" read 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)
+ if(idx < PersCustomLib_LastEntry && &(gPersCustomFuncs[idx].custom_plugin_get_data_handle) != NULL)
{
gPersCustomFuncs[idx].custom_plugin_get_data_handle(key_handle, (char*)buffer, buffer_size-1);
}
+ else
+ {
+ size = EPERS_NOPLUGINFUNCT;
+ }
}
else
{
@@ -200,6 +232,10 @@ int key_handle_read_data(int key_handle, unsigned char* buffer, unsigned long bu
}
}
}
+ else
+ {
+ size = EPERS_LOCKFS;
+ }
return size;
}
@@ -217,7 +253,7 @@ int key_handle_register_notify_on_change(int key_handle)
int key_handle_write_data(int key_handle, unsigned char* buffer, unsigned long buffer_size)
{
- int size = -1;
+ int size = 0;
if(accessNoLock == isAccessLocked() ) // check if access to persistent data is locked
{
@@ -231,12 +267,16 @@ int key_handle_write_data(int key_handle, unsigned char* buffer, unsigned long b
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(" write 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)
+ if(idx < PersCustomLib_LastEntry && *gPersCustomFuncs[idx].custom_plugin_set_data_handle != NULL)
{
gPersCustomFuncs[idx].custom_plugin_set_data_handle(key_handle, (char*)buffer, buffer_size-1);
}
+ else
+ {
+ size = EPERS_NOPLUGINFUNCT;
+ }
}
else
{
@@ -244,12 +284,20 @@ int key_handle_write_data(int key_handle, unsigned char* buffer, unsigned long b
gHandleArray[key_handle].shared_DB, buffer, buffer_size);
}
}
+ else
+ {
+ size = EPERS_MAXHANDLE;
+ }
}
else
{
printf("key_handle_write_data: error - buffer_size to big, limit is [%d] bytes\n", gMaxKeyValDataSize);
}
}
+ else
+ {
+ size = EPERS_LOCKFS;
+ }
return size;
}
@@ -269,6 +317,11 @@ int key_delete(unsigned char ldbid, char* resource_id, unsigned char user_no, un
{
// TODO implement key delete
}
+ else
+ {
+ rval = EPERS_LOCKFS;
+ }
+
return rval;
}
@@ -277,7 +330,7 @@ int key_delete(unsigned char ldbid, char* resource_id, unsigned char user_no, un
// status: OK
int key_get_size(unsigned char ldbid, char* resource_id, unsigned char user_no, unsigned char seat_no)
{
- int data_size = -1;
+ int data_size = 0;
if(accessNoLock == isAccessLocked() ) // check if access to persistent data is locked
{
@@ -299,9 +352,13 @@ int key_get_size(unsigned char ldbid, char* resource_id, unsigned char user_no,
}
else
{
- printf("key_read_data: error - storage policy does not exist \n");
+ data_size = EPERS_BADPOL;
}
}
+ else
+ {
+ data_size = EPERS_LOCKFS;
+ }
return data_size;
}
@@ -312,7 +369,7 @@ int key_get_size(unsigned char ldbid, char* resource_id, unsigned char user_no,
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;
+ int data_size = 0;
if(accessNoLock != isAccessLocked() ) // check if access to persistent data is locked
{
@@ -335,13 +392,14 @@ int key_read_data(unsigned char ldbid, char* resource_id, unsigned char user_no,
}
else
{
- printf("key_read_data: error - storage policy does not exist \n");
+ data_size = EPERS_BADPOL;
}
}
else
{
- printf("key_read_data - accessLocked\n");
+ data_size = EPERS_LOCKFS;
}
+
return data_size;
}
@@ -350,7 +408,7 @@ int key_read_data(unsigned char ldbid, char* resource_id, unsigned char user_no,
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;
+ int data_size = 0;
if(accessNoLock != isAccessLocked() ) // check if access to persistent data is locked
{
@@ -380,14 +438,19 @@ int key_write_data(unsigned char ldbid, char* resource_id, unsigned char user_no
}
else
{
- printf("key_write_data: error - storage policy does not exist \n");
+ data_size = EPERS_BADPOL;
}
}
else
{
+ data_size = EPERS_BUFLIMIT;
printf("key_write_data: error - buffer_size to big, limit is [%d] bytes\n", gMaxKeyValDataSize);
}
}
+ else
+ {
+ data_size = EPERS_LOCKFS;
+ }
return data_size;
}
diff --git a/src/persistence_client_library_lc_interface.c b/src/persistence_client_library_lc_interface.c
index bc40e89..cf52d68 100644
--- a/src/persistence_client_library_lc_interface.c
+++ b/src/persistence_client_library_lc_interface.c
@@ -179,7 +179,7 @@ int send_lifecycle_register(const char* method, const char* busname, const char*
DBusConnection* conn = get_dbus_connection();
DBusMessage* message = dbus_message_new_method_call("com.contiautomotive.NodeStateManager.Consumer", // destination
- "/com/contiautomotive/NodeStateManager/Consumer", // path
+ "/com/contiautomotive/NodeStateManager/Consumer", // path
"com.contiautomotive.NodeStateManager.Consumer", // interface
method); // method
if(message != NULL)
@@ -369,6 +369,9 @@ void process_prepare_shutdown(unsigned char requestId)
// unload custom client libraries
for(i=0; i<get_num_custom_client_libs(); i++)
{
+ // deinitialize plugin
+ gPersCustomFuncs[i].custom_plugin_deinit();
+ // close library handle
dlclose(gPersCustomFuncs[i].handle);
}
diff --git a/test/persistence_client_library_dbus_test.c b/test/persistence_client_library_dbus_test.c
index e9bf0ba..0cbc5fe 100644
--- a/test/persistence_client_library_dbus_test.c
+++ b/test/persistence_client_library_dbus_test.c
@@ -1,12 +1,35 @@
-/*
- * persistence_client_library_dbus_test.c
- *
- * Created on: Aug 8, 2012
- * Author: ihuerner
+/******************************************************************************
+ * 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_dbus_test.c
+ * @ingroup Persistence client library test
+ * @author Ingo Huerner
+ * @brief Test of persistence client library
+ * @see
*/
-
-
#include "../include/persistence_client_library_key.h"
#include "../include/persistence_client_library_file.h"
diff --git a/test/persistence_client_library_test.c b/test/persistence_client_library_test.c
index db3926a..884a67d 100644
--- a/test/persistence_client_library_test.c
+++ b/test/persistence_client_library_test.c
@@ -4,29 +4,23 @@
* Company XS Embedded GmbH
*****************************************************************************/
/******************************************************************************
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- * Neither the name of the <organization> nor the
- names of its contributors may be used to endorse or promote products
- derived from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
-DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ 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_test.c