[Telepathy-commits] [telepathy-glib/master] tp_run_connection_manager: ref a TpDBusDaemon for the duration

Simon McVittie simon.mcvittie at collabora.co.uk
Fri Jan 30 06:22:30 PST 2009


This should mean that by the time CM code runs, we already have our
shared bus connection; it also means that tp_dbus_daemon_dup() will
always return the same object within the scope of
tp_run_connection_manager().
---
 telepathy-glib/run.c |   40 ++++++++++++++++++++++++++++++++++++----
 1 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/telepathy-glib/run.c b/telepathy-glib/run.c
index 3b59c56..a7c2f95 100644
--- a/telepathy-glib/run.c
+++ b/telepathy-glib/run.c
@@ -204,6 +204,9 @@ tp_run_connection_manager (const char *prog_name,
 {
   GLogLevelFlags fatal_mask;
   DBusConnection *connection;
+  TpDBusDaemon *bus_daemon = NULL;
+  GError *error = NULL;
+  int ret = 1;
 
   add_signal_handlers ();
 
@@ -236,6 +239,16 @@ tp_run_connection_manager (const char *prog_name,
 
   mainloop = g_main_loop_new (NULL, FALSE);
 
+  bus_daemon = tp_dbus_daemon_dup (&error);
+
+  if (bus_daemon == NULL)
+    {
+      g_warning ("%s", error->message);
+      g_error_free (error);
+      error = NULL;
+      goto out;
+    }
+
   manager = construct_cm ();
 
   g_signal_connect (manager, "new-connection",
@@ -248,12 +261,15 @@ tp_run_connection_manager (const char *prog_name,
    * DBUS_HANDLER_RESULT_HANDLED for signals, so for *our* filter to have any
    * effect, we need to install it before calling
    * tp_base_connection_manager_register () */
-  connection = dbus_g_connection_get_connection (tp_get_bus ());
+  connection = dbus_g_connection_get_connection (
+      ((TpProxy *) bus_daemon)->dbus_connection);
   dbus_connection_add_filter (connection, dbus_filter_function, NULL, NULL);
 
   if (!tp_base_connection_manager_register (manager))
     {
-      return 1;
+      g_object_unref (manager);
+      manager = NULL;
+      goto out;
     }
 
   g_debug ("started version %s (telepathy-glib version %s)", version,
@@ -262,7 +278,23 @@ tp_run_connection_manager (const char *prog_name,
   timeout_id = g_timeout_add (DIE_TIME, kill_connection_manager, NULL);
 
   g_main_loop_run (mainloop);
-  g_main_loop_unref (mainloop);
 
-  return 0;
+  ret = 0;
+
+out:
+  /* locals */
+
+  if (bus_daemon != NULL)
+    g_object_unref (bus_daemon);
+
+  /* globals */
+
+  if (mainloop != NULL)
+    g_main_loop_unref (mainloop);
+
+  mainloop = NULL;
+
+  g_assert (manager == NULL);
+
+  return ret;
 }
-- 
1.5.6.5




More information about the telepathy-commits mailing list