From cbc8e9abd7a5db1d2aabed60c6fc40e1bc84401a Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 19 Sep 2012 12:12:40 +0100 Subject: [PATCH 06/15] tp_message_set_variant: add and test --- docs/reference/telepathy-glib-sections.txt | 1 + telepathy-glib/message.c | 41 +++++++++++++++++++++++++++- telepathy-glib/message.h | 3 ++ tests/dbus/cm-message.c | 4 +-- 4 files changed, 46 insertions(+), 3 deletions(-) diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt index 5892239..fe3a403 100644 --- a/docs/reference/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib-sections.txt @@ -2763,6 +2763,7 @@ tp_message_append_part tp_message_delete_key tp_message_delete_part tp_message_set +tp_message_set_variant tp_message_set_boolean tp_message_set_bytes tp_message_set_int16 diff --git a/telepathy-glib/message.c b/telepathy-glib/message.c index 508e86e..4b41070 100644 --- a/telepathy-glib/message.c +++ b/telepathy-glib/message.c @@ -614,13 +614,15 @@ tp_message_set_bytes (TpMessage *self, * @part: a part number, which must be strictly less than the number * returned by tp_message_count_parts() * @key: a key in the mapping representing the part - * @source: a value + * @source: a value, encoded as dbus-glib would * * Set @key in part @part of @self to have a copy of @source as its value. * * If @source represents a data structure containing handles, they should * all be referenced with tp_message_ref_handle() first. * + * In high-level language bindings, use tp_message_set_variant() instead. + * * Since: 0.7.21 */ void @@ -639,6 +641,43 @@ tp_message_set (TpMessage *self, } /** + * tp_message_set_variant: + * @self: a message + * @part: a part number, which must be strictly less than the number + * returned by tp_message_count_parts() + * @key: a key in the mapping representing the part + * @value: a value + * + * Set @key in part @part of @self to have @value as its value. + * + * If @value is a floating reference (see g_variant_ref_sink()), then this + * function will take ownership of it. + * + * Since: 0.UNRELEASED + */ +void +tp_message_set_variant (TpMessage *self, + guint part, + const gchar *key, + GVariant *value) +{ + GValue *gvalue; + + g_return_if_fail (part < self->parts->len); + g_return_if_fail (key != NULL); + g_return_if_fail (value != NULL); + g_return_if_fail (self->priv->mutable); + + g_variant_ref_sink (value); + gvalue = g_slice_new0 (GValue); + dbus_g_value_parse_g_variant (value, gvalue); + g_variant_unref (value); + + g_hash_table_insert (g_ptr_array_index (self->parts, part), + g_strdup (key), gvalue); +} + +/** * tp_message_take_message: * @self: a #TpCMMessage * @part: a part number, which must be strictly less than the number diff --git a/telepathy-glib/message.h b/telepathy-glib/message.h index e4f7c28..50df7f2 100644 --- a/telepathy-glib/message.h +++ b/telepathy-glib/message.h @@ -74,6 +74,9 @@ void tp_message_set_bytes (TpMessage *self, guint part, const gchar *key, guint len, gconstpointer bytes); void tp_message_set (TpMessage *self, guint part, const gchar *key, const GValue *source); +_TP_AVAILABLE_IN_UNRELEASED +void tp_message_set_variant (TpMessage *self, guint part, const gchar *key, + GVariant *value); gchar * tp_message_to_text (TpMessage *message, TpChannelTextMessageFlags *out_flags) G_GNUC_WARN_UNUSED_RESULT; diff --git a/tests/dbus/cm-message.c b/tests/dbus/cm-message.c index 0fea5d1..5daf51c 100644 --- a/tests/dbus/cm-message.c +++ b/tests/dbus/cm-message.c @@ -295,8 +295,8 @@ test_take_message (Test *test, tp_message_set_uint32 (msg, 0, "message-type", TP_CHANNEL_TEXT_MESSAGE_TYPE_DELIVERY_REPORT); - tp_message_set_uint32 (msg, 0, "delivery-status", - TP_DELIVERY_STATUS_DELIVERED); + tp_message_set_variant (msg, 0, "delivery-status", + g_variant_new_uint32 (TP_DELIVERY_STATUS_DELIVERED)); tp_cm_message_take_message (msg, 0, "delivery-echo", echo); /* ensure the message was destroyed */ -- 1.7.10.4