diff options
author | Xavier Claessens <xavier.claessens@collabora.co.uk> | 2012-09-12 12:55:09 +0200 |
---|---|---|
committer | Xavier Claessens <xavier.claessens@collabora.co.uk> | 2012-09-15 15:37:26 +0200 |
commit | 51115c42577150c400a9785b77714efd442117a8 (patch) | |
tree | a24764170bfea5e4a3f146ced561aaa9ffd90cb7 | |
parent | 2f3d04a0fb793570967d2451c2ed3b6c6c0ea733 (diff) | |
download | telepathy-glib-51115c42577150c400a9785b77714efd442117a8.tar.gz |
Move GVariant utilities to variant-util.ch
-rw-r--r-- | telepathy-glib/Makefile.am | 7 | ||||
-rw-r--r-- | telepathy-glib/account-request.c | 1 | ||||
-rw-r--r-- | telepathy-glib/account.c | 3 | ||||
-rw-r--r-- | telepathy-glib/base-connection.c | 1 | ||||
-rw-r--r-- | telepathy-glib/capabilities.c | 1 | ||||
-rw-r--r-- | telepathy-glib/channel.c | 1 | ||||
-rw-r--r-- | telepathy-glib/connection.c | 1 | ||||
-rw-r--r-- | telepathy-glib/dbus-internal.h | 8 | ||||
-rw-r--r-- | telepathy-glib/dbus.c | 58 | ||||
-rw-r--r-- | telepathy-glib/telepathy-glib.h | 1 | ||||
-rw-r--r-- | telepathy-glib/tls-certificate.c | 1 | ||||
-rw-r--r-- | telepathy-glib/variant-util-internal.h | 36 | ||||
-rw-r--r-- | telepathy-glib/variant-util.c | 108 | ||||
-rw-r--r-- | telepathy-glib/variant-util.h | 36 |
14 files changed, 194 insertions, 69 deletions
diff --git a/telepathy-glib/Makefile.am b/telepathy-glib/Makefile.am index e84221083..ce60d7d0b 100644 --- a/telepathy-glib/Makefile.am +++ b/telepathy-glib/Makefile.am @@ -139,7 +139,8 @@ our_headers = \ text-mixin.h \ tls-certificate.h \ tls-certificate-rejection.h \ - util.h + util.h \ + variant-util.h tpginclude_HEADERS = \ $(our_headers) \ @@ -309,7 +310,9 @@ libtelepathy_glib_internal_la_SOURCES = \ tls-certificate-rejection.c \ tls-certificate-rejection-internal.h \ util.c \ - util-internal.h + util-internal.h \ + variant-util.c \ + variant-util-internal.h AM_CPPFLAGS = \ -DG_LOG_DOMAIN=\"tp-glib\" \ diff --git a/telepathy-glib/account-request.c b/telepathy-glib/account-request.c index f22641399..474883908 100644 --- a/telepathy-glib/account-request.c +++ b/telepathy-glib/account-request.c @@ -31,6 +31,7 @@ #include "telepathy-glib/dbus-internal.h" #include "telepathy-glib/debug-internal.h" #include "telepathy-glib/util-internal.h" +#include "telepathy-glib/variant-util-internal.h" /** * SECTION:account-request diff --git a/telepathy-glib/account.c b/telepathy-glib/account.c index 805afa547..026ad4657 100644 --- a/telepathy-glib/account.c +++ b/telepathy-glib/account.c @@ -40,7 +40,8 @@ #include "telepathy-glib/debug-internal.h" #include "telepathy-glib/proxy-internal.h" #include "telepathy-glib/simple-client-factory-internal.h" -#include <telepathy-glib/util-internal.h> +#include "telepathy-glib/util-internal.h" +#include "telepathy-glib/variant-util-internal.h" #include "telepathy-glib/_gen/tp-cli-account-body.h" diff --git a/telepathy-glib/base-connection.c b/telepathy-glib/base-connection.c index 66bbfc921..22167dc20 100644 --- a/telepathy-glib/base-connection.c +++ b/telepathy-glib/base-connection.c @@ -267,6 +267,7 @@ #define DEBUG_FLAG TP_DEBUG_CONNECTION #include "telepathy-glib/debug-internal.h" +#include "telepathy-glib/variant-util-internal.h" static void conn_iface_init (gpointer, gpointer); static void requests_iface_init (gpointer, gpointer); diff --git a/telepathy-glib/capabilities.c b/telepathy-glib/capabilities.c index 633617da4..ae1d34f9f 100644 --- a/telepathy-glib/capabilities.c +++ b/telepathy-glib/capabilities.c @@ -31,6 +31,7 @@ #define DEBUG_FLAG TP_DEBUG_CONNECTION #include "telepathy-glib/debug-internal.h" +#include "telepathy-glib/variant-util-internal.h" /** * SECTION:capabilities diff --git a/telepathy-glib/channel.c b/telepathy-glib/channel.c index cc95af172..03e55187f 100644 --- a/telepathy-glib/channel.c +++ b/telepathy-glib/channel.c @@ -36,6 +36,7 @@ #include "telepathy-glib/debug-internal.h" #include "telepathy-glib/proxy-internal.h" #include "telepathy-glib/simple-client-factory-internal.h" +#include "telepathy-glib/variant-util-internal.h" #include "_gen/tp-cli-channel-body.h" diff --git a/telepathy-glib/connection.c b/telepathy-glib/connection.c index 1dce574a7..5fd37b1ab 100644 --- a/telepathy-glib/connection.c +++ b/telepathy-glib/connection.c @@ -48,6 +48,7 @@ #include "telepathy-glib/simple-client-factory-internal.h" #include "telepathy-glib/contact-internal.h" #include "telepathy-glib/util-internal.h" +#include "telepathy-glib/variant-util-internal.h" #include "_gen/tp-cli-connection-body.h" diff --git a/telepathy-glib/dbus-internal.h b/telepathy-glib/dbus-internal.h index aade667d8..4b0322090 100644 --- a/telepathy-glib/dbus-internal.h +++ b/telepathy-glib/dbus-internal.h @@ -37,14 +37,6 @@ DBusGConnection *_tp_dbus_starter_bus_conn (GError **error) gboolean _tp_dbus_daemon_is_the_shared_one (TpDBusDaemon *self); -GVariant *_tp_asv_to_vardict (const GHashTable *asv); - -GVariant * _tp_boxed_to_variant (GType gtype, - const gchar *variant_type, - gpointer boxed); - -GHashTable * _tp_asv_from_vardict (GVariant *variant); - G_END_DECLS #endif /* __TP_INTERNAL_DBUS_GLIB_H__ */ diff --git a/telepathy-glib/dbus.c b/telepathy-glib/dbus.c index aaffce260..04ba84bd4 100644 --- a/telepathy-glib/dbus.c +++ b/telepathy-glib/dbus.c @@ -1952,61 +1952,3 @@ tp_asv_dump (GHashTable *asv) g_debug ("}"); } - -/* - * _tp_asv_to_vardict: - * - * Returns: (transfer full): a #GVariant of type %G_VARIANT_TYPE_VARDICT - */ -GVariant * -_tp_asv_to_vardict (const GHashTable *asv) -{ - return _tp_boxed_to_variant (TP_HASH_TYPE_STRING_VARIANT_MAP, "a{sv}", (gpointer) asv); -} - -GVariant * -_tp_boxed_to_variant (GType gtype, - const gchar *variant_type, - gpointer boxed) -{ - GValue v = G_VALUE_INIT; - GVariant *ret; - - g_return_val_if_fail (boxed != NULL, NULL); - - g_value_init (&v, gtype); - g_value_set_boxed (&v, boxed); - - ret = dbus_g_value_build_g_variant (&v); - g_return_val_if_fail (!tp_strdiff (g_variant_get_type_string (ret), variant_type), NULL); - - g_value_unset (&v); - - return g_variant_ref_sink (ret); -} - -/* - * _tp_asv_from_vardict: - * @variant: a #GVariant of type %G_VARIANT_TYPE_VARDICT - * - * Returns: (transfer full): a newly created #GHashTable of - * type #TP_HASH_TYPE_STRING_VARIANT_MAP - */ -GHashTable * -_tp_asv_from_vardict (GVariant *variant) -{ - GValue v = G_VALUE_INIT; - GHashTable *result; - - g_return_val_if_fail (variant != NULL, NULL); - g_return_val_if_fail (g_variant_is_of_type (variant, G_VARIANT_TYPE_VARDICT), - NULL); - - dbus_g_value_parse_g_variant (variant, &v); - g_assert (G_VALUE_HOLDS (&v, TP_HASH_TYPE_STRING_VARIANT_MAP)); - - result = g_value_dup_boxed (&v); - - g_value_unset (&v); - return result; -} diff --git a/telepathy-glib/telepathy-glib.h b/telepathy-glib/telepathy-glib.h index 6435c64fe..8fa3bef77 100644 --- a/telepathy-glib/telepathy-glib.h +++ b/telepathy-glib/telepathy-glib.h @@ -111,6 +111,7 @@ #include <telepathy-glib/stream-tube-connection.h> #include <telepathy-glib/text-channel.h> #include <telepathy-glib/tls-certificate.h> +#include <telepathy-glib/variant-util.h> /* deprecated, gone in 1.0 */ #include <telepathy-glib/automatic-proxy-factory.h> diff --git a/telepathy-glib/tls-certificate.c b/telepathy-glib/tls-certificate.c index 8827094ca..2a2de5bdb 100644 --- a/telepathy-glib/tls-certificate.c +++ b/telepathy-glib/tls-certificate.c @@ -37,6 +37,7 @@ #include <telepathy-glib/util.h> #include <telepathy-glib/util-internal.h> #include <telepathy-glib/tls-certificate-rejection-internal.h> +#include "telepathy-glib/variant-util-internal.h" #define DEBUG_FLAG TP_DEBUG_TLS #include "debug-internal.h" diff --git a/telepathy-glib/variant-util-internal.h b/telepathy-glib/variant-util-internal.h new file mode 100644 index 000000000..16257e55e --- /dev/null +++ b/telepathy-glib/variant-util-internal.h @@ -0,0 +1,36 @@ +/*<private_header>*/ +/* + * variant-util-internal.h - Headers for non-public GVariant utility functions + * + * Copyright (C) 2012 Collabora Ltd. <http://www.collabora.co.uk/> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef __TP_VARIANT_UTIL_INTERNAL_H__ +#define __TP_VARIANT_UTIL_INTERNAL_H__ + +#include <glib.h> +#include <gio/gio.h> + +GVariant *_tp_asv_to_vardict (const GHashTable *asv); + +GVariant * _tp_boxed_to_variant (GType gtype, + const gchar *variant_type, + gpointer boxed); + +GHashTable * _tp_asv_from_vardict (GVariant *variant); + +#endif /* __TP_VARIANT_UTIL_INTERNAL_H__ */ diff --git a/telepathy-glib/variant-util.c b/telepathy-glib/variant-util.c new file mode 100644 index 000000000..fce3ee17f --- /dev/null +++ b/telepathy-glib/variant-util.c @@ -0,0 +1,108 @@ +/* + * variant-util.c - Source for GVariant utilities + * + * Copyright (C) 2012 Collabora Ltd. <http://www.collabora.co.uk/> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * SECTION:variant-util + * @title: GVariant utilities + * @short_description: some GVariant utility functions + * + * GVariant utility functions used in telepathy-glib. + */ + +/** + * SECTION:vardic + * @title: Manipulating a{sv} mappings + * @short_description: Functions to manipulate mappings from string to + * variant, as represented in GDBus by a %G_VARIANT_TYPE_VARDICT + * + * These functions provide convenient access to the values in such + * a mapping. + * + * Since: 0.UNRELEASED + */ + +#include "config.h" + +#include <telepathy-glib/variant-util.h> +#include <telepathy-glib/variant-util-internal.h> + +#include <telepathy-glib/gtypes.h> +#include <telepathy-glib/util.h> + +#define DEBUG_FLAG TP_DEBUG_MISC +#include "debug-internal.h" + +/* + * _tp_asv_to_vardict: + * + * Returns: (transfer full): a #GVariant of type %G_VARIANT_TYPE_VARDICT + */ +GVariant * +_tp_asv_to_vardict (const GHashTable *asv) +{ + return _tp_boxed_to_variant (TP_HASH_TYPE_STRING_VARIANT_MAP, "a{sv}", (gpointer) asv); +} + +GVariant * +_tp_boxed_to_variant (GType gtype, + const gchar *variant_type, + gpointer boxed) +{ + GValue v = G_VALUE_INIT; + GVariant *ret; + + g_return_val_if_fail (boxed != NULL, NULL); + + g_value_init (&v, gtype); + g_value_set_boxed (&v, boxed); + + ret = dbus_g_value_build_g_variant (&v); + g_return_val_if_fail (!tp_strdiff (g_variant_get_type_string (ret), variant_type), NULL); + + g_value_unset (&v); + + return g_variant_ref_sink (ret); +} + +/* + * _tp_asv_from_vardict: + * @variant: a #GVariant of type %G_VARIANT_TYPE_VARDICT + * + * Returns: (transfer full): a newly created #GHashTable of + * type #TP_HASH_TYPE_STRING_VARIANT_MAP + */ +GHashTable * +_tp_asv_from_vardict (GVariant *variant) +{ + GValue v = G_VALUE_INIT; + GHashTable *result; + + g_return_val_if_fail (variant != NULL, NULL); + g_return_val_if_fail (g_variant_is_of_type (variant, G_VARIANT_TYPE_VARDICT), + NULL); + + dbus_g_value_parse_g_variant (variant, &v); + g_assert (G_VALUE_HOLDS (&v, TP_HASH_TYPE_STRING_VARIANT_MAP)); + + result = g_value_dup_boxed (&v); + + g_value_unset (&v); + return result; +} diff --git a/telepathy-glib/variant-util.h b/telepathy-glib/variant-util.h new file mode 100644 index 000000000..6f1321874 --- /dev/null +++ b/telepathy-glib/variant-util.h @@ -0,0 +1,36 @@ +/* + * variant-util.h - Header for GVariant utilities + * + * Copyright (C) 2012 Collabora Ltd. <http://www.collabora.co.uk/> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#if defined (TP_DISABLE_SINGLE_INCLUDE) && !defined (_TP_IN_META_HEADER) && !defined (_TP_COMPILATION) +#error "Only <telepathy-glib/telepathy-glib.h> and <telepathy-glib/telepathy-glib-dbus.h> can be included directly." +#endif + +#ifndef __TP_VARIANT_UTIL_H__ +#define __TP_VARIANT_UTIL_H__ + +#include <glib.h> +#include <gio/gio.h> + +G_BEGIN_DECLS + + +G_END_DECLS + +#endif /* __TP_VARIANT_UTIL_H__ */ |