From c94b53f6b51fe01e664c3daeb8195752f0b7591e Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Thu, 15 May 2014 10:29:20 +0200 Subject: [PATCH 3/3] handle-set: add GVariant API Fix https://bugs.freedesktop.org/show_bug.cgi?id=77773 --- .../telepathy-glib/telepathy-glib-sections.txt | 2 + telepathy-glib/handle-repo.h | 5 +++ telepathy-glib/handle-set.c | 43 ++++++++++++++++++++++ tests/dbus/handle-set.c | 8 ++++ 4 files changed, 58 insertions(+) diff --git a/docs/reference/telepathy-glib/telepathy-glib-sections.txt b/docs/reference/telepathy-glib/telepathy-glib-sections.txt index 93f6f3f..44fbdf5 100644 --- a/docs/reference/telepathy-glib/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib/telepathy-glib-sections.txt @@ -208,6 +208,7 @@ tp_handle_set_new tp_handle_set_new_containing tp_handle_set_new_from_array tp_handle_set_new_from_intset +tp_handle_set_new_from_variant tp_handle_set_copy tp_handle_set_clear tp_handle_set_destroy @@ -219,6 +220,7 @@ tp_handle_set_foreach tp_handle_set_is_empty tp_handle_set_size tp_handle_set_to_array +tp_handle_set_to_variant tp_handle_set_to_identifier_map tp_handle_set_update tp_handle_set_difference_update diff --git a/telepathy-glib/handle-repo.h b/telepathy-glib/handle-repo.h index ac63995..3d41f25 100644 --- a/telepathy-glib/handle-repo.h +++ b/telepathy-glib/handle-repo.h @@ -143,6 +143,11 @@ GVariant *tp_handle_set_to_identifier_map (TpHandleSet *self) TpHandleSet *tp_handle_set_new_from_array (TpHandleRepoIface *repo, const GArray *array) G_GNUC_WARN_UNUSED_RESULT; +GVariant *tp_handle_set_to_variant (const TpHandleSet *set) + G_GNUC_WARN_UNUSED_RESULT; +TpHandleSet *tp_handle_set_new_from_variant (TpHandleRepoIface *repo, + GVariant *variant) G_GNUC_WARN_UNUSED_RESULT; + TpIntset *tp_handle_set_update (TpHandleSet *set, const TpIntset *add) G_GNUC_WARN_UNUSED_RESULT; TpIntset *tp_handle_set_difference_update (TpHandleSet *set, diff --git a/telepathy-glib/handle-set.c b/telepathy-glib/handle-set.c index 7d61895..328ca96 100644 --- a/telepathy-glib/handle-set.c +++ b/telepathy-glib/handle-set.c @@ -294,6 +294,49 @@ tp_handle_set_to_array (const TpHandleSet *set) } /** + * tp_handle_set_to_variant: + * @set: A handle set + * + * + * + * Returns: (transfer full): a new #GVariant of type 'au' + * representing the handles in the set + * + * Since: UNRELEASED + */ +GVariant * +tp_handle_set_to_variant (const TpHandleSet *set) +{ + g_return_val_if_fail (set != NULL, NULL); + + return tp_intset_to_variant (set->intset); +} + +/** + * tp_handle_set_new_from_variant: + * @repo: #TpHandleRepoIface that holds the handles to be reffed by this set + * @variant: a #GVariant of type 'au' containing the handles to be referenced + * by this set, consumed if floating + * + * Creates a new #TpHandleSet + * + * Returns: (transfer full): A new #TpHandleSet + * + * Since: UNRELEASED + */ +TpHandleSet * +tp_handle_set_new_from_variant (TpHandleRepoIface *repo, + GVariant *v) +{ + TpHandleSet *set = tp_handle_set_new (repo); + TpIntset *tmp = tp_intset_from_variant (v); + + tp_intset_destroy (tp_handle_set_update (set, tmp)); + tp_intset_destroy (tmp); + return set; +} + +/** * tp_handle_set_to_identifier_map: * @self: a handle set * diff --git a/tests/dbus/handle-set.c b/tests/dbus/handle-set.c index b2d4c6d..55cccee 100644 --- a/tests/dbus/handle-set.c +++ b/tests/dbus/handle-set.c @@ -34,6 +34,7 @@ test (Fixture *f, GError *error = NULL; gchar *s; GTestDBus *test_dbus; + GVariant *v; TpHandle h1, h2, h3, h4; @@ -132,6 +133,13 @@ test (Fixture *f, s = tp_handle_set_dump (set); g_free (s); + v = tp_handle_set_to_variant (set); + g_assert (g_variant_is_of_type (v, G_VARIANT_TYPE ("au"))); + other = tp_handle_set_new_from_variant (repo, v); + g_assert (tp_intset_is_equal (tp_handle_set_peek (set), + tp_handle_set_peek (other))); + tp_clear_pointer (&other, tp_handle_set_destroy); + MYASSERT (tp_handle_set_remove (set, h3) == TRUE, ""); tp_handle_set_destroy (set); -- 1.9.0