[telepathy-mission-control/master] McdDispatchOperation: emit ready-to-dispatch just after finished

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


This separates the D-Bus finished signal (which triggers the McdDispatcher
signalling us as finished) from the GObject ready-to-dispatch signal
(which triggers the next stage of the dispatch chain).
---
 src/mcd-dispatch-operation.c |   16 ++++++++++++++++
 src/mcd-dispatcher.c         |   23 +++++++++++++++++------
 2 files changed, 33 insertions(+), 6 deletions(-)

diff --git a/src/mcd-dispatch-operation.c b/src/mcd-dispatch-operation.c
index 34ae9c5..f7cafc8 100644
--- a/src/mcd-dispatch-operation.c
+++ b/src/mcd-dispatch-operation.c
@@ -72,6 +72,14 @@ G_DEFINE_TYPE_WITH_CODE (McdDispatchOperation, _mcd_dispatch_operation,
     G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_DBUS_PROPERTIES, properties_iface_init);
     )
 
+enum
+{
+    S_READY_TO_DISPATCH,
+    N_SIGNALS
+};
+
+static guint signals[N_SIGNALS] = { 0 };
+
 struct _McdDispatchOperationPrivate
 {
     const gchar *unique_name;   /* borrowed from object_path */
@@ -399,6 +407,7 @@ mcd_dispatch_operation_actually_finish (McdDispatchOperation *self)
 {
     DEBUG ("%s/%p: finished", self->priv->unique_name, self);
     tp_svc_channel_dispatch_operation_emit_finished (self);
+    g_signal_emit (self, signals[S_READY_TO_DISPATCH], 0);
 
     if (self->priv->claim_context != NULL)
     {
@@ -814,6 +823,13 @@ _mcd_dispatch_operation_class_init (McdDispatchOperationClass * klass)
                               "appear on D-Bus", FALSE,
                               G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
                               G_PARAM_STATIC_STRINGS));
+
+    signals[S_READY_TO_DISPATCH] = g_signal_new ("ready-to-dispatch",
+        G_OBJECT_CLASS_TYPE (klass),
+        G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
+        0, NULL, NULL,
+        g_cclosure_marshal_VOID__VOID,
+        G_TYPE_NONE, 0);
 }
 
 static void
diff --git a/src/mcd-dispatcher.c b/src/mcd-dispatcher.c
index dc58b2f..e73da43 100644
--- a/src/mcd-dispatcher.c
+++ b/src/mcd-dispatcher.c
@@ -1243,12 +1243,6 @@ static void
 on_operation_finished (McdDispatchOperation *operation,
                        McdDispatcherContext *context)
 {
-    /* This is emitted when the HandleWith() or Claimed() are invoked on the
-     * CDO: according to which of these have happened, we run the choosen
-     * handler or we don't. */
-
-    mcd_dispatcher_context_ref (context, "CTXREF15");
-
     /* don't emit the signal if the CDO never appeared on D-Bus */
     if (context->dispatcher->priv->operation_list_active &&
         _mcd_dispatch_operation_needs_approval (operation))
@@ -1256,6 +1250,17 @@ on_operation_finished (McdDispatchOperation *operation,
         tp_svc_channel_dispatcher_interface_operation_list_emit_dispatch_operation_finished (
             context->dispatcher, _mcd_dispatch_operation_get_path (operation));
     }
+}
+
+static void
+mcd_dispatcher_op_ready_to_dispatch_cb (McdDispatchOperation *operation,
+                                        McdDispatcherContext *context)
+{
+    /* This is emitted when the HandleWith() or Claimed() are invoked on the
+     * CDO: according to which of these have happened, we run the choosen
+     * handler or we don't. */
+
+    mcd_dispatcher_context_ref (context, "CTXREF15");
 
     /* Because of our calls to _mcd_dispatch_operation_block_finished,
      * this cannot happen until all observers and all approvers have
@@ -1368,6 +1373,9 @@ _mcd_dispatcher_enter_state_machine (McdDispatcher *dispatcher,
 
         g_signal_connect (context->operation, "finished",
                           G_CALLBACK (on_operation_finished), context);
+        g_signal_connect (context->operation, "ready-to-dispatch",
+                          G_CALLBACK (mcd_dispatcher_op_ready_to_dispatch_cb),
+                          context);
     }
 
     DEBUG ("entering state machine for context %p", context);
@@ -2030,6 +2038,9 @@ mcd_dispatcher_context_unref (McdDispatcherContext * context,
                                               on_operation_finished,
                                               context);
 
+        g_signal_handlers_disconnect_by_func (context->operation,
+            mcd_dispatcher_op_ready_to_dispatch_cb, context);
+
         if (_mcd_dispatch_operation_finish (context->operation) &&
             context->dispatcher->priv->operation_list_active)
         {
-- 
1.5.6.5




More information about the telepathy-commits mailing list