From abd4ba75a0dfef29f8d8f8897f755cbb2d5b6913 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 15 May 2012 11:41:29 +0100 Subject: [PATCH 05/16] _mcd_client_registry_list_possible_handlers: only take one channel --- src/client-registry.c | 33 +++++++++------------------------ src/client-registry.h | 2 +- src/mcd-dispatcher.c | 10 ++-------- 3 files changed, 12 insertions(+), 33 deletions(-) diff --git a/src/client-registry.c b/src/client-registry.c index 3e01a66..acc65e7 100644 --- a/src/client-registry.c +++ b/src/client-registry.c @@ -604,11 +604,10 @@ GList * _mcd_client_registry_list_possible_handlers (McdClientRegistry *self, const gchar *preferred_handler, GHashTable *request_props, - const GList *channels, + TpChannel *channel, const gchar *must_have_unique_name) { GList *handlers = NULL; - const GList *iter; GList *handlers_iter; GHashTableIter client_iter; gpointer client_p; @@ -618,7 +617,8 @@ _mcd_client_registry_list_possible_handlers (McdClientRegistry *self, while (g_hash_table_iter_next (&client_iter, NULL, &client_p)) { McdClientProxy *client = MCD_CLIENT_PROXY (client_p); - gsize total_quality = 0; + GHashTable *properties; + gsize quality; if (must_have_unique_name != NULL && tp_strdiff (must_have_unique_name, @@ -636,48 +636,33 @@ _mcd_client_registry_list_possible_handlers (McdClientRegistry *self, continue; } - if (channels == NULL) + if (channel == NULL) { - /* We don't know any channels' properties (the next loop will not + /* We don't know the channel's properties (the next part will not * execute), so we must work out the quality of match from the * channel request. We can assume that the request will return one * channel, with the requested properties, plus Requested == TRUE. */ g_assert (request_props != NULL); - total_quality = _mcd_client_match_filters (request_props, + quality = _mcd_client_match_filters (request_props, _mcd_client_proxy_get_handler_filters (client), TRUE); } - - for (iter = channels; iter != NULL; iter = iter->next) + else { - TpChannel *channel = iter->data; - GHashTable *properties; - guint quality; - g_assert (TP_IS_CHANNEL (channel)); properties = tp_channel_borrow_immutable_properties (channel); quality = _mcd_client_match_filters (properties, _mcd_client_proxy_get_handler_filters (client), FALSE); - - if (quality == 0) - { - total_quality = 0; - break; - } - else - { - total_quality += quality; - } } - if (total_quality > 0) + if (quality > 0) { PossibleHandler *ph = g_slice_new0 (PossibleHandler); ph->client = client; ph->bypass = _mcd_client_proxy_get_bypass_approval (client); - ph->quality = total_quality; + ph->quality = quality; handlers = g_list_prepend (handlers, ph); } diff --git a/src/client-registry.h b/src/client-registry.h index 88f1956..ec2e167 100644 --- a/src/client-registry.h +++ b/src/client-registry.h @@ -82,7 +82,7 @@ G_GNUC_INTERNAL void _mcd_client_registry_init_hash_iter ( G_GNUC_INTERNAL GList *_mcd_client_registry_list_possible_handlers ( McdClientRegistry *self, const gchar *preferred_handler, - GHashTable *request_props, const GList *channels, + GHashTable *request_props, TpChannel *channel, const gchar *must_have_unique_name); G_END_DECLS diff --git a/src/mcd-dispatcher.c b/src/mcd-dispatcher.c index 1807f20..88b5a47 100644 --- a/src/mcd-dispatcher.c +++ b/src/mcd-dispatcher.c @@ -181,19 +181,16 @@ mcd_dispatcher_dup_possible_handlers (McdDispatcher *self, TpChannel *channel, const gchar *must_have_unique_name) { - GList *channels = g_list_prepend (NULL, channel); GList *handlers = _mcd_client_registry_list_possible_handlers ( self->priv->clients, request != NULL ? _mcd_request_get_preferred_handler (request) : NULL, request != NULL ? _mcd_request_get_properties (request) : NULL, - channels, must_have_unique_name); + channel, must_have_unique_name); guint n_handlers = g_list_length (handlers); guint i; GStrv ret; const GList *iter; - g_list_free (channels); - if (handlers == NULL) return NULL; @@ -549,7 +546,6 @@ _mcd_dispatcher_lookup_handler (McdDispatcher *self, if (handler == NULL) { GList *possible_handlers; - GList *channels; /* Failing that, maybe the Handler it was dispatched to was temporary; * try to pick another Handler that can deal with it, on the same @@ -557,12 +553,11 @@ _mcd_dispatcher_lookup_handler (McdDispatcher *self, * It can also happen in the case an Observer/Approver Claimed the * channel; in that case we did not get its handler well known name. */ - channels = g_list_prepend (NULL, channel); possible_handlers = _mcd_client_registry_list_possible_handlers ( self->priv->clients, request != NULL ? _mcd_request_get_preferred_handler (request) : NULL, request != NULL ? _mcd_request_get_properties (request) : NULL, - channels, unique_name); + channel, unique_name); if (possible_handlers != NULL) { @@ -579,7 +574,6 @@ _mcd_dispatcher_lookup_handler (McdDispatcher *self, unique_name, object_path); } - g_list_free (channels); g_list_free (possible_handlers); } -- 1.7.10.4