summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIngo Huerner <ingo.huerner@xse.de>2015-01-16 15:19:12 +0100
committerIngo Huerner <ingo.huerner@xse.de>2015-01-16 15:19:12 +0100
commitddccbec6d938dd3b7b8a644d5a191d1f673173a0 (patch)
tree0ad93c96895ad196c6b9351eb75504b2f59bdb40
parentb4d4132157a9c7ea44cedda856b2bf76a021431c (diff)
downloadpersistence-client-library-ddccbec6d938dd3b7b8a644d5a191d1f673173a0.tar.gz
Some code cleanup
-rw-r--r--AUTHORS1
-rw-r--r--configure.ac2
-rw-r--r--src/persistence_client_library.c7
-rw-r--r--src/persistence_client_library_backup_filelist.c70
-rw-r--r--src/persistence_client_library_custom_loader.c64
-rw-r--r--src/persistence_client_library_db_access.c24
-rw-r--r--src/persistence_client_library_dbus_cmd.c59
-rw-r--r--src/persistence_client_library_dbus_service.c145
-rw-r--r--src/persistence_client_library_file.c41
-rw-r--r--src/persistence_client_library_key.c39
-rw-r--r--src/persistence_client_library_lc_interface.c1
-rw-r--r--src/persistence_client_library_lc_interface.h1
-rw-r--r--src/persistence_client_library_pas_interface.c13
-rw-r--r--src/persistence_client_library_pas_interface.h1
-rw-r--r--src/persistence_client_library_prct_access.c30
15 files changed, 191 insertions, 307 deletions
diff --git a/AUTHORS b/AUTHORS
index e69de29..1af085e 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -0,0 +1 @@
+Ingo Huerner <ingo_huerner@mentor.com> \ No newline at end of file
diff --git a/configure.ac b/configure.ac
index 7a8f73a..91c9668 100644
--- a/configure.ac
+++ b/configure.ac
@@ -30,7 +30,7 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
# Overwrite the build in defaults
-CFLAGS="-Wall -O2"
+CFLAGS="-Wall -O2 -Wextra -Werror"
# Checks for programs.
AC_PROG_CC
diff --git a/src/persistence_client_library.c b/src/persistence_client_library.c
index 3123b61..f6e6425 100644
--- a/src/persistence_client_library.c
+++ b/src/persistence_client_library.c
@@ -17,7 +17,6 @@
* @see
*/
-
#include "persistence_client_library_lc_interface.h"
#include "persistence_client_library_pas_interface.h"
#include "persistence_client_library_dbus_service.h"
@@ -40,8 +39,6 @@
#include <pthread.h>
-
-
/// debug log and trace (DLT) setup
DLT_DECLARE_CONTEXT(gPclDLTContext);
@@ -144,8 +141,6 @@ int pclInitLibrary(const char* appName, int shutdownMode)
return rval;
}
-
-
static int private_pclInitLibrary(const char* appName, int shutdownMode)
{
int rval = 1;
@@ -219,6 +214,7 @@ static int private_pclInitLibrary(const char* appName, int shutdownMode)
}
+
int pclDeinitLibrary(void)
{
int rval = 1;
@@ -255,6 +251,7 @@ int pclDeinitLibrary(void)
static int private_pclDeinitLibrary(void)
{
int rval = 1;
+ int* retval;
MainLoopData_u data;
data.message.cmd = (uint32_t)CMD_QUIT;
diff --git a/src/persistence_client_library_backup_filelist.c b/src/persistence_client_library_backup_filelist.c
index f6c3cf2..6853e23 100644
--- a/src/persistence_client_library_backup_filelist.c
+++ b/src/persistence_client_library_backup_filelist.c
@@ -65,8 +65,7 @@ static void fillFileBackupCharTokenArray(unsigned int customConfigFileSize, char
int blankCount=0;
char* tmpPointer = fileMap;
- // set the first pointer to the start of the file
- gpTokenArray[blankCount] = tmpPointer;
+ gpTokenArray[blankCount] = tmpPointer; // set the first pointer to the start of the file
blankCount++;
while(i < customConfigFileSize)
@@ -78,8 +77,7 @@ static void fillFileBackupCharTokenArray(unsigned int customConfigFileSize, char
{
*tmpPointer = 0;
- // check if we are at the end of the token array
- if(blankCount >= TOKENARRAYSIZE)
+ if(blankCount >= TOKENARRAYSIZE) // check if we are at the end of the token array
{
break;
}
@@ -100,7 +98,7 @@ static void createAndStoreFileNames()
char path[128] = {0};
key_value_s* item;
- // creat new tree
+ // create new tree
gRb_tree_bl = jsw_rbnew(key_val_cmp, key_val_dup, key_val_rel);
if(gRb_tree_bl != NULL)
@@ -112,8 +110,7 @@ static void createAndStoreFileNames()
memset(path, 0, sizeof(path));
snprintf(path, 128, "%s", gpTokenArray[i]); // storage type
- // asign key and value to the rbtree item
- item = malloc(sizeof(key_value_s));
+ item = malloc(sizeof(key_value_s)); // asign key and value to the rbtree item
if(item != NULL)
{
//printf("createAndStoreFileNames => path: %s\n", path);
@@ -146,7 +143,7 @@ int readBlacklistConfigFile(const char* filename)
memset(&buffer, 0, sizeof(buffer));
if(stat(filename, &buffer) != -1)
{
- if(buffer.st_size > 0) // check for empty file
+ if(buffer.st_size > 0) // check for empty file
{
char* configFileMap = 0;
int fd = open(filename, O_RDONLY);
@@ -157,8 +154,7 @@ int readBlacklistConfigFile(const char* filename)
return EPERS_COMMON;
}
- // map the config file into memory
- configFileMap = (char*)mmap(0, buffer.st_size, PROT_WRITE, MAP_PRIVATE, fd, 0);
+ configFileMap = (char*)mmap(0, buffer.st_size, PROT_WRITE, MAP_PRIVATE, fd, 0); // map the configuration file into memory
if(configFileMap == MAP_FAILED)
{
@@ -170,8 +166,7 @@ int readBlacklistConfigFile(const char* filename)
fillFileBackupCharTokenArray(buffer.st_size, configFileMap);
- // create filenames and store them in the tree
- createAndStoreFileNames();
+ createAndStoreFileNames(); // create filenames and store them in the tree
munmap(configFileMap, buffer.st_size);
@@ -269,11 +264,9 @@ void* key_val_dup(void *p)
dst = malloc(sizeof(key_value_s));
if(dst != NULL)
{
- // duplicate hash key
- dst->key = src->key;
+ dst->key = src->key; // duplicate hash key
- // duplicate value
- dst->value = malloc(value_size);
+ dst->value = malloc(value_size); // duplicate value
if(dst->value != NULL)
strncpy(dst->value, src->value, value_size);
}
@@ -356,8 +349,6 @@ int pclCreateFile(const char* path, int chached)
strncat(createPath, "/", DbPathMaxLen-1);
strncat(createPath, tokenArray[i], DbPathMaxLen-1);
-
-
#if USE_FILECACHE
if(chached == 0)
{
@@ -380,6 +371,7 @@ int pclCreateFile(const char* path, int chached)
}
+
int pclVerifyConsistency(const char* origPath, const char* backupPath, const char* csumPath, int openFlags)
{
int handle = 0, readSize = 0;
@@ -400,8 +392,8 @@ int pclVerifyConsistency(const char* origPath, const char* backupPath, const cha
if((backupAvail == 0) && (csumAvail == 0) )
{
DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("verifyConsist- there is a backup file AND csum"));
- // calculate checksum form backup file
- fdBackup = open(backupPath, O_RDONLY);
+
+ fdBackup = open(backupPath, O_RDONLY); // calculate checksum form backup file
if(fdBackup != -1)
{
pclCalcCrc32Csum(fdBackup, backCsumBuf);
@@ -414,13 +406,11 @@ int pclVerifyConsistency(const char* origPath, const char* backupPath, const cha
{
if(strcmp(csumBuf, backCsumBuf) == 0)
{
- // checksum matches ==> replace with original file
- handle = pclRecoverFromBackup(fdBackup, origPath);
+ handle = pclRecoverFromBackup(fdBackup, origPath); // checksum matches ==> replace with original file
}
else
{
- // checksum does not match, check checksum with original file
- handle = open(origPath, openFlags);
+ handle = open(origPath, openFlags); // checksum does not match, check checksum with original file
if(handle != -1)
{
pclCalcCrc32Csum(handle, origCsumBuf);
@@ -430,7 +420,6 @@ int pclVerifyConsistency(const char* origPath, const char* backupPath, const cha
handle = -1; // error: file corrupt
}
// else case: checksum matches ==> keep original file ==> nothing to do
-
}
else
{
@@ -470,8 +459,7 @@ int pclVerifyConsistency(const char* origPath, const char* backupPath, const cha
}
close(fdCsum);
- // calculate the checksum form the original file to see if it matches
- handle = open(origPath, openFlags);
+ handle = open(origPath, openFlags); // calculate the checksum form the original file to see if it matches
if(handle != -1)
{
pclCalcCrc32Csum(handle, origCsumBuf);
@@ -502,15 +490,13 @@ int pclVerifyConsistency(const char* origPath, const char* backupPath, const cha
{
DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("verifyConsist - there is ONLY a backup file"));
- // calculate checksum form backup file
- fdBackup = open(backupPath, O_RDONLY);
+ fdBackup = open(backupPath, O_RDONLY); // calculate checksum form backup file
if(fdBackup != -1)
{
pclCalcCrc32Csum(fdBackup, backCsumBuf);
close(fdBackup);
- // calculate the checksum form the original file to see if it matches
- handle = open(origPath, openFlags);
+ handle = open(origPath, openFlags); // calculate the checksum form the original file to see if it matches
if(handle != -1)
{
pclCalcCrc32Csum(handle, origCsumBuf);
@@ -521,7 +507,6 @@ int pclVerifyConsistency(const char* origPath, const char* backupPath, const cha
handle = -1; // checksum does NOT match ==> error: file corrupt
}
// else case: checksum matches ==> keep original file ==> nothing to do
-
}
else
{
@@ -537,9 +522,7 @@ int pclVerifyConsistency(const char* origPath, const char* backupPath, const cha
}
// for else case: nothing to do
-
- // if we are in an inconsistent state: delete file, backup and checksum
- if(handle == -1)
+ if(handle == -1) // if we are in an inconsistent state: delete file, backup and checksum
{
remove(origPath);
remove(backupPath);
@@ -558,8 +541,7 @@ int pclRecoverFromBackup(int backupFd, const char* original)
handle = open(original, O_TRUNC | O_RDWR);
if(handle != -1)
{
- // copy data from one file to another
- if(pclBackupDoFileCopy(backupFd, handle) == -1)
+ if(pclBackupDoFileCopy(backupFd, handle) == -1) // copy data from one file to another
{
DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("rBackup - couldn't write whole buffer"));
}
@@ -582,7 +564,7 @@ int pclCreateBackup(const char* dstPath, int srcfd, const char* csumPath, const
strncpy(pathToCreate, dstPath, DbPathMaxLen);
handle = pclCreateFile(pathToCreate, 0);
- close(handle); // don't need the open file
+ close(handle); // don't need the open file
}
// create checksum file and and write checksum
@@ -621,8 +603,7 @@ int pclCreateBackup(const char* dstPath, int srcfd, const char* csumPath, const
DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("cBackup - err closing fd"));
}
- // set back to the position
- lseek(srcfd, curPos, SEEK_SET);
+ lseek(srcfd, curPos, SEEK_SET); // set back to the position
}
else
{
@@ -650,13 +631,11 @@ int pclCalcCrc32Csum(int fd, char crc32sum[])
if(buf != 0)
{
off_t curPos = 0;
- // remember the current position
- curPos = lseek(fd, 0, SEEK_CUR);
+ curPos = lseek(fd, 0, SEEK_CUR); // remember the current position
if(curPos != 0)
{
- // set to beginning of the file
- lseek(fd, 0, SEEK_SET);
+ lseek(fd, 0, SEEK_SET); // set to beginning of the file
}
while((rval = read(fd, buf, statBuf.st_size)) > 0)
@@ -666,8 +645,7 @@ int pclCalcCrc32Csum(int fd, char crc32sum[])
snprintf(crc32sum, ChecksumBufSize-1, "%x", crc);
}
- // set back to the position
- lseek(fd, curPos, SEEK_SET);
+ lseek(fd, curPos, SEEK_SET); // set back to the position
free(buf);
}
diff --git a/src/persistence_client_library_custom_loader.c b/src/persistence_client_library_custom_loader.c
index e3bda0f..8b9d58a 100644
--- a/src/persistence_client_library_custom_loader.c
+++ b/src/persistence_client_library_custom_loader.c
@@ -46,6 +46,7 @@ static char* gpCustomTokenArray[TOKENARRAYSIZE];
int(* gPlugin_callback_async_t)(int errcode);
+
static void fillCustomCharTokenArray(unsigned int customConfigFileSize, char* fileMap)
{
unsigned int i=0;
@@ -53,8 +54,7 @@ static void fillCustomCharTokenArray(unsigned int customConfigFileSize, char* fi
int blankCount=0;
char* tmpPointer = fileMap;
- // set the first pointer to the start of the file
- gpCustomTokenArray[blankCount] = tmpPointer;
+ gpCustomTokenArray[blankCount] = tmpPointer; // set the first pointer to the start of the file
blankCount++;
while(i < customConfigFileSize)
@@ -63,8 +63,7 @@ static void fillCustomCharTokenArray(unsigned int customConfigFileSize, char* fi
{
*tmpPointer = 0;
- // check if we are at the end of the token array
- if(blankCount >= TOKENARRAYSIZE)
+ if(blankCount >= TOKENARRAYSIZE) // check if we are at the end of the token array
{
break;
}
@@ -79,6 +78,7 @@ static void fillCustomCharTokenArray(unsigned int customConfigFileSize, char* fi
}
+
static PersLoadingType_e getLoadingType(const char* type)
{
PersLoadingType_e persLoadingType = LoadType_Undefined;
@@ -96,6 +96,7 @@ static PersLoadingType_e getLoadingType(const char* type)
}
+
static PersInitType_e getInitType(const char* policy)
{
PersInitType_e persInitType = Init_Undefined;
@@ -119,12 +120,14 @@ PersLoadingType_e getCustomLoadingType(int i)
}
+
PersInitType_e getCustomInitType(int i)
{
return gCustomLibArray[i].initFunction;
}
+
PersistenceCustomLibs_e custom_client_name_to_id(const char* lib_name, int substring)
{
PersistenceCustomLibs_e libId = PersCustomLib_LastEntry;
@@ -226,13 +229,13 @@ int get_custom_libraries()
for(j=0; j<PersCustomLib_LastEntry; j++)
{
- gCustomLibArray[j].valid = -1; // init pos to -1
+ gCustomLibArray[j].valid = -1; // init pos to -1
}
memset(&buffer, 0, sizeof(buffer));
if(stat(filename, &buffer) != -1)
{
- if(buffer.st_size > 0) // check for empty file
+ if(buffer.st_size > 0) // check for empty file
{
char* customConfFileMap = NULL;
int i = 0;
@@ -265,7 +268,7 @@ int get_custom_libraries()
{
int libId = custom_client_name_to_id(gpCustomTokenArray[i], 0); // get the custom libID
- // assign the libraryname
+ // assign the library name
strncpy(gCustomLibArray[libId].libname, gpCustomTokenArray[i+1], CustLibMaxLen);
gCustomLibArray[libId].libname[CustLibMaxLen-1] = '\0'; // Ensures 0-Termination
@@ -311,7 +314,7 @@ int load_default_library(void* handle)
if(handle != NULL)
{
- ///
+ /// D A T A B A S E F U N C T I O N S
*(void **) (&plugin_persComDbOpen) = dlsym(handle, "persComDbOpen");
if ((error = dlerror()) != NULL)
{
@@ -327,7 +330,6 @@ int load_default_library(void* handle)
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_default_library - error:"), DLT_STRING(error));
}
-
*(void **) (&plugin_persComDbReadKey) = dlsym(handle, "persComDbReadKey");
if ((error = dlerror()) != NULL)
{
@@ -354,20 +356,17 @@ int load_default_library(void* handle)
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_default_library - error:"), DLT_STRING(error));
}
-
/// R C T F U N C T I O N S
*(void **) (&plugin_persComRctOpen) = dlsym(handle, "persComRctOpen");
if ((error = dlerror()) != NULL)
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_default_library - error:"), DLT_STRING(error));
}
-
*(void **) (&plugin_persComRctClose) = dlsym(handle, "persComRctClose");
if ((error = dlerror()) != NULL)
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_default_library - error:"), DLT_STRING(error));
}
-
*(void **) (&plugin_persComRctRead) = dlsym(handle, "persComRctRead");
if ((error = dlerror()) != NULL)
{
@@ -380,43 +379,36 @@ int load_default_library(void* handle)
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_default_library - error:"), DLT_STRING(error));
}
-
plugin_gLocalWt = *(char**)dlsym(handle, "gLocalWt");
if ((error = dlerror()) != NULL)
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_default_library - error:"), DLT_STRING(error));
}
-
plugin_gSeat = *(char**)dlsym(handle, "gSeat");
if ((error = dlerror()) != NULL)
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_default_library - error:"), DLT_STRING(error));
}
-
plugin_gLocalFactoryDefault = *(char**)dlsym(handle, "gLocalFactoryDefault");
if ((error = dlerror()) != NULL)
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_default_library - error:"), DLT_STRING(error));
}
-
plugin_gLocalCached = *(char**) dlsym(handle, "gLocalCached");
if ((error = dlerror()) != NULL)
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_default_library - error:"), DLT_STRING(error));
}
-
plugin_gNode = *(char**)dlsym(handle, "gNode");
if ((error = dlerror()) != NULL)
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_default_library - error:"), DLT_STRING(error));
}
-
plugin_gLocalConfigurableDefault = *(char**)dlsym(handle, "gLocalConfigurableDefault");
if ((error = dlerror()) != NULL)
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_default_library - error:"), DLT_STRING(error));
}
-
plugin_gResTableCfg = *(char**)dlsym(handle, "gResTableCfg");
if ((error = dlerror()) != NULL)
{
@@ -459,113 +451,91 @@ int load_custom_library(PersistenceCustomLibs_e customLib, Pers_custom_functs_s
{
dlerror(); // reset error
- // plugin_close
*(void **) (&customFuncts->custom_plugin_handle_close) = dlsym(handle, "plugin_handle_close");
if ((error = dlerror()) != NULL)
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error));
}
- // custom_plugin_delete_data
*(void **) (&customFuncts->custom_plugin_delete_data) = dlsym(handle, "plugin_delete_data");
if ((error = dlerror()) != NULL)
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error));
- }
- // custom_plugin_get_data
+ }
*(void **) (&customFuncts->custom_plugin_handle_get_data) = dlsym(handle, "plugin_handle_get_data");
if ((error = dlerror()) != NULL)
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error));
- }
- // custom_plugin_get_data
+ }
*(void **) (&customFuncts->custom_plugin_get_data) = dlsym(handle, "plugin_get_data");
if ((error = dlerror()) != NULL)
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error));
- }
- // custom_plugin_init
+ }
*(void **) (&customFuncts->custom_plugin_init) = dlsym(handle, "plugin_init");
if ((error = dlerror()) != NULL)
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error));
- }
- // custom_plugin_deinit
+ }
*(void **) (&customFuncts->custom_plugin_deinit) = dlsym(handle, "plugin_deinit");
if ((error = dlerror()) != NULL)
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error));
}
- // custom_plugin_open
*(void **) (&customFuncts->custom_plugin_handle_open) = dlsym(handle, "plugin_handle_open");
if ((error = dlerror()) != NULL)
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error));
- }
- // custom_plugin_set_data
+ }
*(void **) (&customFuncts->custom_plugin_handle_set_data) = dlsym(handle, "plugin_handle_set_data");
if ((error = dlerror()) != NULL)
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error));
- }
- // custom_plugin_set_data
+ }
*(void **) (&customFuncts->custom_plugin_set_data) = dlsym(handle, "plugin_set_data");
if ((error = dlerror()) != NULL)
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error));
}
- // custom_plugin_get_size_handle
*(void **) (&customFuncts->custom_plugin_handle_get_size) = dlsym(handle, "plugin_handle_get_size");
if ((error = dlerror()) != NULL)
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error));
}
- // custom_plugin_get_size
*(void **) (&customFuncts->custom_plugin_get_size) = dlsym(handle, "plugin_get_size");
if ((error = dlerror()) != NULL)
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error));
}
- // create backup
*(void **) (&customFuncts->custom_plugin_create_backup) = dlsym(handle, "plugin_create_backup");
if ((error = dlerror()) != NULL)
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error));
}
- // restore backup
*(void **) (&customFuncts->custom_plugin_restore_backup) = dlsym(handle, "plugin_restore_backup");
if ((error = dlerror()) != NULL)
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error));
}
- // restore backup
*(void **) (&customFuncts->custom_plugin_get_backup) = dlsym(handle, "plugin_get_backup");
if ((error = dlerror()) != NULL)
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error));
}
-
- // 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)
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error));
}
-
- // initialize plugin (non blocking)
*(void **) (&customFuncts->custom_plugin_init_async) = dlsym(handle, "plugin_init_async");
if ((error = dlerror()) != NULL)
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error));
}
-
- // clear all data
*(void **) (&customFuncts->custom_plugin_clear_all_data) = dlsym(handle, "plugin_clear_all_data");
if ((error = dlerror()) != NULL)
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error));
}
-
- // sync data
*(void **) (&customFuncts->custom_plugin_sync) = dlsym(handle, "plugin_sync");
if ((error = dlerror()) != NULL)
{
diff --git a/src/persistence_client_library_db_access.c b/src/persistence_client_library_db_access.c
index cc391f5..075f83e 100644
--- a/src/persistence_client_library_db_access.c
+++ b/src/persistence_client_library_db_access.c
@@ -67,7 +67,7 @@ static int database_get(PersistenceInfo_s* info, const char* dbPath, int dbType)
int arrayIdx = 0;
int handleDB = -1;
- // create array index: index is a combination of resource config table type and group
+ // create array index: index is a combination of resource configuration table type and group
arrayIdx = info->configKey.storage + info->context.ldbid ;
if(arrayIdx < DbTableSize)
@@ -84,7 +84,7 @@ static int database_get(PersistenceInfo_s* info, const char* dbPath, int dbType)
{
snprintf(path, DbPathMaxLen, "%s%s", dbPath, plugin_gLocalCached);
}
- else if(PersistenceDB_confdefault == dbType) // configurable default database
+ else if(PersistenceDB_confdefault == dbType) // configurable default database
{
snprintf(path, DbPathMaxLen, "%s%s", dbPath, plugin_gLocalConfigurableDefault);
}
@@ -259,7 +259,7 @@ int persistence_get_data(char* dbPath, char* key, const char* resourceID, Persis
else if(PersistenceStorage_custom == info->configKey.storage) // custom storage implementation via custom library
{
int idx = custom_client_name_to_id(dbPath, 1);
- char workaroundPath[128]; // workaround, because /sys/ can not be accessed on host!!!!
+ char workaroundPath[128]; // workaround, because /sys/ can not be accessed on host!!!!
snprintf(workaroundPath, 128, "%s%s", "/Data", dbPath );
if(idx < PersCustomLib_LastEntry)
@@ -321,10 +321,10 @@ int persistence_get_data(char* dbPath, char* key, const char* resourceID, Persis
read_size = EPERS_NOPLUGINFUNCT;
}
- if (1 > read_size) /* Try to get default values */
+ if (1 > read_size) // Try to get default values
{
- info->configKey.policy = PersistencePolicy_wc; /* Set the policy */
- info->configKey.type = PersistenceResourceType_key; /* Set the type */
+ 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);
@@ -350,7 +350,7 @@ int persistence_set_data(char* dbPath, char* key, const char* resource_id, Persi
{
int handleDB = -1 ;
int dbType = info->configKey.policy; // assign default policy
- const char* dbInput = key; // assign default key
+ const char* dbInput = key; // assign default key
if(info->context.user_no == PCL_USER_DEFAULTDATA)
{
@@ -669,6 +669,7 @@ int persistence_delete_data(char* dbPath, char* key, const char* resource_id, Pe
}
+
int persistence_notify_on_change(const char* key, unsigned int ldbid, unsigned int user_no, unsigned int seat_no,
pclChangeNotifyCallback_t callback, PersNotifyRegPolicy_e regPolicy)
{
@@ -688,13 +689,11 @@ int persistence_notify_on_change(const char* key, unsigned int ldbid, unsigned i
if(regPolicy == Notify_register)
{
- // assign callback
- gChangeNotifyCallback = callback;
+ gChangeNotifyCallback = callback; // assign callback
}
else if(regPolicy == Notify_unregister)
{
- // remove callback
- gChangeNotifyCallback = NULL;
+ gChangeNotifyCallback = NULL; // remove callback
}
if(-1 == deliverToMainloop(&data))
@@ -750,8 +749,7 @@ void pers_rct_close_all()
{
int i = 0;
- // close all open persistence resource configuration tables
- for(i=0; i< PrctDbTableSize; i++)
+ for(i=0; i< PrctDbTableSize; i++) // close all open persistence resource configuration tables
{
if(get_resource_cfg_table_by_idx(i) != -1)
{
diff --git a/src/persistence_client_library_dbus_cmd.c b/src/persistence_client_library_dbus_cmd.c
index 1631d3d..aece878 100644
--- a/src/persistence_client_library_dbus_cmd.c
+++ b/src/persistence_client_library_dbus_cmd.c
@@ -140,13 +140,11 @@ void process_send_notification_signal(DBusConnection* conn, unsigned int notifyL
DBUS_TYPE_INVALID);
if(ret == TRUE)
{
- // Send the signal
- if(conn != NULL)
+ if(conn != NULL) // Send the signal
{
if(dbus_connection_send(conn, message, 0) == TRUE)
{
- // Free the signal now we have finished with it
- dbus_message_unref(message);
+ dbus_message_unref(message); // Free the signal now we have finished with it
}
else
{
@@ -224,29 +222,24 @@ void process_prepare_shutdown(int complete)
}
}
- // close all opend rct
- pers_rct_close_all();
+ pers_rct_close_all(); // close all opened resource configuration table
- // close opend database
- database_close_all();
+ database_close_all(); // close opened database
if(complete > 0)
{
close_all_persistence_handle();
}
-
if(complete > 0)
{
- // unload custom client libraries
- for(i=0; i<PersCustomLib_LastEntry; i++)
+ for(i=0; i<PersCustomLib_LastEntry; i++) // unload custom client libraries
{
if(gPersCustomFuncs[i].custom_plugin_deinit != NULL)
{
- // deinitialize plugin
- gPersCustomFuncs[i].custom_plugin_deinit();
- // close library handle
- dlclose(gPersCustomFuncs[i].handle);
+ gPersCustomFuncs[i].custom_plugin_deinit(); // deinitialize plugin
+
+ dlclose(gPersCustomFuncs[i].handle); // close library handle
invalidate_custom_plugin(i);
}
@@ -261,9 +254,9 @@ void process_send_pas_request(DBusConnection* conn, unsigned int requestID, int
DBusError error;
dbus_error_init (&error);
- DBusMessage* message = dbus_message_new_method_call(gDbusPersAdminInterface, // destination
- gDbusPersAdminPath, // path
- gDbusPersAdminInterface, // interface
+ DBusMessage* message = dbus_message_new_method_call(gDbusPersAdminInterface, // destination
+ gDbusPersAdminPath, // path
+ gDbusPersAdminInterface, // interface
"PersistenceAdminRequestCompleted"); // method
if(conn != NULL)
{
@@ -293,6 +286,7 @@ void process_send_pas_request(DBusConnection* conn, unsigned int requestID, int
}
+
void process_send_pas_register(DBusConnection* conn, int regType, int notificationFlag)
{
DBusError error;
@@ -312,10 +306,10 @@ void process_send_pas_register(DBusConnection* conn, int regType, int notificati
if(busName != NULL)
{
- DBusMessage* message = dbus_message_new_method_call(gDbusPersAdminInterface, // destination
+ DBusMessage* message = dbus_message_new_method_call(gDbusPersAdminInterface, // destination
gDbusPersAdminPath, // path
- gDbusPersAdminInterface, // interface
- method); // method
+ gDbusPersAdminInterface, // interface
+ method); // method
if(message != NULL)
{
@@ -325,7 +319,7 @@ void process_send_pas_register(DBusConnection* conn, int regType, int notificati
DBUS_TYPE_UINT32, &gTimeoutMs,
DBUS_TYPE_INVALID);
- dbus_connection_send_with_reply(conn, // the connection
+ dbus_connection_send_with_reply(conn, // the connection
message, // the message to write
&pending, // pending
gTimeoutMs); // timeout in milliseconds or -1 for default
@@ -356,6 +350,7 @@ void process_send_pas_register(DBusConnection* conn, int regType, int notificati
}
+
void process_send_lifecycle_register(DBusConnection* conn, int regType, int shutdownMode)
{
DBusError error;
@@ -372,10 +367,10 @@ void process_send_lifecycle_register(DBusConnection* conn, int regType, int shut
{
const char* busName = dbus_bus_get_unique_name(conn);
- DBusMessage* message = dbus_message_new_method_call(gDbusLcConsDest, // destination
- gDbusLcCons, // path
- gDbusLcInterface, // interface
- method); // method
+ DBusMessage* message = dbus_message_new_method_call(gDbusLcConsDest, // destination
+ gDbusLcCons, // path
+ gDbusLcInterface, // interface
+ method); // method
if(message != NULL)
{
if(regType == 1) // register
@@ -419,10 +414,10 @@ void process_send_lifecycle_request(DBusConnection* conn, unsigned int requestId
if(conn != NULL)
{
- DBusMessage* message = dbus_message_new_method_call(gDbusLcConsDest, // destination
- gDbusLcCons, // path
- gDbusLcInterface, // interface
- "LifecycleRequestComplete"); // method
+ DBusMessage* message = dbus_message_new_method_call(gDbusLcConsDest, // destination
+ gDbusLcCons, // path
+ gDbusLcInterface, // interface
+ "LifecycleRequestComplete"); // method
if(message != NULL)
{
dbus_message_append_args(message, DBUS_TYPE_INT32, &requestId,
@@ -477,7 +472,3 @@ void msg_pending_func(DBusPendingCall *call, void *data)
// unlock the mutex because we have received the reply to the dbus message
pthread_mutex_unlock(&gDbusPendingRegMtx);
}
-
-
-
-
diff --git a/src/persistence_client_library_dbus_service.c b/src/persistence_client_library_dbus_service.c
index 450c1ba..6b574ed 100644
--- a/src/persistence_client_library_dbus_service.c
+++ b/src/persistence_client_library_dbus_service.c
@@ -23,7 +23,6 @@
#include "persistence_client_library_dbus_cmd.h"
#include "persistence_client_library_data_organization.h"
-
#include <stdio.h>
#include <errno.h>
#include <string.h>
@@ -32,7 +31,6 @@
pthread_mutex_t gDbusPendingRegMtx = PTHREAD_MUTEX_INITIALIZER;
-
pthread_mutex_t gDeliverpMtx = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t gMainCondMtx = PTHREAD_MUTEX_INITIALIZER;
@@ -105,6 +103,7 @@ static void unregisterMessageHandler(DBusConnection *connection, void *user_data
DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("unregisterObjectPath\n"));
}
+
/* catches messages not directed to any registered object path ("garbage collector") */
static DBusHandlerResult handleObjectPathMessageFallback(DBusConnection * connection, DBusMessage * message, void * user_data)
{
@@ -187,8 +186,7 @@ static DBusHandlerResult handleObjectPathMessageFallback(DBusConnection * connec
notifyStruct.user_no = atoi(user_no);
notifyStruct.seat_no = atoi(seat_no);
- // call the registered callback function
- if(gChangeNotifyCallback != NULL )
+ if(gChangeNotifyCallback != NULL ) // call the registered callback function
{
gChangeNotifyCallback(&notifyStruct);
}
@@ -391,7 +389,7 @@ static void removeTimeout(DBusTimeout *timeout, void *data)
-/** callback for libdbus' when timeout changed */
+// callback for libdbus' when timeout changed
static void timeoutToggled(DBusTimeout *timeout, void *data)
{
int i = gPollInfo.nfds;
@@ -411,18 +409,17 @@ static void timeoutToggled(DBusTimeout *timeout, void *data)
}
+
int setup_dbus_mainloop(void)
{
int rval = 0, doCleanup = 0;
DBusError err;
DBusConnection* conn = NULL;
-
const char *pAddress = getenv("PERS_CLIENT_DBUS_ADDRESS");
dbus_error_init(&err);
- // Connect to the bus and check for errors
- if(pAddress != NULL)
+ if(pAddress != NULL) // Connect to the bus and check for errors
{
DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("setupMainLoop - specific dbus address:"), DLT_STRING(pAddress) );
@@ -447,27 +444,22 @@ int setup_dbus_mainloop(void)
else
{
DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("setupMainLoop - Use def bus (DBUS_BUS_SYSTEM)"));
-
conn = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err);
}
- // create communication pipe with the dbus mainloop
- if (-1 == (pipe(gPipeFd)))
+ if (-1 == (pipe(gPipeFd))) // create communication pipe with the dbus mainloop
{
DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop - eventfd() failed w/ errno:"), DLT_INT(errno) );
rval = EPERS_COMMON;
}
else
{
- // persistence admin message
- const struct DBusObjectPathVTable vtablePersAdmin
- = {unregisterMessageHandler, checkPersAdminMsg, NULL, NULL, NULL, NULL};
+ // persistence administrator message
+ const struct DBusObjectPathVTable vtablePersAdmin = {unregisterMessageHandler, checkPersAdminMsg, NULL, NULL, NULL, NULL};
// lifecycle message
- const struct DBusObjectPathVTable vtableLifecycle
- = {unregisterMessageHandler, checkLifecycleMsg, NULL, NULL, NULL, NULL};
+ const struct DBusObjectPathVTable vtableLifecycle = {unregisterMessageHandler, checkLifecycleMsg, NULL, NULL, NULL, NULL};
// fallback
- const struct DBusObjectPathVTable vtableFallback
- = {unregisterObjectPathFallback, handleObjectPathMessageFallback, NULL, NULL, NULL, NULL};
+ const struct DBusObjectPathVTable vtableFallback = {unregisterObjectPathFallback, handleObjectPathMessageFallback, NULL, NULL, NULL, NULL};
#if USE_PASINTERFACE != 1
(void)vtablePersAdmin;
@@ -516,8 +508,7 @@ int setup_dbus_mainloop(void)
}
}
- // close pipe and close dbus connection if anything goes wrong setting up
- if(doCleanup)
+ if(doCleanup) // close pipe and close dbus connection if anything goes wrong setting up
{
if(gPipeFd[0] != -1)
{
@@ -543,6 +534,51 @@ int setup_dbus_mainloop(void)
+int dispatchInternalCommand(DBusConnection* conn, MainLoopData_u* readData, int* quit)
+{
+ int rval = 1;
+
+ //DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("mainLoop - receive cmd:"), DLT_INT(readData.message.cmd));
+ switch (readData->message.cmd)
+ {
+ case CMD_PAS_BLOCK_AND_WRITE_BACK:
+ process_block_and_write_data_back(readData->message.params[1] /*requestID*/, readData->message.params[0] /*status*/);
+ process_send_pas_request(conn, readData->message.params[1] /*request*/, readData->message.params[0] /*status*/);
+ break;
+ case CMD_LC_PREPARE_SHUTDOWN:
+ process_prepare_shutdown(Shutdown_Full);
+ process_send_lifecycle_request(conn, readData->message.params[1] /*requestID*/, readData->message.params[0] /*status*/);
+ break;
+ case CMD_SEND_NOTIFY_SIGNAL:
+ process_send_notification_signal(conn, readData->message.params[0] /*ldbid*/, readData->message.params[1], /*user*/
+ readData->message.params[2] /*seat*/, readData->message.params[3], /*reason*/
+ readData->message.string);
+ break;
+ case CMD_REG_NOTIFY_SIGNAL:
+ process_reg_notification_signal(conn, readData->message.params[0] /*ldbid*/, readData->message.params[1], /*user*/
+ readData->message.params[2] /*seat*/, readData->message.params[3], /*,policy*/
+ readData->message.string);
+ break;
+ case CMD_SEND_PAS_REGISTER:
+ process_send_pas_register(conn, readData->message.params[0] /*regType*/, readData->message.params[1] /*notifyFlag*/);
+ break;
+ case CMD_SEND_LC_REGISTER:
+ process_send_lifecycle_register(conn, readData->message.params[0] /*regType*/, readData->message.params[1] /*mode*/);
+ break;
+ case CMD_QUIT:
+ rval = 0;
+ *quit = TRUE;
+ break;
+ default:
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop - cmd not handled"), DLT_INT(readData->message.cmd) );
+ break;
+ }
+
+ return rval;
+}
+
+
+
void* mainLoop(void* userData)
{
int ret;
@@ -552,8 +588,6 @@ void* mainLoop(void* userData)
do
{
- bContinue = 0; /* assume error */
-
while(DBUS_DISPATCH_DATA_REMAINS==dbus_connection_dispatch(conn));
while ((-1==(ret=poll(gPollInfo.fds, gPollInfo.nfds, -1)))&&(EINTR==errno));
@@ -573,13 +607,11 @@ void* mainLoop(void* userData)
for (i=0; gPollInfo.nfds>i && !bQuit; ++i)
{
- /* anything to do */
- if (0!=gPollInfo.fds[i].revents)
+ if (0!=gPollInfo.fds[i].revents) // anything to do
{
if (OT_TIMEOUT==gPollInfo.objects[i].objtype)
{
- /* time-out occured */
- unsigned long long nExpCount = 0;
+ unsigned long long nExpCount = 0; // time-out occured
if ((ssize_t)sizeof(nExpCount)!=read(gPollInfo.fds[i].fd, &nExpCount, sizeof(nExpCount)))
{
@@ -595,8 +627,7 @@ void* mainLoop(void* userData)
}
else if (gPollInfo.fds[i].fd == gPipeFd[0])
{
- /* internal command */
- if (0!=(gPollInfo.fds[i].revents & POLLIN))
+ if (0!=(gPollInfo.fds[i].revents & POLLIN)) // dispatch internal command
{
MainLoopData_u readData;
bContinue = TRUE;
@@ -608,42 +639,8 @@ void* mainLoop(void* userData)
else
{
pthread_mutex_lock(&gMainCondMtx);
- //printf("--- *** --- Receive => mainloop => cmd: %d | string: %s | size: %d\n\n", readData.message.cmd, readData.message.string, ret);
- DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("mainLoop - receive cmd:"), DLT_INT(readData.message.cmd));
- switch (readData.message.cmd)
- {
- case CMD_PAS_BLOCK_AND_WRITE_BACK:
- process_block_and_write_data_back(readData.message.params[1] /*requestID*/, readData.message.params[0] /*status*/);
- process_send_pas_request(conn, readData.message.params[1] /*request*/, readData.message.params[0] /*status*/);
- break;
- case CMD_LC_PREPARE_SHUTDOWN:
- process_prepare_shutdown(Shutdown_Full);
- process_send_lifecycle_request(conn, readData.message.params[1] /*requestID*/, readData.message.params[0] /*status*/);
- break;
- case CMD_SEND_NOTIFY_SIGNAL:
- process_send_notification_signal(conn, readData.message.params[0] /*ldbid*/, readData.message.params[1], /*user*/
- readData.message.params[2] /*seat*/, readData.message.params[3], /*reason*/
- readData.message.string);
- break;
- case CMD_REG_NOTIFY_SIGNAL:
- process_reg_notification_signal(conn, readData.message.params[0] /*ldbid*/, readData.message.params[1], /*user*/
- readData.message.params[2] /*seat*/, readData.message.params[3], /*,policy*/
- readData.message.string);
- break;
- case CMD_SEND_PAS_REGISTER:
- process_send_pas_register(conn, readData.message.params[0] /*regType*/, readData.message.params[1] /*notifyFlag*/);
- break;
- case CMD_SEND_LC_REGISTER:
- process_send_lifecycle_register(conn, readData.message.params[0] /*regType*/, readData.message.params[1] /*mode*/);
- break;
- case CMD_QUIT:
- bContinue = 0;
- bQuit = TRUE;
- break;
- default:
- DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop - cmd not handled"), DLT_INT(readData.message.cmd) );
- break;
- }
+
+ bContinue = dispatchInternalCommand(conn, &readData, &bQuit);
gMainLoopCondValue = 1;
pthread_cond_signal(&gMainLoopCond);
@@ -677,10 +674,9 @@ void* mainLoop(void* userData)
}
}
}
- while (0!=bContinue);
+ while (0 != bContinue);
// do some cleanup
-
close(gPipeFd[0]);
close(gPipeFd[1]);
@@ -703,31 +699,28 @@ int deliverToMainloop(MainLoopData_u* payload)
{
int rval = 0;
- pthread_mutex_lock(&gDeliverpMtx);
-
- pthread_mutex_lock(&gMainCondMtx);
-
+ pthread_mutex_lock(&gDeliverpMtx); // make sure deliverToMainloop will be used exclusively
deliverToMainloop_NM(payload);
+
+ pthread_mutex_lock(&gMainCondMtx); // mutex needed for pthread condition used to wait on other thread (mainloop)
while(0 == gMainLoopCondValue)
pthread_cond_wait(&gMainLoopCond, &gMainCondMtx);
-
- gMainLoopCondValue = 0;
pthread_mutex_unlock(&gMainCondMtx);
+
+ gMainLoopCondValue = 0;
pthread_mutex_unlock(&gDeliverpMtx);
return rval;
}
+
+
int deliverToMainloop_NM(MainLoopData_u* payload)
{
int rval = 0, length = 128;
- //length = sizeof(payload->message) + strlen(payload->message.string) + 1; // TODO calculate the correct length of the message
-
- //printf("--- *** --- Send => deliverToMainloop_NM => %d: | String: %s | size: %d\n", payload->message.cmd, payload->message.string, length);
-
if(-1 == write(gPipeFd[1], payload->payload, length))
{
DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("toMainloop => failed write pipe"), DLT_INT(errno));
diff --git a/src/persistence_client_library_file.c b/src/persistence_client_library_file.c
index 49bb5b3..e0fcfce 100644
--- a/src/persistence_client_library_file.c
+++ b/src/persistence_client_library_file.c
@@ -87,7 +87,7 @@ int pclFileClose(int fd)
{
int permission = get_file_permission(fd);
- if(permission != -1) // permission is here also used for range check
+ if(permission != -1) // permission is here also used for range check
{
// check if a backup and checksum file needs to be deleted
if(permission != PersistencePermission_ReadOnly || permission != PersistencePermission_LastEntry)
@@ -183,7 +183,7 @@ void* pclFileMapData(void* addr, long size, long offset, int fd)
if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0)
{
- if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked
+ if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked
{
ptr = mmap(addr,size, PROT_WRITE | PROT_READ, MAP_SHARED, fd, offset);
}
@@ -284,9 +284,8 @@ int pclFileOpenRegular(PersistenceInfo_s* dbContext, const char* resource_id, ch
}
}
#endif
- //
+
// file does not exist, create it and get default data
- //
if(handle == -1 && errno == ENOENT)
{
if((handle = pclCreateFile(dbPath, cacheStatus)) == -1)
@@ -326,9 +325,8 @@ int pclFileOpenRegular(PersistenceInfo_s* dbContext, const char* resource_id, ch
}
}
}
- //
+
// requested resource is not in the RCT, so create resource as local/cached.
- //
else
{
// assemble file string for local cached location
@@ -368,8 +366,7 @@ int pclFileOpenDefaultData(PersistenceInfo_s* dbContext, const char* resource_id
char pathPrefix[DbPathMaxLen] = { [0 ... DbPathMaxLen-1] = 0};
char defaultPath[DbPathMaxLen] = { [0 ... DbPathMaxLen-1] = 0};
- // create path to default data
- if(dbContext->configKey.policy == PersistencePolicy_wc)
+ if(dbContext->configKey.policy == PersistencePolicy_wc) // create path to default data
{
snprintf(pathPrefix, DbPathMaxLen, gLocalCachePath, gAppId);
}
@@ -408,9 +405,7 @@ int pclFileOpen(unsigned int ldbid, const char* resource_id, unsigned int user_n
// get database context: database path and database key
shared_DB = get_db_context(&dbContext, resource_id, ResIsFile, dbKey, dbPath);
- //
// check if the resource is marked as a file resource
- //
if(dbContext.configKey.type == PersistenceResourceType_file)
{
if(user_no == (unsigned int)PCL_USER_DEFAULTDATA)
@@ -585,11 +580,9 @@ int pclFileWriteData(int fd, const void * buffer, int buffer_size)
{
char csumBuf[ChecksumBufSize] = {0};
- // calculate checksum
- pclCalcCrc32Csum(fd, csumBuf);
+ pclCalcCrc32Csum(fd, csumBuf); // calculate checksum
- // create checksum and backup file
- pclCreateBackup(get_file_backup_path(fd), fd, get_file_checksum_path(fd), csumBuf);
+ pclCreateBackup(get_file_backup_path(fd), fd, get_file_checksum_path(fd), csumBuf); // create checksum and backup file
set_file_backup_status(fd, 1);
}
@@ -694,10 +687,9 @@ int pclFileCreatePath(unsigned int ldbid, const char* resource_id, unsigned int
if(handle < MaxPersHandle)
{
*size = strlen(dbPath);
- *path = malloc((*size)+1); // allocate 1 byte for the string termination
+ *path = malloc((*size)+1); // allocate 1 byte for the string termination
- /* Check if malloc was successful */
- if(NULL != (*path))
+ if(NULL != (*path)) // Check if malloc was successful
{
memcpy(*path, dbPath, (*size));
(*path)[(*size)] = '\0'; // terminate string
@@ -730,7 +722,7 @@ int pclFileCreatePath(unsigned int ldbid, const char* resource_id, unsigned int
close(handle); // don't need the open file
}
}
- __sync_fetch_and_add(&gOpenHandleArray[handle], FileOpen); // set open flag
+ __sync_fetch_and_add(&gOpenHandleArray[handle], FileOpen); // set open flag
set_ossfile_handle_data(handle, dbContext.configKey.permission, 0/*backupCreated*/, backupPath, csumPath, *path);
}
@@ -748,9 +740,8 @@ int pclFileCreatePath(unsigned int ldbid, const char* resource_id, unsigned int
}
}
}
- //
+
// requested resource is not in the RCT, so create resource as local/cached.
- //
else
{
// assemble file string for local cached location
@@ -764,7 +755,7 @@ int pclFileCreatePath(unsigned int ldbid, const char* resource_id, unsigned int
snprintf(backupPath, DbPathMaxLen, "%s%s", dbPath, gBackupPostfix);
snprintf(csumPath, DbPathMaxLen, "%s%s", dbPath, gBackupCsPostfix);
- __sync_fetch_and_add(&gOpenHandleArray[handle], FileOpen); // set open flag
+ __sync_fetch_and_add(&gOpenHandleArray[handle], FileOpen); // set open flag
set_ossfile_handle_data(handle, PersistencePermission_ReadWrite, 0/*backupCreated*/, backupPath, csumPath, NULL);
}
@@ -798,7 +789,7 @@ int pclFileReleasePath(int pathHandle)
int permission = get_ossfile_permission(pathHandle);
if(permission != -1) // permission is here also used for range check
{
- // check if a backup and checksum file needs to bel deleted
+ // check if a backup and checksum file needs to be deleted
if(permission != PersistencePermission_ReadOnly)
{
// remove backup file
@@ -812,7 +803,7 @@ int pclFileReleasePath(int pathHandle)
__sync_fetch_and_sub(&gOpenHandleArray[pathHandle], FileClosed); // set closed flag
- set_persistence_handle_close_idx(pathHandle); // TODO
+ set_persistence_handle_close_idx(pathHandle);
set_ossfile_file_path(pathHandle, NULL);
rval = 1;
@@ -856,7 +847,7 @@ int pclFileGetDefaultData(int handle, const char* resource_id, int policy)
}
defaultHandle = open(defaultPath, O_RDONLY);
- if(defaultHandle != -1) // check if default data is available
+ if(defaultHandle != -1) // check if default data is available
{
// copy default data
struct stat buf;
@@ -866,7 +857,7 @@ int pclFileGetDefaultData(int handle, const char* resource_id, int policy)
rval = sendfile(handle, defaultHandle, 0, buf.st_size);
if(rval != -1)
{
- rval = lseek(handle, 0, SEEK_SET); // set fd back to beginning of the file
+ rval = lseek(handle, 0, SEEK_SET); // set fd back to beginning of the file
}
else
{
diff --git a/src/persistence_client_library_key.c b/src/persistence_client_library_key.c
index 2a67839..18eff50 100644
--- a/src/persistence_client_library_key.c
+++ b/src/persistence_client_library_key.c
@@ -322,8 +322,8 @@ int pclKeyDelete(unsigned int ldbid, const char* resource_id, unsigned int user_
{
PersistenceInfo_s dbContext;
- char dbKey[DbKeyMaxLen] = {0}; // database key
- char dbPath[DbPathMaxLen] = {0}; // database location
+ char dbKey[DbKeyMaxLen] = {0}; // database key
+ char dbPath[DbPathMaxLen] = {0}; // database location
dbContext.context.ldbid = ldbid;
dbContext.context.seat_no = seat_no;
@@ -332,9 +332,9 @@ int pclKeyDelete(unsigned int ldbid, const char* resource_id, unsigned int user_
// get database context: database path and database key
rval = get_db_context(&dbContext, resource_id, ResIsNoFile, dbKey, dbPath);
if( (rval >= 0)
- && (dbContext.configKey.type == PersistenceResourceType_key) ) // check if type is matching
+ && (dbContext.configKey.type == PersistenceResourceType_key) ) // check if type is matching
{
- if( dbContext.configKey.storage < PersistenceStorage_LastEntry) // check if store policy is valid
+ if( dbContext.configKey.storage < PersistenceStorage_LastEntry) // check if store policy is valid
{
rval = persistence_delete_data(dbPath, dbKey, resource_id, &dbContext);
}
@@ -360,7 +360,6 @@ int pclKeyDelete(unsigned int ldbid, const char* resource_id, unsigned int user_
-// status: OK
int pclKeyGetSize(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no)
{
int data_size = EPERS_NOT_INITIALIZED;
@@ -371,8 +370,8 @@ int pclKeyGetSize(unsigned int ldbid, const char* resource_id, unsigned int user
{
PersistenceInfo_s dbContext;
- char dbKey[DbKeyMaxLen] = {0}; // database key
- char dbPath[DbPathMaxLen] = {0}; // database location
+ char dbKey[DbKeyMaxLen] = {0}; // database key
+ char dbPath[DbPathMaxLen] = {0}; // database location
dbContext.context.ldbid = ldbid;
dbContext.context.seat_no = seat_no;
@@ -381,9 +380,9 @@ int pclKeyGetSize(unsigned int ldbid, const char* resource_id, unsigned int user
// get database context: database path and database key
data_size = get_db_context(&dbContext, resource_id, ResIsNoFile, dbKey, dbPath);
if( (data_size >= 0)
- && (dbContext.configKey.type == PersistenceResourceType_key) ) // check if type matches
+ && (dbContext.configKey.type == PersistenceResourceType_key) ) // check if type matches
{
- if( dbContext.configKey.storage < PersistenceStorage_LastEntry) // check if store policy is valid
+ if( dbContext.configKey.storage < PersistenceStorage_LastEntry) // check if store policy is valid
{
data_size = persistence_get_data_size(dbPath, dbKey, resource_id, &dbContext);
}
@@ -408,7 +407,6 @@ int pclKeyGetSize(unsigned int ldbid, const char* resource_id, unsigned int user
-// status: OK
int pclKeyReadData(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no,
unsigned char* buffer, int buffer_size)
{
@@ -422,8 +420,8 @@ int pclKeyReadData(unsigned int ldbid, const char* resource_id, unsigned int use
{
PersistenceInfo_s dbContext;
- char dbKey[DbKeyMaxLen] = {0}; // database key
- char dbPath[DbPathMaxLen] = {0}; // database location
+ char dbKey[DbKeyMaxLen] = {0}; // database key
+ char dbPath[DbPathMaxLen] = {0}; // database location
dbContext.context.ldbid = ldbid;
dbContext.context.seat_no = seat_no;
@@ -480,8 +478,8 @@ int pclKeyWriteData(unsigned int ldbid, const char* resource_id, unsigned int us
{
PersistenceInfo_s dbContext;
- char dbKey[DbKeyMaxLen] = {0}; // database key
- char dbPath[DbPathMaxLen] = {0}; // database location
+ char dbKey[DbKeyMaxLen] = {0}; // database key
+ char dbPath[DbPathMaxLen] = {0}; // database location
dbContext.context.ldbid = ldbid;
dbContext.context.seat_no = seat_no;
@@ -492,10 +490,10 @@ int pclKeyWriteData(unsigned int ldbid, const char* resource_id, unsigned int us
if( (data_size >= 0)
&& (dbContext.configKey.type == PersistenceResourceType_key))
{
- if(dbContext.configKey.permission != PersistencePermission_ReadOnly) // don't write to a read only resource
+ if(dbContext.configKey.permission != PersistencePermission_ReadOnly) // don't write to a read only resource
{
// store data
- if(dbContext.configKey.storage < PersistenceStorage_LastEntry) // check if store policy is valid
+ if(dbContext.configKey.storage < PersistenceStorage_LastEntry) // check if store policy is valid
{
if( (dbContext.configKey.storage == PersistenceStorage_shared)
&& (0 != strncmp(dbContext.configKey.reponsible, gAppId, MaxAppNameLen) ) )
@@ -549,6 +547,7 @@ int pclKeyUnRegisterNotifyOnChange( unsigned int ldbid, const char * resource_
}
+
int pclKeyRegisterNotifyOnChange(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no, pclChangeNotifyCallback_t callback)
{
int rval = EPERS_COMMON;
@@ -568,7 +567,6 @@ int pclKeyRegisterNotifyOnChange(unsigned int ldbid, const char* resource_id, un
-
int regNotifyOnChange(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no, pclChangeNotifyCallback_t callback, PersNotifyRegPolicy_e regPolicy)
{
int rval = EPERS_NOT_INITIALIZED;
@@ -620,10 +618,3 @@ int regNotifyOnChange(unsigned int ldbid, const char* resource_id, unsigned int
return rval;
}
-
-
-
-
-
-
-
diff --git a/src/persistence_client_library_lc_interface.c b/src/persistence_client_library_lc_interface.c
index 651c736..766b3cf 100644
--- a/src/persistence_client_library_lc_interface.c
+++ b/src/persistence_client_library_lc_interface.c
@@ -36,6 +36,7 @@
#include <dlfcn.h>
+
int check_lc_request(unsigned int request, unsigned int requestID)
{
int rval = 0;
diff --git a/src/persistence_client_library_lc_interface.h b/src/persistence_client_library_lc_interface.h
index a0aea3d..0ce5572 100644
--- a/src/persistence_client_library_lc_interface.h
+++ b/src/persistence_client_library_lc_interface.h
@@ -54,5 +54,4 @@ int register_lifecycle(int shutdownMode);
int unregister_lifecycle(int shutdownMode);
-
#endif /* PERSISTENCE_CLIENT_LIBRARY_LC_INTERFACE_H */
diff --git a/src/persistence_client_library_pas_interface.c b/src/persistence_client_library_pas_interface.c
index de197c4..2dc4276 100644
--- a/src/persistence_client_library_pas_interface.c
+++ b/src/persistence_client_library_pas_interface.c
@@ -29,23 +29,27 @@
/// flag if access is locked
static int gLockAccess = 0;
+
void pers_lock_access(void)
{
gLockAccess = 0;
__sync_fetch_and_add(&gLockAccess,1);
}
+
void pers_unlock_access(void)
{
__sync_fetch_and_sub(&gLockAccess,1);
}
+
int isAccessLocked(void)
{
return gLockAccess;
}
+
int check_pas_request(unsigned int request, unsigned int requestID)
{
int rval = 0;
@@ -91,8 +95,6 @@ int check_pas_request(unsigned int request, unsigned int requestID)
-
-
DBusHandlerResult msg_persAdminRequest(DBusConnection *connection, DBusMessage *message)
{
int request = 0, requestID = 0;
@@ -102,7 +104,6 @@ DBusHandlerResult msg_persAdminRequest(DBusConnection *connection, DBusMessage *
DBusError error;
dbus_error_init (&error);
-
if (!dbus_message_get_args(message, &error, DBUS_TYPE_INT32 , &request,
DBUS_TYPE_INT32 , &requestID,
DBUS_TYPE_INVALID))
@@ -125,7 +126,6 @@ DBusHandlerResult msg_persAdminRequest(DBusConnection *connection, DBusMessage *
}
errorReturn = check_pas_request(request, requestID);
-
reply = dbus_message_new_method_return(message);
if (reply == 0)
@@ -150,6 +150,7 @@ DBusHandlerResult msg_persAdminRequest(DBusConnection *connection, DBusMessage *
}
+
int signal_persModeChange(DBusConnection *connection, DBusMessage *message)
{
int persistenceMode = 0;
@@ -203,6 +204,7 @@ int signal_persModeChange(DBusConnection *connection, DBusMessage *message)
}
+
DBusHandlerResult checkPersAdminMsg(DBusConnection * connection, DBusMessage * message, void * user_data)
{
DBusHandlerResult result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
@@ -231,7 +233,6 @@ DBusHandlerResult checkPersAdminMsg(DBusConnection * connection, DBusMessage * m
-
int register_pers_admin_service(void)
{
int rval = 0;
@@ -280,5 +281,3 @@ int unregister_pers_admin_service(void)
}
return rval;
}
-
-
diff --git a/src/persistence_client_library_pas_interface.h b/src/persistence_client_library_pas_interface.h
index b865058..6241248 100644
--- a/src/persistence_client_library_pas_interface.h
+++ b/src/persistence_client_library_pas_interface.h
@@ -79,5 +79,4 @@ int register_pers_admin_service(void);
int unregister_pers_admin_service(void);
-
#endif /* PERSISTENCE_CLIENT_LIBRARY_PAS_INTERFACE_H */
diff --git a/src/persistence_client_library_prct_access.c b/src/persistence_client_library_prct_access.c
index e169fa6..85750f0 100644
--- a/src/persistence_client_library_prct_access.c
+++ b/src/persistence_client_library_prct_access.c
@@ -17,8 +17,6 @@
* @see
*/
-
-
#include "persistence_client_library_prct_access.h"
#include "persistence_client_library_db_access.h"
#include "persistence_client_library_custom_loader.h"
@@ -140,7 +138,7 @@ int get_resource_cfg_table(PersistenceRCT_e rct, int group)
}
-// status: OK
+
int get_db_context(PersistenceInfo_s* dbContext, const char* resource_id, unsigned int isFile, char dbKey[], char dbPath[])
{
int rval = 0, resourceFound = 0, groupId = 0;
@@ -149,8 +147,7 @@ int get_db_context(PersistenceInfo_s* dbContext, const char* resource_id, unsign
rct = get_table_id(dbContext->context.ldbid, &groupId);
- // get resource configuration table
- int handleRCT = get_resource_cfg_table(rct, groupId);
+ int handleRCT = get_resource_cfg_table(rct, groupId); // get resource configuration table
if(handleRCT >= 0)
{
@@ -171,8 +168,7 @@ int get_db_context(PersistenceInfo_s* dbContext, const char* resource_id, unsign
// if customer storage, we use the custom name as dbPath
strncpy(dbPath, dbContext->configKey.custom_name, strlen(dbContext->configKey.custom_name));
- // and resource_id as dbKey
- strncpy(dbKey, resource_id, strlen(resource_id));
+ strncpy(dbKey, resource_id, strlen(resource_id)); // and resource_id as dbKey
}
resourceFound = 1;
}
@@ -190,9 +186,7 @@ int get_db_context(PersistenceInfo_s* dbContext, const char* resource_id, unsign
if((resourceFound == 0) && (dbContext->context.ldbid == PCL_LDBID_LOCAL) ) // create only when the resource is local data
{
- //
// resource NOT found in resource table ==> default is local cached key
- //
dbContext->configKey.policy = PersistencePolicy_wc;
dbContext->configKey.storage = PersistenceStorage_local;
dbContext->configKey.permission = PersistencePermission_ReadWrite;
@@ -230,24 +224,18 @@ int get_db_path_and_key(PersistenceInfo_s* dbContext, const char* resource_id, c
{
int storePolicy = PersistenceStorage_LastEntry;
- //
// create resource database key
- //
if(((dbContext->context.ldbid < 0x80) || (dbContext->context.ldbid == PCL_LDBID_LOCAL)) && (NULL != dbKey))
{
// The LDBID is used to find the DBID in the resource table.
if((dbContext->context.user_no == 0) && (dbContext->context.seat_no == 0))
{
- //
// Node is added in front of the resource ID as the key string.
- //
snprintf(dbKey, DbKeyMaxLen, "%s/%s", plugin_gNode, resource_id);
}
else
{
- //
// Node is added in front of the resource ID as the key string.
- //
if(dbContext->context.seat_no == 0)
{
// /User/<user_no_parameter> is added in front of the resource ID as the key string.
@@ -269,7 +257,6 @@ int get_db_path_and_key(PersistenceInfo_s* dbContext, const char* resource_id, c
// 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(dbContext->context.seat_no != 0)
{
snprintf(dbKey, DbKeyMaxLen, "/%x%s%d%s%d/%s", dbContext->context.ldbid, plugin_gUser, dbContext->context.user_no, plugin_gSeat, dbContext->context.seat_no, resource_id);
@@ -281,9 +268,7 @@ int get_db_path_and_key(PersistenceInfo_s* dbContext, const char* resource_id, c
storePolicy = PersistenceStorage_local;
}
- //
// create resource database path
- //
if(dbContext->context.ldbid < 0x80)
{
// S H A R E D database
@@ -293,7 +278,6 @@ int get_db_path_and_key(PersistenceInfo_s* dbContext, const char* resource_id, c
// 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 == dbContext->configKey.policy)
{
if(dbContext->configKey.type == PersistenceResourceType_key)
@@ -314,7 +298,6 @@ int get_db_path_and_key(PersistenceInfo_s* dbContext, const char* resource_id, c
// 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 == dbContext->configKey.policy)
{
if(dbContext->configKey.type == PersistenceResourceType_key)
@@ -330,7 +313,6 @@ int get_db_path_and_key(PersistenceInfo_s* dbContext, const char* resource_id, c
snprintf(dbPath, DbPathMaxLen, gSharedPublicWtPathKey, gAppId, dbKey);
}
}
-
storePolicy = PersistenceStorage_shared; // we have a shared database
}
else
@@ -359,9 +341,3 @@ int get_db_path_and_key(PersistenceInfo_s* dbContext, const char* resource_id, c
return storePolicy;
}
-
-
-
-
-
-