telepathy-mission-control: _mcd_channel_depart: use tp_channel_leave_async or tp_channel_close_async

Simon McVittie smcv at kemper.freedesktop.org
Thu Sep 12 03:38:44 PDT 2013


Module: telepathy-mission-control
Branch: master
Commit: fe1e8ce4b830f665fbe098b1928969d26c553441
URL:    http://cgit.freedesktop.org/telepathy/telepathy-mission-control/commit/?id=fe1e8ce4b830f665fbe098b1928969d26c553441

Author: Simon McVittie <simon.mcvittie at collabora.co.uk>
Date:   Tue Sep 10 12:00:14 2013 +0100

_mcd_channel_depart: use tp_channel_leave_async or tp_channel_close_async

This avoids some deprecated APIs, and is considerably simpler.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=55391
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=55392
Signed-off-by: Simon McVittie <simon.mcvittie at collabora.co.uk>
Reviewed-by: Xavier Claessens <xavier.claessens at collabora.co.uk>

---

 src/mcd-channel.c |   52 ++++++++++++++++++++++------------------------------
 1 files changed, 22 insertions(+), 30 deletions(-)

diff --git a/src/mcd-channel.c b/src/mcd-channel.c
index cba836c..fe2b032 100644
--- a/src/mcd-channel.c
+++ b/src/mcd-channel.c
@@ -1124,20 +1124,22 @@ mcd_channel_get_tp_channel (McdChannel *channel)
 }
 
 static void
-mcd_channel_depart_cb (TpChannel *channel,
-                       const GError *error,
-                       gpointer data G_GNUC_UNUSED,
-                       GObject *weak_object G_GNUC_UNUSED)
+mcd_channel_depart_cb (GObject *source_object,
+                       GAsyncResult *result,
+                       gpointer data G_GNUC_UNUSED)
 {
-    if (error == NULL)
+    GError *error = NULL;
+
+    /* By this point, TpChannel has already called Close() for us;
+     * we only get an error if that failed. If Close() fails, there's
+     * not a whole lot we can do about it. */
+
+    if (!tp_channel_leave_finish (TP_CHANNEL (source_object), result, &error))
     {
-        DEBUG ("successful");
-        return;
+        WARNING ("failed to depart, even via Close(): %s %d: %s",
+               g_quark_to_string (error->domain), error->code, error->message);
+        g_error_free (error);
     }
-
-    DEBUG ("failed to depart, calling Close instead: %s %d: %s",
-           g_quark_to_string (error->domain), error->code, error->message);
-    tp_cli_channel_call_close (channel, -1, NULL, NULL, NULL, NULL);
 }
 
 typedef struct {
@@ -1164,22 +1166,10 @@ mcd_channel_ready_to_depart_cb (GObject *source_object,
         return;
     }
 
-    if (tp_proxy_has_interface_by_id (channel,
-                                      TP_IFACE_QUARK_CHANNEL_INTERFACE_GROUP))
-    {
-        GArray *a = g_array_sized_new (FALSE, FALSE, sizeof (guint), 1);
-        guint self_handle = tp_channel_group_get_self_handle (channel);
-
-        g_array_append_val (a, self_handle);
-
-        tp_cli_channel_interface_group_call_remove_members_with_reason (
-            channel, -1, a, d->message, d->reason,
-            mcd_channel_depart_cb, NULL, NULL, NULL);
-
-        g_array_unref (a);
-        g_free (d->message);
-        g_slice_free (DepartData, d);
-    }
+    /* If it's a Group, this will leave gracefully.
+     * If not, it will just close it. Either's good. */
+    tp_channel_leave_async (channel, d->reason, d->message,
+                            mcd_channel_depart_cb, NULL);
 }
 
 void
@@ -1189,6 +1179,7 @@ _mcd_channel_depart (McdChannel *channel,
 {
     DepartData *d;
     const GError *invalidated;
+    GQuark just_group_feature[] = { TP_CHANNEL_FEATURE_GROUP, 0 };
 
     g_return_if_fail (MCD_IS_CHANNEL (channel));
 
@@ -1207,8 +1198,7 @@ _mcd_channel_depart (McdChannel *channel,
     if (message[0] == '\0' && reason == TP_CHANNEL_GROUP_CHANGE_REASON_NONE)
     {
         /* exactly equivalent to Close(), so skip the Group interface */
-        tp_cli_channel_call_close (channel->priv->tp_chan, -1,
-                                   NULL, NULL, NULL, NULL);
+        tp_channel_close_async (channel->priv->tp_chan, NULL, NULL);
         return;
     }
 
@@ -1216,7 +1206,9 @@ _mcd_channel_depart (McdChannel *channel,
     d->reason = reason;
     d->message = g_strdup (message);
 
-    tp_proxy_prepare_async (channel->priv->tp_chan, NULL,
+    /* tp_channel_leave_async documents calling it without first preparing
+     * GROUP as deprecated. */
+    tp_proxy_prepare_async (channel->priv->tp_chan, just_group_feature,
                             mcd_channel_ready_to_depart_cb, d);
 }
 



More information about the telepathy-commits mailing list