diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2011-05-06 15:15:51 +0100 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2011-05-06 15:22:58 +0100 |
commit | 1d224057ae7c1be1c438070db3469b1047921603 (patch) | |
tree | 1b228ca98e6614eefa787cd4df962fe980fa1fdf | |
parent | 9ac3c5f4c5c4147734f0529bd43bdf1e13dd3f60 (diff) | |
download | telepathy-mission-control-1d224057ae7c1be1c438070db3469b1047921603.tar.gz |
put Claim attempts through the handler suitability check, too
These get a NULL TpClient, since it's non-obvious.
-rw-r--r-- | src/mcd-dispatch-operation.c | 86 | ||||
-rw-r--r-- | tests/twisted/dispatcher/dispatch-delayed-by-mini-plugin.py | 14 |
2 files changed, 92 insertions, 8 deletions
diff --git a/src/mcd-dispatch-operation.c b/src/mcd-dispatch-operation.c index 30c87e6d..8f79d5b5 100644 --- a/src/mcd-dispatch-operation.c +++ b/src/mcd-dispatch-operation.c @@ -924,27 +924,97 @@ dispatch_operation_handle_with (TpSvcChannelDispatchOperation *cdo, context); } +typedef struct { + McdDispatchOperation *self; + DBusGMethodInvocation *context; + gsize handler_suitable_pending; +} ClaimAttempt; + +static void +claim_attempt_resolve (ClaimAttempt *claim_attempt) +{ + if (claim_attempt->context != NULL) + { + g_queue_push_tail (claim_attempt->self->priv->approvals, + approval_new_claim (claim_attempt->context)); + _mcd_dispatch_operation_check_client_locks (claim_attempt->self); + } + + g_object_unref (claim_attempt->self); + g_slice_free (ClaimAttempt, claim_attempt); +} + +static void +claim_attempt_suitability_cb (GObject *source, + GAsyncResult *res, + gpointer user_data) +{ + ClaimAttempt *claim_attempt = user_data; + GError *error = NULL; + + if (!mcp_dispatch_operation_policy_handler_is_suitable_finish ( + MCP_DISPATCH_OPERATION_POLICY (source), res, &error)) + { + if (claim_attempt->context != NULL) + dbus_g_method_return_error (claim_attempt->context, error); + + claim_attempt->context = NULL; + g_error_free (error); + } + + if (--claim_attempt->handler_suitable_pending == 0) + { + DEBUG ("all plugins have finished, resolving claim attempt"); + claim_attempt_resolve (claim_attempt); + } +} + static void dispatch_operation_claim (TpSvcChannelDispatchOperation *cdo, DBusGMethodInvocation *context) { McdDispatchOperation *self = MCD_DISPATCH_OPERATION (cdo); - McdDispatchOperationPrivate *priv = self->priv; + ClaimAttempt *claim_attempt; + gchar *sender = dbus_g_method_get_sender (context); + McpDispatchOperation *plugin_api = MCP_DISPATCH_OPERATION ( + self->priv->plugin_api); + const GList *p; if (self->priv->result != NULL) { - gchar *sender = dbus_g_method_get_sender (context); - DEBUG ("Giving error to %s: %s", sender, priv->result->message); - dbus_g_method_return_error (context, priv->result); + DEBUG ("Giving error to %s: %s", sender, self->priv->result->message); + dbus_g_method_return_error (context, self->priv->result); + goto finally; + } - g_free (sender); + claim_attempt = g_slice_new0 (ClaimAttempt); + claim_attempt->self = g_object_ref (self); + claim_attempt->context = context; + claim_attempt->handler_suitable_pending = 0; - return; + for (p = mcp_list_objects (); p != NULL; p = g_list_next (p)) + { + if (MCP_IS_DISPATCH_OPERATION_POLICY (p->data)) + { + McpDispatchOperationPolicy *plugin = p->data; + + DEBUG ("%s: checking policy for %s", + G_OBJECT_TYPE_NAME (plugin), sender); + + claim_attempt->handler_suitable_pending++; + mcp_dispatch_operation_policy_handler_is_suitable_async (plugin, + NULL, sender, plugin_api, + claim_attempt_suitability_cb, + claim_attempt); + } } - g_queue_push_tail (priv->approvals, approval_new_claim (context)); - _mcd_dispatch_operation_check_client_locks (self); + if (claim_attempt->handler_suitable_pending == 0) + claim_attempt_resolve (claim_attempt); + +finally: + g_free (sender); } static void diff --git a/tests/twisted/dispatcher/dispatch-delayed-by-mini-plugin.py b/tests/twisted/dispatcher/dispatch-delayed-by-mini-plugin.py index bcd5807c..eeab38cb 100644 --- a/tests/twisted/dispatcher/dispatch-delayed-by-mini-plugin.py +++ b/tests/twisted/dispatcher/dispatch-delayed-by-mini-plugin.py @@ -174,10 +174,24 @@ def test(q, bus, mc): q.dbus_return(e.message, signature='') q.dbus_return(k.message, signature='') + empathy_cdo = bus.get_object(cs.CD, cdo_path) + empathy_cdo_iface = dbus.Interface(empathy_cdo, cs.CDO) + call_async(q, empathy_cdo_iface, 'Claim') + + check_handler = q.expect('dbus-method-call', path='/com/example/Policy', + interface='com.example.Policy', method='CheckHandler') + q.dbus_raise(check_handler.message, 'com.example.Errors.No', + "That handler doesn't have enough options") + q.expect('dbus-error', method='Claim', name=cs.PERMISSION_DENIED) + kopete_cdo = bus.get_object(cs.CD, cdo_path) kopete_cdo_iface = dbus.Interface(kopete_cdo, cs.CDO) call_async(q, kopete_cdo_iface, 'Claim') + check_handler = q.expect('dbus-method-call', path='/com/example/Policy', + interface='com.example.Policy', method='CheckHandler') + q.dbus_return(check_handler.message, signature='') + q.expect_many( EventPattern('dbus-signal', path=cdo_path, signal='Finished'), EventPattern('dbus-signal', path=cs.CD_PATH, |