From 5aa2791910b1fd1e9ec25b2c4859abca70904888 Mon Sep 17 00:00:00 2001 From: Chandni Verma Date: Mon, 17 Sep 2012 21:00:52 +0530 Subject: [PATCH] Add tp_dbus_tube_channel_dup_parameters_vardict() Bug: https://bugs.freedesktop.org/show_bug.cgi?id=55024 --- docs/reference/telepathy-glib-sections.txt | 1 + telepathy-glib/dbus-tube-channel.c | 30 ++++++++++++++++++++++++++++ telepathy-glib/dbus-tube-channel.h | 3 +++ tests/dbus/dbus-tube.c | 22 ++++++++++++++++++++ 4 files changed, 56 insertions(+) diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt index d277555..b482fe3 100644 --- a/docs/reference/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib-sections.txt @@ -6417,6 +6417,7 @@ TpDBusTubeChannel TpDBusTubeChannelClass TP_DBUS_TUBE_CHANNEL_FEATURE_CORE tp_dbus_tube_channel_get_parameters +tp_dbus_tube_channel_dup_parameters_vardict tp_dbus_tube_channel_get_service_name tp_dbus_tube_channel_offer_async tp_dbus_tube_channel_offer_finish diff --git a/telepathy-glib/dbus-tube-channel.c b/telepathy-glib/dbus-tube-channel.c index c8156ab..3ecaec0 100644 --- a/telepathy-glib/dbus-tube-channel.c +++ b/telepathy-glib/dbus-tube-channel.c @@ -97,6 +97,7 @@ #include "telepathy-glib/automatic-client-factory-internal.h" #include "telepathy-glib/channel-internal.h" #include "telepathy-glib/debug-internal.h" +#include "telepathy-glib/variant-util-internal.h" #include #include @@ -512,6 +513,35 @@ tp_dbus_tube_channel_get_parameters (TpDBusTubeChannel *self) } /** + * tp_dbus_tube_channel_dup_parameters_vardict + * @self: a #TpDBusTubeChannel + * + * Return the parameters of the dbus-tube channel in a variant of + * type %G_VARIANT_TYPE_VARDICT whose keys are strings representing + * parameter names and values are GValues representing corresponding + * parameter values set by the offerer when offering this channel. + * + * The GVariant returned is NULL if this is an outgoing tube that has not + * yet been offered or the parameters property has not been set. + * + * Use g_variant_lookup() or g_variant_lookup_value() for convenient + * access to the values, the expected types of which should match the ones + * defined upon the creation of the parameters #GHashTable. + * + * Since: 0.20.0 + */ +GVariant * +tp_dbus_tube_channel_dup_parameters_vardict (TpDBusTubeChannel *self) +{ + g_return_val_if_fail (TP_IS_DBUS_TUBE_CHANNEL (self), NULL); + + if (self->priv->parameters == NULL) + return NULL; + + return _tp_asv_to_vardict (self->priv->parameters); +} + +/** * TP_DBUS_TUBE_CHANNEL_FEATURE_CORE: * * Expands to a call to a function that returns a quark representing the diff --git a/telepathy-glib/dbus-tube-channel.h b/telepathy-glib/dbus-tube-channel.h index 7d08eae..1171afd 100644 --- a/telepathy-glib/dbus-tube-channel.h +++ b/telepathy-glib/dbus-tube-channel.h @@ -69,6 +69,9 @@ const gchar * tp_dbus_tube_channel_get_service_name (TpDBusTubeChannel *self); _TP_AVAILABLE_IN_0_18 GHashTable * tp_dbus_tube_channel_get_parameters (TpDBusTubeChannel *self); +_TP_AVAILABLE_IN_UNRELEASED +GVariant * tp_dbus_tube_channel_dup_parameters_vardict (TpDBusTubeChannel *self); + /* Outgoing tube methods */ _TP_AVAILABLE_IN_0_18 diff --git a/tests/dbus/dbus-tube.c b/tests/dbus/dbus-tube.c index 71f4784..27ac21c 100644 --- a/tests/dbus/dbus-tube.c +++ b/tests/dbus/dbus-tube.c @@ -180,11 +180,24 @@ check_parameters (GHashTable *parameters) } static void +check_parameters_vardict (GVariant *parameters_vardict) +{ + guint32 badger_value; + + g_assert (parameters_vardict != NULL); + + g_assert (g_variant_lookup (parameters_vardict, "badger", + "u", &badger_value)); + g_assert_cmpuint (badger_value, ==, 42); +} + +static void test_properties (Test *test, gconstpointer data G_GNUC_UNUSED) { gchar *service; GHashTable *parameters; + GVariant *parameters_vardict; /* Outgoing tube */ create_tube_service (test, TRUE, TRUE); @@ -198,10 +211,13 @@ test_properties (Test *test, /* Parameters */ parameters = tp_dbus_tube_channel_get_parameters (test->tube); + parameters_vardict = tp_dbus_tube_channel_dup_parameters_vardict ( + test->tube); /* NULL as the tube has not be offered yet */ g_assert (parameters == NULL); g_object_get (test->tube, "parameters", ¶meters, NULL); g_assert (parameters == NULL); + g_assert (parameters_vardict == NULL); /* Incoming tube */ create_tube_service (test, FALSE, FALSE); @@ -211,7 +227,13 @@ test_properties (Test *test, check_parameters (parameters); g_object_get (test->tube, "parameters", ¶meters, NULL); check_parameters (parameters); + + parameters_vardict = tp_dbus_tube_channel_dup_parameters_vardict ( + test->tube); + check_parameters_vardict (parameters_vardict); + g_hash_table_unref (parameters); + g_variant_unref (parameters_vardict); } static void -- 1.7.9.5