[telepathy-mission-control/master] McdDispatchOperation: implement the response to Claim() and a successful HandleChannels() internally
Simon McVittie
simon.mcvittie at collabora.co.uk
Mon Nov 2 06:41:39 PST 2009
---
src/mcd-dispatch-operation-priv.h | 3 +
src/mcd-dispatch-operation.c | 97 ++++++++++++++++++++++++++++++++++++
src/mcd-dispatcher.c | 98 +------------------------------------
3 files changed, 102 insertions(+), 96 deletions(-)
diff --git a/src/mcd-dispatch-operation-priv.h b/src/mcd-dispatch-operation-priv.h
index e940133..509004c 100644
--- a/src/mcd-dispatch-operation-priv.h
+++ b/src/mcd-dispatch-operation-priv.h
@@ -150,6 +150,9 @@ G_GNUC_INTERNAL gboolean _mcd_dispatch_operation_get_cancelled (
G_GNUC_INTERNAL void _mcd_dispatch_operation_check_client_locks (
McdDispatchOperation *self);
+G_GNUC_INTERNAL void _mcd_dispatch_operation_handle_channels_cb (
+ McdDispatchOperation *self, TpClient *client, const GError *error);
+
G_END_DECLS
#endif
diff --git a/src/mcd-dispatch-operation.c b/src/mcd-dispatch-operation.c
index 4bc79c2..f3a40d4 100644
--- a/src/mcd-dispatch-operation.c
+++ b/src/mcd-dispatch-operation.c
@@ -428,10 +428,49 @@ properties_iface_init (TpSvcDBusPropertiesClass *iface, gpointer iface_data)
}
static void
+mcd_dispatch_operation_set_channel_handled_by (McdDispatchOperation *self,
+ McdChannel *channel,
+ const gchar *unique_name)
+{
+ const gchar *path;
+ TpChannel *tp_channel;
+
+ g_assert (unique_name != NULL);
+
+ path = mcd_channel_get_object_path (channel);
+ tp_channel = mcd_channel_get_tp_channel (channel);
+ g_return_if_fail (tp_channel != NULL);
+
+ _mcd_channel_set_status (channel, MCD_CHANNEL_STATUS_DISPATCHED);
+
+ _mcd_handler_map_set_channel_handled (self->priv->handler_map,
+ tp_channel, unique_name);
+}
+
+static void
mcd_dispatch_operation_actually_finish (McdDispatchOperation *self)
{
DEBUG ("%s/%p: finished", self->priv->unique_name, self);
tp_svc_channel_dispatch_operation_emit_finished (self);
+
+ if (self->priv->claimer != NULL)
+ {
+ const GList *list;
+
+ /* we don't release the client lock, in order to not run the handlers,
+ * but we do have to mark all channels as dispatched */
+ for (list = self->priv->channels; list != NULL; list = list->next)
+ {
+ McdChannel *channel = MCD_CHANNEL (list->data);
+
+ mcd_dispatch_operation_set_channel_handled_by (self, channel,
+ self->priv->claimer);
+ }
+
+ g_assert (!_mcd_dispatch_operation_get_channels_handled (self));
+ _mcd_dispatch_operation_set_channels_handled (self, TRUE);
+ }
+
g_signal_emit (self, signals[S_READY_TO_DISPATCH], 0);
if (self->priv->claim_context != NULL)
@@ -1346,3 +1385,61 @@ _mcd_dispatch_operation_dup_channels (McdDispatchOperation *self)
g_list_foreach (copy, (GFunc) g_object_ref, NULL);
return copy;
}
+
+void _mcd_dispatch_operation_handle_channels_cb (McdDispatchOperation *self,
+ TpClient *client,
+ const GError *error)
+{
+ if (error)
+ {
+ DEBUG ("error: %s", error->message);
+
+ _mcd_dispatch_operation_set_handler_failed (self,
+ tp_proxy_get_bus_name (client));
+
+ /* try again */
+ g_signal_emit (self, signals[S_RUN_HANDLERS], 0);
+ }
+ else
+ {
+ const GList *list;
+
+ for (list = self->priv->channels; list != NULL; list = list->next)
+ {
+ McdChannel *channel = list->data;
+ const gchar *unique_name;
+
+ unique_name = _mcd_client_proxy_get_unique_name (MCD_CLIENT_PROXY (client));
+
+ /* This should always be false in practice - either we already know
+ * the handler's unique name (because active handlers' unique names
+ * are discovered before their handler filters), or the handler
+ * is activatable and was not running, the handler filter came
+ * from a .client file, and the bus daemon activated the handler
+ * as a side-effect of HandleChannels (in which case
+ * NameOwnerChanged should have already been emitted by the time
+ * we got a reply to HandleChannels).
+ *
+ * We recover by whining to stderr and closing the channels, in the
+ * interests of at least failing visibly.
+ *
+ * If dbus-glib exposed more of the details of the D-Bus message
+ * passing system, then we could just look at the sender of the
+ * reply and bypass this rubbish...
+ */
+ if (G_UNLIKELY (unique_name == NULL || unique_name[0] == '\0'))
+ {
+ g_warning ("Client %s returned successfully but doesn't "
+ "exist? dbus-daemon bug suspected",
+ tp_proxy_get_bus_name (client));
+ g_warning ("Closing channel %s as a result",
+ mcd_channel_get_object_path (channel));
+ _mcd_channel_undispatchable (channel);
+ continue;
+ }
+
+ mcd_dispatch_operation_set_channel_handled_by (self, channel,
+ unique_name);
+ }
+ }
+}
diff --git a/src/mcd-dispatcher.c b/src/mcd-dispatcher.c
index dfda270..f898ce4 100644
--- a/src/mcd-dispatcher.c
+++ b/src/mcd-dispatcher.c
@@ -457,26 +457,6 @@ mcd_dispatcher_guess_request_handler (McdDispatcher *dispatcher,
return NULL;
}
-static void
-mcd_dispatcher_set_channel_handled_by (McdDispatcher *self,
- McdChannel *channel,
- const gchar *unique_name)
-{
- const gchar *path;
- TpChannel *tp_channel;
-
- g_assert (unique_name != NULL);
-
- path = mcd_channel_get_object_path (channel);
- tp_channel = mcd_channel_get_tp_channel (channel);
- g_return_if_fail (tp_channel != NULL);
-
- _mcd_channel_set_status (channel, MCD_CHANNEL_STATUS_DISPATCHED);
-
- _mcd_handler_map_set_channel_handled (self->priv->handler_map,
- tp_channel, unique_name);
-}
-
static void mcd_dispatcher_run_handlers (McdDispatchOperation *op,
McdDispatcherContext *context);
@@ -485,62 +465,10 @@ handle_channels_cb (TpClient *proxy, const GError *error, gpointer user_data,
GObject *weak_object)
{
McdDispatcherContext *context = user_data;
- const GList *list;
mcd_dispatcher_context_ref (context, "CTXREF02");
- if (error)
- {
- DEBUG ("error: %s", error->message);
-
- _mcd_dispatch_operation_set_handler_failed (context->operation,
- tp_proxy_get_bus_name (proxy));
-
- /* try again */
- mcd_dispatcher_run_handlers (context->operation, context);
- }
- else
- {
- for (list = _mcd_dispatch_operation_peek_channels (context->operation);
- list != NULL;
- list = list->next)
- {
- McdChannel *channel = list->data;
- const gchar *unique_name;
-
- unique_name = _mcd_client_proxy_get_unique_name (MCD_CLIENT_PROXY (proxy));
-
- /* This should always be false in practice - either we already know
- * the handler's unique name (because active handlers' unique names
- * are discovered before their handler filters), or the handler
- * is activatable and was not running, the handler filter came
- * from a .client file, and the bus daemon activated the handler
- * as a side-effect of HandleChannels (in which case
- * NameOwnerChanged should have already been emitted by the time
- * we got a reply to HandleChannels).
- *
- * We recover by whining to stderr and closing the channels, in the
- * interests of at least failing visibly.
- *
- * If dbus-glib exposed more of the details of the D-Bus message
- * passing system, then we could just look at the sender of the
- * reply and bypass this rubbish...
- */
- if (G_UNLIKELY (unique_name == NULL || unique_name[0] == '\0'))
- {
- g_warning ("Client %s returned successfully but doesn't "
- "exist? dbus-daemon bug suspected",
- tp_proxy_get_bus_name (proxy));
- g_warning ("Closing channel %s as a result",
- mcd_channel_get_object_path (channel));
- _mcd_channel_undispatchable (channel);
- continue;
- }
-
- mcd_dispatcher_set_channel_handled_by (context->dispatcher,
- channel, unique_name);
- }
- }
-
+ _mcd_dispatch_operation_handle_channels_cb (context->operation,
+ proxy, error);
mcd_dispatcher_context_unref (context, "CTXREF02");
}
@@ -1237,28 +1165,6 @@ mcd_dispatcher_op_ready_to_dispatch_cb (McdDispatchOperation *operation,
_mcd_dispatch_operation_set_channels_handled (context->operation,
TRUE);
}
- else if (_mcd_dispatch_operation_is_claimed (operation))
- {
- const GList *list;
-
- /* we don't release the client lock, in order to not run the handlers.
- * But we have to mark all channels as dispatched, and free the
- * @context */
- for (list = _mcd_dispatch_operation_peek_channels (context->operation);
- list != NULL;
- list = list->next)
- {
- McdChannel *channel = MCD_CHANNEL (list->data);
-
- mcd_dispatcher_set_channel_handled_by (context->dispatcher,
- channel, _mcd_dispatch_operation_get_claimer (operation));
- }
-
- g_assert (!_mcd_dispatch_operation_get_channels_handled
- (context->operation));
- _mcd_dispatch_operation_set_channels_handled (context->operation,
- TRUE);
- }
if (_mcd_dispatch_operation_is_awaiting_approval (context->operation))
{
--
1.5.6.5
More information about the telepathy-commits
mailing list