[empathy] tube-handler: wait that the connection is ready before creating the TpChannel



commit 46fcfa0a1c15e58b98cfec0c1ce998dee6de5a40
Author: Guillaume Desmottes <guillaume desmottes collabora co uk>
Date:   Mon Apr 27 14:19:25 2009 +0100

    tube-handler: wait that the connection is ready before creating the TpChannel
---
 libempathy/empathy-tube-handler.c |   39 ++++++++++++++++++++++++++----------
 1 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/libempathy/empathy-tube-handler.c b/libempathy/empathy-tube-handler.c
index 43e19fd..ec12d18 100644
--- a/libempathy/empathy-tube-handler.c
+++ b/libempathy/empathy-tube-handler.c
@@ -85,21 +85,20 @@ tube_ready_destroy_notify (gpointer data)
   g_slice_free (IdleData, idle_data);
 }
 
-static gboolean
-tube_handler_handle_tube_idle_cb (gpointer data)
+static void
+connection_ready_cb (TpConnection *connection,
+                     const GError *error,
+                     gpointer data)
 {
-  IdleData *idle_data = data;
-  TpConnection *connection;
   TpChannel *channel;
-  static TpDBusDaemon *daemon = NULL;
-
-  DEBUG ("New tube to be handled");
+  IdleData *idle_data = data;
 
-  if (!daemon)
-    daemon = tp_dbus_daemon_new (tp_get_bus ());
+  if (error != NULL)
+    {
+      DEBUG ("connection has been invalidated: %s", error->message);
+      return;
+    }
 
-  connection = tp_connection_new (daemon, idle_data->bus_name,
-      idle_data->connection, NULL);
   channel = tp_channel_new (connection, idle_data->channel,
       TP_IFACE_CHANNEL_TYPE_TUBES, idle_data->handle_type,
       idle_data->handle, NULL);
@@ -111,6 +110,24 @@ tube_handler_handle_tube_idle_cb (gpointer data)
 
   g_object_unref (channel);
   g_object_unref (connection);
+}
+
+static gboolean
+tube_handler_handle_tube_idle_cb (gpointer data)
+{
+  IdleData *idle_data = data;
+  TpConnection *connection;
+  static TpDBusDaemon *daemon = NULL;
+
+  DEBUG ("New tube to be handled");
+
+  if (!daemon)
+    daemon = tp_dbus_daemon_new (tp_get_bus ());
+
+  connection = tp_connection_new (daemon, idle_data->bus_name,
+      idle_data->connection, NULL);
+  tp_connection_call_when_ready (connection,
+      connection_ready_cb, idle_data);
 
   return FALSE;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]