telepathy-glib: Fire the 'failed' signal when channel is invalidated

Guillaume Desmottes gdesmott at kemper.freedesktop.org
Mon Apr 30 02:47:39 PDT 2012


Module: telepathy-glib
Branch: master
Commit: fa2cbf7cb4153fa0f18ed2606cb9dfbca060bfc8
URL:    http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=fa2cbf7cb4153fa0f18ed2606cb9dfbca060bfc8

Author: Guillaume Desmottes <guillaume.desmottes at collabora.co.uk>
Date:   Tue Apr 17 17:42:10 2012 +0200

Fire the 'failed' signal when channel is invalidated

---

 telepathy-glib/room-list.c |   24 ++++++++++++++++++++++++
 tests/dbus/room-list.c     |   40 +++++++++++++++++++++++++++++++++++++++-
 2 files changed, 63 insertions(+), 1 deletions(-)

diff --git a/telepathy-glib/room-list.c b/telepathy-glib/room-list.c
index 080cb64..c6c7290 100644
--- a/telepathy-glib/room-list.c
+++ b/telepathy-glib/room-list.c
@@ -71,6 +71,7 @@ struct _TpRoomListPrivate
   TpChannel *channel;
 
   GSimpleAsyncResult *async_res;
+  gulong invalidated_id;
 };
 
 enum
@@ -195,6 +196,10 @@ tp_room_list_dispose (GObject *object)
   void (*chain_up) (GObject *) =
       ((GObjectClass *) tp_room_list_parent_class)->dispose;
 
+  if (self->priv->channel != NULL)
+    g_signal_handler_disconnect (self->priv->channel,
+        self->priv->invalidated_id);
+
   destroy_channel (self);
   g_clear_object (&self->priv->account);
 
@@ -397,6 +402,22 @@ tp_room_list_start (TpRoomList *self)
 }
 
 static void
+chan_invalidated_cb (TpChannel *channel,
+    guint domain,
+    gint code,
+    gchar *message,
+    TpRoomList *self)
+{
+  GError *error = g_error_new_literal (domain, code, message);
+
+  DEBUG ("RoomList channel invalidated: %s", message);
+
+  g_signal_emit (self, signals[SIG_FAILED], 0, error);
+
+  g_error_free (error);
+}
+
+static void
 create_channel_cb (GObject *source_object,
     GAsyncResult *result,
     gpointer user_data)
@@ -420,6 +441,9 @@ create_channel_cb (GObject *source_object,
 
   DEBUG ("Got channel: %s", tp_proxy_get_object_path (self->priv->channel));
 
+  self->priv->invalidated_id = tp_g_signal_connect_object (self->priv->channel,
+      "invalidated", G_CALLBACK (chan_invalidated_cb), self, 0);
+
   if (tp_cli_channel_type_room_list_connect_to_got_rooms (self->priv->channel,
         got_rooms_cb, NULL, NULL, G_OBJECT (self), &error) == NULL)
     {
diff --git a/tests/dbus/room-list.c b/tests/dbus/room-list.c
index 572bca7..2bdf8b8 100644
--- a/tests/dbus/room-list.c
+++ b/tests/dbus/room-list.c
@@ -247,12 +247,14 @@ static void
 test_list_room_fails (Test *test,
     gconstpointer data G_GNUC_UNUSED)
 {
+  gulong id;
+
   /* Use magic server to tell to the channel to fail ListRooms() */
   tp_clear_object (&test->room_list);
 
   create_room_list (test, "ListRoomsFail");
 
-  g_signal_connect (test->room_list, "failed",
+  id = g_signal_connect (test->room_list, "failed",
       G_CALLBACK (room_list_failed_cb), test);
 
   tp_room_list_start (test->room_list);
@@ -260,6 +262,40 @@ test_list_room_fails (Test *test,
   test->wait = 1;
   g_main_loop_run (test->mainloop);
   g_assert_error (test->error, TP_ERRORS, TP_ERROR_SERVICE_CONFUSED);
+
+  /* We don't want the 'failed' cb be called when disconnecting the
+   * connection */
+  g_signal_handler_disconnect (test->room_list, id);
+}
+
+static void
+test_invalidated (Test *test,
+    gconstpointer data G_GNUC_UNUSED)
+{
+  const gchar *path;
+  TpChannel *chan;
+  gulong id;
+
+  id = g_signal_connect (test->room_list, "failed",
+      G_CALLBACK (room_list_failed_cb), test);
+
+  /* Create a proxy on the room list channel to close it */
+  path = tp_tests_simple_connection_ensure_room_list_chan (
+      TP_TESTS_SIMPLE_CONNECTION (test->base_connection), SERVER, NULL);
+
+  chan = tp_channel_new (test->connection, path,
+      TP_IFACE_CHANNEL_TYPE_ROOM_LIST, TP_HANDLE_TYPE_NONE, 0,
+      &test->error);
+  g_assert_no_error (test->error);
+
+  tp_channel_close_async (chan, NULL, NULL);
+  g_object_unref (chan);
+
+  test->wait = 1;
+  g_main_loop_run (test->mainloop);
+  g_assert_error (test->error, TP_DBUS_ERRORS, TP_DBUS_ERROR_OBJECT_REMOVED);
+
+  g_signal_handler_disconnect (test->room_list, id);
 }
 
 int
@@ -277,6 +313,8 @@ main (int argc,
       test_listing, teardown);
   g_test_add ("/room-list-channel/list-rooms-fail", Test, NULL, setup,
       test_list_room_fails, teardown);
+  g_test_add ("/room-list-channel/invalidated", Test, NULL, setup,
+      test_invalidated, teardown);
 
   return g_test_run ();
 }



More information about the telepathy-commits mailing list