#include "persistence_client_library_dbus_service.h"
#include "persistence_client_library_lc_interface.h"
#include "persistence_client_library_pas_interface.h"
-#include "../include_protected/persistence_client_library_data_organization.h"
+#include "persistence_client_library_dbus_cmd.h"
+#include "persistence_client_library_data_organization.h"
+
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
+
pthread_cond_t gDbusInitializedCond = PTHREAD_COND_INITIALIZER;
pthread_mutex_t gDbusInitializedMtx = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t gDbusPendingRegMtx = PTHREAD_MUTEX_INITIALIZER;
-pthread_mutex_t gMainLoopMtx = PTHREAD_MUTEX_INITIALIZER;
-pthread_cond_t gMainLoopCond = PTHREAD_COND_INITIALIZER;
-int gEfds;
+pthread_mutex_t gDeliverpMtx = PTHREAD_MUTEX_INITIALIZER;
+
+pthread_mutex_t gMainCondMtx = PTHREAD_MUTEX_INITIALIZER;
+pthread_cond_t gMainLoopCond = PTHREAD_COND_INITIALIZER;
+
+pthread_t gMainLoopThread;
+
+
+int gEfds; // communication channel int dbus mainloop
typedef enum EDBusObjectType
/* function to unregister ojbect path message handler */
static void unregisterMessageHandler(DBusConnection *connection, void *user_data)
{
- DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("unregisterObjectPath\n"));
+ (void)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)
{
DBusHandlerResult result = DBUS_HANDLER_RESULT_HANDLED;
+ (void)user_data;
// org.genivi.persistence.admin S I G N A L
if((0==strcmp("org.genivi.persistence.admin", dbus_message_get_interface(message))))
}
else
{
- DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("handleObjectPathMessageFallback -> unknown signal:"), DLT_STRING(dbus_message_get_interface(message)) );
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("handleObjectPathMessageFallback -> unknown signal:"), DLT_STRING(dbus_message_get_interface(message)) );
}
}
}
if (reply == 0)
{
- DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("handleObjectPathMessageFallback => DBus No memory"), DLT_STRING(dbus_message_get_interface(message)) );
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("handleObjectPathMessageFallback => DBus No memory"), DLT_STRING(dbus_message_get_interface(message)) );
}
if (!dbus_connection_send(connection, reply, 0))
{
- DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("handleObjectPathMessageFallback => DBus No memory"), DLT_STRING(dbus_message_get_interface(message)) );
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("handleObjectPathMessageFallback => DBus No memory"), DLT_STRING(dbus_message_get_interface(message)) );
}
result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;;
}
else
{
- DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("handleObjectPathMessageFallback => gChangeNotifyCallback is not set (possibly NULL)") );
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("handleObjectPathMessageFallback => gChangeNotifyCallback is not set (possibly NULL)") );
}
result = DBUS_HANDLER_RESULT_HANDLED;
}
}
else
{
- DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("handleObjectPathMessageFallback -> unknown property:"), DLT_STRING(dbus_message_get_interface(message)) );
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("handleObjectPathMessageFallback -> unknown property:"), DLT_STRING(dbus_message_get_interface(message)) );
}
}
else
{
- DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("handleObjectPathMessageFallback -> not a signal:"), DLT_STRING(dbus_message_get_member(message)) );
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("handleObjectPathMessageFallback -> not a signal:"), DLT_STRING(dbus_message_get_member(message)) );
}
}
return result;
static void unregisterObjectPathFallback(DBusConnection *connection, void *user_data)
{
- DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("unregisterObjectPathFallback\n"));
+ (void)connection;
+ (void)user_data;
+ DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("unregisterObjectPathFallback\n"));
}
{
// persistence admin message
static const struct DBusObjectPathVTable vtablePersAdmin
- = {unregisterMessageHandler, checkPersAdminMsg, NULL, };
+ = {unregisterMessageHandler, checkPersAdminMsg, NULL, NULL, NULL, NULL};
// lifecycle message
static const struct DBusObjectPathVTable vtableLifecycle
- = {unregisterMessageHandler, checkLifecycleMsg, NULL, };
+ = {unregisterMessageHandler, checkLifecycleMsg, NULL, NULL, NULL, NULL};
// fallback
static const struct DBusObjectPathVTable vtableFallback
- = {unregisterObjectPathFallback, handleObjectPathMessageFallback, NULL, };
+ = {unregisterObjectPathFallback, handleObjectPathMessageFallback, NULL, NULL, NULL, NULL};
// setup the dbus
mainLoop(vtablePersAdmin, vtableLifecycle, vtableFallback, dataPtr);
int setup_dbus_mainloop(void)
{
int rval = 0;
- pthread_t thread;
DBusError err;
DBusConnection* conn = NULL;
dbus_error_init(&err);
- // wain until dbus main loop has been setup and running
+ // wait until dbus main loop has been setup and running
pthread_mutex_lock(&gDbusInitializedMtx);
// Connect to the bus and check for errors
if(pAddress != NULL)
{
- DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("setup_dbus_mainloop -> Use specific dbus address:"), DLT_STRING(pAddress) );
+ DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("setup_dbus_mainloop -> Use specific dbus address:"), DLT_STRING(pAddress) );
conn = dbus_connection_open_private(pAddress, &err);
{
if(!dbus_bus_register(conn, &err))
{
- DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("dbus_bus_register() Error :"), DLT_STRING(err.message) );
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("dbus_bus_register() Error :"), DLT_STRING(err.message) );
dbus_error_free (&err);
pthread_mutex_unlock(&gDbusInitializedMtx);
return -1;
}
else
{
- DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("dbus_connection_open_private() Error :"), DLT_STRING(err.message) );
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("dbus_connection_open_private() Error :"), DLT_STRING(err.message) );
dbus_error_free(&err);
pthread_mutex_unlock(&gDbusInitializedMtx);
return -1;
}
else
{
- DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("Use default dbus bus (DBUS_BUS_SYSTEM)"));
+ DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("Use default dbus bus (DBUS_BUS_SYSTEM)"));
conn = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err);
}
// create here the dbus connection and pass to main loop
- rval = pthread_create(&thread, NULL, run_mainloop, conn);
+ rval = pthread_create(&gMainLoopThread, NULL, run_mainloop, conn);
if(rval)
{
- DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pthread_create( DBUS run_mainloop ) returned an error:"), DLT_INT(rval) );
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pthread_create( DBUS run_mainloop ) returned an error:"), DLT_INT(rval) );
pthread_mutex_unlock(&gDbusInitializedMtx);
return -1;
}
static dbus_bool_t addWatch(DBusWatch *watch, void *data)
{
dbus_bool_t result = FALSE;
+ (void)data;
if (ARRAY_SIZE(gPollInfo.fds)>gPollInfo.nfds)
{
{
void* w_data = dbus_watch_get_data(watch);
- DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("removeWatch called "), DLT_INT( (int)watch) );
+ (void)data;
+
+ DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("removeWatch called "), DLT_INT( (int)watch) );
if(w_data)
free(w_data);
static void watchToggled(DBusWatch *watch, void *data)
{
- DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("watchToggled called "), DLT_INT( (int)watch) );
+ (void)data;
+ DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("watchToggled called "), DLT_INT( (int)watch) );
if(dbus_watch_get_enabled(watch))
addWatch(watch, data);
static dbus_bool_t addTimeout(DBusTimeout *timeout, void *data)
{
+ (void)data;
dbus_bool_t ret = FALSE;
if (ARRAY_SIZE(gPollInfo.fds)>gPollInfo.nfds)
}
else
{
- DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("addTimeout => timerfd_settime() failed"), DLT_STRING(strerror(errno)) );
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("addTimeout => timerfd_settime() failed"), DLT_STRING(strerror(errno)) );
}
}
else
{
- DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("addTimeout => timerfd_create() failed"), DLT_STRING(strerror(errno)) );
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("addTimeout => timerfd_create() failed"), DLT_STRING(strerror(errno)) );
}
}
}
else
{
- DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("addTimeout => cannot create another fd to be poll()'ed"));
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("addTimeout => cannot create another fd to be poll()'ed"));
}
return ret;
static void removeTimeout(DBusTimeout *timeout, void *data)
{
-
int i = gPollInfo.nfds;
+ (void)data;
+
while ((0<i--)&&(timeout!=gPollInfo.objects[i].timeout));
if (0<i)
{
if (-1==close(gPollInfo.fds[i].fd))
{
- DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("removeTimeout => close() timerfd"), DLT_STRING(strerror(errno)) );
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("removeTimeout => close() timerfd"), DLT_STRING(strerror(errno)) );
}
--gPollInfo.nfds;
static void timeoutToggled(DBusTimeout *timeout, void *data)
{
int i = gPollInfo.nfds;
+ (void)data;
+
while ((0<i--)&&(timeout!=gPollInfo.objects[i].timeout));
- DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("timeoutToggled") );
+ DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("timeoutToggled") );
if (0<i)
{
const int interval = (TRUE==dbus_timeout_get_enabled(timeout))?dbus_timeout_get_interval(timeout):0;
const struct itimerspec its = { .it_value= {interval/1000, interval%1000} };
if (-1!=timerfd_settime(gPollInfo.fds[i].fd, 0, &its, NULL))
{
- DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("timeoutToggled => timerfd_settime()"), DLT_STRING(strerror(errno)) );
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("timeoutToggled => timerfd_settime()"), DLT_STRING(strerror(errno)) );
}
}
}
if (dbus_error_is_set(&err))
{
- DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop => Connection Error:"), DLT_STRING(err.message) );
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop => Connection Error:"), DLT_STRING(err.message) );
dbus_error_free(&err);
}
else if (NULL != conn)
dbus_connection_set_exit_on_disconnect(conn, FALSE);
if (-1 == (gEfds = eventfd(0, 0)))
{
- DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop => eventfd() failed w/ errno:"), DLT_INT(errno) );
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop => eventfd() failed w/ errno:"), DLT_INT(errno) );
}
else
{
dbus_bus_add_match(conn, "type='signal',interface='org.genivi.persistence.admin',member='PersistenceModeChanged',path='/org/genivi/persistence/admin'", &err);
// register for messages
- if ( (TRUE==dbus_connection_register_object_path(conn, "/org/genivi/persistence/adminconsumer", &vtable, userData))
- && (TRUE==dbus_connection_register_object_path(conn, "/org/genivi/NodeStateManager/LifeCycleConsumer", &vtable2, userData))
+ if ( (TRUE==dbus_connection_register_object_path(conn, "/org/genivi/NodeStateManager/LifeCycleConsumer", &vtable2, userData))
+#if USE_PASINTERFACE == 1
+ && (TRUE==dbus_connection_register_object_path(conn, "/org/genivi/persistence/adminconsumer", &vtable, userData))
+#endif
&& (TRUE==dbus_connection_register_fallback(conn, "/", &vtableFallback, userData)) )
{
if( (TRUE!=dbus_connection_set_watch_functions(conn, addWatch, removeWatch, watchToggled, NULL, NULL))
|| (TRUE!=dbus_connection_set_timeout_functions(conn, addTimeout, removeTimeout, timeoutToggled, NULL, NULL)) )
{
- DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop => dbus_connection_set_watch_functions() failed"));
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop => dbus_connection_set_watch_functions() failed"));
}
else
{
while (DBUS_DISPATCH_DATA_REMAINS==dbus_connection_dispatch(conn));
- while ((-1==(ret=poll(gPollInfo.fds, gPollInfo.nfds, -1)))&&(EINTR==errno));
+ while ((-1==(ret=poll(gPollInfo.fds, gPollInfo.nfds, 750)))&&(EINTR==errno));
if (0>ret)
{
- DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop => poll() failed w/ errno "), DLT_INT(errno) );
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop => poll() failed w/ errno "), DLT_INT(errno) );
}
else if (0==ret)
{
unsigned long long nExpCount = 0;
if ((ssize_t)sizeof(nExpCount)!=read(gPollInfo.fds[i].fd, &nExpCount, sizeof(nExpCount)))
{
- DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop => read failed"));
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop => read failed"));
}
- DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop => timeout"));
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop => timeout"));
if (FALSE==dbus_timeout_handle(gPollInfo.objects[i].timeout))
{
- DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop => dbus_timeout_handle() failed!?"));
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop => dbus_timeout_handle() failed!?"));
}
bContinue = TRUE;
}
while ((-1==(ret = read(gPollInfo.fds[i].fd, buf, 64)))&&(EINTR == errno));
if(ret < 0)
{
- DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop => read() failed"), DLT_STRING(strerror(errno)) );
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop => read() failed"), DLT_STRING(strerror(errno)) );
}
else
{
- pthread_mutex_lock(&gMainLoopMtx);
+ pthread_mutex_lock(&gMainCondMtx);
switch (buf[0])
{
case CMD_PAS_BLOCK_AND_WRITE_BACK:
process_block_and_write_data_back((buf[2]), buf[1]);
+ process_send_pas_request(conn, (buf[2]), buf[1]);
break;
case CMD_LC_PREPARE_SHUTDOWN:
- process_prepare_shutdown((buf[2]), buf[1]);
+ process_prepare_shutdown(Shutdown_Full);
+ process_send_lifecycle_request(conn, (buf[2]), buf[1]);
break;
case CMD_SEND_NOTIFY_SIGNAL:
process_send_notification_signal(conn);
case CMD_REG_NOTIFY_SIGNAL:
process_reg_notification_signal(conn);
break;
- case CMD_SEND_PAS_REQUEST:
- process_send_pas_request(conn, (buf[2]), buf[1]);
- break;
case CMD_SEND_PAS_REGISTER:
process_send_pas_register(conn, (buf[1]), buf[2]);
break;
- case CMD_SEND_LC_REQUEST:
- process_send_lifecycle_request(conn, (buf[2]), buf[1]);
- break;
case CMD_SEND_LC_REGISTER:
process_send_lifecycle_register(conn, (buf[1]), buf[2]);
break;
case CMD_QUIT:
- bContinue = FALSE;
+ bContinue = 0;
break;
+
+ // ******************************************************
+ /*
+ case CMD_SEND_LC_REQUEST: // remove
+ process_send_lifecycle_request(conn, (buf[2]), buf[1]);
+ break;
+ case CMD_SEND_PAS_REQUEST: /// remove
+ process_send_pas_request(conn, (buf[2]), buf[1]);
+ break;
+ */
+ // ******************************************************
default:
- DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop => command not handled"), DLT_INT(buf[0]) );
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop => command not handled"), DLT_INT(buf[0]) );
break;
}
pthread_cond_signal(&gMainLoopCond);
- pthread_mutex_unlock(&gMainLoopMtx);
+ pthread_mutex_unlock(&gMainCondMtx);
}
}
}
}
while (0!=bContinue);
}
+#if USE_PASINTERFACE == 1
dbus_connection_unregister_object_path(conn, "/org/genivi/persistence/adminconsumer");
+#endif
dbus_connection_unregister_object_path(conn, "/org/genivi/NodeStateManager/LifeCycleConsumer");
dbus_connection_unregister_object_path(conn, "/");
}
int deliverToMainloop(tCmd mainloopCmd, unsigned int param1, unsigned int param2)
{
int rval = 0;
- uint64_t cmd;
- uint16_t* cmd_chk;
- pthread_mutex_lock(&gMainLoopMtx);
+ pthread_mutex_lock(&gDeliverpMtx);
+
+
+ pthread_mutex_lock(&gMainCondMtx);
+
+ deliverToMainloop_NM(mainloopCmd, param1, param2);
+
+ pthread_cond_wait(&gMainLoopCond, &gMainCondMtx);
+ pthread_mutex_unlock(&gMainCondMtx);
+
+
+ pthread_mutex_unlock(&gDeliverpMtx);
+
+ return rval;
+}
+
+int deliverToMainloop_NM(tCmd mainloopCmd, unsigned int param1, unsigned int param2)
+{
+ int rval = 0;
+ uint64_t cmd;
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));
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("deliverToMainloop => failed to write to pipe"), DLT_INT(errno));
rval = -1;
}
- // wait for condition variable
- pthread_cond_wait(&gMainLoopCond, &gMainLoopMtx);
- pthread_mutex_unlock(&gMainLoopMtx);
-
return rval;
}