/// blacklist path environment variable
const char *pBlacklistPath = getenv("PERS_BLACKLIST_PATH");
- printf("\nInitial => Mutex Lock\n");
pthread_mutex_lock(&gDbusPendingRegMtx); // block until pending received
- printf("Initial <= Mutex Lock\n");
if(pDataSize != NULL)
{
return EPERS_DBUS_MAINLOOP;
}
-#if 1
- if(register_pers_admin_service() == -1)
- {
- DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclInitLibrary => Failed to register to pers admin dbus interface"));
- return EPERS_REGISTER_ADMIN;
- }
-#endif
-
-#if 1
if(gShutdownMode != PCL_SHUTDOWN_TYPE_NONE)
{
// register for lifecycle and persistence admin service dbus messages
return EPERS_REGISTER_LIFECYCLE;
}
}
-#endif
+
+ if(register_pers_admin_service() == -1)
+ {
+ DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclInitLibrary => Failed to register to pers admin dbus interface"));
+ return EPERS_REGISTER_ADMIN;
+ }
/// get custom library names to load
status = get_custom_libraries();
DLT_STRING("- init counter: "), DLT_INT(gPclInitialized));
// unregister for lifecycle and persistence admin service dbus messages
- rval = unregister_pers_admin_service();
rval = unregister_lifecycle(gShutdownMode);
+ rval = unregister_pers_admin_service();
// unload custom client libraries
for(i=0; i<PersCustomLib_LastEntry; i++)
pclChangeNotifyCallback_t callback, PersNotifyRegPolicy_e regPolicy)
{
int rval = 0;
- uint64_t cmd;
if(regPolicy < Notify_lastEntry)
{
gChangeNotifyCallback = NULL;
}
- // add command and data to queue
- cmd = (uint64_t)CMD_REG_NOTIFY_SIGNAL;
-
- if(-1 == write(gEfds, &cmd, (sizeof(uint64_t))))
+ if(-1 == deliverToMainloop(CMD_REG_NOTIFY_SIGNAL, 0, 0))
{
DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("persistence_notify_on_change => failed to write to pipe"), DLT_INT(errno));
rval = -1;
gSendNotifySeatNo = context->seat_no;
gSendNotifyReason = reason;
- //printf("pers_send_Notification_Signal => key: %s | lbid: %d | gUserNo: %d | gSeatNo: %d | gReason: %d \n", key, gLdbid, gUserNo, gSeatNo, gReason);
-
- uint64_t cmd;
- // add command and data to queue
- cmd = (uint64_t)CMD_SEND_NOTIFY_SIGNAL;
-
- if(-1 == write(gEfds, &cmd, (sizeof(uint64_t))))
+ if(-1 == deliverToMainloop(CMD_SEND_NOTIFY_SIGNAL, 0,0) )
{
DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_send_Notification_Signal => failed to write to pipe"), DLT_INT(errno));
rval = EPERS_NOTIFY_SIG;
if(!dbus_pending_call_set_notify(pending, msg_pending_func, "PersistenceAdminRequestCompleted", NULL))
{
- printf("process_send_pas_request => dbus_pending_call_set_notify: FAILED\n");
+ DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("process_send_pas_request => dbus_pending_call_set_notify: FAILED\n"));
}
dbus_pending_call_unref(pending);
}
DBusPendingCall* pending = NULL;
char* method = NULL;
- printf(" process_send_pas_register => regType: %d | notificaiton flag: %d\n", regType, notificationFlag);
if(regType == 0)
method = "UnRegisterPersAdminNotification";
dbus_error_init (&error);
char* method = NULL;
- printf(" process_send_lifecycle_register => reg: %d | shutdownMode flag: %d\n", regType, shutdownMode);
if(regType == 1)
method = "RegisterShutdownClient";
DBusError error;
dbus_error_init (&error);
- printf(" process_send_lifecycle_request => requestID: %d | status: %d\n", requestId, status);
-
if(conn != NULL)
{
DBusMessage* message = dbus_message_new_method_call("org.genivi.NodeStateManager", // destination
}
else
{
- DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("msg_pending_func ==> UNlock mutex") );
+ //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("msg_pending_func ==> UNlock mutex") );
dbus_message_get_args(message, &err, DBUS_TYPE_INT32, &replyArg, DBUS_TYPE_INVALID);
}
dbus_message_unref(message);
// unlock the mutex because we have received the reply to the dbus message
- printf("msg_pending_func => mutex unlock: %s \n",(char*)(data));
pthread_mutex_unlock(&gDbusPendingRegMtx);
- printf("msg_pending_func <= mutex unlock\n");
}
pthread_cond_t gDbusInitializedCond = PTHREAD_COND_INITIALIZER;
pthread_mutex_t gDbusInitializedMtx = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t gDbusPendingRegMtx = PTHREAD_MUTEX_INITIALIZER;
-int gEfds = 0;
+pthread_mutex_t gMainLoopMtx = PTHREAD_MUTEX_INITIALIZER;
+
+int gEfds;
+
typedef enum EDBusObjectType
{
// enable locking of data structures in the D-Bus library for multi threading.
dbus_threads_init_default();
-
dbus_error_init(&err);
// wain until dbus main loop has been setup and running
else if (NULL != conn)
{
dbus_connection_set_exit_on_disconnect(conn, FALSE);
- if (-1 == (gEfds = eventfd(0, EFD_NONBLOCK)))
+ if (-1 == (gEfds = eventfd(0, 0)))
{
DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop => eventfd() failed w/ errno:"), DLT_INT(errno) );
}
if (0>ret)
{
DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop => read() failed"), DLT_STRING(strerror(errno)) );
- printf(" * mainloop: read F A I L E D\n");
}
else if (ret != -1)
{
- printf(" * mainloop: dispatch command => [0]: %d | [1]: %d | [2]: %d\n", buf[0], buf[1], buf[2]);
switch (buf[0])
{
case CMD_PAS_BLOCK_AND_WRITE_BACK:
process_block_and_write_data_back((buf[2]), buf[1]);
break;
case CMD_LC_PREPARE_SHUTDOWN:
- printf(" CMD => Prepare shutdown\n");
process_prepare_shutdown((buf[2]), buf[1]);
break;
case CMD_SEND_NOTIFY_SIGNAL:
- printf(" CMD => Send notification signal\n");
process_send_notification_signal(conn);
break;
case CMD_REG_NOTIFY_SIGNAL:
- printf(" CMD => Register notification signal\n");
process_reg_notification_signal(conn);
break;
case CMD_SEND_PAS_REQUEST:
- printf(" CMD => Admin request => request: %d | status: %d\n", (buf[2]), buf[1]);
process_send_pas_request(conn, (buf[2]), buf[1]);
break;
case CMD_SEND_PAS_REGISTER:
- printf(" CMD => Admin register => mode: %d | type: %d\n", (buf[2]), buf[1]);
process_send_pas_register(conn, (buf[1]), buf[2]);
break;
case CMD_SEND_LC_REQUEST:
- printf(" CMD => Lifecycle request => request: %d | status\n", (buf[2]), buf[1]);
process_send_lifecycle_request(conn, (buf[2]), buf[1]);
break;
case CMD_SEND_LC_REGISTER:
- printf(" CMD => Lifecycle register => mode: %d | type: %d\n", (buf[2]), buf[1]);
process_send_lifecycle_register(conn, (buf[1]), buf[2]);
break;
case CMD_QUIT:
DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop => command not handled"), DLT_INT(buf[0]) );
break;
}
+ pthread_mutex_unlock(&gMainLoopMtx);
}
}
}
return 0;
}
+
+
+int deliverToMainloop(tCmd mainloopCmd, unsigned int param1, unsigned int param2)
+{
+ int rval = 0;
+ uint64_t cmd;
+ uint16_t* cmd_chk;
+
+ pthread_mutex_lock(&gMainLoopMtx);
+
+ cmd = ( ((uint64_t)param2 << 32) | ((uint64_t)param1 << 16) | mainloopCmd);
+
+ if(-1 == write(gEfds, &cmd, (sizeof(uint64_t))))
+ {
+ DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("deliverToMainloop => failed to write to pipe"), DLT_INT(errno));
+ rval = -1;
+ }
+
+ return rval;
+}
+
int setup_dbus_mainloop(void);
+int deliverToMainloop(tCmd mainloopCmd, unsigned int param1, unsigned int param2);
+
#endif /* PERSISTENCE_CLIENT_LIBRARY_DBUS_SERVICE_H_ */
{
case NsmShutdownNormal:
{
- uint64_t cmd;
- // add command and data to queue
- cmd = ( ((uint64_t)requestID << 32) | ((uint64_t)request << 16) | CMD_LC_PREPARE_SHUTDOWN);
-
- if(-1 == write(gEfds, &cmd, (sizeof(uint64_t))))
+ if(-1 == deliverToMainloop(CMD_LC_PREPARE_SHUTDOWN, request, requestID) )
{
DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("check_lc_request => failed to write to pipe"), DLT_INT(errno));
rval = NsmErrorStatus_Fail;
int register_lifecycle(int shutdownMode)
{
- int rval = 0;
- uint64_t cmd;
- uint16_t* cmd_chk;
-
- cmd = ( ((uint64_t)shutdownMode << 32) | ((uint64_t)1 << 16) | CMD_SEND_LC_REGISTER);
- cmd_chk = &cmd;
- printf("register_lifecycle => cmd_chk: [0]: %d | [1]: %d | [2]: %d \n", cmd_chk[0],cmd_chk[1],cmd_chk[2]);
-
- if(-1 == write(gEfds, &cmd, (sizeof(uint64_t))))
- {
- DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("register_lifecycle => failed to write to pipe"), DLT_INT(errno));
- rval = -1;
- }
- printf("register_lifecycle <= \n\n");
- return rval;
+ return deliverToMainloop(CMD_SEND_LC_REGISTER, 1, shutdownMode);
}
int unregister_lifecycle(int shutdownMode)
{
- int rval = 0;
- uint64_t cmd;
- uint16_t* cmd_chk;
-
- cmd = ( ((uint64_t)shutdownMode << 32) | ((uint64_t)0 << 16) | CMD_SEND_LC_REGISTER);
- cmd_chk = &cmd;
- printf("unregister_lifecycle => cmd_chk: [0]: %d | [1]: %d | [2]: %d \n", cmd_chk[0],cmd_chk[1],cmd_chk[2]);
- if(-1 == write(gEfds, &cmd, (sizeof(uint64_t))))
- {
- DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("unregister_lifecycle => failed to write to pipe"), DLT_INT(errno));
- rval = -1;
- }
- printf("unregister_lifecycle <= \n\n");
- return rval;
+ return deliverToMainloop(CMD_SEND_LC_REGISTER, 0, shutdownMode);
}
int send_prepare_shutdown_complete(int requestId, int status)
{
- int rval = 0;
- uint64_t cmd;
- uint16_t* cmd_chk;
-
- cmd = ( ((uint64_t)requestId << 32) | ((uint64_t)status << 16) | CMD_SEND_LC_REQUEST);
- cmd_chk = &cmd;
- //printf("cmd_chk: [0]: %d | [1]: %d | [2]: %d \n", cmd_chk[0],cmd_chk[1],cmd_chk[2]);
- if(-1 == write(gEfds, &cmd, (sizeof(uint64_t))))
- {
- DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("send_prepare_shutdown_complete => failed to write to pipe"), DLT_INT(errno));
- rval = -1;
- }
-
- return rval;
+ return deliverToMainloop(CMD_SEND_LC_REQUEST, status, requestId);
}
{
case (PasMsg_Block|PasMsg_WriteBack):
{
- uint64_t cmd;
- // add command and data to queue
- cmd = ( ((uint64_t)requestID << 32) | ((uint64_t)request << 16) | CMD_PAS_BLOCK_AND_WRITE_BACK);
-
- if(-1 == write(gEfds, &cmd, (sizeof(uint64_t))))
+ if(-1 == deliverToMainloop(CMD_PAS_BLOCK_AND_WRITE_BACK, request, requestID))
{
DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("write failed w/ errno "), DLT_INT(errno), DLT_STRING(strerror(errno)));
rval = PasErrorStatus_FAIL;
int register_pers_admin_service(void)
{
int rval = 0;
- uint64_t cmd;
- uint16_t* cmd_chk;
-
-
- // register for everything
- int notificationFlag = PasMsg_Block | PasMsg_WriteBack | PasMsg_Unblock;
- cmd = ( ((uint64_t)notificationFlag << 32) | ((uint64_t)1 << 16) | CMD_SEND_PAS_REGISTER);
- cmd_chk = &cmd;
- printf("register_pers_admin_service => cmd_chk: [0]: %d | [1]: %d | [2]: %d \n", cmd_chk[0],cmd_chk[1],cmd_chk[2]);
- if(-1 == write(gEfds, &cmd, (sizeof(uint64_t))))
+ if(-1 == deliverToMainloop(CMD_SEND_PAS_REGISTER, 1, (PasMsg_Block | PasMsg_WriteBack | PasMsg_Unblock)))
{
DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("register_pers_admin_service => failed to write to pipe"), DLT_INT(errno));
rval = -1;
}
else
{
- printf(" register_pers_admin_service => Mutex Lock\n");
pthread_mutex_lock(&gDbusPendingRegMtx); // block until pending received
- printf(" register_pers_admin_service <= Mutex Lock\n");
rval = gDbusPendingRvalue;
}
- printf("register_pers_admin_service <= \n\n");
return rval;
}
int unregister_pers_admin_service(void)
{
int rval = 0;
- uint64_t cmd;
- uint16_t* cmd_chk;
- // register for everything
- int notificationFlag = PasMsg_Block | PasMsg_WriteBack | PasMsg_Unblock;
-
- cmd = ( ((uint64_t)notificationFlag << 32) | ((uint64_t)0 << 16) | CMD_SEND_PAS_REGISTER);
- cmd_chk = &cmd;
- printf("unregister_pers_admin_service => cmd_chk: [0]: %d | [1]: %d | [2]: %d \n", cmd_chk[0],cmd_chk[1],cmd_chk[2]);
-
- if(-1 == write(gEfds, &cmd, (sizeof(uint64_t))))
+ if(-1 == deliverToMainloop(CMD_SEND_PAS_REGISTER, 0, (PasMsg_Block | PasMsg_WriteBack | PasMsg_Unblock)))
{
DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("unregister_pers_admin_service => failed to write to pipe"), DLT_INT(errno));
rval = -1;
}
else
{
- printf(" UnRegister admin => Mutex Lock\n");
pthread_mutex_lock(&gDbusPendingRegMtx); // block until pending received
- printf(" UnRegister admin<= Mutex Lock\n");
rval = gDbusPendingRvalue;
}
- printf("unregister_pers_admin_service <=\n\n");
return rval;
}
int pers_admin_service_data_sync_complete(unsigned int requestID, unsigned int status)
{
int rval = 0;
- uint64_t cmd;
- // add command and data to queue
- cmd = ( ((uint64_t)requestID << 32) | ((uint64_t)status << 16) | CMD_SEND_PAS_REQUEST);
- if(-1 == write(gEfds, &cmd, (sizeof(uint64_t))))
+
+ if(-1 == deliverToMainloop(CMD_SEND_PAS_REQUEST, status, requestID))
{
DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_admin_service_data_sync_complete => failed to write to pipe"), DLT_INT(errno));
- printf("pers_admin_service_data_sync_complete => f a i l e d to write to pipe\n");
rval = -1;
}
else
ret = pclInitLibrary(gTheAppId, shutdownReg);
fail_unless(ret <= 1, "Failed to init PCL");
-#if 0
+#if 1
/**
* Logical DB ID: 0xFF with user 0 and seat 0
* ==> local value accessible by all users (user 0, seat 0)
ret = pclInitLibrary(gTheAppId, shutdownReg);
fail_unless(ret <= 1, "Failed to init PCL");
-#if 0
+#if 1
time_t t = time(0);
locTime = localtime(&t);
ret = pclInitLibrary(gTheAppId, shutdownReg);
fail_unless(ret <= 1, "Failed to init PCL");
-#if 0
+#if 1
time_t t = time(0);
locTime = localtime(&t);
ret = pclInitLibrary(gTheAppId, shutdownReg);
fail_unless(ret <= 1, "Failed to init PCL");
-#if 0
+#if 1
time_t t = time(0);
char sysTimeBuffer[128];
ret = pclInitLibrary(gTheAppId, shutdownReg);
fail_unless(ret <= 1, "Failed to init PCL");
-#if 0
+#if 1
/**
* Logical DB ID: 0xFF with user 3 and seat 2
* ==> local USER value (user 3, seat 2)
rval = pclInitLibrary(gTheAppId, shutdownReg);
fail_unless(rval <= 1, "Failed to init PCL");
-#if 0
+#if 1
// read data from key
rval = pclKeyReadData(0xFF, "key_70", 1, 2, buffer, READ_SIZE);
fail_unless(rval != EPERS_NOKEY, "Read form key key_70 fails");
ret = pclInitLibrary(gTheAppId, shutdownReg);
fail_unless(ret <= 1, "Failed to init PCL");
-#if 0
+#if 1
writeBuffer = malloc(writeSize);
ret = pclInitLibrary(gTheAppId, shutdownReg);
fail_unless(ret <= 1, "Failed to init PCL");
-#if 0
+#if 1
// test backup creation --------------------------------------------
fd_RO = pclFileOpen(0xFF, "media/mediaDB_ReadOnly.db", 1, 1);
fail_unless(fd_RO != -1, "Could not open file ==> /media/mediaDB_ReadOnly.db");
ret = pclInitLibrary(gTheAppId, shutdownReg);
fail_unless(ret <= 1, "Failed to init PCL");
-#if 0
+#if 1
// test file handles
handle1 = pclFileOpen(0xFF, "media/mediaDB.db", 1, 1);
fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB.db");
ret = pclInitLibrary(gTheAppId, shutdownReg);
fail_unless(ret <= 1, "Failed to init PCL");
-#if 0
+#if 1
// open handles ----------------------------------------------------
hd1 = pclKeyHandleOpen(0xFF, "posHandle/last_position1", 0, 0);
fail_unless(hd1 == 1, "Failed to open handle ==> /posHandle/last_position1");
rval = pclInitLibrary(gTheAppId, shutdownReg);
fail_unless(rval <= 1, "Failed to init PCL");
-#if 0
+#if 1
// create cursor
handle = pers_db_cursor_create("/Data/mnt-c/lt-persistence_client_library_test/cached.itz");
fail_unless(handle != -1, "Failed to create cursor!!");
ret = pclInitLibrary(gTheAppId, shutdownReg);
fail_unless(ret <= 1, "Failed to init PCL");
-#if 0
+#if 1
ret = pclKeyReadData(0xFF, "language/country_code", 0, 0, buffer, READ_SIZE);
fail_unless(ret != EPERS_NOT_INITIALIZED);
fail_unless(strncmp((char*)buffer,"Custom plugin -> plugin_get_data: secure!",
ret = pclInitLibrary(gTheAppId, shutdownReg);
fail_unless(ret <= 1, "Failed to init PCL");
-#if 0
+#if 1
ret = pclKeyReadData(0xFF, "statusHandle/default01", 3, 2, buffer, READ_SIZE);
fail_unless(ret != EPERS_NOT_INITIALIZED);
//printf("B U F F E R: %s\n", buffer);
ret = pclInitLibrary(gTheAppId, shutdownReg);
fail_unless(ret <= 1, "Failed to init PCL");
-#if 0
+#if 1
ret = pclKeyReadData(0xFF, "statusHandle/confdefault01", 3, 2, buffer, READ_SIZE);
fail_unless(ret != EPERS_NOT_INITIALIZED);
fail_unless(strncmp((char*)buffer,"CONF_DEFAULT_01!", strlen((char*)buffer)) == 0, "Buffer not correctly read");
ret = pclInitLibrary(gTheAppId, shutdownReg);
fail_unless(ret <= 1, "Failed to init PCL");
-#if 0
+#if 1
ret = pclFileCreatePath(0xFF, "media/mediaDB.db", 1, 1, &path, &pathSize);
//printf("PATH: %s \n", path);
fail_unless(strncmp((char*)path, thePath, strlen((char*)path)) == 0, "Path not correct");