[telepathy-mission-control/master] _mcd_client_match_property, _mcd_client_match_filters: move from McdDispatcher

Simon McVittie simon.mcvittie at collabora.co.uk
Mon Nov 2 06:41:41 PST 2009


---
 src/mcd-client-priv.h |    8 +++
 src/mcd-client.c      |  149 +++++++++++++++++++++++++++++++++++++++++++++
 src/mcd-dispatcher.c  |  159 ++-----------------------------------------------
 3 files changed, 163 insertions(+), 153 deletions(-)

diff --git a/src/mcd-client-priv.h b/src/mcd-client-priv.h
index f718e01..5af1c04 100644
--- a/src/mcd-client-priv.h
+++ b/src/mcd-client-priv.h
@@ -105,6 +105,14 @@ G_GNUC_INTERNAL void _mcd_client_proxy_dec_ready_lock (McdClientProxy *self);
 
 #define MC_CLIENT_BUS_NAME_BASE_LEN (sizeof (TP_CLIENT_BUS_NAME_BASE) - 1)
 
+G_GNUC_INTERNAL gboolean _mcd_client_match_property (
+    GHashTable *channel_properties, gchar *property_name,
+    GValue *filter_value);
+
+G_GNUC_INTERNAL guint _mcd_client_match_filters (
+    GHashTable *channel_properties, const GList *filters,
+    gboolean assume_requested);
+
 G_END_DECLS
 
 #endif
diff --git a/src/mcd-client.c b/src/mcd-client.c
index e16c7e4..a0cc1b9 100644
--- a/src/mcd-client.c
+++ b/src/mcd-client.c
@@ -1387,3 +1387,152 @@ _mcd_client_proxy_dup_handler_capabilities (McdClientProxy *self)
 
     return va;
 }
+
+/* returns TRUE if the channel matches one property criteria
+ */
+gboolean
+_mcd_client_match_property (GHashTable *channel_properties,
+                            gchar *property_name,
+                            GValue *filter_value)
+{
+    GType filter_type = G_VALUE_TYPE (filter_value);
+
+    g_assert (G_IS_VALUE (filter_value));
+
+    if (filter_type == G_TYPE_STRING)
+    {
+        const gchar *string;
+
+        string = tp_asv_get_string (channel_properties, property_name);
+        if (!string)
+            return FALSE;
+
+        return !tp_strdiff (string, g_value_get_string (filter_value));
+    }
+
+    if (filter_type == DBUS_TYPE_G_OBJECT_PATH)
+    {
+        const gchar *path;
+
+        path = tp_asv_get_object_path (channel_properties, property_name);
+        if (!path)
+            return FALSE;
+
+        return !tp_strdiff (path, g_value_get_boxed (filter_value));
+    }
+
+    if (filter_type == G_TYPE_BOOLEAN)
+    {
+        gboolean valid;
+        gboolean b;
+
+        b = tp_asv_get_boolean (channel_properties, property_name, &valid);
+        if (!valid)
+            return FALSE;
+
+        return !!b == !!g_value_get_boolean (filter_value);
+    }
+
+    if (filter_type == G_TYPE_UCHAR || filter_type == G_TYPE_UINT ||
+        filter_type == G_TYPE_UINT64)
+    {
+        gboolean valid;
+        guint64 i;
+
+        i = tp_asv_get_uint64 (channel_properties, property_name, &valid);
+        if (!valid)
+            return FALSE;
+
+        if (filter_type == G_TYPE_UCHAR)
+            return i == g_value_get_uchar (filter_value);
+        else if (filter_type == G_TYPE_UINT)
+            return i == g_value_get_uint (filter_value);
+        else
+            return i == g_value_get_uint64 (filter_value);
+    }
+
+    if (filter_type == G_TYPE_INT || filter_type == G_TYPE_INT64)
+    {
+        gboolean valid;
+        gint64 i;
+
+        i = tp_asv_get_int64 (channel_properties, property_name, &valid);
+        if (!valid)
+            return FALSE;
+
+        if (filter_type == G_TYPE_INT)
+            return i == g_value_get_int (filter_value);
+        else
+            return i == g_value_get_int64 (filter_value);
+    }
+
+    g_warning ("%s: Invalid type: %s",
+               G_STRFUNC, g_type_name (filter_type));
+    return FALSE;
+}
+
+/* if the channel matches one of the channel filters, returns a positive
+ * number that increases with more specific matches; otherwise, returns 0
+ *
+ * (implementation detail: the positive number is 1 + the number of keys in the
+ * largest filter that matched)
+ */
+guint
+_mcd_client_match_filters (GHashTable *channel_properties,
+                           const GList *filters,
+                           gboolean assume_requested)
+{
+    const GList *list;
+    guint best_quality = 0;
+
+    for (list = filters; list != NULL; list = list->next)
+    {
+        GHashTable *filter = list->data;
+        GHashTableIter filter_iter;
+        gboolean filter_matched = TRUE;
+        gchar *property_name;
+        GValue *filter_value;
+        guint quality;
+
+        /* +1 because the empty hash table matches everything :-) */
+        quality = g_hash_table_size (filter) + 1;
+
+        if (quality <= best_quality)
+        {
+            /* even if this filter matches, there's no way it can be a
+             * better-quality match than the best one we saw so far */
+            continue;
+        }
+
+        g_hash_table_iter_init (&filter_iter, filter);
+        while (g_hash_table_iter_next (&filter_iter,
+                                       (gpointer *) &property_name,
+                                       (gpointer *) &filter_value))
+        {
+            if (assume_requested &&
+                ! tp_strdiff (property_name, TP_IFACE_CHANNEL ".Requested"))
+            {
+                if (! G_VALUE_HOLDS_BOOLEAN (filter_value) ||
+                    ! g_value_get_boolean (filter_value))
+                {
+                    filter_matched = FALSE;
+                    break;
+                }
+            }
+            else if (! _mcd_client_match_property (channel_properties,
+                                                   property_name,
+                                                   filter_value))
+            {
+                filter_matched = FALSE;
+                break;
+            }
+        }
+
+        if (filter_matched)
+        {
+            best_quality = quality;
+        }
+    }
+
+    return best_quality;
+}
diff --git a/src/mcd-dispatcher.c b/src/mcd-dispatcher.c
index 202ea62..7ca99f9 100644
--- a/src/mcd-dispatcher.c
+++ b/src/mcd-dispatcher.c
@@ -258,89 +258,6 @@ on_master_abort (McdMaster *master, McdDispatcherPrivate *priv)
     priv->master = NULL;
 }
 
