[next] telepathy-glib: TpStreamTubeChannel: add parameters-vardict and its getter
Simon McVittie
smcv at kemper.freedesktop.org
Mon Oct 8 08:23:23 PDT 2012
Module: telepathy-glib
Branch: next
Commit: 426d2e6f389b5a691b6eb03a0a740bcbef173749
URL: http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=426d2e6f389b5a691b6eb03a0a740bcbef173749
Author: Simon McVittie <simon.mcvittie at collabora.co.uk>
Date: Wed Sep 19 15:39:14 2012 +0100
TpStreamTubeChannel: add parameters-vardict and its getter
Signed-off-by: Simon McVittie <simon.mcvittie at collabora.co.uk>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=55095
https://bugs.freedesktop.org/show_bug.cgi?id=55024
---
docs/reference/telepathy-glib-sections.txt | 1 +
telepathy-glib/stream-tube-channel.c | 61 +++++++++++++++++++++++++++-
telepathy-glib/stream-tube-channel.h | 4 ++
tests/dbus/stream-tube.c | 48 +++++++++++++++++++---
4 files changed, 107 insertions(+), 7 deletions(-)
diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt
index 5f749d8..691d68e 100644
--- a/docs/reference/telepathy-glib-sections.txt
+++ b/docs/reference/telepathy-glib-sections.txt
@@ -6376,6 +6376,7 @@ TpStreamTubeChannelClass
tp_stream_tube_channel_accept_async
tp_stream_tube_channel_accept_finish
tp_stream_tube_channel_get_parameters
+tp_stream_tube_channel_dup_parameters_vardict
tp_stream_tube_channel_get_service
tp_stream_tube_channel_new
tp_stream_tube_channel_offer_async
diff --git a/telepathy-glib/stream-tube-channel.c b/telepathy-glib/stream-tube-channel.c
index 171fcdb..0139978 100644
--- a/telepathy-glib/stream-tube-channel.c
+++ b/telepathy-glib/stream-tube-channel.c
@@ -59,6 +59,7 @@
#include <telepathy-glib/stream-tube-connection-internal.h>
#include <telepathy-glib/util-internal.h>
#include <telepathy-glib/util.h>
+#include <telepathy-glib/variant-util-internal.h>
#define DEBUG_FLAG TP_DEBUG_CHANNEL
#include "telepathy-glib/channel-internal.h"
@@ -177,7 +178,8 @@ struct _TpStreamTubeChannelPrivate
enum
{
PROP_SERVICE = 1,
- PROP_PARAMETERS
+ PROP_PARAMETERS,
+ PROP_PARAMETERS_VARDICT
};
enum /* signals */
@@ -289,6 +291,11 @@ tp_stream_tube_channel_get_property (GObject *object,
g_value_set_boxed (value, self->priv->parameters);
break;
+ case PROP_PARAMETERS_VARDICT:
+ g_value_take_variant (value,
+ tp_stream_tube_channel_dup_parameters_vardict (self));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -431,6 +438,11 @@ tp_stream_tube_channel_class_init (TpStreamTubeChannelClass *klass)
*
* Will be %NULL for outgoing tubes until the tube has been offered.
*
+ * In high-level language bindings, use
+ * #TpStreamTubeChannel:parameters-vardict or
+ * tp_stream_tube_channel_dup_parameters_vardict() to get the same
+ * information in a more convenient format.
+ *
* Since: 0.13.2
*/
param_spec = g_param_spec_boxed ("parameters", "Parameters",
@@ -440,6 +452,22 @@ tp_stream_tube_channel_class_init (TpStreamTubeChannelClass *klass)
g_object_class_install_property (gobject_class, PROP_PARAMETERS, param_spec);
/**
+ * TpStreamTubeChannel:parameters-vardict:
+ *
+ * A %G_VARIANT_TYPE_VARDICT representing the parameters of the tube.
+ *
+ * Will be %NULL for outgoing tubes until the tube has been offered.
+ *
+ * Since: 0.UNRELEASED
+ */
+ param_spec = g_param_spec_variant ("parameters-vardict", "Parameters",
+ "The parameters of the stream tube",
+ G_VARIANT_TYPE_VARDICT, NULL,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+ g_object_class_install_property (gobject_class, PROP_PARAMETERS_VARDICT,
+ param_spec);
+
+ /**
* TpStreamTubeChannel::incoming:
* @self: the #TpStreamTubeChannel
* @tube_connection: the #TpStreamTubeConnection for the connection
@@ -1250,6 +1278,7 @@ _offer_with_address (TpStreamTubeChannel *self,
self->priv->parameters = tp_asv_new (NULL, NULL);
g_object_notify (G_OBJECT (self), "parameters");
+ g_object_notify (G_OBJECT (self), "parameters-vardict");
/* Call Offer */
tp_cli_channel_type_stream_tube_call_offer (TP_CHANNEL (self), -1,
@@ -1552,3 +1581,33 @@ tp_stream_tube_channel_get_parameters (TpStreamTubeChannel *self)
{
return self->priv->parameters;
}
+
+/**
+ * tp_stream_tube_channel_dup_parameters_vardict:
+ * @self: a #TpStreamTubeChannel
+ *
+ * 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 variants 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(), g_variant_lookup_value(), or tp_vardict_get_uint32()
+ * and similar functions for convenient access to the values.
+ *
+ * Returns: (transfer full): a new reference to a #GVariant
+ *
+ * Since: 0.UNRELEASED
+ */
+GVariant *
+tp_stream_tube_channel_dup_parameters_vardict (TpStreamTubeChannel *self)
+{
+ g_return_val_if_fail (TP_IS_STREAM_TUBE_CHANNEL (self), NULL);
+
+ if (self->priv->parameters == NULL)
+ return NULL;
+
+ return _tp_asv_to_vardict (self->priv->parameters);
+}
diff --git a/telepathy-glib/stream-tube-channel.h b/telepathy-glib/stream-tube-channel.h
index 53548d0..1c761e2 100644
--- a/telepathy-glib/stream-tube-channel.h
+++ b/telepathy-glib/stream-tube-channel.h
@@ -69,6 +69,10 @@ const gchar * tp_stream_tube_channel_get_service (TpStreamTubeChannel *self);
GHashTable * tp_stream_tube_channel_get_parameters (TpStreamTubeChannel *self);
+_TP_AVAILABLE_IN_UNRELEASED
+GVariant *tp_stream_tube_channel_dup_parameters_vardict (
+ TpStreamTubeChannel *self);
+
/* Incoming tube methods */
void tp_stream_tube_channel_accept_async (TpStreamTubeChannel *self,
diff --git a/tests/dbus/stream-tube.c b/tests/dbus/stream-tube.c
index f5b46b9..9b49465 100644
--- a/tests/dbus/stream-tube.c
+++ b/tests/dbus/stream-tube.c
@@ -231,12 +231,24 @@ test_creation (Test *test,
}
static void
-check_parameters (GHashTable *parameters)
+check_parameters (GHashTable *parameters,
+ GVariant *parameters_vardict)
{
+ gboolean found;
+ guint32 u32;
+
g_assert (parameters != NULL);
+ g_assert (parameters_vardict != NULL);
+ g_assert_cmpstr (g_variant_get_type_string (parameters_vardict), ==,
+ "a{sv}");
g_assert_cmpuint (g_hash_table_size (parameters), ==, 1);
+ g_assert_cmpuint (g_variant_n_children (parameters_vardict), ==, 1);
+
g_assert_cmpuint (tp_asv_get_uint32 (parameters, "badger", NULL), ==, 42);
+ found = g_variant_lookup (parameters_vardict, "badger", "u", &u32);
+ g_assert_cmpint (found, ==, TRUE);
+ g_assert_cmpuint (u32, ==, 42);
}
static void
@@ -245,6 +257,7 @@ test_properties (Test *test,
{
gchar *service;
GHashTable *parameters;
+ GVariant *parameters_vardict;
/* Outgoing tube */
create_tube_service (test, TRUE, TP_SOCKET_ADDRESS_TYPE_UNIX,
@@ -259,10 +272,18 @@ test_properties (Test *test,
/* Parameters */
parameters = tp_stream_tube_channel_get_parameters (test->tube);
- /* NULL as the tube has not be offered yet */
+ /* NULL as the tube has not been offered yet */
g_assert (parameters == NULL);
g_object_get (test->tube, "parameters", ¶meters, NULL);
g_assert (parameters == NULL);
+ parameters_vardict = tp_stream_tube_channel_dup_parameters_vardict (
+ test->tube);
+ /* NULL as the tube has not been offered yet */
+ g_assert (parameters_vardict == NULL);
+ g_object_get (test->tube,
+ "parameters-vardict", ¶meters_vardict,
+ NULL);
+ g_assert (parameters_vardict == NULL);
/* Incoming tube */
create_tube_service (test, FALSE, TP_SOCKET_ADDRESS_TYPE_UNIX,
@@ -270,10 +291,20 @@ test_properties (Test *test,
/* Parameters */
parameters = tp_stream_tube_channel_get_parameters (test->tube);
- check_parameters (parameters);
- g_object_get (test->tube, "parameters", ¶meters, NULL);
- check_parameters (parameters);
+ parameters_vardict = tp_stream_tube_channel_dup_parameters_vardict (
+ test->tube);
+ check_parameters (parameters, parameters_vardict);
+ g_variant_unref (parameters_vardict);
+
+ g_object_get (test->tube,
+ "parameters", ¶meters,
+ "parameters-vardict", ¶meters_vardict,
+ NULL);
+
+ g_assert (parameters_vardict != NULL);
+ check_parameters (parameters, parameters_vardict);
g_hash_table_unref (parameters);
+ g_variant_unref (parameters_vardict);
}
static void
@@ -535,6 +566,7 @@ test_offer_success (Test *test,
GSocketClient *client;
TpHandle bob_handle;
TpContact *contact;
+ GVariant *parameters_vardict;
if (contexts[i].address_type == TP_SOCKET_ADDRESS_TYPE_UNIX &&
contexts[i].access_control == TP_SOCKET_ACCESS_CONTROL_CREDENTIALS &&
@@ -561,7 +593,11 @@ test_offer_success (Test *test,
tp_stream_tube_channel_offer_async (test->tube, params, tube_offer_cb, test);
g_hash_table_unref (params);
- check_parameters (tp_stream_tube_channel_get_parameters (test->tube));
+ parameters_vardict = tp_stream_tube_channel_dup_parameters_vardict (
+ test->tube);
+ check_parameters (tp_stream_tube_channel_get_parameters (test->tube),
+ parameters_vardict);
+ g_variant_unref (parameters_vardict);
test->wait = 1;
g_main_loop_run (test->mainloop);
More information about the telepathy-commits
mailing list