[next] telepathy-glib: add tp_handles_are_valid_variant()
Guillaume Desmottes
gdesmott at kemper.freedesktop.org
Fri May 16 06:04:55 PDT 2014
Module: telepathy-glib
Branch: next
Commit: 9e9b72992179763cef7e02b130dc898d434e0ec5
URL: http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=9e9b72992179763cef7e02b130dc898d434e0ec5
Author: Guillaume Desmottes <guillaume.desmottes at collabora.co.uk>
Date: Thu May 15 15:44:46 2014 +0200
add tp_handles_are_valid_variant()
Will be needed to simply code in base-connection. Ideally the vfunc should
take a GVariant as well so we safe one conversion.
---
.../telepathy-glib/telepathy-glib-sections.txt | 1 +
telepathy-glib/handle-repo.c | 49 ++++++++++++++++++++
telepathy-glib/handle-repo.h | 4 ++
tests/dbus/handle-set.c | 7 +++
4 files changed, 61 insertions(+)
diff --git a/docs/reference/telepathy-glib/telepathy-glib-sections.txt b/docs/reference/telepathy-glib/telepathy-glib-sections.txt
index 44fbdf5..b7ba8fb 100644
--- a/docs/reference/telepathy-glib/telepathy-glib-sections.txt
+++ b/docs/reference/telepathy-glib/telepathy-glib-sections.txt
@@ -187,6 +187,7 @@ TpHandleRepoIface
TpHandleRepoIfaceClass
tp_handle_is_valid
tp_handles_are_valid
+tp_handles_are_valid_variant
tp_handles_supported_and_valid
tp_handle_inspect
tp_handle_ensure
diff --git a/telepathy-glib/handle-repo.c b/telepathy-glib/handle-repo.c
index be4c128..955cbe9 100644
--- a/telepathy-glib/handle-repo.c
+++ b/telepathy-glib/handle-repo.c
@@ -86,6 +86,55 @@ tp_handles_are_valid (TpHandleRepoIface *self,
handles, allow_zero, error);
}
+static GArray *
+handles_variant_to_array (GVariant *variant)
+{
+ const TpHandle *handles;
+ GArray *array;
+ gsize n;
+
+ handles = g_variant_get_fixed_array (variant, &n, sizeof (TpHandle));
+ array = g_array_sized_new (FALSE, FALSE, sizeof (TpHandle), n);
+ g_array_append_vals (array, handles, n);
+
+ return array;
+}
+
+/**
+ * tp_handles_are_valid_variant:
+ * @self: A handle repository implementation
+ * @handles: a #GVariant of type 'au' (array of uint32) representing handles of
+ * the type stored in the repository @self, consumed if floating
+ * @allow_zero: If %TRUE, zero is treated like a valid handle
+ * @error: Set to InvalidHandle if %FALSE is returned
+ *
+ * <!--Returns: says it all-->
+ *
+ * Returns: %TRUE if the handle is present in the repository, else %FALSE
+ */
+gboolean
+tp_handles_are_valid_variant (TpHandleRepoIface *self,
+ GVariant *handles,
+ gboolean allow_zero,
+ GError **error)
+{
+ GArray *arr;
+ gboolean result;
+
+ g_return_val_if_fail (g_variant_is_of_type (handles, G_VARIANT_TYPE ("au")),
+ FALSE);
+
+ g_variant_ref_sink (handles);
+ arr = handles_variant_to_array (handles);
+
+ result = TP_HANDLE_REPO_IFACE_GET_CLASS (self)->handles_are_valid (self,
+ arr, allow_zero, error);
+
+ g_variant_unref (handles);
+ g_array_unref (arr);
+ return result;
+}
+
/**
* tp_handle_inspect: (skip)
diff --git a/telepathy-glib/handle-repo.h b/telepathy-glib/handle-repo.h
index 3d41f25..c2d19d3 100644
--- a/telepathy-glib/handle-repo.h
+++ b/telepathy-glib/handle-repo.h
@@ -87,6 +87,10 @@ gboolean tp_handle_is_valid (TpHandleRepoIface *self,
TpHandle handle, GError **error);
gboolean tp_handles_are_valid (TpHandleRepoIface *self,
const GArray *handles, gboolean allow_zero, GError **error);
+gboolean tp_handles_are_valid_variant (TpHandleRepoIface *self,
+ GVariant *handles,
+ gboolean allow_zero,
+ GError **error);
const char *tp_handle_inspect (TpHandleRepoIface *self,
TpHandle handle) G_GNUC_WARN_UNUSED_RESULT;
diff --git a/tests/dbus/handle-set.c b/tests/dbus/handle-set.c
index 55cccee..2e5e476 100644
--- a/tests/dbus/handle-set.c
+++ b/tests/dbus/handle-set.c
@@ -140,6 +140,13 @@ test (Fixture *f,
tp_handle_set_peek (other)));
tp_clear_pointer (&other, tp_handle_set_destroy);
+ g_assert (tp_handles_are_valid_variant (repo,
+ g_variant_new_parsed ("[%u, %u]", h1, h2), FALSE, &error));
+ g_assert_no_error (error);
+ g_assert (!tp_handles_are_valid_variant (repo,
+ g_variant_new_parsed ("[%u, %u]", h1, 666), FALSE, &error));
+ g_assert_error (error, TP_ERROR, TP_ERROR_INVALID_HANDLE);
+
MYASSERT (tp_handle_set_remove (set, h3) == TRUE, "");
tp_handle_set_destroy (set);
More information about the telepathy-commits
mailing list