From 88786d1a083b6bddf49bcb7dbe6397318f5c548a Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Thu, 27 Feb 2014 13:07:16 +0100 Subject: [PATCH 6/6] client-factory: take a vardict for new channel props --- telepathy-glib/automatic-client-factory.c | 26 ++++++++++++++----- telepathy-glib/base-client.c | 2 +- telepathy-glib/channel-dispatch-operation.c | 5 ++-- telepathy-glib/channel-request.c | 3 ++- telepathy-glib/client-factory.c | 40 +++++++++++++++++++++-------- telepathy-glib/client-factory.h | 4 +-- telepathy-logger/client-factory.c | 23 ++++++++++++----- tests/dbus/call-channel.c | 5 ++-- tests/dbus/dbus-tube.c | 3 ++- tests/dbus/file-transfer-channel.c | 3 ++- tests/dbus/stream-tube.c | 3 ++- tests/dbus/text-channel.c | 5 ++-- tests/lib/util.c | 2 +- 13 files changed, 86 insertions(+), 38 deletions(-) diff --git a/telepathy-glib/automatic-client-factory.c b/telepathy-glib/automatic-client-factory.c index f1f7eac..813d7a3 100644 --- a/telepathy-glib/automatic-client-factory.c +++ b/telepathy-glib/automatic-client-factory.c @@ -121,7 +121,7 @@ G_DEFINE_TYPE (TpAutomaticClientFactory, tp_automatic_client_factory, typedef gboolean (*CheckPropertiesFunc) ( const gchar *object_path, - const GHashTable *properties); + GVariant *properties); typedef TpChannel *(*NewFunc) ( TpClientFactory *client, @@ -190,16 +190,19 @@ static TpChannel * create_channel_impl (TpClientFactory *self, TpConnection *conn, const gchar *object_path, - const GHashTable *properties, + GVariant *properties, GError **error) { - const gchar *chan_type; + const gchar *chan_type = NULL; ChannelTypeMapping *m; + TpChannel *channel = NULL; - chan_type = tp_asv_get_string (properties, TP_PROP_CHANNEL_CHANNEL_TYPE); + g_variant_lookup (properties, TP_PROP_CHANNEL_CHANNEL_TYPE, "&s", &chan_type); for (m = channel_type_mapping; m->channel_type != NULL; m++) { + GHashTable *asv; + if (tp_strdiff (chan_type, m->channel_type)) continue; @@ -207,11 +210,20 @@ create_channel_impl (TpClientFactory *self, !m->check_properties (object_path, properties)) break; - return m->new_func (self, conn, object_path, properties, error); + asv = tp_asv_from_vardict (properties); + channel = m->new_func (self, conn, object_path, asv, error); + g_hash_table_unref (asv); + break; + } + + if (channel == NULL) + { + /* Chainup on parent implementation as fallback */ + channel = chainup->create_channel (self, conn, object_path, properties, + error); } - /* Chainup on parent implementation as fallback */ - return chainup->create_channel (self, conn, object_path, properties, error); + return channel; } static GArray * diff --git a/telepathy-glib/base-client.c b/telepathy-glib/base-client.c index 8f61d70..4571661 100644 --- a/telepathy-glib/base-client.c +++ b/telepathy-glib/base-client.c @@ -1542,7 +1542,7 @@ ensure_account_connection_channel (TpBaseClient *self, _tp_connection_set_account (*connection, *account); *channel = tp_client_factory_ensure_channel (self->priv->factory, - *connection, chan_path, chan_props, error); + *connection, chan_path, tp_asv_to_vardict (chan_props), error); if (*channel == NULL) goto error; diff --git a/telepathy-glib/channel-dispatch-operation.c b/telepathy-glib/channel-dispatch-operation.c index dcbc7ec..2d5a078 100644 --- a/telepathy-glib/channel-dispatch-operation.c +++ b/telepathy-glib/channel-dispatch-operation.c @@ -34,6 +34,7 @@ #include #include #include +#include #define DEBUG_FLAG TP_DEBUG_DISPATCHER #include "telepathy-glib/dbus-internal.h" @@ -276,8 +277,8 @@ maybe_set_channel (TpChannelDispatchOperation *self, return; self->priv->channel = tp_client_factory_ensure_channel ( - tp_proxy_get_factory (self), self->priv->connection, path, properties, - &error); + tp_proxy_get_factory (self), self->priv->connection, path, + tp_asv_to_vardict (properties), &error); if (self->priv->channel == NULL) { DEBUG ("Failed to create channel %s: %s", path, error->message); diff --git a/telepathy-glib/channel-request.c b/telepathy-glib/channel-request.c index 2e73cba..ec1d1fc 100644 --- a/telepathy-glib/channel-request.c +++ b/telepathy-glib/channel-request.c @@ -33,6 +33,7 @@ #include #include #include +#include #define DEBUG_FLAG TP_DEBUG_DISPATCHER #include "telepathy-glib/dbus-internal.h" @@ -221,7 +222,7 @@ tp_channel_request_succeeded_cb (TpChannelRequest *self, } channel = tp_client_factory_ensure_channel (tp_proxy_get_factory (self), - connection, chan_path, chan_props, &error); + connection, chan_path, tp_asv_to_vardict (chan_props), &error); if (channel == NULL) { DEBUG ("Failed to create TpChannel: %s", error->message); diff --git a/telepathy-glib/client-factory.c b/telepathy-glib/client-factory.c index 7b5242e..7e4823d 100644 --- a/telepathy-glib/client-factory.c +++ b/telepathy-glib/client-factory.c @@ -230,11 +230,19 @@ static TpChannel * create_channel_impl (TpClientFactory *self, TpConnection *conn, const gchar *object_path, - const GHashTable *immutable_properties, + GVariant *immutable_properties, GError **error) { - return _tp_channel_new_with_factory (self, conn, object_path, - immutable_properties, error); + TpChannel *channel; + GHashTable *props; + + props = tp_asv_from_vardict (immutable_properties); + + channel = _tp_channel_new_with_factory (self, conn, object_path, + props, error); + + g_hash_table_unref (props); + return channel; } static GArray * @@ -716,8 +724,8 @@ tp_client_factory_add_connection_features_varargs ( * @self: a #TpClientFactory * @connection: a #TpConnection whose #TpProxy:factory is this object * @object_path: the object path of a channel on @connection - * @immutable_properties: (transfer none) (element-type utf8 GObject.Value): - * the immutable properties of the channel + * @immutable_properties: (allow-none) a #G_VARIANT_TYPE_VARDICT containing + * the immutable properties of the account, or %NULL. * @error: Used to raise an error if @object_path is not valid * * Returns a #TpChannel proxy for the channel at @object_path on @connection. @@ -733,6 +741,8 @@ tp_client_factory_add_connection_features_varargs ( * #TpAccountChannelRequest and #TpBaseClient are more appropriate ways * to obtain channels for most applications. * + * @immutable_properties is consumed if it is floating. + * * Returns: (transfer full): a reference to a #TpChannel; * see tp_channel_new_from_properties(). * @@ -742,7 +752,7 @@ TpChannel * tp_client_factory_ensure_channel (TpClientFactory *self, TpConnection *connection, const gchar *object_path, - const GHashTable *immutable_properties, + GVariant *immutable_properties, GError **error) { TpChannel *channel; @@ -754,11 +764,21 @@ tp_client_factory_ensure_channel (TpClientFactory *self, channel = lookup_proxy (self, object_path); if (channel != NULL) - return g_object_ref (channel); + { + g_object_ref (channel); + } + else + { + channel = TP_CLIENT_FACTORY_GET_CLASS (self)->create_channel (self, + connection, object_path, immutable_properties, error); + insert_proxy (self, channel); + } - channel = TP_CLIENT_FACTORY_GET_CLASS (self)->create_channel (self, - connection, object_path, immutable_properties, error); - insert_proxy (self, channel); + if (immutable_properties != NULL) + { + g_variant_ref_sink (immutable_properties); + g_variant_unref (immutable_properties); + } return channel; } diff --git a/telepathy-glib/client-factory.h b/telepathy-glib/client-factory.h index 4806fce..1a79da8 100644 --- a/telepathy-glib/client-factory.h +++ b/telepathy-glib/client-factory.h @@ -63,7 +63,7 @@ struct _TpClientFactoryClass { TpChannel * (*create_channel) (TpClientFactory *self, TpConnection *conn, const gchar *object_path, - const GHashTable *immutable_properties, + GVariant *immutable_properties, GError **error); GArray * (*dup_channel_features) (TpClientFactory *self, TpChannel *channel); @@ -138,7 +138,7 @@ void tp_client_factory_add_connection_features_varargs (TpClientFactory *self, TpChannel *tp_client_factory_ensure_channel (TpClientFactory *self, TpConnection *connection, const gchar *object_path, - const GHashTable *immutable_properties, + GVariant *immutable_properties, GError **error); GArray *tp_client_factory_dup_channel_features (TpClientFactory *self, TpChannel *channel); diff --git a/telepathy-logger/client-factory.c b/telepathy-logger/client-factory.c index cedd189..38253a5 100644 --- a/telepathy-logger/client-factory.c +++ b/telepathy-logger/client-factory.c @@ -36,25 +36,34 @@ static TpChannel * create_channel_impl (TpClientFactory *self, TpConnection *conn, const gchar *object_path, - const GHashTable *properties, + GVariant *properties, GError **error) { const gchar *chan_type; + GHashTable *asv; + TpChannel *channel; - chan_type = tp_asv_get_string (properties, TP_PROP_CHANNEL_CHANNEL_TYPE); + asv = tp_asv_from_vardict (properties); + chan_type = tp_asv_get_string (asv, TP_PROP_CHANNEL_CHANNEL_TYPE); if (!tp_strdiff (chan_type, TP_IFACE_CHANNEL_TYPE_TEXT)) { - return (TpChannel *) _tpl_text_channel_new_with_factory (self, conn, - object_path, properties, error); + channel = (TpChannel *) _tpl_text_channel_new_with_factory (self, conn, + object_path, asv, error); } else if (!tp_strdiff (chan_type, TP_IFACE_CHANNEL_TYPE_CALL1)) { - return (TpChannel *) _tpl_call_channel_new_with_factory (self, conn, - object_path, properties, error); + channel = (TpChannel *) _tpl_call_channel_new_with_factory (self, conn, + object_path, asv, error); + } + else + { + channel = chainup->create_channel (self, conn, object_path, properties, + error); } - return chainup->create_channel (self, conn, object_path, properties, error); + g_hash_table_unref (asv); + return channel; } static GArray * diff --git a/tests/dbus/call-channel.c b/tests/dbus/call-channel.c index ba8cf8e..eda2f1b 100644 --- a/tests/dbus/call-channel.c +++ b/tests/dbus/call-channel.c @@ -154,7 +154,8 @@ channel_created_cb (TpConnection *connection, g_assert_no_error ((GError *) error); test->chan = tp_client_factory_ensure_channel (test->factory, - connection, object_path, immutable_properties, &new_error); + connection, object_path, tp_asv_to_vardict (immutable_properties), + &new_error); g_assert_no_error (new_error); g_assert (TP_IS_CALL_CHANNEL (test->chan)); @@ -873,7 +874,7 @@ expect_incoming_call_cb (TpConnection *conn, g_assert (test->chan == NULL); test->chan = tp_client_factory_ensure_channel (test->factory, - conn, object_path, properties, &error); + conn, object_path, tp_asv_to_vardict (properties), &error); g_assert_no_error (error); g_assert (TP_IS_CALL_CHANNEL (test->chan)); diff --git a/tests/dbus/dbus-tube.c b/tests/dbus/dbus-tube.c index ff0f3e2..3fc693d 100644 --- a/tests/dbus/dbus-tube.c +++ b/tests/dbus/dbus-tube.c @@ -139,7 +139,8 @@ create_tube_service (Test *test, factory = tp_proxy_get_factory (test->connection); test->tube = (TpDBusTubeChannel *) tp_client_factory_ensure_channel ( - factory, test->connection, chan_path, props, &test->error); + factory, test->connection, chan_path, tp_asv_to_vardict (props), + &test->error); g_assert (TP_IS_DBUS_TUBE_CHANNEL (test->tube)); g_assert_no_error (test->error); diff --git a/tests/dbus/file-transfer-channel.c b/tests/dbus/file-transfer-channel.c index 02255b6..9daa525 100644 --- a/tests/dbus/file-transfer-channel.c +++ b/tests/dbus/file-transfer-channel.c @@ -216,7 +216,8 @@ create_file_transfer_channel (Test *test, factory = tp_proxy_get_factory (test->connection); test->channel = TP_FILE_TRANSFER_CHANNEL (tp_client_factory_ensure_channel ( - factory, test->connection, chan_path, props, &test->error)); + factory, test->connection, chan_path, tp_asv_to_vardict (props), + &test->error)); g_assert_no_error (test->error); g_assert (TP_IS_FILE_TRANSFER_CHANNEL (test->channel)); diff --git a/tests/dbus/stream-tube.c b/tests/dbus/stream-tube.c index 533b348..c157ef3 100644 --- a/tests/dbus/stream-tube.c +++ b/tests/dbus/stream-tube.c @@ -208,7 +208,8 @@ create_tube_service (Test *test, factory = tp_proxy_get_factory (test->connection); test->tube = TP_STREAM_TUBE_CHANNEL (tp_client_factory_ensure_channel ( - factory, test->connection, chan_path, props, &test->error)); + factory, test->connection, chan_path, tp_asv_to_vardict (props), + &test->error)); g_assert_no_error (test->error); g_assert (TP_IS_STREAM_TUBE_CHANNEL (test->tube)); diff --git a/tests/dbus/text-channel.c b/tests/dbus/text-channel.c index f2bae6d..876e344 100644 --- a/tests/dbus/text-channel.c +++ b/tests/dbus/text-channel.c @@ -83,7 +83,7 @@ create_contact_chan (Test *test) factory = tp_proxy_get_factory (test->connection); test->channel = TP_TEXT_CHANNEL (tp_client_factory_ensure_channel (factory, - test->connection, chan_path, props, &test->error)); + test->connection, chan_path, tp_asv_to_vardict (props), &test->error)); g_assert_no_error (test->error); g_assert (TP_IS_TEXT_CHANNEL (test->channel)); @@ -107,7 +107,8 @@ create_contact_chan (Test *test) NULL); test->sms_channel = TP_TEXT_CHANNEL (tp_client_factory_ensure_channel ( - factory, test->connection, chan_path, props, &test->error)); + factory, test->connection, chan_path, tp_asv_to_vardict (props), + &test->error)); g_assert_no_error (test->error); g_assert (TP_IS_TEXT_CHANNEL (test->sms_channel)); diff --git a/tests/lib/util.c b/tests/lib/util.c index 245efcc..ce63199 100644 --- a/tests/lib/util.c +++ b/tests/lib/util.c @@ -678,7 +678,7 @@ tp_tests_channel_new_from_properties (TpConnection *conn, factory = tp_proxy_get_factory (conn); return tp_client_factory_ensure_channel (factory, conn, - object_path, immutable_properties, error); + object_path, tp_asv_to_vardict (immutable_properties), error); } GHashTable * -- 1.8.5.3