[telepathy-mission-control/master] McdDispatchOperation: move McdDispatcherContext's @account member here
Simon McVittie
simon.mcvittie at collabora.co.uk
Mon Sep 21 05:36:05 PDT 2009
---
src/mcd-dispatch-operation-priv.h | 2 +
src/mcd-dispatch-operation.c | 69 ++++++++++++++++++++++++++++++------
src/mcd-dispatcher.c | 14 ++-----
3 files changed, 63 insertions(+), 22 deletions(-)
diff --git a/src/mcd-dispatch-operation-priv.h b/src/mcd-dispatch-operation-priv.h
index 824f36f..c0e09e2 100644
--- a/src/mcd-dispatch-operation-priv.h
+++ b/src/mcd-dispatch-operation-priv.h
@@ -53,6 +53,8 @@ G_GNUC_INTERNAL GType _mcd_dispatch_operation_get_type (void);
G_GNUC_INTERNAL const gchar *_mcd_dispatch_operation_get_path
(McdDispatchOperation *operation);
+G_GNUC_INTERNAL const gchar *_mcd_dispatch_operation_get_account_path
+ (McdDispatchOperation *self);
G_GNUC_INTERNAL GHashTable *_mcd_dispatch_operation_get_properties
(McdDispatchOperation *operation);
G_GNUC_INTERNAL gboolean _mcd_dispatch_operation_is_claimed
diff --git a/src/mcd-dispatch-operation.c b/src/mcd-dispatch-operation.c
index 1d5cdda..6320c12 100644
--- a/src/mcd-dispatch-operation.c
+++ b/src/mcd-dispatch-operation.c
@@ -97,6 +97,7 @@ struct _McdDispatchOperationPrivate
/* DBUS connection */
TpDBusDaemon *dbus_daemon;
+ McdAccount *account;
McdConnection *connection;
/* Owned McdChannels we're dispatching */
@@ -133,18 +134,10 @@ get_connection (TpSvcDBusProperties *self, const gchar *name, GValue *value)
static void
get_account (TpSvcDBusProperties *self, const gchar *name, GValue *value)
{
- McdDispatchOperationPrivate *priv = MCD_DISPATCH_OPERATION_PRIV (self);
- McdAccount *account;
- const gchar *object_path;
-
- DEBUG ("called for %s", priv->unique_name);
g_value_init (value, DBUS_TYPE_G_OBJECT_PATH);
- if (priv->connection &&
- (account = mcd_connection_get_account (priv->connection)) &&
- (object_path = mcd_account_get_object_path (account)))
- g_value_set_boxed (value, object_path);
- else
- g_value_set_static_boxed (value, "/");
+ g_value_set_boxed (value,
+ _mcd_dispatch_operation_get_account_path
+ (MCD_DISPATCH_OPERATION (self)));
}
GPtrArray *
@@ -409,12 +402,34 @@ mcd_dispatch_operation_set_property (GObject *obj, guint prop_id,
priv->channels = g_value_get_pointer (val);
if (G_LIKELY (priv->channels))
{
- /* get the connection from the first channel */
+ /* get the connection and account from the first channel */
McdChannel *channel = MCD_CHANNEL (priv->channels->data);
+
priv->connection = (McdConnection *)
mcd_mission_get_parent (MCD_MISSION (channel));
+
if (G_LIKELY (priv->connection))
+ {
g_object_ref (priv->connection);
+ }
+ else
+ {
+ /* shouldn't happen? */
+ g_warning ("Channel has no Connection?!");
+ }
+
+ priv->account = mcd_channel_get_account (channel);
+
+ if (G_LIKELY (priv->account != NULL))
+ {
+ g_object_ref (priv->account);
+ }
+ else
+ {
+ /* shouldn't happen? */
+ g_warning ("Channel given to McdDispatchOperation has no "
+ "Account?!");
+ }
/* reference the channels */
for (list = priv->channels; list != NULL; list = list->next)
@@ -515,6 +530,12 @@ mcd_dispatch_operation_dispose (GObject *object)
priv->connection = NULL;
}
+ if (priv->account != NULL)
+ {
+ g_object_unref (priv->account);
+ priv->account = NULL;
+ }
+
if (priv->dbus_daemon)
{
g_object_unref (priv->dbus_daemon);
@@ -614,6 +635,30 @@ _mcd_dispatch_operation_get_path (McdDispatchOperation *operation)
}
/*
+ * _mcd_dispatch_operation_get_account_path:
+ * @operation: the #McdDispatchOperation.
+ *
+ * Returns: the D-Bus object path of the Account associated with @operation,
+ * or "/" if none.
+ */
+const gchar *
+_mcd_dispatch_operation_get_account_path (McdDispatchOperation *self)
+{
+ const gchar *path;
+
+ g_return_val_if_fail (MCD_IS_DISPATCH_OPERATION (self), "/");
+
+ if (self->priv->account == NULL)
+ return "/";
+
+ path = mcd_account_get_object_path (self->priv->account);
+
+ g_return_val_if_fail (path != NULL, "/");
+
+ return path;
+}
+
+/*
* _mcd_dispatch_operation_get_properties:
* @operation: the #McdDispatchOperation.
*
diff --git a/src/mcd-dispatcher.c b/src/mcd-dispatcher.c
index 3a26c76..01aa56f 100644
--- a/src/mcd-dispatcher.c
+++ b/src/mcd-dispatcher.c
@@ -118,7 +118,6 @@ struct _McdDispatcherContext
McdDispatcher *dispatcher;
GList *channels;
- McdAccount *account;
McdDispatchOperation *operation;
/* The number of observers that have not yet returned from ObserveChannels.
@@ -901,9 +900,8 @@ mcd_dispatcher_handle_channels (McdDispatcherContext *context,
mcd_connection_get_object_path (connection) : NULL;
if (G_UNLIKELY (!connection_path)) connection_path = "/";
- g_assert (context->account != NULL);
- account_path = mcd_account_get_object_path (context->account);
- if (G_UNLIKELY (!account_path)) account_path = "/";
+ account_path = _mcd_dispatch_operation_get_account_path
+ (context->operation);
channels_array = _mcd_channel_details_build_from_list (channels);
@@ -1153,7 +1151,6 @@ mcd_dispatcher_run_observers (McdDispatcherContext *context)
{
GList *observed = NULL;
McdConnection *connection;
- McdAccount *account;
const gchar *account_path, *connection_path;
GPtrArray *channels_array, *satisfied_requests;
@@ -1175,9 +1172,8 @@ mcd_dispatcher_run_observers (McdDispatcherContext *context)
g_assert (connection != NULL);
connection_path = mcd_connection_get_object_path (connection);
- account = mcd_connection_get_account (connection);
- g_assert (account != NULL);
- account_path = mcd_account_get_object_path (account);
+ account_path = _mcd_dispatch_operation_get_account_path
+ (context->operation);
/* TODO: there's room for optimization here: reuse the channels_array,
* if the observed list is the same */
@@ -1598,7 +1594,6 @@ _mcd_dispatcher_enter_state_machine (McdDispatcher *dispatcher,
DEBUG ("CTXREF11 on %p", context);
context->ref_count = 1;
context->dispatcher = dispatcher;
- context->account = account;
context->channels = channels;
context->chain = priv->filters;
@@ -3834,7 +3829,6 @@ _mcd_dispatcher_reinvoke_handler (McdDispatcher *dispatcher,
context->ref_count = 1;
context->dispatcher = dispatcher;
context->channels = g_list_prepend (NULL, channel);
- context->account = mcd_channel_get_account (channel);
list = g_list_append (NULL, channel);
possible_handlers = mcd_dispatcher_get_possible_handlers (dispatcher,
--
1.5.6.5
More information about the telepathy-commits
mailing list