-/* returns TRUE if the channel matches one property criteria
- */
-static gboolean
-match_property (GHashTable *channel_properties,
-                gchar *property_name,
-                GValue *filter_value)
-{
-    GType filter_type = G_VALUE_TYPE (filter_value);
-
-    g_assert (G_IS_VALUE (filter_value));
-
-    if (filter_type == G_TYPE_STRING)
-    {
-        const gchar *string;
-
-        string = tp_asv_get_string (channel_properties, property_name);
-        if (!string)
-            return FALSE;
-
-        return !tp_strdiff (string, g_value_get_string (filter_value));
-    }
-
-    if (filter_type == DBUS_TYPE_G_OBJECT_PATH)
-    {
-        const gchar *path;
-
-        path = tp_asv_get_object_path (channel_properties, property_name);
-        if (!path)
-            return FALSE;
-
-        return !tp_strdiff (path, g_value_get_boxed (filter_value));
-    }
-
-    if (filter_type == G_TYPE_BOOLEAN)
-    {
-        gboolean valid;
-        gboolean b;
-
-        b = tp_asv_get_boolean (channel_properties, property_name, &valid);
-        if (!valid)
-            return FALSE;
-
-        return !!b == !!g_value_get_boolean (filter_value);
-    }
-
-    if (filter_type == G_TYPE_UCHAR || filter_type == G_TYPE_UINT ||
-        filter_type == G_TYPE_UINT64)
-    {
-        gboolean valid;
-        guint64 i;
-
-        i = tp_asv_get_uint64 (channel_properties, property_name, &valid);
-        if (!valid)
-            return FALSE;
-
-        if (filter_type == G_TYPE_UCHAR)
-            return i == g_value_get_uchar (filter_value);
-        else if (filter_type == G_TYPE_UINT)
-            return i == g_value_get_uint (filter_value);
-        else
-            return i == g_value_get_uint64 (filter_value);
-    }
-
-    if (filter_type == G_TYPE_INT || filter_type == G_TYPE_INT64)
-    {
-        gboolean valid;
-        gint64 i;
-
-        i = tp_asv_get_int64 (channel_properties, property_name, &valid);
-        if (!valid)
-            return FALSE;
-
-        if (filter_type == G_TYPE_INT)
-            return i == g_value_get_int (filter_value);
-        else
-            return i == g_value_get_int64 (filter_value);
-    }
-
-    g_warning ("%s: Invalid type: %s",
-               G_STRFUNC, g_type_name (filter_type));
-    return FALSE;
-}
-
 /* return TRUE if the two channel classes are equals
  */
 static gboolean
