[telepathy-mission-control/master] Create a CDO even if channels don't need approval
Simon McVittie
simon.mcvittie at collabora.co.uk
Fri Sep 18 08:05:34 PDT 2009
This lets us start to migrate the dispatching state machine from the
Dispatcher to the CDO, reducing the size of the Dispatcher.
---
src/mcd-dispatch-operation-priv.h | 5 +++-
src/mcd-dispatch-operation.c | 38 +++++++++++++++++++++++++++++++++++-
src/mcd-dispatcher.c | 36 +++++++++++++++++++++++++---------
3 files changed, 66 insertions(+), 13 deletions(-)
diff --git a/src/mcd-dispatch-operation-priv.h b/src/mcd-dispatch-operation-priv.h
index a485a8c..1d3083e 100644
--- a/src/mcd-dispatch-operation-priv.h
+++ b/src/mcd-dispatch-operation-priv.h
@@ -70,7 +70,8 @@ G_GNUC_INTERNAL void _mcd_dispatch_operation_approve
#define MCD_DISPATCH_OPERATION_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MCD_TYPE_DISPATCH_OPERATION, McdDispatchOperationClass))
G_GNUC_INTERNAL McdDispatchOperation *_mcd_dispatch_operation_new (
- TpDBusDaemon *dbus_daemon, GList *channels, GStrv possible_handlers);
+ TpDBusDaemon *dbus_daemon, gboolean needs_approval, GList *channels,
+ GStrv possible_handlers);
G_GNUC_INTERNAL void _mcd_dispatch_operation_lose_channel (
McdDispatchOperation *self, McdChannel *channel, GList **channels);
@@ -86,6 +87,8 @@ G_GNUC_INTERNAL const gchar *_mcd_dispatch_operation_get_claimer (
McdDispatchOperation *operation);
G_GNUC_INTERNAL gboolean _mcd_dispatch_operation_finish (
McdDispatchOperation *operation);
+G_GNUC_INTERNAL gboolean _mcd_dispatch_operation_needs_approval (
+ McdDispatchOperation *self);
G_END_DECLS
diff --git a/src/mcd-dispatch-operation.c b/src/mcd-dispatch-operation.c
index e0d8950..ad95880 100644
--- a/src/mcd-dispatch-operation.c
+++ b/src/mcd-dispatch-operation.c
@@ -80,6 +80,10 @@ struct _McdDispatchOperationPrivate
GHashTable *properties;
gsize block_finished;
+ /* If FALSE, we're not actually on D-Bus; an object path is reserved,
+ * but we're inaccessible. */
+ guint needs_approval : 1;
+
/* Results */
guint finished : 1;
gchar *handler;
@@ -104,6 +108,7 @@ enum
PROP_DBUS_DAEMON,
PROP_CHANNELS,
PROP_POSSIBLE_HANDLERS,
+ PROP_NEEDS_APPROVAL,
};
static void
@@ -355,7 +360,8 @@ mcd_dispatch_operation_constructor (GType type, guint n_params,
dbus_connection = TP_PROXY (priv->dbus_daemon)->dbus_connection;
create_object_path (priv);
- DEBUG ("%s/%p", priv->unique_name, object);
+ DEBUG ("%s/%p: needs_approval=%c", priv->unique_name, object,
+ priv->needs_approval ? 'T' : 'F');
if (DEBUGGING)
{
@@ -367,7 +373,9 @@ mcd_dispatch_operation_constructor (GType type, guint n_params,
}
}
- if (G_LIKELY (dbus_connection))
+ /* If approval is not needed, we don't appear on D-Bus (and approvers
+ * don't run) */
+ if (priv->needs_approval && G_LIKELY (dbus_connection))
dbus_g_connection_register_g_object (dbus_connection,
priv->object_path, object);
@@ -416,6 +424,10 @@ mcd_dispatch_operation_set_property (GObject *obj, guint prop_id,
g_assert (priv->possible_handlers != NULL);
break;
+ case PROP_NEEDS_APPROVAL:
+ priv->needs_approval = g_value_get_boolean (val);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
break;
@@ -438,6 +450,10 @@ mcd_dispatch_operation_get_property (GObject *obj, guint prop_id,
g_value_set_boxed (val, priv->possible_handlers);
break;
+ case PROP_NEEDS_APPROVAL:
+ g_value_set_boolean (val, priv->needs_approval);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
break;
@@ -526,6 +542,13 @@ _mcd_dispatch_operation_class_init (McdDispatchOperationClass * klass)
G_TYPE_STRV,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (object_class, PROP_NEEDS_APPROVAL,
+ g_param_spec_boolean ("needs-approval", "Needs approval?",
+ "TRUE if this CDO should run Approvers and "
+ "appear on D-Bus", FALSE,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
}
static void
@@ -553,6 +576,7 @@ _mcd_dispatch_operation_init (McdDispatchOperation *operation)
*/
McdDispatchOperation *
_mcd_dispatch_operation_new (TpDBusDaemon *dbus_daemon,
+ gboolean needs_approval,
GList *channels,
const GStrv possible_handlers)
{
@@ -561,7 +585,9 @@ _mcd_dispatch_operation_new (TpDBusDaemon *dbus_daemon,
"dbus-daemon", dbus_daemon,
"channels", channels,
"possible-handlers", possible_handlers,
+ "needs-approval", needs_approval,
NULL);
+
return MCD_DISPATCH_OPERATION (obj);
}
@@ -639,6 +665,14 @@ _mcd_dispatch_operation_is_claimed (McdDispatchOperation *operation)
return (operation->priv->claimer != NULL);
}
+gboolean
+_mcd_dispatch_operation_needs_approval (McdDispatchOperation *self)
+{
+ g_return_val_if_fail (MCD_IS_DISPATCH_OPERATION (self), FALSE);
+
+ return self->priv->needs_approval;
+}
+
const gchar *
_mcd_dispatch_operation_get_claimer (McdDispatchOperation *operation)
{
diff --git a/src/mcd-dispatcher.c b/src/mcd-dispatcher.c
index d6fc50d..7d0e182 100644
--- a/src/mcd-dispatcher.c
+++ b/src/mcd-dispatcher.c
@@ -1210,13 +1210,14 @@ mcd_dispatcher_run_observers (McdDispatcherContext *context)
satisfied_requests = collect_satisfied_requests (observed);
- if (context->operation)
+ if (_mcd_dispatch_operation_needs_approval (context->operation))
{
dispatch_operation_path =
_mcd_dispatch_operation_get_path (context->operation);
- _mcd_dispatch_operation_block_finished (context->operation);
}
+ _mcd_dispatch_operation_block_finished (context->operation);
+
context->observers_pending++;
mcd_dispatcher_context_ref (context, "CTXREF05");
DEBUG ("calling ObserveChannels on %s for context %p",
@@ -1320,6 +1321,8 @@ mcd_dispatcher_run_approvers (McdDispatcherContext *context)
McdClient *client;
g_return_if_fail (context->operation != NULL);
+ g_return_if_fail (_mcd_dispatch_operation_needs_approval (
+ context->operation));
sp_timestamp ("run approvers");
/* we temporarily increment this count and decrement it at the end of the
@@ -1426,9 +1429,9 @@ mcd_dispatcher_run_clients (McdDispatcherContext *context)
mcd_dispatcher_run_observers (context);
- /* if we have a dispatch operation, it means that the channels were not
- * requested: start the Approvers */
- if (context->operation)
+ /* if the dispatch operation thinks the channels were not
+ * requested, start the Approvers */
+ if (_mcd_dispatch_operation_needs_approval (context->operation))
{
/* but if the handlers have the BypassApproval flag set, then don't
*
@@ -1544,7 +1547,9 @@ on_operation_finished (McdDispatchOperation *operation,
mcd_dispatcher_context_ref (context, "CTXREF15");
- if (context->dispatcher->priv->operation_list_active)
+ /* 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))
{
tp_svc_channel_dispatcher_interface_operation_list_emit_dispatch_operation_finished (
context->dispatcher, _mcd_dispatch_operation_get_path (operation));
@@ -1641,6 +1646,15 @@ _mcd_dispatcher_enter_state_machine (McdDispatcher *dispatcher,
priv->contexts = g_list_prepend (priv->contexts, context);
+ /* FIXME: what should we do when the channels are a mixture of Requested
+ * and unRequested? At the moment we act as though they're all Requested;
+ * perhaps we should act as though they're all unRequested, or split up the
+ * bundle? */
+
+ context->operation =
+ _mcd_dispatch_operation_new (priv->dbus_daemon, !requested, channels,
+ possible_handlers);
+
if (requested)
{
context->approved = TRUE;
@@ -1648,9 +1662,6 @@ _mcd_dispatcher_enter_state_machine (McdDispatcher *dispatcher,
else
{
context->approved = FALSE;
- context->operation =
- _mcd_dispatch_operation_new (priv->dbus_daemon, channels,
- possible_handlers);
if (priv->operation_list_active)
{
@@ -1753,7 +1764,8 @@ _mcd_dispatcher_get_property (GObject * obj, guint prop_id,
{
McdDispatcherContext *context = iter->data;
- if (context->operation != NULL &&
+ if (_mcd_dispatch_operation_needs_approval (context->operation)
+ &&
!_mcd_dispatch_operation_is_finished (context->operation))
{
GValueArray *va = g_value_array_new (2);
@@ -3876,6 +3888,10 @@ _mcd_dispatcher_reinvoke_handler (McdDispatcher *dispatcher,
dispatcher, list);
g_list_free (list);
+ context->operation = _mcd_dispatch_operation_new (
+ dispatcher->priv->dbus_daemon, FALSE, context->channels,
+ context->possible_handlers);
+
/* We must ref() the channel, because
* mcd_dispatcher_context_unref() will unref() it */
g_object_ref (channel);
--
1.5.6.5
More information about the telepathy-commits
mailing list