From 2d45eabb19347b2b9b05f5fadff8b07ef4c1ad27 Mon Sep 17 00:00:00 2001 From: Michael Schuldt Date: Thu, 8 Sep 2011 12:54:56 +0200 Subject: [PATCH] Introducing changing used bus via environment variable. Enable LM_USE_SESSION_BUS via export LM_USE_SESSION_BUS=enable to use DBUS_BUS_SESSION instead of DBUS_BUS_SYSTEM --- LayerManagerClient/ilmClient/src/ilm_client.c | 27 +++++++++------------- .../DBUSCommunicator/src/DBUSMessageHandler.cpp | 17 ++++++++++++-- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/LayerManagerClient/ilmClient/src/ilm_client.c b/LayerManagerClient/ilmClient/src/ilm_client.c index a3f7a10..c9a9a4d 100644 --- a/LayerManagerClient/ilmClient/src/ilm_client.c +++ b/LayerManagerClient/ilmClient/src/ilm_client.c @@ -39,7 +39,16 @@ ilmErrorTypes ilm_init() g_ilm_init = ILM_TRUE; // initialize the dbus connection dbus_error_init(&g_ilm_client->dbus_error); - g_ilm_client->dbus_type = DBUS_BUS_SYSTEM; + char* useSessionBus = getenv("LM_USE_SESSION_BUS"); + if ( NULL != useSessionBus && strcmp(useSessionBus,"enable") == 0 ) + { + g_ilm_client->dbus_type = DBUS_BUS_SESSION; + } + else + { + g_ilm_client->dbus_type = DBUS_BUS_SYSTEM; + } + g_ilm_client->dbus_connection = dbus_bus_get(g_ilm_client->dbus_type, &g_ilm_client->dbus_error); if (!g_ilm_client->dbus_connection) { @@ -48,21 +57,7 @@ ilmErrorTypes ilm_init() } else { -/* // request name on connection - dbus_bus_request_name(g_ilm_client->dbus_connection, - ILM_INTERFACE_COMPOSITE_CLIENT, - DBUS_NAME_FLAG_REPLACE_EXISTING, - &g_ilm_client->dbus_error); - - if (dbus_error_is_set(&g_ilm_client->dbus_error)) - { - ILM_ERROR("ilm_init","Can not request name\n"); - dbus_error_free(&g_ilm_client->dbus_error); - } - else - {*/ - result = ILM_SUCCESS; -/* }*/ + result = ILM_SUCCESS; } } } diff --git a/LayerManagerPlugins/Communicators/DBUSCommunicator/src/DBUSMessageHandler.cpp b/LayerManagerPlugins/Communicators/DBUSCommunicator/src/DBUSMessageHandler.cpp index 15dbad9..2c0a54a 100644 --- a/LayerManagerPlugins/Communicators/DBUSCommunicator/src/DBUSMessageHandler.cpp +++ b/LayerManagerPlugins/Communicators/DBUSCommunicator/src/DBUSMessageHandler.cpp @@ -2,6 +2,7 @@ #include "DBUSMessageHandler.h" #include "DBUSConfiguration.h" #include +#include #include "Log.h" DBUSMessageHandler::DBUSMessageHandler() @@ -13,7 +14,18 @@ DBUSMessageHandler::DBUSMessageHandler() dbus_error_init(&m_err); // connect to the bus and check for errors - m_pConnection = dbus_bus_get(DBUS_BUS_SYSTEM, &m_err); + char* useSessionBus = getenv("LM_USE_SESSION_BUS"); + if ( NULL != useSessionBus && strcmp(useSessionBus,"enable") == 0 ) + { + LOG_INFO("DBUSCommunicator", "Using Session Bus"); + m_pConnection = dbus_bus_get(DBUS_BUS_SESSION, &m_err); + } + else + { + LOG_INFO("DBUSCommunicator", "Using System Bus"); + m_pConnection = dbus_bus_get(DBUS_BUS_SYSTEM, &m_err); + } + if (dbus_error_is_set(&m_err)) { LOG_ERROR("DBUSCommunicator","Connection error"); @@ -50,7 +62,8 @@ DBUSMessageHandler::~DBUSMessageHandler() { LOG_ERROR("DBUSCommunicator","there was an dbus error"); } - LOG_INFO("ask about owner name",0); + dbus_connection_unregister_object_path(m_pConnection,DBUS_SERVICE_OBJECT_PATH); + LOG_INFO("DBUSCommunicator","Ask about owner name"); dbus_bus_name_has_owner(m_pConnection, DBUS_SERVICE_PREFIX, &err); errorset = dbus_error_is_set(&err); if (errorset) -- 2.7.4