[telepathy-mission-control/master] McdDispatcher: use GetAll rather than Get for Handler properties

Simon McVittie simon.mcvittie at collabora.co.uk
Wed May 13 03:59:28 PDT 2009


---
 src/mcd-dispatcher.c |  104 +++++++++++++++++++++++++------------------------
 1 files changed, 53 insertions(+), 51 deletions(-)

diff --git a/src/mcd-dispatcher.c b/src/mcd-dispatcher.c
index 67460f9..08a3d1e 100644
--- a/src/mcd-dispatcher.c
+++ b/src/mcd-dispatcher.c
@@ -1716,46 +1716,6 @@ parse_client_filter (GKeyFile *file, const gchar *group)
 }
 
 static void
-get_bypass_approval_cb (TpProxy *proxy,
-                        const GValue *value,
-                        const GError *error,
-                        gpointer user_data,
-                        GObject *weak_object)
-{
-    McdDispatcher *self = MCD_DISPATCHER (weak_object);
-    const gchar *bus_name = tp_proxy_get_bus_name (proxy);
-    McdClient *client;
-
-    client = g_hash_table_lookup (self->priv->clients, bus_name);
-
-    if (G_UNLIKELY (client == NULL))
-    {
-        DEBUG ("Client %s vanished while we were getting BypassApproval",
-               bus_name);
-        return;
-    }
-
-    if (error != NULL)
-    {
-        DEBUG ("error getting BypassApproval for client %s: %s #%d: %s",
-               tp_proxy_get_object_path (proxy),
-               g_quark_to_string (error->domain), error->code, error->message);
-        client->bypass_approver = FALSE;
-        return;
-    }
-
-    if (!G_VALUE_HOLDS_BOOLEAN (value))
-    {
-        DEBUG ("wrong type for BypassApproval on client %s: %s",
-               tp_proxy_get_object_path (proxy), G_VALUE_TYPE_NAME (value));
-        client->bypass_approver = FALSE;
-        return;
-    }
-
-    client->bypass_approver = g_value_get_boolean (value);
-}
-
-static void
 mcd_client_set_filters (McdClient *client,
                         McdClientInterface interface,
                         GPtrArray *filters)
@@ -1884,6 +1844,57 @@ get_channel_filter_cb (TpProxy *proxy,
 }
 
 static void
+handler_get_all_cb (TpProxy *proxy,
+                    GHashTable *properties,
+                    const GError *error,
+                    gpointer unused G_GNUC_UNUSED,
+                    GObject *weak_object)
+{
+    McdDispatcher *self = MCD_DISPATCHER (weak_object);
+    McdClient *client;
+    const gchar *bus_name = tp_proxy_get_bus_name (proxy);
+    GPtrArray *filters;
+
+    if (error != NULL)
+    {
+        DEBUG ("GetAll(Handler) for client %s failed: %s #%d: %s",
+               bus_name, g_quark_to_string (error->domain), error->code,
+               error->message);
+        return;
+    }
+
+    client = g_hash_table_lookup (self->priv->clients, bus_name);
+
+    if (G_UNLIKELY (client == NULL))
+    {
+        DEBUG ("Client %s vanished while getting its Handler properties",
+               bus_name);
+        return;
+    }
+
+    filters = tp_asv_get_boxed (properties, "HandlerChannelFilter",
+                                TP_ARRAY_TYPE_STRING_VARIANT_MAP_LIST);
+
+    if (filters != NULL)
+    {
+        DEBUG ("%s has %u HandlerChannelFilter entries", client->name,
+               filters->len);
+        mcd_client_set_filters (client, MCD_CLIENT_HANDLER, filters);
+    }
+    else
+    {
+        DEBUG ("%s HandlerChannelFilter absent or wrong type, assuming "
+               "no channels can match", client->name);
+    }
+
+    /* if wrong type or absent, assuming False is reasonable */
+    client->bypass_approver = tp_asv_get_boolean (properties, "BypassApproval",
+                                                  NULL);
+    DEBUG ("%s has BypassApproval=%c", client->name,
+           client->bypass_approver ? 'T' : 'F');
+}
+
+static void
 client_add_interface_by_id (McdClient *client)
 {
     tp_proxy_add_interface_by_id (client->proxy, MC_IFACE_QUARK_CLIENT);
@@ -1952,10 +1963,6 @@ get_interfaces_cb (TpProxy *proxy,
         arr++;
     }
 
-    /* FIXME: refactor this stuff to use GetAll (also, I suspect it has a
-     * use-after-free if the client disappears after the D-Bus method call,
-     * but before we get a response) */
-
     client_add_interface_by_id (client);
     if (client->interfaces & MCD_CLIENT_APPROVER)
     {
@@ -1966,14 +1973,9 @@ get_interfaces_cb (TpProxy *proxy,
     }
     if (client->interfaces & MCD_CLIENT_HANDLER)
     {
-        tp_cli_dbus_properties_call_get
-            (client->proxy, -1, MC_IFACE_CLIENT_HANDLER,
-             "BypassApproval", get_bypass_approval_cb,
-             NULL, NULL, G_OBJECT (self));
-        tp_cli_dbus_properties_call_get
+        tp_cli_dbus_properties_call_get_all
             (client->proxy, -1, MC_IFACE_CLIENT_HANDLER,
-             "HandlerChannelFilter", get_channel_filter_cb,
-             GUINT_TO_POINTER (MCD_CLIENT_HANDLER), NULL, G_OBJECT (self));
+             handler_get_all_cb, NULL, NULL, G_OBJECT (self));
     }
     if (client->interfaces & MCD_CLIENT_OBSERVER)
     {
-- 
1.5.6.5



More information about the telepathy-commits mailing list