missing copyright section added, and few typo fixes
[profile/ivi/message-port.git] / daemon / dbus-server.c
index eaa755e..1b5bb01 100644 (file)
@@ -1,7 +1,7 @@
 /* vi: set et sw=4 ts=4 cino=t0,(0: */
 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /*
- * Copyright (C) 2012 Intel Corporation.
+ * Copyright (C) 2013 Intel Corporation.
  *
  * Contact: Amarnath Valluri <amarnath.valluri@linux.intel.com>
  *
@@ -20,6 +20,7 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA
  */
+
 #include <errno.h>
 #include <string.h>
 #include <gio/gio.h>
@@ -29,7 +30,6 @@
 #include "common/log.h"
 #include "dbus-server.h"
 #include "dbus-manager.h"
-#include "manager.h"
 
 
 G_DEFINE_TYPE (MsgPortDbusServer, msgport_dbus_server, G_TYPE_OBJECT)
@@ -38,10 +38,6 @@ G_DEFINE_TYPE (MsgPortDbusServer, msgport_dbus_server, G_TYPE_OBJECT)
 #define MSGPORT_DBUS_SERVER_GET_PRIV(obj) \
     G_TYPE_INSTANCE_GET_PRIVATE ((obj), MSGPORT_TYPE_DBUS_SERVER, MsgPortDbusServerPrivate)
 
-#ifndef MSGPORT_DBUS_ADDRESS
-#   define MSGPORT_DBUS_ADDRESS "unix:path=%s/.message_port"
-#endif /* MSGPORT_DBUS_ADDRESS */
-
 enum
 {
     PROP_0,
@@ -56,7 +52,6 @@ struct _MsgPortDbusServerPrivate
 {
     GDBusServer    *bus_server;
     gchar          *address;
-    MsgPortManager *manager;
     GHashTable     *dbus_managers; /* {GDBusConnection,MsgPortDbusManager} */
 };
 
@@ -174,7 +169,6 @@ msgport_dbus_server_init (MsgPortDbusServer *self)
     self->priv->bus_server = NULL;
     self->priv->address = NULL;
 
-    self->priv->manager = msgport_manager_new ();
     self->priv->dbus_managers = g_hash_table_new_full (
         g_direct_hash, g_direct_equal, NULL, g_object_unref);
 }
@@ -208,11 +202,17 @@ msgport_dbus_server_start_dbus_manager_for_connection (
     GDBusConnection *connection)
 {
     MsgPortDbusManager *dbus_manager = NULL;
+    GError *error = NULL;
 
     DBG("Starting dbus manager on connection %p", connection);
 
     dbus_manager = msgport_dbus_manager_new (
-        connection, server, server->priv->manager);
+        connection, server, &error);
+    if (!dbus_manager) {
+        WARN ("Could not create dbus manager on conneciton %p: %s", connection, error->message);
+        g_error_free (error);
+        return;
+    }
 
     g_hash_table_insert (server->priv->dbus_managers, connection, dbus_manager);
 
@@ -223,11 +223,8 @@ static gboolean
 _on_client_request (GDBusServer *dbus_server, GDBusConnection *connection, gpointer userdata)
 {
     MsgPortDbusServer *server = MSGPORT_DBUS_SERVER(userdata);
-
-    if (!server) {
-        ERR ("memory corruption");
-        return TRUE;
-    }
+    
+    g_return_val_if_fail (server && MSGPORT_IS_DBUS_SERVER (server), FALSE);
 
     msgport_dbus_server_start_dbus_manager_for_connection (server, connection);
 
@@ -289,7 +286,18 @@ MsgPortDbusServer * msgport_dbus_server_new_with_address (const gchar *address)
 MsgPortDbusServer *
 msgport_dbus_server_new () {
        MsgPortDbusServer *server = NULL;
-       gchar *address = g_strdup_printf (MSGPORT_DBUS_ADDRESS, g_get_user_runtime_dir());
+       gchar *address = NULL;
+
+    if (g_getenv("MESSAGEPORT_BUS_ADDRESS")) {
+        address = g_strdup (g_getenv ("MESSAGEPORT_BUS_ADDRESS"));
+    }
+    else {
+#       ifdef MESSAGEPORT_BUS_ADDRESS
+           address = g_strdup_printf (MESSAGEPORT_BUS_ADDRESS);
+#       endif
+    }
+    if (!address)
+        address = g_strdup_printf ("unix:path=%s/.message-port", g_get_user_runtime_dir());
 
     server = msgport_dbus_server_new_with_address (address);
     g_free (address);
@@ -297,14 +305,6 @@ msgport_dbus_server_new () {
     return server ;
 }
 
-MsgPortManager *
-msgport_dbus_server_get_manager (MsgPortDbusServer *server)
-{
-    g_return_val_if_fail (server && MSGPORT_IS_DBUS_SERVER (server), NULL);
-
-    return server->priv->manager;
-}
-
 static gboolean
 _find_dbus_manager_by_app_id (
     GDBusConnection *key,