int pclInitLibrary(const char* appName, int shutdownMode)
{
int status = 0;
- int i = 0, rval = 0;
+ int i = 0, rval = 1;
if(gPclInitialized == PCLnotInitialized)
{
gMaxKeyValDataSize = atoi(pDataSize);
}
- setup_dbus_mainloop();
+ if( setup_dbus_mainloop() == -1)
+ {
+ DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclInitLibrary => Failed to setup main loop"));
+ return -1;
+ }
#if USE_DBUS
// register for lifecycle and persistence admin service dbus messages
- register_lifecycle(shutdownMode);
- register_pers_admin_service();
-#endif
+ if(register_lifecycle(shutdownMode) == -1)
+ {
+ DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclInitLibrary => Failed to register to lifecycle dbus interface"));
+ return -1;
+ }
- // clear the open file descriptor array
- memset(gOpenFdArray, 0, MaxPersHandle * sizeof(int));
+ rval = register_pers_admin_service();
+ {
+ DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclInitLibrary => Failed to register to pers admin dbus interface"));
+ return -1;
+ }
+#endif
/// get custom library names to load
status = get_custom_libraries();
// unregister for lifecycle and persistence admin service dbus messages
#if USE_DBUS
- unregister_lifecycle(gShutdownMode);
- unregister_pers_admin_service();
+ rval = unregister_lifecycle(gShutdownMode);
+ rval = unregister_pers_admin_service();
#endif
// unload custom client libraries
}
else
{
+ error = dlerror();
DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("load_custom_library - error:"), DLT_STRING(error));
rval = EPERS_DLOPENERROR;
}
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_handle_get_data != NULL) )
+ if( (idx < PersCustomLib_LastEntry) && (gPersCustomFuncs[idx].custom_plugin_get_data != NULL) )
{
if(info->configKey.customID[0] == '\0') // if we have not a customID we use the key
{
else if(PersistenceStorage_custom == info->configKey.storage) // custom storage implementation via custom library
{
int idx = custom_client_name_to_id(dbPath, 1);
- if((idx < PersCustomLib_LastEntry) && (gPersCustomFuncs[idx].custom_plugin_handle_set_data != NULL) )
+ if((idx < PersCustomLib_LastEntry) && (gPersCustomFuncs[idx].custom_plugin_set_data != NULL) )
{
if(info->configKey.customID[0] == '\0') // if we have not a customID we use the key
{
else if(PersistenceStorage_custom == info->configKey.storage) // custom storage implementation via custom library
{
int idx = custom_client_name_to_id(dbPath, 1);
- if((idx < PersCustomLib_LastEntry) && (gPersCustomFuncs[idx].custom_plugin_handle_set_data != NULL) )
+ if((idx < PersCustomLib_LastEntry) && (gPersCustomFuncs[idx].custom_plugin_get_size != NULL) )
{
if(info->configKey.customID[0] == '\0') // if we have not a customID we use the key
{
else // custom storage implementation via custom library
{
int idx = custom_client_name_to_id(dbPath, 1);
- if((idx < PersCustomLib_LastEntry) && (gPersCustomFuncs[idx].custom_plugin_handle_set_data != NULL) )
+ if((idx < PersCustomLib_LastEntry) && (gPersCustomFuncs[idx].custom_plugin_delete_data != NULL) )
{
if(info->configKey.customID[0] == '\0') // if we have not a customID we use the key
{
#include <unistd.h>
#include <stdlib.h>
+//#define DEBUG_MODE 1
pthread_mutex_t gDbusInitializedMtx = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t gDbusInitializedCond = PTHREAD_COND_INITIALIZER;
return gDbusConn;
}
+int bContinue = 0;
+
//------------------------------------------------------------------------
// debugging only until "correct" exit of main loop is possible!!!!!
//------------------------------------------------------------------------
+#ifdef DEBUG_MODE
+
#include "signal.h"
-static int endLoop = 0;
void sigHandler(int signo)
{
- endLoop = 1;
+ bContinue = FALSE;
}
+#endif
//------------------------------------------------------------------------
{
DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("dbus_connection_open() Error :"), DLT_STRING(err.message) );
dbus_error_free(&err);
+ return -1;
}
}
else
if(rval)
{
DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pthread_create( DBUS run_mainloop ) returned an error:"), DLT_INT(rval) );
+ return -1;
}
// wait for condition variable
// lock mutex to make sure dbus main loop is running
pthread_mutex_lock(&gDbusInitializedMtx);
- signal(SIGTERM, sigHandler);
- signal(SIGQUIT, sigHandler);
+#if DEBUG_MODE
signal(SIGINT, sigHandler);
+#endif
+
DBusConnection* conn = (DBusConnection*)userData;
dbus_error_init(&err);
else
{
int ret;
- int bContinue = 0;
memset(&gPollInfo, 0 , sizeof(gPollInfo));
gPollInfo.nfds = 1;
}
}
}
- if(endLoop == 1)
- break;
}
while (0!=bContinue);
}
int shared_DB = 0;
PersistenceInfo_s dbContext;
- char dbKey[DbKeyMaxLen]; // database key
- char dbPath[DbPathMaxLen]; // database location
- char backupPath[DbKeyMaxLen]; // backup file
- char csumPath[DbPathMaxLen]; // checksum file
+ char dbKey[DbKeyMaxLen] = {0}; // database key
+ char dbPath[DbPathMaxLen] = {0}; // database location
+ char backupPath[DbKeyMaxLen] = {0}; // backup file
+ char csumPath[DbPathMaxLen] = {0}; // checksum file
//DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileOpen: "), DLT_INT(ldbid), DLT_STRING(resource_id) );
- memset(dbKey, 0, DbKeyMaxLen);
- memset(dbPath, 0, DbPathMaxLen);
-
dbContext.context.ldbid = ldbid;
dbContext.context.seat_no = seat_no;
dbContext.context.user_no = user_no;
if( dbContext.configKey.permission != PersistencePermission_ReadOnly
&& pclBackupNeeded(dbPath) )
{
- memset(backupPath, 0, DbKeyMaxLen);
- memset(csumPath, 0, DbPathMaxLen);
-
snprintf(backupPath, DbPathMaxLen, "%s%s", dbPath, "~");
snprintf(csumPath, DbPathMaxLen, "%s%s", dbPath, "~.crc");
{
if(handle < MaxPersHandle)
{
- memset(backupPath, 0, DbKeyMaxLen);
- memset(csumPath, 0, DbPathMaxLen);
-
snprintf(backupPath, DbPathMaxLen, "%s%s", dbPath, "~");
snprintf(csumPath, DbPathMaxLen, "%s%s", dbPath, "~.crc");
int shared_DB = 0;
PersistenceInfo_s dbContext;
- char dbKey[DbKeyMaxLen]; // database key
- char dbPath[DbPathMaxLen]; // database location
-
- memset(dbKey, 0, DbKeyMaxLen);
- memset(dbPath, 0, DbPathMaxLen);
+ char dbKey[DbKeyMaxLen] = {0}; // database key
+ char dbPath[DbPathMaxLen] = {0}; // database location
dbContext.context.ldbid = ldbid;
dbContext.context.seat_no = seat_no;
if( gFileHandleArray[fd].permission != PersistencePermission_ReadOnly
&& gFileHandleArray[fd].backupCreated == 0)
{
- char csumBuf[ChecksumBufSize];
- memset(csumBuf, 0, ChecksumBufSize);
+ char csumBuf[ChecksumBufSize] = {0};
// calculate checksum
pclCalcCrc32Csum(fd, csumBuf);
const char* delimiters = "/\n"; // search for blank and end of line
char* tokenArray[24];
char* thePath = (char*)path;
- char createPath[DbPathMaxLen];
int numTokens = 0, i = 0, validPath = 1;
int handle = 0;
if(validPath == 1)
{
- memset(createPath, 0, DbPathMaxLen);
+ char createPath[DbPathMaxLen] = {0};
snprintf(createPath, DbPathMaxLen, "/%s",tokenArray[0] );
for(i=1; i<numTokens-1; i++)
{
int backupAvail = 0, csumAvail = 0;
int fdCsum = 0, fdBackup = 0;
- char origCsumBuf[ChecksumBufSize];
- char backCsumBuf[ChecksumBufSize];
- char csumBuf[ChecksumBufSize];
-
- memset(origCsumBuf, 0, ChecksumBufSize);
- memset(backCsumBuf, 0, ChecksumBufSize);
- memset(csumBuf, 0, ChecksumBufSize);
+ char origCsumBuf[ChecksumBufSize] = {0};
+ char backCsumBuf[ChecksumBufSize] = {0};
+ char csumBuf[ChecksumBufSize] = {0};
// check if we have a backup and checksum file
backupAvail = access(backupPath, F_OK);
static int gInitialized = 0;
/// open file descriptor handle array
-int gOpenFdArray[MaxPersHandle];
+int gOpenFdArray[MaxPersHandle] = {0};
/// persistence key handle array
PersistenceKeyHandle_s gKeyHandleArray[MaxPersHandle];
{
PersistenceInfo_s dbContext;
- char dbKey[DbKeyMaxLen]; // database key
- char dbPath[DbPathMaxLen]; // database location
+ char dbKey[DbKeyMaxLen] = {0}; // database key
+ char dbPath[DbPathMaxLen] = {0}; // database location
//DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyHandleOpen: "), DLT_INT(ldbid), DLT_STRING(resource_id) );
-
- memset(dbKey, 0, DbKeyMaxLen);
- memset(dbPath, 0, DbPathMaxLen);
-
dbContext.context.ldbid = ldbid;
dbContext.context.seat_no = seat_no;
dbContext.context.user_no = user_no;
{
PersistenceInfo_s dbContext;
- char dbKey[DbKeyMaxLen]; // database key
- char dbPath[DbPathMaxLen]; // database location
-
- memset(dbKey, 0, DbKeyMaxLen);
- memset(dbPath, 0, DbPathMaxLen);
+ char dbKey[DbKeyMaxLen] = {0}; // database key
+ char dbPath[DbPathMaxLen] = {0}; // database location
dbContext.context.ldbid = ldbid;
dbContext.context.seat_no = seat_no;
{
PersistenceInfo_s dbContext;
- char dbKey[DbKeyMaxLen]; // database key
- char dbPath[DbPathMaxLen]; // database location
-
- memset(dbKey, 0, DbKeyMaxLen);
- memset(dbPath, 0, DbPathMaxLen);
+ char dbKey[DbKeyMaxLen] = {0}; // database key
+ char dbPath[DbPathMaxLen] = {0}; // database location
dbContext.context.ldbid = ldbid;
dbContext.context.seat_no = seat_no;
{
PersistenceInfo_s dbContext;
- char dbKey[DbKeyMaxLen]; // database key
- char dbPath[DbPathMaxLen]; // database location
-
- memset(dbKey, 0, DbKeyMaxLen);
- memset(dbPath, 0, DbPathMaxLen);
+ char dbKey[DbKeyMaxLen] = {0}; // database key
+ char dbPath[DbPathMaxLen] = {0}; // database location
dbContext.context.ldbid = ldbid;
dbContext.context.seat_no = seat_no;
unsigned int hash_val_data = 0;
- char dbKey[DbKeyMaxLen]; // database key
- char dbPath[DbPathMaxLen]; // database location
-
- memset(dbKey, 0, DbKeyMaxLen);
- memset(dbPath, 0, DbPathMaxLen);
+ char dbKey[DbKeyMaxLen] = {0}; // database key
+ char dbPath[DbPathMaxLen] = {0}; // database location
dbContext.context.ldbid = ldbid;
dbContext.context.seat_no = seat_no;
PersistenceInfo_s dbContext;
// unsigned int hash_val_data = 0;
- char dbKey[DbKeyMaxLen]; // database key
- char dbPath[DbPathMaxLen]; // database location
-
- memset(dbKey, 0, DbKeyMaxLen);
- memset(dbPath, 0, DbPathMaxLen);
+ char dbKey[DbKeyMaxLen] = {0}; // database key
+ char dbPath[DbPathMaxLen] = {0}; // database location
//DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyRegisterNotifyOnChange: "), DLT_INT(ldbid), DLT_STRING(resource_id) );
if(!dbus_connection_send(conn, message, 0))
{
DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("send_lifecycle_register => Access denied"), DLT_STRING(error.message) );
+ rval = -1;
}
dbus_connection_flush(conn);
else
{
DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("send_lifecycle_register => ERROR: Invalid connection"));
+ rval = -1;
}
dbus_message_unref(message);
}
else
{
DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("send_lifecycle_register => ERROR: Invalid message"));
+ rval = -1;
}
}
else
{
DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("send_lifecycle_register => ERROR: connection isn NULL"));
+ rval = -1;
}
return rval;
if(!dbus_connection_send(conn, message, 0))
{
DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("send_lifecycle_request => Access denied"), DLT_STRING(error.message) );
+ rval = -1;
}
dbus_connection_flush(conn);
else
{
DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("send_lifecycle_request => ERROR: Invalid connection"));
+ rval = -1;
}
dbus_message_unref(message);
}
else
{
DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("send_lifecycle_request => ERROR: Invalid message"));
+ rval = -1;
}
}
else
{
DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("send_lifecycle_request => ERROR: connection isn NULL"));
+ rval = -1;
}
return rval;
if(busName != NULL)
{
- DBusMessage* message = dbus_message_new_method_call("org.genivi.persistence", // destination
- "/org/genivi/persistence", // path
- "org.genivi.persistence.admin", // interface
- method); // method
+ DBusMessage* message = dbus_message_new_method_call("org.genivi.persistence.admin", // destination
+ "/org/genivi/persistence/admin", // path
+ "org.genivi.persistence.admin", // interface
+ method); // method
if(message != NULL)
{
if(gResourceOpen[arrayIdx] == 0) // check if database is already open
{
itzam_state state;
- char filename[DbPathMaxLen];
- memset(filename, 0, DbPathMaxLen);
+ char filename[DbPathMaxLen] = {0};
switch(rct) // create db name
{
gPollInfo.fds[0].events = POLLIN;
// register for messages
- if ( (TRUE==dbus_connection_register_object_path(conn, "/org/genivi/persistence", &vtable, userData))
+ if ( (TRUE==dbus_connection_register_object_path(conn, "/org/genivi/persistence/admin", &vtable, userData))
&& (TRUE==dbus_connection_register_fallback(conn, "/", &vtableFallback, userData)) )
{
if (TRUE!=dbus_connection_set_watch_functions(conn, addWatch, removeWatch, watchToggled, NULL, NULL))
switch (buf[0])
{
case CMD_REQUEST_NAME:
- if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER !=dbus_bus_request_name(conn, "org.genivi.persistence", DBUS_NAME_FLAG_DO_NOT_QUEUE, &err))
+ if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER !=dbus_bus_request_name(conn, "org.genivi.persistence.admin", DBUS_NAME_FLAG_DO_NOT_QUEUE, &err))
{
- fprintf(stderr, "Cannot acquire name 'org.genivi.persistence': \n \"(%s)\". Bailing out!\n", err.message);
+ fprintf(stderr, "Cannot acquire name 'org.genivi.persistence.admin': \n \"(%s)\". Bailing out!\n", err.message);
dbus_error_free(&err);
bContinue = FALSE;
}
fail_unless(ret != -1, "Failed to close handle!!");
ret = pclKeyHandleClose(1024);
- fail_unless(ret == -1, "Could close, but should not!!");
+ fail_unless(ret == -4, "Max handle!!");
pclDeinitLibrary();
}
TCase * tc_Plugin = tcase_create("Plugin");
tcase_add_test(tc_Plugin, test_Plugin);
+
suite_add_tcase(s, tc_persGetData);
suite_add_tcase(s, tc_persSetData);
suite_add_tcase(s, tc_persSetDataNoPRCT);
suite_add_tcase(s, tc_Cursor);
suite_add_tcase(s, tc_Plugin); // activate only if the plugins are available
-
return s;
}
DBusHandlerResult result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
//printf("checkPersAdminMsg '%s' -> '%s'\n", dbus_message_get_interface(message), dbus_message_get_member(message));
- if((0==strcmp("org.genivi.NodeStateManager.Consumer", dbus_message_get_interface(message))))
+ if((0==strcmp("org.genivi.NodeStateManager.LifeCycleConsumer", dbus_message_get_interface(message))))
{
if((0==strcmp("RegisterShutdownClient", dbus_message_get_member(message))))
{
- printf(" ==> org.genivi.NodeStateManager.Consumer - received - ==> RegisterShutdownClient \n");
+ printf(" ==> org.genivi.NodeStateManager.LifeCycleConsumer - received - ==> RegisterShutdownClient \n");
result = checkAdminMsg(connection, message, 1);
}
else if((0==strcmp("UnRegisterShutdownClient", dbus_message_get_member(message))))
{
- printf(" ==> org.genivi.NodeStateManager.Consumer - received - ==> UnRegisterShutdownClient \n");
+ printf(" ==> org.genivi.NodeStateManager.LifeCycleConsumer - received - ==> UnRegisterShutdownClient \n");
result = checkAdminMsg(connection, message, 0);
}
else if((0==strcmp("LifecycleRequestComplete", dbus_message_get_member(message))))
{
- printf(" ==> org.genivi.NodeStateManager.Consumer - received - ==> LifecycleRequestComplete \n");
+ printf(" ==> org.genivi.NodeStateManager.LifeCycleConsumer - received - ==> LifecycleRequestComplete \n");
result = checkAdminMsg(connection, message, 0);
}
else
{
- printf(" ==> org.genivi.NodeStateManager.Consumer - received U N KN O W N-'%s'\n", dbus_message_get_interface(message));
+ printf(" ==> org.genivi.NodeStateManager.LifeCycleConsumer - received U N KN O W N-'%s'\n", dbus_message_get_interface(message));
}
}
else
gPollInfo.fds[0].events = POLLIN;
// register for messages
- if ( (TRUE==dbus_connection_register_object_path(conn, "/org/genivi/NodeStateManager", &vtable, userData))
+ if ( (TRUE==dbus_connection_register_object_path(conn, "/org/genivi/NodeStateManager/LifecycleConsumer", &vtable, userData))
&& (TRUE==dbus_connection_register_fallback(conn, "/", &vtableFallback, userData)) )
{
if (TRUE!=dbus_connection_set_watch_functions(conn, addWatch, removeWatch, watchToggled, NULL, NULL))
switch (buf[0])
{
case CMD_REQUEST_NAME:
- if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER !=dbus_bus_request_name(conn, "org.genivi.NodeStateManager", DBUS_NAME_FLAG_DO_NOT_QUEUE, &err))
+ if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER !=dbus_bus_request_name(conn, "org.genivi.NodeStateManager.LifecycleConsumer", DBUS_NAME_FLAG_DO_NOT_QUEUE, &err))
{
- fprintf(stderr, "Cannot acquire name 'org.genivi.NodeStateManager.Consumer': \n \"(%s)\". Bailing out!\n", err.message);
+ fprintf(stderr, "Cannot acquire name 'org.genivi.NodeStateManager.LifeCycleConsumer': \n \"(%s)\". Bailing out!\n", err.message);
dbus_error_free(&err);
bContinue = FALSE;
}
}
while (0!=bContinue);
}
- dbus_connection_unregister_object_path(conn, "/org/genivi/NodeStateManager/Consumer");
+ dbus_connection_unregister_object_path(conn, "/org/genivi/NodeStateManager/LifeCycleConsumer");
dbus_connection_unregister_object_path(conn, "/");
}
close(gEfds);
printf("Wait, press enter to exit!!\n");
getchar();
- printf("Exiting Persistence Admin mockup!!\n");
+ printf("Exiting Persistence Lifecycle mockup!!\n");
return 0;
}