summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Claessens <xclaesse@gmail.com>2011-07-15 16:54:41 +0200
committerXavier Claessens <xclaesse@gmail.com>2011-07-20 15:00:24 +0200
commitdede71ff8ff450a8137f37ba2cad8063deb203d8 (patch)
tree30a392caf4e9f0d6727167d253ba9ca1872d37a9
parent3b61b734df953582fe48cb7626709dca35d3a128 (diff)
downloadtelepathy-glib-dede71ff8ff450a8137f37ba2cad8063deb203d8.tar.gz
Always create TpChannelDispatchOperation through a factory
-rw-r--r--telepathy-glib/base-client.c15
-rw-r--r--telepathy-glib/channel-dispatch-operation-internal.h11
-rw-r--r--telepathy-glib/channel-dispatch-operation.c88
3 files changed, 36 insertions, 78 deletions
diff --git a/telepathy-glib/base-client.c b/telepathy-glib/base-client.c
index 43a4724e7..4d684d017 100644
--- a/telepathy-glib/base-client.c
+++ b/telepathy-glib/base-client.c
@@ -1669,8 +1669,10 @@ _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_ensure_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 +1885,18 @@ _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_ensure_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 4e19acaaa..9db160733 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 1c560a5e0..8e7285961 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_ensure_connection (
+ tp_proxy_get_factory (self), path, NULL, &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_ensure_account (
+ tp_proxy_get_factory (self), path, NULL, &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)
+/* FIXME: 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)));
}
/**