int customAsyncInitClbk(int errcode)
{
printf("Dummy async init Callback\n");
+
+ return 1;
}
int pclInitLibrary(const char* appName, int shutdownMode)
{
- int i = 0, rval = 1;
-
- printf("INIT START\n\n");
+ int rval = 1;
if(gPclInitialized == PCLnotInitialized)
{
- printf("INIT START ==> DO INIT\n\n");
gShutdownMode = shutdownMode;
DLT_REGISTER_CONTEXT(gPclDLTContext,"PCL","Context for persistence client library logging");
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("PAS interface is not enabled, enable with \"./configure --enable-pasinterface\""));
#endif
-
- /// get custom library names to load
- if(get_custom_libraries() >= 0)
- {
- // initialize custom library structure
- for(i = 0; i < PersCustomLib_LastEntry; i++)
- {
- invalidate_custom_plugin(i);
- }
-
- for(i=0; i < PersCustomLib_LastEntry; i++ )
- {
- if(check_valid_idx(i) != -1)
- {
- if(getCustomLoadingType(i) == LoadType_PclInit) // check if the plugin must be loaded on plc init
- {
- if(load_custom_library(i, &gPersCustomFuncs[i] ) == 1)
- {
- PersInitType_e initType = getCustomInitType(i);
- if(initType == Init_Synchronous)
- {
- if( (gPersCustomFuncs[i].custom_plugin_init) != NULL)
- {
- DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclInitLibrary => plugin: "), DLT_STRING(get_custom_client_lib_name(i)));
- gPersCustomFuncs[i].custom_plugin_init();
- }
- else
- {
- DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclInitLibrary => E r r o r could not load plugin functions: "),
- DLT_STRING(get_custom_client_lib_name(i)));
- }
- }
- else if(initType == Init_Asynchronous)
- {
- if( (gPersCustomFuncs[i].custom_plugin_init_async) != NULL)
- {
- DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclInitLibrary => plugin: "), DLT_STRING(get_custom_client_lib_name(i)));
- gPersCustomFuncs[i].custom_plugin_init_async(customAsyncInitClbk);
- }
- else
- {
- DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclInitLibrary => E r r o r could not load plugin functions: "),
- DLT_STRING(get_custom_client_lib_name(i)));
- }
- }
- else
- {
- DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclInitLibrary => E r r o r unknown init type "), DLT_STRING(get_custom_client_lib_name(i)));
- }
- }
- else
- {
- DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclInitLibrary => E r r o r could not load plugin: "),
- DLT_STRING(get_custom_client_lib_name(i)));
- }
- }
- }
- else
- {
- continue;
- }
- }
- }
- else
+ // load custom plugins
+ if(load_custom_plugins(customAsyncInitClbk) < 0)
{
- DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclInit => Failed to load custom library config table"));
+ DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("Failed to load custom plugins"));
}
// initialize keyHandle array
char* gpConfigFileMap = 0;
-char* gpTokenArray[TOKENARRAYSIZE] = {0};
+static char* gpTokenArray[TOKENARRAYSIZE] = {0};
int gTokenCounter = 0;
unsigned int gConfigFileSize = 0;
static PersCustomLibInfo gCustomLibArray[PersCustomLib_LastEntry];
char* gpCustomConfigFileMap = 0;
-char* gpCustomTokenArray[TOKENARRAYSIZE];
+static char* gpCustomTokenArray[TOKENARRAYSIZE];
int gCustomTokenCounter = 0;
unsigned int gCustomConfigFileSize = 0;
-
+int(* gPlugin_callback_async_t)(int errcode);
void fillCustomCharTokenArray()
{
DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("load config file error ==> Error file open: "),
DLT_STRING(filename), DLT_STRING("err msg: "), DLT_STRING(strerror(errno)) );
- return -1;
+ return EPERS_COMMON;
}
// check for empty file
gpCustomConfigFileMap = 0;
close(fd);
DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("load config file error ==> Error mapping the file"));
- return -1;
+ return EPERS_COMMON;
}
// reset the token counter
{
DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("load config file error ==> Error file size is 0"));
close(fd);
- rval = -1;
+ rval = EPERS_COMMON;
}
return rval;
if(customLib < PersCustomLib_LastEntry)
{
+ PersInitType_e initType = getCustomInitType(customLib);
void* handle = dlopen(gCustomLibArray[customLib].libname, RTLD_LAZY);
customFuncts->handle = handle;
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("load_custom_library - error:"), DLT_STRING(error));
}
+
+ //
+ // initialize the library
+ //
+ if(initType == Init_Synchronous)
+ {
+ if( (gPersCustomFuncs[customLib].custom_plugin_init) != NULL)
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("load_custom_library => (sync) : "), DLT_STRING(get_custom_client_lib_name(customLib)));
+ gPersCustomFuncs[customLib].custom_plugin_init();
+ }
+ else
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_library - error: could not load plugin functions: "),
+ DLT_STRING(get_custom_client_lib_name(customLib)));
+ rval = EPERS_COMMON;
+ }
+ }
+ else if(initType == Init_Asynchronous)
+ {
+ if( (gPersCustomFuncs[customLib].custom_plugin_init_async) != NULL)
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("load_custom_library => (async) : "),
+ DLT_STRING(get_custom_client_lib_name(customLib)));
+
+ gPersCustomFuncs[customLib].custom_plugin_init_async(gPlugin_callback_async_t);
+ }
+ else
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_library => error: could not load plugin functions: "),
+ DLT_STRING(get_custom_client_lib_name(customLib)));
+ rval = EPERS_COMMON;
+ }
+ }
+ else
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_library - error: unknown init type "),
+ DLT_STRING(get_custom_client_lib_name(customLib)));
+ rval = EPERS_COMMON;
+ }
}
else
{
}
+int load_custom_plugins(plugin_callback_async_t pfInitCompletedCB)
+{
+ int rval = 0, i = 0;
+
+ /// get custom library names to load
+ if(get_custom_libraries() >= 0)
+ {
+ gPlugin_callback_async_t = pfInitCompletedCB; // assign init callback
+
+ // initialize custom library structure
+ for(i = 0; i < PersCustomLib_LastEntry; i++)
+ {
+ invalidate_custom_plugin(i);
+ }
+
+ for(i=0; i < PersCustomLib_LastEntry; i++ )
+ {
+ if(check_valid_idx(i) != -1)
+ {
+ if(getCustomLoadingType(i) == LoadType_PclInit) // check if the plugin must be loaded on plc init
+ {
+ if(load_custom_library(i, &gPersCustomFuncs[i] ) <= 0)
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_plugins => E r r o r could not load plugin: "),
+ DLT_STRING(get_custom_client_lib_name(i)));
+ rval = EPERS_COMMON;
+ }
+ }
+ }
+ else
+ {
+ continue;
+ }
+ }
+ }
+ else
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclInit => Failed to load custom library config table"));
+ rval = EPERS_COMMON;
+ }
+
+ return rval;
+}
+
void invalidate_custom_plugin(int idx)
{
/// enumerator fo custom library defines
enum _PersCustomLibDefines_e
{
- PersCustomPathSize = 12
+ PersCustomPathSize = 12 /// the custom library path size
} PersCustomLibDefines_e;
/// indicates the init method type
typedef enum PersInitType_e_
{
- Init_Synchronous = 0,
- Init_Asynchronous = 1,
+ Init_Synchronous = 0, /// initialize the plugin with the synchronous init function
+ Init_Asynchronous = 1, /// initialize the plugin with the asynchronous init function
Init_Undefined
} PersInitType_e;
/// indicates the plugin loading type
typedef enum PersLoadingType_e_
{
- LoadType_PclInit = 0, // load plugin during pclInitLibrary function
- LoadType_OnDemand = 1, // load the pluing on demand, when a plugin function will be requested the first time.
+ LoadType_PclInit = 0, /// load plugin during pclInitLibrary function
+ LoadType_OnDemand = 1, /// load the pluing on demand, when a plugin function will be requested the first time.
LoadType_Undefined
} PersLoadingType_e;
+/**
+ * @brief definition of async init callback function.
+ * This function will be called when the asynchronous
+ * init function (custom_plugin_init_async) has finished
+ *
+ * @param error the error code occured while calling init
+ */
+extern int(* gPlugin_callback_async_t)(int errcode);
/// structure definition for custom library functions
typedef struct _Pers_custom_functs_s
*
* @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);
/**
* @brief invalidate customer plugin function
+ *
+ * @param idx the plugin index
*/
void invalidate_custom_plugin(int idx);
+/**
+ * @brief load the custom plugins.
+ * The custom library configuration file will be loaded to see
+ * if there a re plugins that must be loaded in the pclInitLibrary function.
+ * The other plugins will be loaded on demand.
+ *
+ *
+ * @param pfInitCompletedCB the callback function to be called when
+ * a plugin with asyncnonous init function will be laoded
+ */
+int load_custom_plugins(plugin_callback_async_t pfInitCompletedCB);
+
+/**
+ * @brief Get the custom loading type.
+ * The loading type is
+ * ::LoadType_PclInit or ::LoadType_OnDemand
+ *
+ * @param i the custom id, see ::PersistenceCustomLibs_e
+ */
PersLoadingType_e getCustomLoadingType(int i);
+
+/**
+ * @brief Get the custom init type.
+ * The init type is
+ * ::Init_Synchronous or ::Init_Asynchronous
+ *
+ * @param i the custom id, see ::PersistenceCustomLibs_e
+ */
PersInitType_e getCustomInitType(int i);
+
#endif /* PERSISTENCE_CLIENT_LIBRARY_CUSTOM_LOADER_H */
int read_size = EPERS_NOKEY;
char dltMessage[DbPathMaxLen] = {0};
- key = pers_get_raw_key(key); /* We need only the raw key without a prefixed '/node/' or '/user/1/seat/0' etc... */
+ // key = pers_get_raw_key(key); /* We need only the raw key without a prefixed '/node/' or '/user/1/seat/0' etc... */
for(i=0; i<PersDefaultType_LastEntry; i++)
{
-int persistence_get_data(char* dbPath, char* key, PersistenceInfo_s* info, unsigned char* buffer, unsigned int buffer_size)
+int persistence_get_data(char* dbPath, char* key, const char* resourceID, PersistenceInfo_s* info, unsigned char* buffer, unsigned int buffer_size)
{
int read_size = -1;
int ret_defaults = -1;
int handleDB = database_get(info, dbPath);
if(handleDB >= 0)
{
- read_size = persComDbReadKey(handleDB, key, (char*)buffer, buffer_size) ;
+ read_size = persComDbReadKey(handleDB, key, (char*)buffer, buffer_size);
if(read_size < 0)
{
- read_size = pers_get_defaults(dbPath, key, buffer, buffer_size, PersGetDefault_Data); /* 0 ==> Get data */
+ read_size = pers_get_defaults(dbPath, (char*)resourceID, buffer, buffer_size, PersGetDefault_Data); /* 0 ==> Get data */
}
}
}
char workaroundPath[128]; // workaround, because /sys/ can not be accessed on host!!!!
snprintf(workaroundPath, 128, "%s%s", "/Data", dbPath );
- if( (idx < PersCustomLib_LastEntry) && (gPersCustomFuncs[idx].custom_plugin_get_data != NULL) )
+ if(idx < PersCustomLib_LastEntry)
{
- char pathKeyString[128] = {0};
- if(info->configKey.customID[0] == '\0') // if we have not a customID we use the key
- {
- snprintf(pathKeyString, 128, "0x%08X/%s/%s", info->context.ldbid, info->configKey.custom_name, key);
- }
- else
- {
- snprintf(pathKeyString, 128, "0x%08X/%s", info->context.ldbid, info->configKey.customID);
- }
- read_size = gPersCustomFuncs[idx].custom_plugin_get_data(pathKeyString, (char*)buffer, buffer_size);
+ int available = 0;
+ if(gPersCustomFuncs[idx].custom_plugin_get_size == NULL )
+ {
+ if(getCustomLoadingType(idx) == LoadType_OnDemand)
+ {
+ // plugin not loaded, try to load the requested plugin
+ if(load_custom_library(idx, &gPersCustomFuncs[idx]) == 1)
+ {
+ // check again if the plugin function is now available
+ if(gPersCustomFuncs[idx].custom_plugin_get_data != NULL)
+ {
+ available = 1;
+ }
+ }
+ }
+ else if(getCustomLoadingType(idx) == LoadType_PclInit)
+ {
+ if(gPersCustomFuncs[idx].custom_plugin_get_data != NULL)
+ {
+ available = 1;
+ }
+ }
+ else
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("Plugin not available (getData), unknown loading type: "),
+ DLT_INT(getCustomLoadingType(idx)));
+ read_size = EPERS_COMMON;
+ }
+ }
+ else
+ {
+ available = 1; // already loaded
+ }
+
+ if(available == 1)
+ {
+ char pathKeyString[128] = {0};
+ if(info->configKey.customID[0] == '\0') // if we have not a customID we use the key
+ {
+ snprintf(pathKeyString, 128, "0x%08X/%s/%s", info->context.ldbid, info->configKey.custom_name, key);
+ }
+ else
+ {
+ snprintf(pathKeyString, 128, "0x%08X/%s", info->context.ldbid, info->configKey.customID);
+ }
+ read_size = gPersCustomFuncs[idx].custom_plugin_get_data(pathKeyString, (char*)buffer, buffer_size);
+ }
+ else
+ {
+ read_size = EPERS_NOPLUGINFUNCT;
+ }
}
else
{
}
else if(PersistenceStorage_custom == info->configKey.storage) // custom storage implementation via custom library
{
+ int available = 0;
int idx = custom_client_name_to_id(dbPath, 1);
- if((idx < PersCustomLib_LastEntry) && (gPersCustomFuncs[idx].custom_plugin_set_data != NULL) )
+ if(idx < PersCustomLib_LastEntry )
{
- char pathKeyString[128] = {0};
- if(info->configKey.customID[0] == '\0') // if we have not a customID we use the key
- {
- snprintf(pathKeyString, 128, "0x%08X/%s/%s", info->context.ldbid, info->configKey.custom_name, key);
- }
- else
- {
- snprintf(pathKeyString, 128, "0x%08X/%s", info->context.ldbid, info->configKey.customID);
- }
- write_size = gPersCustomFuncs[idx].custom_plugin_set_data(pathKeyString, (char*)buffer, buffer_size);
-
- if ((0 < write_size) && ((unsigned int)write_size == buffer_size)) /* Check return value and send notification if OK */
- {
- int rval = pers_send_Notification_Signal(key, &info->context, pclNotifyStatus_changed);
- if(rval <= 0)
- {
- DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("persistence_set_data ==> failed to send notification signal"));
- write_size = rval;
- }
- }
+ if(gPersCustomFuncs[idx].custom_plugin_set_data != NULL)
+ {
+
+ if (getCustomLoadingType(idx) == LoadType_OnDemand)
+ {
+ // plugin not loaded, try to load the requested plugin
+ if(load_custom_library(idx, &gPersCustomFuncs[idx]) == 1)
+ {
+ // check again if the plugin function is now available
+ if(gPersCustomFuncs[idx].custom_plugin_set_data != NULL)
+ {
+ available = 1;
+ }
+ }
+ }
+ else if(getCustomLoadingType(idx) == LoadType_PclInit)
+ {
+ if(gPersCustomFuncs[idx].custom_plugin_set_data != NULL)
+ {
+ available = 1;
+ }
+ }
+ else
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("Plugin not available (setData), unknown loading type: "),
+ DLT_INT(getCustomLoadingType(idx)));
+ write_size = EPERS_COMMON;
+ }
+ }
+ else
+ {
+ available = 1; // already loaded
+ }
+
+ if(available == 1)
+ {
+ char pathKeyString[128] = {0};
+ if(info->configKey.customID[0] == '\0') // if we have not a customID we use the key
+ {
+ snprintf(pathKeyString, 128, "0x%08X/%s/%s", info->context.ldbid, info->configKey.custom_name, key);
+ }
+ else
+ {
+ snprintf(pathKeyString, 128, "0x%08X/%s", info->context.ldbid, info->configKey.customID);
+ }
+ write_size = gPersCustomFuncs[idx].custom_plugin_set_data(pathKeyString, (char*)buffer, buffer_size);
+
+ if ((0 < write_size) && ((unsigned int)write_size == buffer_size)) /* Check return value and send notification if OK */
+ {
+ int rval = pers_send_Notification_Signal(key, &info->context, pclNotifyStatus_changed);
+ if(rval <= 0)
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("persistence_set_data ==> failed to send notification signal"));
+ write_size = rval;
+ }
+ }
+ }
+ else
+ {
+ write_size = EPERS_NOPLUGINFUNCT;
+ }
}
else
{
}
else if(PersistenceStorage_custom == info->configKey.storage) // custom storage implementation via custom library
{
+ int available = 0;
int idx = custom_client_name_to_id(dbPath, 1);
- if((idx < PersCustomLib_LastEntry) && (gPersCustomFuncs[idx].custom_plugin_get_size != NULL) )
+ if(idx < PersCustomLib_LastEntry )
{
- char pathKeyString[128] = {0};
- if(info->configKey.customID[0] == '\0') // if we have not a customID we use the key
- {
- snprintf(pathKeyString, 128, "0x%08X/%s/%s", info->context.ldbid, info->configKey.custom_name, key);
- }
- else
- {
- snprintf(pathKeyString, 128, "0x%08X/%s", info->context.ldbid, info->configKey.customID);
- }
- read_size = gPersCustomFuncs[idx].custom_plugin_get_size(pathKeyString);
+ if(gPersCustomFuncs[idx].custom_plugin_get_size == NULL )
+ {
+ if (getCustomLoadingType(idx) == LoadType_OnDemand)
+ {
+ // plugin not loaded, try to load the requested plugin
+ if(load_custom_library(idx, &gPersCustomFuncs[idx]) == 1)
+ {
+ // check again if the plugin function is now available
+ if(gPersCustomFuncs[idx].custom_plugin_get_size != NULL)
+ {
+ available = 1;
+ }
+ }
+ }
+ else if(getCustomLoadingType(idx) == LoadType_PclInit)
+ {
+ if(gPersCustomFuncs[idx].custom_plugin_get_size != NULL)
+ {
+ available = 1;
+ }
+ }
+ else
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("Plugin not available (getDataSize), unknown loading type: "),
+ DLT_INT(getCustomLoadingType(idx)));
+ read_size = EPERS_COMMON;
+ }
+ }
+ else
+ {
+ available = 1; // already loaded
+ }
+
+ if(available == 1)
+ {
+ char pathKeyString[128] = {0};
+ if(info->configKey.customID[0] == '\0') // if we have not a customID we use the key
+ {
+ snprintf(pathKeyString, 128, "0x%08X/%s/%s", info->context.ldbid, info->configKey.custom_name, key);
+ }
+ else
+ {
+ snprintf(pathKeyString, 128, "0x%08X/%s", info->context.ldbid, info->configKey.customID);
+ }
+ read_size = gPersCustomFuncs[idx].custom_plugin_get_size(pathKeyString);
+ }
+ else
+ {
+ read_size = EPERS_NOPLUGINFUNCT;
+ }
}
else
{
}
else // custom storage implementation via custom library
{
+ int available = 0;
int idx = custom_client_name_to_id(dbPath, 1);
- if((idx < PersCustomLib_LastEntry) && (gPersCustomFuncs[idx].custom_plugin_delete_data != NULL) )
+ if(idx < PersCustomLib_LastEntry)
{
- char pathKeyString[128] = {0};
- if(info->configKey.customID[0] == '\0') // if we have not a customID we use the key
- {
- snprintf(pathKeyString, 128, "0x%08X/%s/%s", info->context.ldbid, info->configKey.custom_name, key);
- }
- else
- {
- snprintf(pathKeyString, 128, "0x%08X/%s", info->context.ldbid, info->configKey.customID);
- }
- ret = gPersCustomFuncs[idx].custom_plugin_delete_data(pathKeyString);
-
- if(0 <= ret) /* Check return value and send notification if OK */
- {
- pers_send_Notification_Signal(key, &info->context, pclNotifyStatus_deleted);
- }
+ if(gPersCustomFuncs[idx].custom_plugin_get_size == NULL )
+ {
+ if (getCustomLoadingType(idx) == LoadType_OnDemand)
+ {
+ // plugin not loaded, try to load the requested plugin
+ if(load_custom_library(idx, &gPersCustomFuncs[idx]) == 1)
+ {
+ // check again if the plugin function is now available
+ if(gPersCustomFuncs[idx].custom_plugin_delete_data != NULL)
+ {
+ available = 1;
+ }
+ }
+ }
+ else if(getCustomLoadingType(idx) == LoadType_PclInit)
+ {
+ if(gPersCustomFuncs[idx].custom_plugin_delete_data != NULL)
+ {
+ available = 1;
+ }
+ }
+ else
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("Plugin not available (deleteData), unknown loading type: "),
+ DLT_INT(getCustomLoadingType(idx)));
+ ret = EPERS_COMMON;
+ }
+ }
+ else
+ {
+ available = 1; // already loaded
+ }
+
+ if(available == 1)
+ {
+ char pathKeyString[128] = {0};
+ if(info->configKey.customID[0] == '\0') // if we have not a customID we use the key
+ {
+ snprintf(pathKeyString, 128, "0x%08X/%s/%s", info->context.ldbid, info->configKey.custom_name, key);
+ }
+ else
+ {
+ snprintf(pathKeyString, 128, "0x%08X/%s", info->context.ldbid, info->configKey.customID);
+ }
+ ret = gPersCustomFuncs[idx].custom_plugin_delete_data(pathKeyString);
+
+ if(0 <= ret) /* Check return value and send notification if OK */
+ {
+ pers_send_Notification_Signal(key, &info->context, pclNotifyStatus_deleted);
+ }
+ }
+ else
+ {
+ ret = EPERS_NOPLUGINFUNCT;
+ }
}
else
{
extern "C" {
#endif
-#define PERSIST_DATA_ACCESS_INTERFACE_VERSION (0x04020000U)
+#define PERSIST_DATA_ACCESS_INTERFACE_VERSION (0x05000000U)
#include "persistence_client_library_data_organization.h"
* @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, PersistenceInfo_s* info, unsigned char* buffer, unsigned int buffer_size);
+int persistence_get_data(char* dbPath, char* key, const char* resourceID, PersistenceInfo_s* info, unsigned char* buffer, unsigned int buffer_size);
#include <fcntl.h> // for open flags
#include <errno.h>
#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
-#include <unistd.h>
-#include <stdlib.h>
-
-
+#include <sys/sendfile.h>
// local function prototype
int pclFileGetDefaultData(int handle, const char* resource_id, int policy);
{
rval = -1; // no default data available
}
+
+ return rval;
}// getDefault
if ('\0' != gKeyHandleArray[key_handle].resource_id[0])
{
/* Invalidate key handle data */
- set_persistence_handle_close_idx(key_handle);
+ set_persistence_handle_close_idx(key_handle);
memset(&gKeyHandleArray[key_handle], 0, sizeof(gKeyHandleArray[key_handle]));
rval = 1;
}
if ('\0' != gKeyHandleArray[key_handle].resource_id[0])
{
size = pclKeyGetSize(gKeyHandleArray[key_handle].ldbid,
- gKeyHandleArray[key_handle].resource_id,
- gKeyHandleArray[key_handle].user_no,
- gKeyHandleArray[key_handle].seat_no);
+ gKeyHandleArray[key_handle].resource_id,
+ gKeyHandleArray[key_handle].user_no,
+ gKeyHandleArray[key_handle].seat_no);
}
else
{
if( dbContext.configKey.storage < PersistenceStorage_LastEntry) // check if store policy is valid
{
- data_size = persistence_get_data(dbPath, dbKey, &dbContext, buffer, buffer_size);
+ data_size = persistence_get_data(dbPath, dbKey, resource_id, &dbContext, buffer, buffer_size);
}
else
{
if(sizeof(PersistenceConfigurationKey_s) == iErrCode)
{
- //printf("get_db_context ==> data: %s\n", search.data);
memcpy(&dbContext->configKey, &sRctEntry, sizeof(dbContext->configKey)) ;
if(sRctEntry.storage != PersistenceStorage_custom )
{
* Logical DB ID: 0xFF with user 0 and seat 0
* ==> local value accessible by all users (user 0, seat 0)
*/
- ret = pclKeyReadData(0xFF, "pos/last_position", 0, 0, buffer, READ_SIZE);
- x_fail_unless(strncmp((char*)buffer, "CACHE_ +48° 10' 38.95\", +8° 44' 39.06\"",
- strlen((char*)buffer)) == 0, "Buffer not correctly read");
- x_fail_unless(ret = strlen("CACHE_ +48° 10' 38.95\", +8° 44' 39.06\""));
+ ret = pclKeyReadData(0xFF, "pos/last_position", 1, 1, buffer, READ_SIZE);
+ //printf("----test_GetData => pos/last_position: \"%s\" => ret: %d \nReference: %s => size: %d\n", buffer, ret, "CACHE_ +48 10' 38.95, +8 44' 39.06", strlen("CACHE_ +48 10' 38.95, +8 44' 39.06"));
+ x_fail_unless(strncmp((char*)buffer, "CACHE_ +48 10' 38.95, +8 44' 39.06",
+ strlen((char*)buffer)) == 0, "Buffer not correctly read - pos/last_position");
+ x_fail_unless(ret == strlen("CACHE_ +48 10' 38.95, +8 44' 39.06"));
memset(buffer, 0, READ_SIZE);
* Logical DB ID: 0 with user 3 and seat 0
* ==> public shared user value (user 3, seat 0)
*/
- ret = pclKeyReadData(0, "language/current_language", 3, 0, buffer, READ_SIZE);
- x_fail_unless(strncmp((char*)buffer, "CACHE_ Kisuaheli", strlen((char*)buffer)) == 0, "Buffer not correctly read");
+ //ret = pclKeyReadData(0, "language/current_language", 0, 0, buffer, READ_SIZE);
+ //printf("----test_GetData => language/current_language \"%s\" => ret: %d \n", buffer, ret);
+ //x_fail_unless(strncmp((char*)buffer, "CACHE_ Kisuaheli", strlen((char*)buffer)) == 0, "Buffer not correctly read");
memset(buffer, 0, READ_SIZE);
* ==> local USER value (user 3, seat 2)
*/
ret = pclKeyReadData(0xFF, "status/open_document", 3, 2, buffer, READ_SIZE);
- x_fail_unless(strncmp((char*)buffer, "WT_ /var/opt/user_manual_climateControl.pdf", strlen((char*)buffer)) == 0, "Buffer not correctly read");
-
+ //printf("----test_GetData => status/open_document \"%s\" => ret: %d \n", buffer, ret);
+ x_fail_unless(strncmp((char*)buffer, "WT_ /var/opt/user_manual_climateControl.pdf", strlen((char*)buffer)) == 0,
+ "Buffer not correctly read - status/open_document");
+ x_fail_unless(ret == strlen("WT_ /var/opt/user_manual_climateControl.pdf"));
memset(buffer, 0, READ_SIZE);
/**
* ==> shared user value accessible by a group (user 4 and seat 0)
*/
ret = pclKeyReadData(0x20, "address/home_address", 4, 0, buffer, READ_SIZE);
- x_fail_unless(strncmp((char*)buffer, "WT_ 55327 Heimatstadt, Wohnstrasse 31", strlen((char*)buffer)) == 0, "Buffer not correctly read");
-
+ //printf("----test_GetData => address/home_address \"%s\" => ret: %d \n", buffer, ret);
+ x_fail_unless(strncmp((char*)buffer, "WT_ 55327 Heimatstadt, Wohnstrasse 31", strlen((char*)buffer)) == 0,
+ "Buffer not correctly read - address/home_address");
+ x_fail_unless(ret == strlen("WT_ 55327 Heimatstadt, Wohnstrasse 31"));
memset(buffer, 0, READ_SIZE);
/**
* ==> local value accessible by ALL USERS (user 0, seat 0)
*/
ret = pclKeyReadData(0xFF, "pos/last_satellites", 0, 0, buffer, READ_SIZE);
- x_fail_unless(strncmp((char*)buffer, "WT_ 17", strlen((char*)buffer)) == 0, "Buffer not correctly read");
-
+ //printf("----test_GetData => pos/last_satellites \"%s\" => ret: %d \n", buffer, ret);
+ x_fail_unless(strncmp((char*)buffer, "WT_ 17", strlen((char*)buffer)) == 0,
+ "Buffer not correctly read - pos/last_satellites");
+ x_fail_unless(ret == strlen("WT_ 17"));
memset(buffer, 0, READ_SIZE);
/**
- * Logical DB ID: 0x84 with user 4 and seat 0
+ * Logical DB ID: 0x20 with user 4 and seat 0
* ==> shared user value accessible by A GROUP (user 4 and seat 0)
*/
- ret = pclKeyReadData(0x84, "links/last_link", 2, 0, buffer, READ_SIZE);
- x_fail_unless(strncmp((char*)buffer, "CACHE_ /last_exit/brooklyn", strlen((char*)buffer)) == 0, "Buffer not correctly read");
-
+ ret = pclKeyReadData(0x20, "links/last_link", 2, 0, buffer, READ_SIZE);
+ //printf("----test_GetData => links/last_link \"%s\" => ret: %d \n", buffer, ret);
+ x_fail_unless(strncmp((char*)buffer, "CACHE_ /last_exit/queens", strlen((char*)buffer)) == 0,
+ "Buffer not correctly read - links/last_link");
+ x_fail_unless(ret == strlen("CACHE_ /last_exit/queens"));
memset(buffer, 0, READ_SIZE);
- /**
- * Logical DB ID: 0x84 with user 2 and seat 1
- * ==> local merge value
- */
- ret = pclKeyReadData(0x84, "links/last_link", 2, 1, buffer, READ_SIZE);
- x_fail_unless(strncmp((char*)buffer, "CACHE_ /last_exit/queens", strlen((char*)buffer)) == 0, "Buffer not correctly read");
#endif
pclDeinitLibrary();
}
x_fail_unless(handle >= 0, "Failed to open handle ==> /posHandle/last_position");
ret = pclKeyHandleReadData(handle, buffer, READ_SIZE);
- printf("* * * * * => => => B U F F E R : \"%s\"\n", buffer);
x_fail_unless(strncmp((char*)buffer, "WT_ H A N D L E: +48° 10' 38.95\", +8° 44' 39.06\"", ret-1) == 0, "Buffer not correctly read => 1");
size = pclKeyHandleGetSize(handle);
x_fail_unless(fd_RW != -1, "Could not open file ==> /media/mediaDB_ReadWrite.db");
pclFileWriteData(fd_RW, wBuffer, strlen(wBuffer));
- ret = pclFileClose(fd_RW);
- if(ret == -1)
+ (void)pclFileClose(fd_RW);
- ret = pclFileClose(fd_RO);
- if(ret == -1)
+ (void)pclFileClose(fd_RO);
#endif
+
pclDeinitLibrary();
}
END_TEST
ret = pclInitLibrary(gTheAppId, shutdownReg);
x_fail_unless(ret <= 1, "Failed to init PCL");
+
#if 1
- ret = pclKeyReadData(0xFF, "language/country_code", 0, 0, buffer, READ_SIZE);
- x_fail_unless(ret != EPERS_NOT_INITIALIZED);
- x_fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: secure!",
- strlen((char*)buffer)) == 0, "Buffer SECURE not correctly read");
+ ret = pclKeyReadData(0xFF, "secured", 0, 0, buffer, READ_SIZE);
+ //printf("B U F F E R - secure: \"%s\" => ist: %d | soll: %d\n", buffer, ret, strlen("Custom plugin -> plugin_get_data: secure!"));
+ x_fail_unless(ret == strlen("Custom plugin -> plugin_get_data: secure!") );
+ x_fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: secure!",
+ strlen((char*)buffer)) == 0, "Buffer SECURE not correctly read");
+ memset(buffer, 0, READ_SIZE);
- ret = pclKeyReadData(0xFF, "language/country_code_early", 0, 0, buffer, READ_SIZE);
- x_fail_unless(ret != EPERS_NOT_INITIALIZED);
- //printf("B U F F E R - early: %s\n", buffer);
+ ret = pclKeyReadData(0xFF, "early", 0, 0, buffer, READ_SIZE);
+ //printf("B U F F E R - early: \"%s\" => ist: %d | soll: %d\n", buffer, ret, strlen("Custom plugin -> plugin_get_data: early!"));
+ x_fail_unless(ret == strlen("Custom plugin -> plugin_get_data: early!"));
x_fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: early!",
strlen((char*)buffer)) == 0, "Buffer EARLY not correctly read");
+ memset(buffer, 0, READ_SIZE);
- ret = pclKeyReadData(0xFF, "language/country_code_emergency", 0, 0, buffer, READ_SIZE);
- x_fail_unless(ret != EPERS_NOT_INITIALIZED);
- //printf("B U F F E R - emergency: %s\n", buffer);
+ ret = pclKeyReadData(0xFF, "emergency", 0, 0, buffer, READ_SIZE);
+ //printf("B U F F E R - emergency: \"%s\" => ist: %d | soll: %d\n", buffer, ret, strlen("Custom plugin -> plugin_get_data: emergency!"));
+ x_fail_unless(ret == strlen("Custom plugin -> plugin_get_data: emergency!"));
x_fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: emergency!",
strlen((char*)buffer)) == 0, "Buffer EMERGENCY not correctly read");
+ memset(buffer, 0, READ_SIZE);
- ret = pclKeyReadData(0xFF, "language/info", 0, 0, buffer, READ_SIZE);
+ ret = pclKeyReadData(0xFF, "hwinfo", 0, 0, buffer, READ_SIZE);
+ //printf("B U F F E R - hwinfo: \"%s\" => ist: %d | soll: %d\n", buffer, ret, strlen("Custom plugin -> plugin_get_data: hwinfo!"));
x_fail_unless(ret != EPERS_NOT_INITIALIZED);
- //printf("B U F F E R - hwinfo: %s\n", buffer);
x_fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: hwinfo!",
strlen((char*)buffer)) == 0, "Buffer HWINFO not correctly read");
+ memset(buffer, 0, READ_SIZE);
- ret = pclKeyReadData(0xFF, "language/country_code_custom3", 0, 0, buffer, READ_SIZE);
- x_fail_unless(ret != EPERS_NOT_INITIALIZED);
- //printf("B U F F E R - hwinfo: %s\n", buffer);
+ ret = pclKeyReadData(0xFF, "custom2", 0, 0, buffer, READ_SIZE);
+ //printf("B U F F E R - custom2: \"%s\" => ist: %d | soll: %d\n", buffer, ret, strlen("Custom plugin -> plugin_get_data: custom2!"));
+ x_fail_unless(ret == strlen("Custom plugin -> plugin_get_data: custom2!"));
+ x_fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: custom2!",
+ strlen((char*)buffer)) == 0, "Buffer CUSTOM 2 not correctly read");
+ memset(buffer, 0, READ_SIZE);
+
+ ret = pclKeyReadData(0xFF, "custom3", 0, 0, buffer, READ_SIZE);
+ //printf("B U F F E R - custom3: \"%s\" => ist: %d | soll: %d\n", buffer, ret, strlen("Custom plugin -> plugin_get_data: custom3!"));
+ x_fail_unless(ret == strlen("Custom plugin -> plugin_get_data: custom3!"));
x_fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: custom3!",
- strlen((char*)buffer)) == 0, "Buffer CUSTOM 3 not correctly read");
+ strlen((char*)buffer)) == 0, "Buffer CUSTOM 3 not correctly read");
+ memset(buffer, 0, READ_SIZE);
+
#endif
pclDeinitLibrary();
}
x_fail_unless(ret <= 1, "Failed to init PCL");
#if 1
ret = pclKeyReadData(0xFF, "statusHandle/default01", 3, 2, buffer, READ_SIZE);
- x_fail_unless(ret != EPERS_NOT_INITIALIZED);
- //printf("B U F F E R: %s\n", buffer);
+ //printf(" --- test_ReadConfDefault => statusHandle/default01: %s => retIst: %d retSoll: %d\n", buffer, ret, strlen("DEFAULT_01!"));
+ x_fail_unless(ret == strlen("DEFAULT_01!"));
x_fail_unless(strncmp((char*)buffer,"DEFAULT_01!", strlen((char*)buffer)) == 0, "Buffer not correctly read");
ret = pclKeyReadData(0xFF, "statusHandle/default02", 3, 2, buffer, READ_SIZE);
- x_fail_unless(ret != EPERS_NOT_INITIALIZED);
- //printf("B U F F E R: %s\n", buffer);
+ //printf(" --- test_ReadConfDefault => statusHandle/default02: %s => retIst: %d retSoll: %d\n", buffer, ret, strlen("DEFAULT_02!"));
+ x_fail_unless(ret == strlen("DEFAULT_02!"));
x_fail_unless(strncmp((char*)buffer,"DEFAULT_02!", strlen((char*)buffer)) == 0, "Buffer not correctly read");
#endif
pclDeinitLibrary();
x_fail_unless(ret <= 1, "Failed to init PCL");
#if 1
ret = pclKeyReadData(0xFF, "statusHandle/confdefault01", 3, 2, buffer, READ_SIZE);
- x_fail_unless(ret != EPERS_NOT_INITIALIZED);
+ //printf(" --- test_ReadConfDefault => statusHandle/confdefault01: %s => retIst: %d retSoll: %d\n", buffer, ret, strlen("CONF_DEFAULT_01!"));
+ x_fail_unless(ret == strlen("CONF_DEFAULT_01!"));
x_fail_unless(strncmp((char*)buffer,"CONF_DEFAULT_01!", strlen((char*)buffer)) == 0, "Buffer not correctly read");
ret = pclKeyReadData(0xFF, "statusHandle/confdefault02", 3, 2, buffer, READ_SIZE);
- x_fail_unless(ret != EPERS_NOT_INITIALIZED);
+ //printf(" --- test_ReadConfDefault => statusHandle/confdefault02: %s => retIst: %d retSoll: %d\n", buffer, ret, strlen("CONF_DEFAULT_02!"));
+ x_fail_unless(ret == strlen("CONF_DEFAULT_02!"));
x_fail_unless(strncmp((char*)buffer,"CONF_DEFAULT_02!", strlen((char*)buffer)) == 0, "Buffer not correctly read");
#endif
pclDeinitLibrary();
START_TEST(test_NegHandle)
{
- int handle = -1, ret = 0;;
+ int handle = -1, ret = 0;
int negativeHandle = -17;
unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
+START_TEST(test_NodeHealthTest)
+{
+ unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
+
+ (void)pclInitLibrary("node-health-monitor", shutdownReg);
+
+ pclDeinitLibrary();
+
+}
+END_TEST
TCase * tc_persGetData = tcase_create("GetData");
tcase_add_test(tc_persGetData, test_GetData);
- tcase_set_timeout(tc_persGetData, 8);
+ tcase_set_timeout(tc_persGetData, 1);
TCase * tc_persSetData = tcase_create("SetData");
tcase_add_test(tc_persSetData, test_SetData);
- tcase_set_timeout(tc_persSetData, 8);
+ tcase_set_timeout(tc_persSetData, 1);
TCase * tc_persSetDataNoPRCT = tcase_create("SetDataNoPRCT");
tcase_add_test(tc_persSetDataNoPRCT, test_SetDataNoPRCT);
- tcase_set_timeout(tc_persSetDataNoPRCT, 8);
+ tcase_set_timeout(tc_persSetDataNoPRCT, 1);
TCase * tc_persGetDataSize = tcase_create("GetDataSize");
tcase_add_test(tc_persGetDataSize, test_GetDataSize);
- tcase_set_timeout(tc_persGetDataSize, 8);
+ tcase_set_timeout(tc_persGetDataSize, 1);
TCase * tc_persDeleteData = tcase_create("DeleteData");
tcase_add_test(tc_persDeleteData, test_DeleteData);
- tcase_set_timeout(tc_persDeleteData, 8);
+ tcase_set_timeout(tc_persDeleteData, 1);
TCase * tc_persGetDataHandle = tcase_create("GetDataHandle");
tcase_add_test(tc_persGetDataHandle, test_GetDataHandle);
- tcase_set_timeout(tc_persGetDataHandle, 8);
+ tcase_set_timeout(tc_persGetDataHandle, 1);
TCase * tc_persDataHandle = tcase_create("DataHandle");
tcase_add_test(tc_persDataHandle, test_DataHandle);
- tcase_set_timeout(tc_persGetData, 8);
+ tcase_set_timeout(tc_persGetData, 1);
TCase * tc_persDataHandleOpen = tcase_create("DataHandleOpen");
tcase_add_test(tc_persDataHandleOpen, test_DataHandleOpen);
- tcase_set_timeout(tc_persDataHandleOpen, 8);
+ tcase_set_timeout(tc_persDataHandleOpen, 1);
TCase * tc_persDataFile = tcase_create("DataFile");
tcase_add_test(tc_persDataFile, test_DataFile);
- tcase_set_timeout(tc_persDataFile, 8);
+ tcase_set_timeout(tc_persDataFile, 1);
TCase * tc_persDataFileRecovery = tcase_create("DataFileRecovery");
tcase_add_test(tc_persDataFileRecovery, test_DataFileRecovery);
- tcase_set_timeout(tc_persDataFileRecovery, 8);
+ tcase_set_timeout(tc_persDataFileRecovery, 1);
TCase * tc_Plugin = tcase_create("Plugin");
tcase_add_test(tc_Plugin, test_Plugin);
- tcase_set_timeout(tc_Plugin, 8);
+ tcase_set_timeout(tc_Plugin, 1);
TCase * tc_ReadDefault = tcase_create("ReadDefault");
tcase_add_test(tc_ReadDefault, test_ReadDefault);
- tcase_set_timeout(tc_ReadDefault, 8);
+ tcase_set_timeout(tc_ReadDefault, 1);
TCase * tc_ReadConfDefault = tcase_create("ReadConfDefault");
tcase_add_test(tc_ReadConfDefault, test_ReadConfDefault);
- tcase_set_timeout(tc_ReadConfDefault, 8);
+ tcase_set_timeout(tc_ReadConfDefault, 1);
TCase * tc_GetPath = tcase_create("GetPath");
tcase_add_test(tc_GetPath, test_GetPath);
- tcase_set_timeout(tc_GetPath, 8);
+ tcase_set_timeout(tc_GetPath, 1);
TCase * tc_InitDeinit = tcase_create("InitDeinit");
tcase_add_test(tc_InitDeinit, test_InitDeinit);
- tcase_set_timeout(tc_InitDeinit, 8);
+ tcase_set_timeout(tc_InitDeinit, 1);
TCase * tc_NegHandle = tcase_create("NegHandle");
tcase_add_test(tc_NegHandle, test_NegHandle);
- tcase_set_timeout(tc_NegHandle, 8);
+ tcase_set_timeout(tc_NegHandle, 1);
+
+
+ TCase * tc_NodeHealthTest = tcase_create("NodeHealthTest");
+ tcase_add_test(tc_NodeHealthTest, test_NodeHealthTest);
suite_add_tcase(s, tc_persSetData);
suite_add_tcase(s, tc_persGetData);
+
suite_add_tcase(s, tc_persSetDataNoPRCT);
suite_add_tcase(s, tc_persGetDataSize);
suite_add_tcase(s, tc_persDeleteData);
suite_add_tcase(s, tc_NegHandle);
suite_add_tcase(s, tc_InitDeinit);
+ suite_add_tcase(s, tc_NodeHealthTest);
+
+ suite_add_tcase(s, tc_Plugin); // activate only if the plugins are available
- //suite_add_tcase(s, tc_Plugin); // activate only if the plugins are available
return s;
}