@@ -358,77 +275,13 @@ channel_classes_equals (GHashTable *channel_class1, GHashTable *channel_class2)
     while (g_hash_table_iter_next (&iter, (gpointer *) &property_name,
                                    (gpointer *) &property_value))
     {
-        if (!match_property (channel_class2, property_name, property_value))
+        if (!_mcd_client_match_property (channel_class2, property_name,
+                                         property_value))
             return FALSE;
     }
     return TRUE;
 }
 
-/* if the channel matches one of the channel filters, returns a positive
- * number that increases with more specific matches; otherwise, returns 0
- *
- * (implementation detail: the positive number is 1 + the number of keys in the
- * largest filter that matched)
- */
-static guint
-match_filters (GHashTable *channel_properties,
-               const GList *filters,
-               gboolean assume_requested)
-{
-    const GList *list;
-    guint best_quality = 0;
-
-    for (list = filters; list != NULL; list = list->next)
-    {
-        GHashTable *filter = list->data;
-        GHashTableIter filter_iter;
-        gboolean filter_matched = TRUE;
-        gchar *property_name;
-        GValue *filter_value;
-        guint quality;
-
-        /* +1 because the empty hash table matches everything :-) */
-        quality = g_hash_table_size (filter) + 1;
-
-        if (quality <= best_quality)
-        {
-            /* even if this filter matches, there's no way it can be a
-             * better-quality match than the best one we saw so far */
-            continue;
-        }
-
-        g_hash_table_iter_init (&filter_iter, filter);
-        while (g_hash_table_iter_next (&filter_iter,
-                                       (gpointer *) &property_name,
-                                       (gpointer *) &filter_value))
-        {
-            if (assume_requested &&
-                ! tp_strdiff (property_name, TP_IFACE_CHANNEL ".Requested"))
-            {
-                if (! G_VALUE_HOLDS_BOOLEAN (filter_value) ||
-                    ! g_value_get_boolean (filter_value))
-                {
-                    filter_matched = FALSE;
-                    break;
-                }
-            }
-            else if (! match_property (channel_properties, property_name,
-                                       filter_value))
-            {
-                filter_matched = FALSE;
-                break;
-            }
-        }
-
-        if (filter_matched)
-        {
-            best_quality = quality;
-        }
-    }
-
-    return best_quality;
-}
-
 static McdClientProxy *
 mcd_dispatcher_guess_request_handler (McdDispatcher *dispatcher,
                                       McdChannel *channel)
@@ -449,7 +302,7 @@ mcd_dispatcher_guess_request_handler (McdDispatcher *dispatcher,
                                            TP_IFACE_QUARK_CLIENT_HANDLER))
             continue;
 
-        if (match_filters (channel_properties,
+        if (_mcd_client_match_filters (channel_properties,
             _mcd_client_proxy_get_handler_filters (client),
             TRUE) > 0)
             return client;
@@ -562,7 +415,7 @@ mcd_dispatcher_dup_possible_handlers (McdDispatcher *self,
                 properties = _mcd_channel_get_requested_properties (channel);
             }
 
-            quality = match_filters (properties,
+            quality = _mcd_client_match_filters (properties,
                 _mcd_client_proxy_get_handler_filters (client),
                 FALSE);
 
@@ -902,7 +755,7 @@ mcd_dispatcher_run_observers (McdDispatcherContext *context)
             properties = _mcd_channel_get_immutable_properties (channel);
             g_assert (properties != NULL);
 
-            if (match_filters (properties,
+            if (_mcd_client_match_filters (properties,
                 _mcd_client_proxy_get_observer_filters (client),
                 FALSE))
                 observed = g_list_prepend (observed, channel);
@@ -1024,7 +877,7 @@ mcd_dispatcher_run_approvers (McdDispatcherContext *context)
             channel_properties = _mcd_channel_get_immutable_properties (channel);
             g_assert (channel_properties != NULL);
 
-            if (match_filters (channel_properties,
+            if (_mcd_client_match_filters (channel_properties,
                 _mcd_client_proxy_get_approver_filters (client),
                 FALSE))
             {
-- 
1.5.6.5




More information about the telepathy-commits mailing list