summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIngo Huerner <ingo.huerner@xse.de>2014-07-09 15:32:59 +0200
committerIngo Huerner <ingo.huerner@xse.de>2014-07-09 15:32:59 +0200
commitc2b8dbd1a8cc3b7a2edd57beb8f548e5f890dc5b (patch)
tree889bbb42b9b0243c352883af5e28c563d3ff7236 /src
parent4680fad3bd70ee363838ceb74c0259e5718be3fa (diff)
downloadpersistence-client-library-c2b8dbd1a8cc3b7a2edd57beb8f548e5f890dc5b.tar.gz
Fixed a problem with getting the size of the default data; extended tests to increase code coverage
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am3
-rw-r--r--src/persistence_client_library_db_access.c19
-rw-r--r--src/persistence_client_library_db_access.h5
-rw-r--r--src/persistence_client_library_key.c11
-rw-r--r--src/rbtree.c81
-rw-r--r--src/rbtree.h18
6 files changed, 69 insertions, 68 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 7a2248a..26248f0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -2,8 +2,7 @@ AUTOMAKE_OPTIONS = foreign
if DEBUG
-AM_CFLAGS = $(DEPS_CFLAGS) -g -I../include \
- -Idbus-1.0
+AM_CFLAGS = -fprofile-arcs -ftest-coverage $(DEPS_CFLAGS) -g -I../include -Idbus-1.0
else
AM_CFLAGS = $(DEPS_CFLAGS) -I../include -Idbus-1.0
#AM_CFLAGS = -fprofile-arcs -ftest-coverage $(DEPS_CFLAGS) -I../include -Idbus-1.0
diff --git a/src/persistence_client_library_db_access.c b/src/persistence_client_library_db_access.c
index 2749882..cad0e5d 100644
--- a/src/persistence_client_library_db_access.c
+++ b/src/persistence_client_library_db_access.c
@@ -43,6 +43,7 @@ static int gHandlesDBCreated[DbTableSize][PersistencePolicy_LastEntry] = { {0} }
int pers_send_Notification_Signal(const char* key, PersistenceDbContext_s* context, unsigned int reason);
+#if 0
char* pers_get_raw_key(char *key)
{
char *temp = NULL;
@@ -57,7 +58,7 @@ char* pers_get_raw_key(char *key)
return rawKey;
}
-
+#endif
int pers_db_open_default(const char* dbPath, PersDefaultType_e DefaultType)
{
@@ -229,7 +230,7 @@ static int database_get(PersistenceInfo_s* info, const char* dbPath)
return handleDB;
}
-
+#if 0
void database_close(PersistenceInfo_s* info)
{
int arrayIdx = info->configKey.storage + info->context.ldbid;
@@ -251,7 +252,7 @@ void database_close(PersistenceInfo_s* info)
DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("database_close ==> invalid storage type"), DLT_INT(info->context.ldbid ));
}
}
-
+#endif
void database_close_all()
{
int i = 0;
@@ -378,9 +379,8 @@ int persistence_get_data(char* dbPath, char* key, const char* resourceID, Persis
info->configKey.policy = PersistencePolicy_wc; /* Set the policy */
info->configKey.type = PersistenceResourceType_key; /* Set the type */
(void)get_db_path_and_key(info, key, NULL, dbPath);
- DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("Plugin data not available. Try to get default data of key:"),
- DLT_STRING(key));
- ret_defaults = pers_get_defaults(dbPath, key, buffer, buffer_size, PersGetDefault_Data);
+ DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("Plugin data not available. Try to get default data of key:"), DLT_STRING(key));
+ ret_defaults = pers_get_defaults(dbPath, (char*)resourceID, buffer, buffer_size, PersGetDefault_Data);
if (0 < ret_defaults)
{
read_size = ret_defaults;
@@ -508,7 +508,7 @@ int persistence_set_data(char* dbPath, char* key, PersistenceInfo_s* info, unsig
-int persistence_get_data_size(char* dbPath, char* key, PersistenceInfo_s* info)
+int persistence_get_data_size(char* dbPath, char* key, const char* resourceID, PersistenceInfo_s* info)
{
int read_size = -1;
int ret_defaults = -1;
@@ -519,10 +519,11 @@ int persistence_get_data_size(char* dbPath, char* key, PersistenceInfo_s* info)
int handleDB = database_get(info, dbPath);
if(handleDB >= 0)
{
+
read_size = persComDbGetKeySize(handleDB, key);
if(read_size < 0)
{
- read_size = pers_get_defaults(dbPath, key, NULL, 0, PersGetDefault_Size);
+ read_size = pers_get_defaults( dbPath, (char*)resourceID, NULL, 0, PersGetDefault_Size);
}
}
}
@@ -595,7 +596,7 @@ int persistence_get_data_size(char* dbPath, char* key, PersistenceInfo_s* info)
(void)get_db_path_and_key(info, key, NULL, dbPath);
DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("Plugin data not available. Try to get size of default data for key:"),
DLT_STRING(key));
- ret_defaults = pers_get_defaults(dbPath, key, NULL, 0, PersGetDefault_Size);
+ ret_defaults = pers_get_defaults(dbPath, (char*)resourceID, NULL, 0, PersGetDefault_Size);
if (0 < ret_defaults)
{
read_size = ret_defaults;
diff --git a/src/persistence_client_library_db_access.h b/src/persistence_client_library_db_access.h
index dc80496..3f3e6b7 100644
--- a/src/persistence_client_library_db_access.h
+++ b/src/persistence_client_library_db_access.h
@@ -115,12 +115,13 @@ int persistence_get_data(char* dbPath, char* key, const char* resourceID, Persis
*
* @param dbPath the path to the database where the key is in
* @param key the database key
+ * @param resourceID the resource id
* @param info persistence information
*
* @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, PersistenceInfo_s* info);
+int persistence_get_data_size(char* dbPath, char* key, const char* resourceID, PersistenceInfo_s* info);
@@ -143,7 +144,7 @@ int persistence_delete_data(char* dbPath, char* key, PersistenceInfo_s* info);
*
* @param info persistence information
*/
-void database_close(PersistenceInfo_s* info);
+//void database_close(PersistenceInfo_s* info);
diff --git a/src/persistence_client_library_key.c b/src/persistence_client_library_key.c
index 3540251..c73cf4c 100644
--- a/src/persistence_client_library_key.c
+++ b/src/persistence_client_library_key.c
@@ -49,7 +49,7 @@ int pclKeyHandleOpen(unsigned int ldbid, const char* resource_id, unsigned int u
{
PersistenceInfo_s dbContext;
- char dbKey[DbKeyMaxLen] = {0}; // database key
+ char dbKey[DbKeyMaxLen] = {0}; // database key
char dbPath[DbPathMaxLen] = {0}; // database location
dbContext.context.ldbid = ldbid;
@@ -338,7 +338,7 @@ int pclKeyGetSize(unsigned int ldbid, const char* resource_id, unsigned int user
{
if( dbContext.configKey.storage < PersistenceStorage_LastEntry) // check if store policy is valid
{
- data_size = persistence_get_data_size(dbPath, dbKey, &dbContext);
+ data_size = persistence_get_data_size(dbPath, dbKey, resource_id, &dbContext);
}
else
{
@@ -529,11 +529,8 @@ int regNotifyOnChange(unsigned int ldbid, const char* resource_id, unsigned int
}
else
{
- DLT_LOG(gPclDLTContext, DLT_LOG_ERROR,
- DLT_STRING("regNotifyOnChange: Not allowed! Resource is local or it is a file:"),
- DLT_STRING(resource_id),
- DLT_STRING("LDBID:"),
- DLT_UINT(ldbid));
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("regNotifyOnChange: Not allowed! Resource is local or it is a file:"),
+ DLT_STRING(resource_id), DLT_STRING("LDBID:"), DLT_UINT(ldbid));
rval = EPERS_NOTIFY_NOT_ALLOWED;
}
}
diff --git a/src/rbtree.c b/src/rbtree.c
index a1439f8..7107979 100644
--- a/src/rbtree.c
+++ b/src/rbtree.c
@@ -193,44 +193,6 @@ jsw_rbtree_t *jsw_rbnew ( cmp_f cmp, dup_f dup, rel_f rel )
return rt;
}
-/**
- <summary>
- Releases a valid red black tree
- <summary>
- <param name="tree">The tree to release</param>
- <remarks>
- The tree must have been created using jsw_rbnew
- </remarks>
-*/
-void jsw_rbdelete ( jsw_rbtree_t *tree )
-{
- jsw_rbnode_t *it = tree->root;
- jsw_rbnode_t *save;
-
- /*
- Rotate away the left links so that
- we can treat this like the destruction
- of a linked list
- */
- while ( it != NULL ) {
- if ( it->link[0] == NULL ) {
- /* No left links, just kill the node and move on */
- save = it->link[1];
- tree->rel ( it->data );
- free ( it );
- }
- else {
- /* Rotate away the left link and check again */
- save = it->link[0];
- it->link[0] = save->link[1];
- save->link[1] = it;
- }
-
- it = save;
- }
-
- free ( tree );
-}
/**
<summary>
@@ -363,6 +325,47 @@ int jsw_rbinsert ( jsw_rbtree_t *tree, void *data )
return 1;
}
+#if 0
+/**
+ <summary>
+ Releases a valid red black tree
+ <summary>
+ <param name="tree">The tree to release</param>
+ <remarks>
+ The tree must have been created using jsw_rbnew
+ </remarks>
+*/
+void jsw_rbdelete ( jsw_rbtree_t *tree )
+{
+ jsw_rbnode_t *it = tree->root;
+ jsw_rbnode_t *save;
+
+ /*
+ Rotate away the left links so that
+ we can treat this like the destruction
+ of a linked list
+ */
+ while ( it != NULL ) {
+ if ( it->link[0] == NULL ) {
+ /* No left links, just kill the node and move on */
+ save = it->link[1];
+ tree->rel ( it->data );
+ free ( it );
+ }
+ else {
+ /* Rotate away the left link and check again */
+ save = it->link[0];
+ it->link[0] = save->link[1];
+ save->link[1] = it;
+ }
+
+ it = save;
+ }
+
+ free ( tree );
+}
+
+
/**
<summary>
Remove a node from a red black tree
@@ -632,4 +635,4 @@ void *jsw_rbtprev ( jsw_rbtrav_t *trav )
}
-
+#endif
diff --git a/src/rbtree.h b/src/rbtree.h
index 81d8ed0..429be29 100644
--- a/src/rbtree.h
+++ b/src/rbtree.h
@@ -77,19 +77,19 @@ typedef void (*rel_f) ( void *p );
/* Red Black tree functions */
jsw_rbtree_t *jsw_rbnew ( cmp_f cmp, dup_f dup, rel_f rel );
-void jsw_rbdelete ( jsw_rbtree_t *tree );
+//void jsw_rbdelete ( jsw_rbtree_t *tree );
void *jsw_rbfind ( jsw_rbtree_t *tree, void *data );
int jsw_rbinsert ( jsw_rbtree_t *tree, void *data );
-int jsw_rberase ( jsw_rbtree_t *tree, void *data );
-size_t jsw_rbsize ( jsw_rbtree_t *tree );
+//int jsw_rberase ( jsw_rbtree_t *tree, void *data );
+//size_t jsw_rbsize ( jsw_rbtree_t *tree );
/* Traversal functions */
-jsw_rbtrav_t *jsw_rbtnew ( void );
-void jsw_rbtdelete ( jsw_rbtrav_t *trav );
-void *jsw_rbtfirst ( jsw_rbtrav_t *trav, jsw_rbtree_t *tree );
-void *jsw_rbtlast ( jsw_rbtrav_t *trav, jsw_rbtree_t *tree );
-void *jsw_rbtnext ( jsw_rbtrav_t *trav );
-void *jsw_rbtprev ( jsw_rbtrav_t *trav );
+//jsw_rbtrav_t *jsw_rbtnew ( void );
+//void jsw_rbtdelete ( jsw_rbtrav_t *trav );
+//void *jsw_rbtfirst ( jsw_rbtrav_t *trav, jsw_rbtree_t *tree );
+//void *jsw_rbtlast ( jsw_rbtrav_t *trav, jsw_rbtree_t *tree );
+//void *jsw_rbtnext ( jsw_rbtrav_t *trav );
+//void *jsw_rbtprev ( jsw_rbtrav_t *trav );
#ifdef __cplusplus
}