Introducing changing used bus via environment variable.
authorMichael Schuldt <michael.schuldt@bmw-carit.de>
Thu, 8 Sep 2011 10:54:56 +0000 (12:54 +0200)
committerMichael Schuldt <michael.schuldt@bmw-carit.de>
Thu, 8 Sep 2011 11:11:37 +0000 (13:11 +0200)
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
LayerManagerPlugins/Communicators/DBUSCommunicator/src/DBUSMessageHandler.cpp

index a3f7a10..c9a9a4d 100644 (file)
@@ -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;
             }
         }
     }
index 15dbad9..2c0a54a 100644 (file)
@@ -2,6 +2,7 @@
 #include "DBUSMessageHandler.h"
 #include "DBUSConfiguration.h"
 #include <stdlib.h>
+#include <string.h>
 #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)