From 5faf5bd086f978852c9ca28caf7fae6d00087159 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Mon, 24 Feb 2014 12:21:27 +0100 Subject: [PATCH 02/13] TpFileTransferChannel: store metadata as a GVariant --- .../telepathy-glib/telepathy-glib-sections.txt | 2 +- telepathy-glib/file-transfer-channel.c | 31 +++++++++++--------- telepathy-glib/file-transfer-channel.h | 3 +- tests/dbus/file-transfer-channel.c | 33 +++++++++++++++++----- 4 files changed, 45 insertions(+), 24 deletions(-) diff --git a/docs/reference/telepathy-glib/telepathy-glib-sections.txt b/docs/reference/telepathy-glib/telepathy-glib-sections.txt index 1808f6f..76643f2 100644 --- a/docs/reference/telepathy-glib/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib/telepathy-glib-sections.txt @@ -5440,7 +5440,7 @@ tp_file_transfer_channel_get_size tp_file_transfer_channel_get_transferred_bytes tp_file_transfer_channel_get_state tp_file_transfer_channel_get_service_name -tp_file_transfer_channel_get_metadata +tp_file_transfer_channel_dup_metadata tp_file_transfer_channel_accept_file_async tp_file_transfer_channel_accept_file_finish tp_file_transfer_channel_provide_file_async diff --git a/telepathy-glib/file-transfer-channel.c b/telepathy-glib/file-transfer-channel.c index 28e6c37..8cd01cc 100644 --- a/telepathy-glib/file-transfer-channel.c +++ b/telepathy-glib/file-transfer-channel.c @@ -108,6 +108,7 @@ #include #include #include +#include #define DEBUG_FLAG TP_DEBUG_CHANNEL #include "telepathy-glib/automatic-client-factory-internal.h" @@ -146,7 +147,7 @@ struct _TpFileTransferChannelPrivate goffset initial_offset; /* Metadata */ const gchar *service_name; - GHashTable *metadata; /* const gchar* => const gchar* const* */ + GVariant *metadata; /* a{sas} */ /* Streams and sockets for sending and receiving the actual file */ GSocket *client_socket; @@ -525,6 +526,7 @@ tp_file_transfer_channel_constructed (GObject *obj) gboolean valid; gint64 date; const gchar *uri; + GHashTable *metadata; G_OBJECT_CLASS (tp_file_transfer_channel_parent_class)->constructed (obj); @@ -608,14 +610,15 @@ tp_file_transfer_channel_constructed (GObject *obj) self->priv->service_name = tp_asv_get_string (properties, TP_PROP_CHANNEL_INTERFACE_FILE_TRANSFER_METADATA1_SERVICE_NAME); - self->priv->metadata = tp_asv_get_boxed (properties, + metadata = tp_asv_get_boxed (properties, TP_PROP_CHANNEL_INTERFACE_FILE_TRANSFER_METADATA1_METADATA, TP_HASH_TYPE_METADATA); - if (self->priv->metadata == NULL) - self->priv->metadata = g_hash_table_new (g_str_hash, g_str_equal); + if (metadata == NULL) + self->priv->metadata = g_variant_new ("a{ss}", NULL); else - g_hash_table_ref (self->priv->metadata); + self->priv->metadata = _tp_boxed_to_variant (TP_HASH_TYPE_METADATA, + "a{sas}", metadata); self->priv->cancellable = g_cancellable_new (); g_signal_connect (self, "invalidated", @@ -673,7 +676,7 @@ tp_file_transfer_channel_get_property (GObject *object, break; case PROP_METADATA: - g_value_set_boxed (value, self->priv->metadata); + g_value_set_variant (value, self->priv->metadata); break; default: @@ -714,7 +717,7 @@ tp_file_transfer_channel_dispose (GObject *obj) tp_clear_pointer (&self->priv->date, g_date_time_unref); g_clear_object (&self->priv->file); - tp_clear_pointer (&self->priv->metadata, g_hash_table_unref); + tp_clear_pointer (&self->priv->metadata, g_variant_unref); g_clear_object (&self->priv->stream); if (self->priv->cancellable != NULL) @@ -997,10 +1000,10 @@ tp_file_transfer_channel_class_init (TpFileTransferChannelClass *klass) * * Since: 0.17.1 */ - param_spec = g_param_spec_boxed ("metadata", + param_spec = g_param_spec_variant ("metadata", "Metadata", "The Metadata.Metadata property of this channel", - TP_HASH_TYPE_METADATA, + G_VARIANT_TYPE ("a{sas}"), NULL, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); g_object_class_install_property (object_class, PROP_METADATA, param_spec); @@ -1637,20 +1640,20 @@ tp_file_transfer_channel_get_service_name (TpFileTransferChannel *self) } /** - * tp_file_transfer_channel_get_metadata: + * tp_file_transfer_channel_dup_metadata: * @self: a #TpFileTransferChannel * * Return the #TpFileTransferChannel:metadata property * - * Returns: (transfer none) (element-type utf8 GStrv): the + * Returns: (transfer full): the * value of the #TpFileTransferChannel:metadata property * * Since: 0.17.1 */ -const GHashTable * -tp_file_transfer_channel_get_metadata (TpFileTransferChannel *self) +GVariant * +tp_file_transfer_channel_dup_metadata (TpFileTransferChannel *self) { g_return_val_if_fail (TP_IS_FILE_TRANSFER_CHANNEL (self), NULL); - return self->priv->metadata; + return g_variant_ref (self->priv->metadata); } diff --git a/telepathy-glib/file-transfer-channel.h b/telepathy-glib/file-transfer-channel.h index 6d9e112..192b896 100644 --- a/telepathy-glib/file-transfer-channel.h +++ b/telepathy-glib/file-transfer-channel.h @@ -127,8 +127,7 @@ _TP_AVAILABLE_IN_0_18 const gchar * tp_file_transfer_channel_get_service_name ( TpFileTransferChannel *self); -_TP_AVAILABLE_IN_0_18 -const GHashTable * tp_file_transfer_channel_get_metadata ( +GVariant * tp_file_transfer_channel_dup_metadata ( TpFileTransferChannel *self); G_END_DECLS diff --git a/tests/dbus/file-transfer-channel.c b/tests/dbus/file-transfer-channel.c index 1e33a03..02255b6 100644 --- a/tests/dbus/file-transfer-channel.c +++ b/tests/dbus/file-transfer-channel.c @@ -377,6 +377,24 @@ test_create_unrequested (Test *test, g_assert_no_error (error); } +static void +check_metadata (GVariant *metadata) +{ + GVariant *as; + const gchar **metadata_values; + gsize len; + + g_assert (metadata != NULL); + g_assert_cmpuint (g_variant_n_children (metadata), ==, 1); + as = g_variant_lookup_value (metadata, "banana", G_VARIANT_TYPE ("as")); + metadata_values = g_variant_get_strv (as, &len); + g_assert_cmpuint (len, ==, 1); + g_assert_cmpuint (g_strv_length ((GStrv) metadata_values), ==, 1); + g_assert_cmpstr (metadata_values[0], ==, "cheese"); + g_free (metadata_values); + g_variant_unref (as); +} + /* Test setting and getting properties */ static void test_properties (Test *test, @@ -385,8 +403,7 @@ test_properties (Test *test, GDateTime *date1, *date2; TpFileTransferStateChangeReason reason; const GError *error = NULL; - const GHashTable *metadata; - const gchar * const *metadata_values; + GVariant *metadata; create_file_transfer_channel (test, FALSE, TP_SOCKET_ADDRESS_TYPE_UNIX, TP_SOCKET_ACCESS_CONTROL_LOCALHOST); @@ -417,11 +434,13 @@ test_properties (Test *test, g_assert_cmpstr (tp_file_transfer_channel_get_service_name (test->channel), ==, "fit.service.name"); - metadata = tp_file_transfer_channel_get_metadata (test->channel); - g_assert_cmpuint (g_hash_table_size ((GHashTable *) metadata), ==, 1); - metadata_values = g_hash_table_lookup ((GHashTable *) metadata, "banana"); - g_assert_cmpuint (g_strv_length ((GStrv) metadata_values), ==, 1); - g_assert_cmpstr (metadata_values[0], ==, "cheese"); + metadata = tp_file_transfer_channel_dup_metadata (test->channel); + check_metadata (metadata); + g_variant_unref (metadata); + + g_object_get (test->channel, "metadata", &metadata, NULL); + check_metadata (metadata); + g_variant_unref (metadata); error = tp_proxy_get_invalidated (test->channel); g_assert_no_error (error); -- 1.8.5.3