[telepathy-mission-control/master] McdDispatchOperation: move failed_handlers from McdDispatcherContext

Simon McVittie simon.mcvittie at collabora.co.uk
Mon Sep 21 04:26:16 PDT 2009


---
 src/mcd-dispatch-operation-priv.h |    5 ++++
 src/mcd-dispatch-operation.c      |   45 +++++++++++++++++++++++++++++++++++++
 src/mcd-dispatcher.c              |   34 +++++-----------------------
 3 files changed, 56 insertions(+), 28 deletions(-)

diff --git a/src/mcd-dispatch-operation-priv.h b/src/mcd-dispatch-operation-priv.h
index ca817dc..824f36f 100644
--- a/src/mcd-dispatch-operation-priv.h
+++ b/src/mcd-dispatch-operation-priv.h
@@ -93,6 +93,11 @@ G_GNUC_INTERNAL
 const gchar * const *_mcd_dispatch_operation_get_possible_handlers (
     McdDispatchOperation *self);
 
+G_GNUC_INTERNAL void _mcd_dispatch_operation_set_handler_failed (
+    McdDispatchOperation *self, const gchar *bus_name);
+G_GNUC_INTERNAL gboolean _mcd_dispatch_operation_get_handler_failed (
+    McdDispatchOperation *self, const gchar *bus_name);
+
 G_END_DECLS
 
 #endif
diff --git a/src/mcd-dispatch-operation.c b/src/mcd-dispatch-operation.c
index 333589e..1d5cdda 100644
--- a/src/mcd-dispatch-operation.c
+++ b/src/mcd-dispatch-operation.c
@@ -84,6 +84,10 @@ struct _McdDispatchOperationPrivate
      * but we're inaccessible. */
     guint needs_approval : 1;
 
+    /* set of handlers we already tried
+     * dup'd bus name (string) => arbitrary non-NULL pointer */
+    GHashTable *failed_handlers;
+
     /* Results */
     guint finished : 1;
     gchar *handler;
@@ -471,6 +475,11 @@ mcd_dispatch_operation_finalize (GObject *object)
     if (priv->properties)
         g_hash_table_unref (priv->properties);
 
+    if (priv->failed_handlers != NULL)
+    {
+        g_hash_table_unref (priv->failed_handlers);
+    }
+
     g_free (priv->handler);
     g_free (priv->object_path);
     g_free (priv->claimer);
@@ -890,3 +899,39 @@ _mcd_dispatch_operation_unblock_finished (McdDispatchOperation *self)
         }
     }
 }
+
+void
+_mcd_dispatch_operation_set_handler_failed (McdDispatchOperation *self,
+                                            const gchar *bus_name)
+{
+    g_return_if_fail (MCD_IS_DISPATCH_OPERATION (self));
+    g_return_if_fail (bus_name != NULL);
+
+    if (self->priv->failed_handlers == NULL)
+    {
+        self->priv->failed_handlers = g_hash_table_new_full (g_str_hash,
+                                                             g_str_equal,
+                                                             g_free, NULL);
+    }
+
+    /* the value is an arbitrary non-NULL pointer - the hash table itself
+     * will do nicely */
+    g_hash_table_insert (self->priv->failed_handlers, g_strdup (bus_name),
+                         self->priv->failed_handlers);
+}
+
+gboolean
+_mcd_dispatch_operation_get_handler_failed (McdDispatchOperation *self,
+                                            const gchar *bus_name)
+{
+    /* return TRUE on error so we can't get an infinite loop of trying the
+     * same handler */
+    g_return_val_if_fail (MCD_IS_DISPATCH_OPERATION (self), TRUE);
+    g_return_val_if_fail (bus_name != NULL, TRUE);
+
+    if (self->priv->failed_handlers == NULL)
+        return FALSE;
+
+    return (g_hash_table_lookup (self->priv->failed_handlers, bus_name)
+            != NULL);
+}
diff --git a/src/mcd-dispatcher.c b/src/mcd-dispatcher.c
index a8a8645..3a26c76 100644
--- a/src/mcd-dispatcher.c
+++ b/src/mcd-dispatcher.c
@@ -121,10 +121,6 @@ struct _McdDispatcherContext
     McdAccount *account;
     McdDispatchOperation *operation;
 
-    /* set of handlers we already tried
-     * dup'd bus name (string) => arbitrary non-NULL pointer */
-    GHashTable *failed_handlers;
-
     /* The number of observers that have not yet returned from ObserveChannels.
      * Until they have done so, we can't allow the dispatch operation to
      * finish. This is a client lock.
@@ -696,15 +692,8 @@ handle_channels_cb (TpClient *proxy, const GError *error, gpointer user_data,
     {
         DEBUG ("error: %s", error->message);
 
-        /* we created this in mcd_dispatcher_run_handlers, so it had better
-         * exist */
-        g_assert (context->failed_handlers != NULL);
-
-         /* the value is an arbitrary non-NULL pointer - the hash table itself
-          * will do nicely */
-        g_hash_table_insert (context->failed_handlers,
-                             g_strdup (tp_proxy_get_bus_name (proxy)),
-                             context->failed_handlers);
+        _mcd_dispatch_operation_set_handler_failed (context->operation,
+            tp_proxy_get_bus_name (proxy));
 
         /* try again */
         mcd_dispatcher_run_handlers (context);
@@ -980,13 +969,6 @@ mcd_dispatcher_run_handlers (McdDispatcherContext *context)
     sp_timestamp ("run handlers");
     mcd_dispatcher_context_ref (context, "CTXREF04");
 
-    if (context->failed_handlers == NULL)
-    {
-        context->failed_handlers = g_hash_table_new_full (g_str_hash,
-                                                          g_str_equal,
-                                                          g_free, NULL);
-    }
-
     /* mcd_dispatcher_handle_channels steals this list */
     channels = g_list_copy (context->channels);
 
@@ -999,8 +981,8 @@ mcd_dispatcher_run_handlers (McdDispatcherContext *context)
                                        approved_handler, NULL);
         McdClient *handler = g_hash_table_lookup (self->priv->clients,
                                                   bus_name);
-        gboolean failed = (g_hash_table_lookup (context->failed_handlers,
-                                                bus_name) != NULL);
+        gboolean failed = _mcd_dispatch_operation_get_handler_failed
+            (context->operation, bus_name);
 
         DEBUG ("Approved handler is %s (still exists: %c, "
                "already failed: %c)", bus_name,
@@ -1030,8 +1012,8 @@ mcd_dispatcher_run_handlers (McdDispatcherContext *context)
     for (iter = possible_handlers; iter != NULL && *iter != NULL; iter++)
     {
         McdClient *handler = g_hash_table_lookup (self->priv->clients, *iter);
-        gboolean failed = (g_hash_table_lookup (context->failed_handlers,
-                                                *iter) != NULL);
+        gboolean failed = _mcd_dispatch_operation_get_handler_failed
+            (context->operation, *iter);
 
         DEBUG ("Possible handler: %s (still exists: %c, already failed: %c)",
                *iter, handler != NULL ? 'Y' : 'N', failed ? 'Y' : 'N');
@@ -3372,10 +3354,6 @@ mcd_dispatcher_context_unref (McdDispatcherContext * context,
         priv = MCD_DISPATCHER_PRIV (context->dispatcher);
         priv->contexts = g_list_remove (priv->contexts, context);
 
-        if (context->failed_handlers != NULL)
-        {
-            g_hash_table_destroy (context->failed_handlers);
-        }
         g_free (context->protocol);
         g_free (context);
     }
-- 
1.5.6.5




More information about the telepathy-commits mailing list