From 49c1232685c78e477715e10dc26b51faea4f0ec3 Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Thu, 5 Feb 2009 09:07:28 +0000 Subject: [PATCH] Try to short-circuit 5-second wait for contact's presence. Doesn't work, because presences-updated is emitted *before* discos are sent, so we just wind up waiting longer. --- src/media-channel.c | 30 ++++++++++++++++++++++++++++++ 1 files changed, 30 insertions(+), 0 deletions(-) diff --git a/src/media-channel.c b/src/media-channel.c index 0e5fd4c..aeb6625 100644 --- a/src/media-channel.c +++ b/src/media-channel.c @@ -163,6 +163,7 @@ struct _GabbleMediaChannelPrivate struct _delayed_request_streams_ctx { GabbleMediaChannel *chan; gulong caps_disco_id; + gulong presences_updated_id; guint timeout_id; guint contact_handle; GArray *types; @@ -1494,6 +1495,10 @@ destroy_request (struct _delayed_request_streams_ctx *ctx, g_signal_handler_disconnect (priv->conn->presence_cache, ctx->caps_disco_id); + if (ctx->presences_updated_id) + g_signal_handler_disconnect (priv->conn->presence_cache, + ctx->presences_updated_id); + if (ctx->context != NULL) { GError *error = NULL; @@ -1543,6 +1548,28 @@ capabilities_discovered_cb (GabblePresenceCache *cache, } static void +presences_updated_cb (GabblePresenceCache *cache, + GArray *handles, + struct _delayed_request_streams_ctx *ctx) +{ + TpHandle handle; + guint i; + + for (i = 0; i < handles->len; i++) + { + handle = g_array_index (handles, TpHandle, i); + + if (ctx->contact_handle == handle) + { + DEBUG ("presence for %u updated. repeating request.", handle); + g_source_remove (ctx->timeout_id); + repeat_request (ctx); + break; + } + } +} + +static void delay_stream_request (GabbleMediaChannel *chan, TpSvcChannelTypeStreamedMedia *iface, guint contact_handle, @@ -1565,11 +1592,14 @@ delay_stream_request (GabbleMediaChannel *chan, ctx->caps_disco_id = g_signal_connect (priv->conn->presence_cache, "capabilities-discovered", G_CALLBACK (capabilities_discovered_cb), ctx); + ctx->presences_updated_id = 0; ctx->timeout_id = 0; } else { ctx->caps_disco_id = 0; + ctx->presences_updated_id = g_signal_connect (priv->conn->presence_cache, + "presences-updated", G_CALLBACK (presences_updated_cb), ctx); ctx->timeout_id = g_timeout_add_seconds (5, (GSourceFunc) repeat_request, ctx); } -- 1.6.0.6