From be1854744b16e3fdf1818e3197776e217eea50c1 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Thu, 14 Jul 2011 14:57:20 +0200 Subject: [PATCH] Ensure TpChannelDispatchOperation always has a factory Use it to share its TpAccount and TpConnection, and also TpChannel in the future --- telepathy-glib/base-client.c | 13 ++- .../channel-dispatch-operation-internal.h | 11 +-- telepathy-glib/channel-dispatch-operation.c | 88 +++++-------------- 3 files changed, 34 insertions(+), 78 deletions(-) diff --git a/telepathy-glib/base-client.c b/telepathy-glib/base-client.c index 6765291..6a059b8 100644 --- a/telepathy-glib/base-client.c +++ b/telepathy-glib/base-client.c @@ -1669,8 +1669,9 @@ _tp_base_client_observe_channels (TpSvcClientObserver *iface, } else { - dispatch_operation = tp_channel_dispatch_operation_new (self->priv->dbus, - dispatch_operation_path, NULL, &error); + dispatch_operation = tp_simple_client_factory_dup_channel_dispatch_operation ( + tp_proxy_get_factory (self->priv->account_mgr), + dispatch_operation_path, NULL, &error); if (dispatch_operation == NULL) { DEBUG ("Failed to create TpChannelDispatchOperation: %s", @@ -1883,15 +1884,17 @@ _tp_base_client_add_dispatch_operation (TpSvcClientApprover *iface, g_ptr_array_add (channels, channel); } - dispatch_operation = _tp_channel_dispatch_operation_new_with_objects ( - self->priv->dbus, dispatch_operation_path, properties, - account, connection, channels, &error); + dispatch_operation = tp_simple_client_factory_dup_channel_dispatch_operation ( + tp_proxy_get_factory (self->priv->account_mgr), + dispatch_operation_path, properties, &error); if (dispatch_operation == NULL) { DEBUG ("Failed to create TpChannelDispatchOperation: %s", error->message); goto out; } + _tp_channel_dispatch_operation_ensure_channels (dispatch_operation, channels); + ctx = _tp_add_dispatch_operation_context_new (account, connection, channels, dispatch_operation, context); diff --git a/telepathy-glib/channel-dispatch-operation-internal.h b/telepathy-glib/channel-dispatch-operation-internal.h index 4e19aca..9db1607 100644 --- a/telepathy-glib/channel-dispatch-operation-internal.h +++ b/telepathy-glib/channel-dispatch-operation-internal.h @@ -25,14 +25,9 @@ G_BEGIN_DECLS -TpChannelDispatchOperation * _tp_channel_dispatch_operation_new_with_objects ( - TpDBusDaemon *bus_daemon, - const gchar *object_path, - GHashTable *immutable_properties, - TpAccount *account, - TpConnection *connection, - GPtrArray *channels, - GError **error); +void _tp_channel_dispatch_operation_ensure_channels ( + TpChannelDispatchOperation *self, + GPtrArray *channels); G_END_DECLS diff --git a/telepathy-glib/channel-dispatch-operation.c b/telepathy-glib/channel-dispatch-operation.c index c66496e..00dc348 100644 --- a/telepathy-glib/channel-dispatch-operation.c +++ b/telepathy-glib/channel-dispatch-operation.c @@ -244,7 +244,6 @@ static void maybe_set_connection (TpChannelDispatchOperation *self, const gchar *path) { - TpDBusDaemon *dbus; GError *error = NULL; if (self->priv->connection != NULL) @@ -253,9 +252,8 @@ maybe_set_connection (TpChannelDispatchOperation *self, if (path == NULL) return; - dbus = tp_proxy_get_dbus_daemon (self); - - self->priv->connection = tp_connection_new (dbus, NULL, path, &error); + self->priv->connection = tp_simple_client_factory_dup_connection ( + tp_proxy_get_factory (self), path, &error); if (self->priv->connection == NULL) { DEBUG ("Failed to create connection %s: %s", path, error->message); @@ -278,7 +276,6 @@ static void maybe_set_account (TpChannelDispatchOperation *self, const gchar *path) { - TpDBusDaemon *dbus; GError *error = NULL; if (self->priv->account != NULL) @@ -287,9 +284,8 @@ maybe_set_account (TpChannelDispatchOperation *self, if (path == NULL) return; - dbus = tp_proxy_get_dbus_daemon (self); - - self->priv->account = tp_account_new (dbus, path, &error); + self->priv->account = tp_simple_client_factory_dup_account ( + tp_proxy_get_factory (self), path, &error); if (self->priv->account == NULL) { DEBUG ("Failed to create account %s: %s", path, error->message); @@ -366,28 +362,9 @@ tp_channel_dispatch_operation_set_property (GObject *object, break; case PROP_CHANNELS: - { - GPtrArray *tmp; - guint i; - - g_assert (self->priv->channels == NULL); /* construct-only */ - - /* g_value_dup_boxed returns a new reference to the same - * GPtrArray which is not what we want (removing a channel from the - * CDO array shouldn't remove it from the caller). Copying the - * GPtrArray to avoid this problem.*/ - tmp = g_value_get_boxed (value); - - if (tmp == NULL) - break; - - self->priv->channels = _tp_g_ptr_array_sized_new_with_free_func ( - tmp->len, g_object_unref); - - for (i = 0; i < tmp->len; i++) - g_ptr_array_add (self->priv->channels, - g_object_ref (g_ptr_array_index (tmp, i))); - } + g_assert (self->priv->channels == NULL); /* construct-only */ + _tp_channel_dispatch_operation_ensure_channels (self, + g_value_get_boxed (value)); break; case PROP_CDO_PROPERTIES: @@ -423,6 +400,8 @@ tp_channel_dispatch_operation_constructed (GObject *object) g_return_if_fail (tp_proxy_get_dbus_daemon (self) != NULL); + _tp_proxy_ensure_factory (self, NULL); + maybe_set_connection (self, tp_asv_get_boxed (self->priv->immutable_properties, TP_PROP_CHANNEL_DISPATCH_OPERATION_CONNECTION, @@ -1279,45 +1258,24 @@ tp_channel_dispatch_operation_claim_finish ( return TRUE; } -/* This can be used by tp-glib to create a new CDO using existing proxies - * (account, connection, channels) rather than creating new ones. */ -TpChannelDispatchOperation * -_tp_channel_dispatch_operation_new_with_objects (TpDBusDaemon *bus_daemon, - const gchar *object_path, - GHashTable *immutable_properties, - TpAccount *account, - TpConnection *connection, - GPtrArray *channels, - GError **error) +/* This is temporary solution to share TpChannel objects until + * TpSimpleClientFactory can be used for that */ +void +_tp_channel_dispatch_operation_ensure_channels (TpChannelDispatchOperation *self, + GPtrArray *channels) { - TpChannelDispatchOperation *self; - gchar *unique_name; - - g_return_val_if_fail (bus_daemon != NULL, NULL); - g_return_val_if_fail (object_path != NULL, NULL); - g_return_val_if_fail (error == NULL || *error == NULL, NULL); - - if (!tp_dbus_check_valid_object_path (object_path, error)) - return NULL; - - if (!_tp_dbus_daemon_get_name_owner (bus_daemon, -1, - TP_CHANNEL_DISPATCHER_BUS_NAME, &unique_name, error)) - return NULL; + guint i; - self = TP_CHANNEL_DISPATCH_OPERATION (g_object_new ( - TP_TYPE_CHANNEL_DISPATCH_OPERATION, - "dbus-daemon", bus_daemon, - "bus-name", unique_name, - "object-path", object_path, - "cdo-properties", immutable_properties, - "account", account, - "connection", connection, - "channels", channels, - NULL)); + if (self->priv->channels != NULL || channels == NULL) + return; - g_free (unique_name); + /* Do not just ref the GPtrArray because we'll modify its content */ + self->priv->channels = _tp_g_ptr_array_sized_new_with_free_func ( + channels->len, g_object_unref); - return self; + for (i = 0; i < channels->len; i++) + g_ptr_array_add (self->priv->channels, + g_object_ref (g_ptr_array_index (channels, i))); } /** -- 1.7.4.1