diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2014-04-03 12:05:29 +0100 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2014-04-03 15:47:09 +0100 |
commit | 7b60eaef51b07813edcd640f89fa51aa9b62094a (patch) | |
tree | 53147c992dbc8de824c03c94a9d137009f83c61f | |
parent | 89daca7d915fff2d7e60c88360165503f7fbc34a (diff) |
Move dbus-glib-style a{sv} utilities into the dbus library
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=76855
Reviewed-by: Xavier Claessens
72 files changed, 1511 insertions, 1370 deletions
diff --git a/examples/cm/call/protocol.c b/examples/cm/call/protocol.c index f65c99f75..6806d7fd3 100644 --- a/examples/cm/call/protocol.c +++ b/examples/cm/call/protocol.c @@ -13,6 +13,7 @@ #include "protocol.h" #include <telepathy-glib/telepathy-glib.h> +#include <telepathy-glib/telepathy-glib-dbus.h> #include "call-manager.h" #include "conn.h" diff --git a/examples/cm/channelspecific/protocol.c b/examples/cm/channelspecific/protocol.c index 6874689c0..10520841c 100644 --- a/examples/cm/channelspecific/protocol.c +++ b/examples/cm/channelspecific/protocol.c @@ -13,6 +13,7 @@ #include <string.h> #include <telepathy-glib/telepathy-glib.h> +#include <telepathy-glib/telepathy-glib-dbus.h> #include "conn.h" #include "room-manager.h" diff --git a/examples/cm/contactlist/protocol.c b/examples/cm/contactlist/protocol.c index 3f76e1785..eb0b2b646 100644 --- a/examples/cm/contactlist/protocol.c +++ b/examples/cm/contactlist/protocol.c @@ -13,6 +13,7 @@ #include "protocol.h" #include <telepathy-glib/telepathy-glib.h> +#include <telepathy-glib/telepathy-glib-dbus.h> #include "conn.h" #include "contact-list.h" diff --git a/examples/cm/extended/protocol.c b/examples/cm/extended/protocol.c index 0b20659bd..66ebcac06 100644 --- a/examples/cm/extended/protocol.c +++ b/examples/cm/extended/protocol.c @@ -13,6 +13,7 @@ #include "protocol.h" #include <telepathy-glib/telepathy-glib.h> +#include <telepathy-glib/telepathy-glib-dbus.h> #include "conn.h" diff --git a/telepathy-glib/Makefile.am b/telepathy-glib/Makefile.am index 32c02c8bb..1465c670e 100644 --- a/telepathy-glib/Makefile.am +++ b/telepathy-glib/Makefile.am @@ -135,6 +135,7 @@ tpginclude_HEADERS = \ $(NULL) tpgdbusinclude_HEADERS = \ + asv.h \ cli-call.h \ cli-channel.h \ cli-connection.h \ @@ -201,6 +202,7 @@ libtelepathy_glib_dbus_internal_la_LIBADD = \ libtelepathy-glib-1-core.la \ $(NULL) libtelepathy_glib_dbus_internal_la_SOURCES = \ + asv.c \ cli-channel.c \ cli-connection.c \ cli-misc.c \ diff --git a/telepathy-glib/account-manager.c b/telepathy-glib/account-manager.c index f89690c0d..069c0a82d 100644 --- a/telepathy-glib/account-manager.c +++ b/telepathy-glib/account-manager.c @@ -24,6 +24,7 @@ #include "telepathy-glib/account-manager-internal.h" #include "telepathy-glib/account-internal.h" +#include <telepathy-glib/asv.h> #include <telepathy-glib/cli-misc.h> #include <telepathy-glib/defs.h> #include <telepathy-glib/gtypes.h> diff --git a/telepathy-glib/account-request.c b/telepathy-glib/account-request.c index d7b92f920..da3e1cf29 100644 --- a/telepathy-glib/account-request.c +++ b/telepathy-glib/account-request.c @@ -24,6 +24,7 @@ #include <dbus/dbus-glib.h> +#include <telepathy-glib/asv.h> #include <telepathy-glib/cli-misc.h> #include <telepathy-glib/gtypes.h> #include <telepathy-glib/interfaces.h> diff --git a/telepathy-glib/account.c b/telepathy-glib/account.c index 4f62a8f26..1f90cf472 100644 --- a/telepathy-glib/account.c +++ b/telepathy-glib/account.c @@ -28,6 +28,7 @@ #include <dbus/dbus-glib.h> +#include <telepathy-glib/asv.h> #include <telepathy-glib/cli-misc.h> #include <telepathy-glib/dbus.h> #include <telepathy-glib/defs.h> diff --git a/telepathy-glib/asv.c b/telepathy-glib/asv.c new file mode 100644 index 000000000..dcd325fda --- /dev/null +++ b/telepathy-glib/asv.c @@ -0,0 +1,1313 @@ +/* + * asv.c - GHashTable<gchar *,GValue *> utilities + * + * Copyright © 2005-2010 Collabora Ltd. <http://www.collabora.co.uk/> + * Copyright © 2005-2009 Nokia Corporation + * + * 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 + */ + +#include "config.h" +#include <telepathy-glib/asv.h> + +#include <string.h> + +#include <glib.h> +#include <gobject/gvaluecollector.h> + +#include <dbus/dbus-glib.h> + +#include <telepathy-glib/sliced-gvalue.h> + +/* this is the core library, we don't have debug infrastructure yet */ +#define CRITICAL(format, ...) \ + g_log (G_LOG_DOMAIN "/misc", G_LOG_LEVEL_CRITICAL, "%s: " format, \ + G_STRFUNC, ##__VA_ARGS__) +#define WARNING(format, ...) \ + g_log (G_LOG_DOMAIN "/misc", G_LOG_LEVEL_WARNING, "%s: " format, \ + G_STRFUNC, ##__VA_ARGS__) + +/** + * SECTION:asv + * @title: Manipulating a{sv} mappings + * @short_description: Functions to manipulate mappings from string to + * variant, as represented in dbus-glib by a #GHashTable from string + * to #GValue + * + * Mappings from string to variant (D-Bus signature a{sv}) are commonly used + * to provide extensibility, but in dbus-glib they're somewhat awkward to deal + * with. + * + * These functions provide convenient access to the values in such + * a mapping. + * + * They also work around the fact that none of the #GHashTable public API + * takes a const pointer to a #GHashTable, even the read-only methods that + * logically ought to. + * + * Parts of telepathy-glib return const pointers to #GHashTable, to encourage + * the use of this API. + * + * Since: 0.7.9 + */ + +/** + * tp_asv_size: (skip) + * @asv: a GHashTable + * + * Return the size of @asv as if via g_hash_table_size(). + * + * The only difference is that this version takes a const #GHashTable and + * casts it. + * + * Since: 0.7.12 + */ +/* (#define + static inline in dbus.h) */ + +/** + * tp_asv_new: (skip) + * @first_key: the name of the first key (or NULL) + * @...: type and value for the first key, followed by a NULL-terminated list + * of (key, type, value) tuples + * + * Creates a new #GHashTable for use with a{sv} maps, containing the values + * passed in as parameters. + * + * The #GHashTable is synonymous with: + * <informalexample><programlisting> + * GHashTable *asv = g_hash_table_new_full (g_str_hash, g_str_equal, + * NULL, (GDestroyNotify) tp_g_value_slice_free); + * </programlisting></informalexample> + * Followed by manual insertion of each of the parameters. + * + * Parameters are stored in slice-allocated GValues and should be set using + * tp_asv_set_*() and retrieved using tp_asv_get_*(). + * + * tp_g_value_slice_new() and tp_g_value_slice_dup() may also be used to insert + * into the map if required. + * <informalexample><programlisting> + * g_hash_table_insert (parameters, "account", + * tp_g_value_slice_new_string ("bob@mcbadgers.com")); + * </programlisting></informalexample> + * + * <example> + * <title>Using tp_asv_new()</title> + * <programlisting> + * GHashTable *parameters = tp_asv_new ( + * "answer", G_TYPE_INT, 42, + * "question", G_TYPE_STRING, "We just don't know", + * NULL);</programlisting> + * </example> + * + * Allocated values will be automatically free'd when overwritten, removed or + * the hash table destroyed with g_hash_table_unref(). + * + * Returns: a newly created #GHashTable for storing a{sv} maps, free with + * g_hash_table_unref(). + * Since: 0.7.29 + */ +GHashTable * +tp_asv_new (const gchar *first_key, ...) +{ + va_list var_args; + char *key; + GType type; + GValue *value; + char *error = NULL; /* NB: not a GError! */ + + /* create a GHashTable */ + GHashTable *asv = g_hash_table_new_full (g_str_hash, g_str_equal, + NULL, (GDestroyNotify) tp_g_value_slice_free); + + va_start (var_args, first_key); + + for (key = (char *) first_key; key != NULL; key = va_arg (var_args, char *)) + { + type = va_arg (var_args, GType); + + value = tp_g_value_slice_new (type); + G_VALUE_COLLECT (value, var_args, 0, &error); + + if (error != NULL) + { + CRITICAL ("key %s: %s", key, error); + g_free (error); + error = NULL; + tp_g_value_slice_free (value); + continue; + } + + g_hash_table_insert (asv, key, value); + } + + va_end (var_args); + + return asv; +} + +/** + * tp_asv_get_boolean: + * @asv: (element-type utf8 GObject.Value): A GHashTable where the keys are + * strings and the values are GValues + * @key: The key to look up + * @valid: (out): Either %NULL, or a location to store %TRUE if the key actually + * exists and has a boolean value + * + * If a value for @key in @asv is present and boolean, return it, + * and set *@valid to %TRUE if @valid is not %NULL. + * + * Otherwise return %FALSE, and set *@valid to %FALSE if @valid is not %NULL. + * + * Returns: a boolean value for @key + * Since: 0.7.9 + */ +gboolean +tp_asv_get_boolean (const GHashTable *asv, + const gchar *key, + gboolean *valid) +{ + GValue *value; + + g_return_val_if_fail (asv != NULL, FALSE); + g_return_val_if_fail (key != NULL, FALSE); + + value = g_hash_table_lookup ((GHashTable *) asv, key); + + if (value == NULL || !G_VALUE_HOLDS_BOOLEAN (value)) + { + if (valid != NULL) + *valid = FALSE; + + return FALSE; + } + + if (valid != NULL) + *valid = TRUE; + + return g_value_get_boolean (value); +} + +/** + * tp_asv_set_boolean: (skip) + * @asv: a #GHashTable created with tp_asv_new() + * @key: string key + * @value: value + * + * Stores the value in the map. + * + * The value is stored as a slice-allocated GValue. + * + * See Also: tp_asv_new(), tp_asv_get_boolean(), tp_g_value_slice_new_boolean() + * Since: 0.7.29 + */ +void +tp_asv_set_boolean (GHashTable *asv, + const gchar *key, + gboolean value) +{ + g_return_if_fail (asv != NULL); + g_return_if_fail (key != NULL); + + g_hash_table_insert (asv, (char *) key, tp_g_value_slice_new_boolean (value)); +} + +/** + * tp_asv_get_bytes: + * @asv: (element-type utf8 GObject.Value): A GHashTable where the keys are + * strings and the values are GValues + * @key: The key to look up + * + * If a value for @key in @asv is present and is an array of bytes + * (its GType is %DBUS_TYPE_G_UCHAR_ARRAY), return it. + * + * Otherwise return %NULL. + * + * The returned value is not copied, and is only valid as long as the value + * for @key in @asv is not removed or altered. Copy it with + * g_boxed_copy (DBUS_TYPE_G_UCHAR_ARRAY, ...) if you need to keep + * it for longer. + * + * Returns: (transfer none) (allow-none) (element-type guint8): the string value + * of @key, or %NULL + * Since: 0.7.9 + */ +const GArray * +tp_asv_get_bytes (const GHashTable *asv, + const gchar *key) +{ + GValue *value; + + g_return_val_if_fail (asv != NULL, NULL); + g_return_val_if_fail (key != NULL, NULL); + + value = g_hash_table_lookup ((GHashTable *) asv, key); + + if (value == NULL || !G_VALUE_HOLDS (value, DBUS_TYPE_G_UCHAR_ARRAY)) + return NULL; + + return g_value_get_boxed (value); +} + +/** + * tp_asv_set_bytes: (skip) + * @asv: a #GHashTable created with tp_asv_new() + * @key: string key + * @length: the number of bytes to copy + * @bytes: location of an array of bytes to be copied (this may be %NULL + * if and only if length is 0) + * + * Stores the value in the map. + * + * The value is stored as a slice-allocated GValue. + * + * See Also: tp_asv_new(), tp_asv_get_bytes(), tp_g_value_slice_new_bytes() + * Since: 0.7.29 + */ +void +tp_asv_set_bytes (GHashTable *asv, + const gchar *key, + guint length, + gconstpointer bytes) +{ + g_return_if_fail (asv != NULL); + g_return_if_fail (key != NULL); + g_return_if_fail (!(length > 0 && bytes == NULL)); + + g_hash_table_insert (asv, (char *) key, + tp_g_value_slice_new_bytes (length, bytes)); +} + +/** + * tp_asv_take_bytes: (skip) + * @asv: a #GHashTable created with tp_asv_new() + * @key: string key + * @value: a non-NULL #GArray of %guchar, ownership of which will be taken by + * the #GValue + * + * Stores the value in the map. + * + * The value is stored as a slice-allocated GValue. + * + * See Also: tp_asv_new(), tp_asv_get_bytes(), tp_g_value_slice_new_take_bytes() + * Since: 0.7.29 + */ +void +tp_asv_take_bytes (GHashTable *asv, + const gchar *key, + GArray *value) +{ + g_return_if_fail (asv != NULL); + g_return_if_fail (key != NULL); + g_return_if_fail (value != NULL); + + g_hash_table_insert (asv, (char *) key, + tp_g_value_slice_new_take_bytes (value)); +} + +/** + * tp_asv_get_string: + * @asv: (element-type utf8 GObject.Value): A GHashTable where the keys are + * strings and the values are GValues + * @key: The key to look up + * + * If a value for @key in @asv is present and is a string, return it. + * + * Otherwise return %NULL. + * + * The returned value is not copied, and is only valid as long as the value + * for @key in @asv is not removed or altered. Copy it with g_strdup() if you + * need to keep it for longer. + * + * Returns: (transfer none) (allow-none): the string value of @key, or %NULL + * Since: 0.7.9 + */ +const gchar * +tp_asv_get_string (const GHashTable *asv, + const gchar *key) +{ + GValue *value; + + g_return_val_if_fail (asv != NULL, NULL); + g_return_val_if_fail (key != NULL, NULL); + + value = g_hash_table_lookup ((GHashTable *) asv, key); + + if (value == NULL || !G_VALUE_HOLDS_STRING (value)) + return NULL; + + return g_value_get_string (value); +} + +/** + * tp_asv_set_string: (skip) + * @asv: a #GHashTable created with tp_asv_new() + * @key: string key + * @value: value + * + * Stores the value in the map. + * + * The value is stored as a slice-allocated GValue. + * + * See Also: tp_asv_new(), tp_asv_get_string(), tp_g_value_slice_new_string() + * Since: 0.7.29 + */ +void +tp_asv_set_string (GHashTable *asv, + const gchar *key, + const gchar *value) +{ + g_return_if_fail (asv != NULL); + g_return_if_fail (key != NULL); + + g_hash_table_insert (asv, (char *) key, tp_g_value_slice_new_string (value)); +} + +/** + * tp_asv_take_string: (skip) + * @asv: a #GHashTable created with tp_asv_new() + * @key: string key + * @value: value + * + * Stores the value in the map. + * + * The value is stored as a slice-allocated GValue. + * + * See Also: tp_asv_new(), tp_asv_get_string(), + * tp_g_value_slice_new_take_string() + * Since: 0.7.29 + */ +void +tp_asv_take_string (GHashTable *asv, + const gchar *key, + gchar *value) +{ + g_return_if_fail (asv != NULL); + g_return_if_fail (key != NULL); + + g_hash_table_insert (asv, (char *) key, + tp_g_value_slice_new_take_string (value)); +} + +/** + * tp_asv_set_static_string: (skip) + * @asv: a #GHashTable created with tp_asv_new() + * @key: string key + * @value: value + * + * Stores the value in the map. + * + * The value is stored as a slice-allocated GValue. + * + * See Also: tp_asv_new(), tp_asv_get_string(), + * tp_g_value_slice_new_static_string() + * Since: 0.7.29 + */ +void +tp_asv_set_static_string (GHashTable *asv, + const gchar *key, + const gchar *value) +{ + g_return_if_fail (asv != NULL); + g_return_if_fail (key != NULL); + + g_hash_table_insert (asv, (char *) key, + tp_g_value_slice_new_static_string (value)); +} + +/** + * tp_asv_get_int32: + * @asv: (element-type utf8 GObject.Value): A GHashTable where the keys are + * strings and the values are GValues + * @key: The key to look up + * @valid: (out): Either %NULL, or a location in which to store %TRUE on success + * or %FALSE on failure + * + * If a value for @key in @asv is present, has an integer type used by + * dbus-glib (guchar, gint, guint, gint64 or guint64) and fits in the + * range of a gint32, return it, and if @valid is not %NULL, set *@valid to + * %TRUE. + * + * Otherwise, return 0, and if @valid is not %NULL, set *@valid to %FALSE. + * + * Returns: the 32-bit signed integer value of @key, or 0 + * Since: 0.7.9 + */ +gint32 +tp_asv_get_int32 (const GHashTable *asv, + const gchar *key, + gboolean *valid) +{ + gint64 i; + guint64 u; + gint32 ret; + GValue *value; + + g_return_val_if_fail (asv != NULL, 0); + g_return_val_if_fail (key != NULL, 0); + + value = g_hash_table_lookup ((GHashTable *) asv, key); + + if (value == NULL) + goto return_invalid; + + switch (G_VALUE_TYPE (value)) + { + case G_TYPE_UCHAR: + ret = g_value_get_uchar (value); + break; + + case G_TYPE_UINT: + u = g_value_get_uint (value); + + if (G_UNLIKELY (u > G_MAXINT32)) + goto return_invalid; + + ret = u; + break; + + case G_TYPE_INT: + ret = g_value_get_int (value); + break; + + case G_TYPE_INT64: + i = g_value_get_int64 (value); + + if (G_UNLIKELY (i < G_MININT32 || i > G_MAXINT32)) + goto return_invalid; + + ret = i; + break; + + case G_TYPE_UINT64: + u = g_value_get_uint64 (value); + + if (G_UNLIKELY (u > G_MAXINT32)) + goto return_invalid; + + ret = u; + break; + + default: + goto return_invalid; + } + + if (valid != NULL) + *valid = TRUE; + + return ret; + +return_invalid: + if (valid != NULL) + *valid = FALSE; + + return 0; +} + +/** + * tp_asv_set_int32: (skip) + * @asv: a #GHashTable created with tp_asv_new() + * @key: string key + * @value: value + * + * Stores the value in the map. + * + * The value is stored as a slice-allocated GValue. + * + * See Also: tp_asv_new(), tp_asv_get_int32(), tp_g_value_slice_new_int() + * Since: 0.7.29 + */ +void +tp_asv_set_int32 (GHashTable *asv, + const gchar *key, + gint32 value) +{ + g_return_if_fail (asv != NULL); + g_return_if_fail (key != NULL); + + g_hash_table_insert (asv, (char *) key, tp_g_value_slice_new_int (value)); +} + +/** + * tp_asv_get_uint32: + * @asv: (element-type utf8 GObject.Value): A GHashTable where the keys are + * strings and the values are GValues + * @key: The key to look up + * @valid: (out): Either %NULL, or a location in which to store %TRUE on success + * or %FALSE on failure + * + * If a value for @key in @asv is present, has an integer type used by + * dbus-glib (guchar, gint, guint, gint64 or guint64) and fits in the + * range of a guint32, return it, and if @valid is not %NULL, set *@valid to + * %TRUE. + * + * Otherwise, return 0, and if @valid is not %NULL, set *@valid to %FALSE. + * + * Returns: the 32-bit unsigned integer value of @key, or 0 + * Since: 0.7.9 + */ +guint32 +tp_asv_get_uint32 (const GHashTable *asv, + const gchar *key, + gboolean *valid) +{ + gint64 i; + guint64 u; + guint32 ret; + GValue *value; + + g_return_val_if_fail (asv != NULL, 0); + g_return_val_if_fail (key != NULL, 0); + + value = g_hash_table_lookup ((GHashTable *) asv, key); + + if (value == NULL) + goto return_invalid; + + switch (G_VALUE_TYPE (value)) + { + case G_TYPE_UCHAR: + ret = g_value_get_uchar (value); + break; + + case G_TYPE_UINT: + ret = g_value_get_uint (value); + break; + + case G_TYPE_INT: + i = g_value_get_int (value); + + if (G_UNLIKELY (i < 0)) + goto return_invalid; + + ret = i; + break; + + case G_TYPE_INT64: + i = g_value_get_int64 (value); + + if (G_UNLIKELY (i < 0 || i > G_MAXUINT32)) + goto return_invalid; + + ret = i; + break; + + case G_TYPE_UINT64: + u = g_value_get_uint64 (value); + + if (G_UNLIKELY (u > G_MAXUINT32)) + goto return_invalid; + + ret = u; + break; + + default: + goto return_invalid; + } + + if (valid != NULL) + *valid = TRUE; + + return ret; + +return_invalid: + if (valid != NULL) + *valid = FALSE; + + return 0; +} + +/** + * tp_asv_set_uint32: (skip) + * @asv: a #GHashTable created with tp_asv_new() + * @key: string key + * @value: value + * + * Stores the value in the map. + * + * The value is stored as a slice-allocated GValue. + * + * See Also: tp_asv_new(), tp_asv_get_uint32(), tp_g_value_slice_new_uint() + * Since: 0.7.29 + */ +void +tp_asv_set_uint32 (GHashTable *asv, + const gchar *key, + guint32 value) +{ + g_return_if_fail (asv != NULL); + g_return_if_fail (key != NULL); + + g_hash_table_insert (asv, (char *) key, tp_g_value_slice_new_uint (value)); +} + +/** + * tp_asv_get_int64: + * @asv: (element-type utf8 GObject.Value): A GHashTable where the keys are + * strings and the values are GValues + * @key: The key to look up + * @valid: (out): Either %NULL, or a location in which to store %TRUE on success + * or %FALSE on failure + * + * If a value for @key in @asv is present, has an integer type used by + * dbus-glib (guchar, gint, guint, gint64 or guint64) and fits in the + * range of a gint64, return it, and if @valid is not %NULL, set *@valid to + * %TRUE. + * + * Otherwise, return 0, and if @valid is not %NULL, set *@valid to %FALSE. + * + * Returns: the 64-bit signed integer value of @key, or 0 + * Since: 0.7.9 + */ +gint64 +tp_asv_get_int64 (const GHashTable *asv, + const gchar *key, + gboolean *valid) +{ + gint64 ret; + guint64 u; + GValue *value; + + g_return_val_if_fail (asv != NULL, 0); + g_return_val_if_fail (key != NULL, 0); + + value = g_hash_table_lookup ((GHashTable *) asv, key); + + if (value == NULL) + goto return_invalid; + + switch (G_VALUE_TYPE (value)) + { + case G_TYPE_UCHAR: + ret = g_value_get_uchar (value); + break; + + case G_TYPE_UINT: + ret = g_value_get_uint (value); + break; + + case G_TYPE_INT: + ret = g_value_get_int (value); + break; + + case G_TYPE_INT64: + ret = g_value_get_int64 (value); + break; + + case G_TYPE_UINT64: + u = g_value_get_uint64 (value); + + if (G_UNLIKELY (u > G_MAXINT64)) + goto return_invalid; + + ret = u; + break; + + default: + goto return_invalid; + } + + if (valid != NULL) + *valid = TRUE; + + return ret; + +return_invalid: + if (valid != NULL) + *valid = FALSE; + + return 0; +} + +/** + * tp_asv_set_int64: (skip) + * @asv: a #GHashTable created with tp_asv_new() + * @key: string key + * @value: value + * + * Stores the value in the map. + * + * The value is stored as a slice-allocated GValue. + * + * See Also: tp_asv_new(), tp_asv_get_int64(), tp_g_value_slice_new_int64() + * Since: 0.7.29 + */ +void +tp_asv_set_int64 (GHashTable *asv, + const gchar *key, + gint64 value) +{ + g_return_if_fail (asv != NULL); + g_return_if_fail (key != NULL); + + g_hash_table_insert (asv, (char *) key, tp_g_value_slice_new_int64 (value)); +} + +/** + * tp_asv_get_uint64: + * @asv: (element-type utf8 GObject.Value): A GHashTable where the keys are + * strings and the values are GValues + * @key: The key to look up + * @valid: (out): Either %NULL, or a location in which to store %TRUE on success + * or %FALSE on failure + * + * If a value for @key in @asv is present, has an integer type used by + * dbus-glib (guchar, gint, guint, gint64 or guint64) and is non-negative, + * return it, and if @valid is not %NULL, set *@valid to %TRUE. + * + * Otherwise, return 0, and if @valid is not %NULL, set *@valid to %FALSE. + * + * Returns: the 64-bit unsigned integer value of @key, or 0 + * Since: 0.7.9 + */ +guint64 +tp_asv_get_uint64 (const GHashTable *asv, + const gchar *key, + gboolean *valid) +{ + gint64 tmp; + guint64 ret; + GValue *value; + + g_return_val_if_fail (asv != NULL, 0); + g_return_val_if_fail (key != NULL, 0); + + value = g_hash_table_lookup ((GHashTable *) asv, key); + + if (value == NULL) + goto return_invalid; + + switch (G_VALUE_TYPE (value)) + { + case G_TYPE_UCHAR: + ret = g_value_get_uchar (value); + break; + + case G_TYPE_UINT: + ret = g_value_get_uint (value); + break; + + case G_TYPE_INT: + tmp = g_value_get_int (value); + + if (G_UNLIKELY (tmp < 0)) + goto return_invalid; + + ret = tmp; + break; + + case G_TYPE_INT64: + tmp = g_value_get_int64 (value); + + if (G_UNLIKELY (tmp < 0)) + goto return_invalid; + + ret = tmp; + break; + + case G_TYPE_UINT64: + ret = g_value_get_uint64 (value); + break; + + default: + goto return_invalid; + } + + if (valid != NULL) + *valid = TRUE; + + return ret; + +return_invalid: + if (valid != NULL) + *valid = FALSE; + + return 0; +} + +/** + * tp_asv_set_uint64: (skip) + * @asv: a #GHashTable created with tp_asv_new() + * @key: string key + * @value: value + * + * Stores the value in the map. + * + * The value is stored as a slice-allocated GValue. + * + * See Also: tp_asv_new(), tp_asv_get_uint64(), tp_g_value_slice_new_uint64() + * Since: 0.7.29 + */ +void +tp_asv_set_uint64 (GHashTable *asv, + const gchar *key, + guint64 value) +{ + g_return_if_fail (asv != NULL); + g_return_if_fail (key != NULL); + + g_hash_table_insert (asv, (char *) key, tp_g_value_slice_new_uint64 (value)); +} + +/** + * tp_asv_get_double: + * @asv: (element-type utf8 GObject.Value): A GHashTable where the keys are + * strings and the values are GValues + * @key: The key to look up + * @valid: (out): Either %NULL, or a location in which to store %TRUE on success + * or %FALSE on failure + * + * If a value for @key in @asv is present and has any numeric type used by + * dbus-glib (guchar, gint, guint, gint64, guint64 or gdouble), + * return it as a double, and if @valid is not %NULL, set *@valid to %TRUE. + * + * Otherwise, return 0.0, and if @valid is not %NULL, set *@valid to %FALSE. + * + * Returns: the double precision floating-point value of @key, or 0.0 + * Since: 0.7.9 + */ +gdouble +tp_asv_get_double (const GHashTable *asv, + const gchar *key, + gboolean *valid) +{ + gdouble ret; + GValue *value; + + g_return_val_if_fail (asv != NULL, 0.0); + g_return_val_if_fail (key != NULL, 0.0); + + value = g_hash_table_lookup ((GHashTable *) asv, key); + + if (value == NULL) + goto return_invalid; + + switch (G_VALUE_TYPE (value)) + { + case G_TYPE_DOUBLE: + ret = g_value_get_double (value); + break; + + case G_TYPE_UCHAR: + ret = g_value_get_uchar (value); + break; + + case G_TYPE_UINT: + ret = g_value_get_uint (value); + break; + + case G_TYPE_INT: + ret = g_value_get_int (value); + break; + + case G_TYPE_INT64: + ret = g_value_get_int64 (value); + break; + + case G_TYPE_UINT64: + ret = g_value_get_uint64 (value); + break; + + default: + goto return_invalid; + } + + if (valid != NULL) + *valid = TRUE; + + return ret; + +return_invalid: + if (valid != NULL) + *valid = FALSE; + + return 0; +} + +/** + * tp_asv_set_double: (skip) + * @asv: a #GHashTable created with tp_asv_new() + * @key: string key + * @value: value + * + * Stores the value in the map. + * + * The value is stored as a slice-allocated GValue. + * + * See Also: tp_asv_new(), tp_asv_get_double(), tp_g_value_slice_new_double() + * Since: 0.7.29 + */ +void +tp_asv_set_double (GHashTable *asv, + const gchar *key, + gdouble value) +{ + g_return_if_fail (asv != NULL); + g_return_if_fail (key != NULL); + + g_hash_table_insert (asv, (char *) key, tp_g_value_slice_new_double (value)); +} + +/** + * tp_asv_get_object_path: + * @asv: (element-type utf8 GObject.Value): A GHashTable where the keys are + * strings and the values are GValues + * @key: The key to look up + * + * If a value for @key in @asv is present and is an object path, return it. + * + * Otherwise return %NULL. + * + * The returned value is not copied, and is only valid as long as the value + * for @key in @asv is not removed or altered. Copy it with g_strdup() if you + * need to keep it for longer. + * + * Returns: (transfer none) (allow-none): the object-path value of @key, or + * %NULL + * Since: 0.7.9 + */ +const gchar * +tp_asv_get_object_path (const GHashTable *asv, + const gchar *key) +{ + GValue *value; + + g_return_val_if_fail (asv != NULL, 0); + g_return_val_if_fail (key != NULL, 0); + + value = g_hash_table_lookup ((GHashTable *) asv, key); + + if (value == NULL || !G_VALUE_HOLDS (value, DBUS_TYPE_G_OBJECT_PATH)) + return NULL; + + return g_value_get_boxed (value); +} + +/** + * tp_asv_set_object_path: (skip) + * @asv: a #GHashTable created with tp_asv_new() + * @key: string key + * @value: value + * + * Stores the value in the map. + * + * The value is stored as a slice-allocated GValue. + * + * See Also: tp_asv_new(), tp_asv_get_object_path(), + * tp_g_value_slice_new_object_path() + * Since: 0.7.29 + */ +void +tp_asv_set_object_path (GHashTable *asv, + const gchar *key, + const gchar *value) +{ + g_return_if_fail (asv != NULL); + g_return_if_fail (key != NULL); + + g_hash_table_insert (asv, (char *) key, + tp_g_value_slice_new_object_path (value)); +} + +/** + * tp_asv_take_object_path: (skip) + * @asv: a #GHashTable created with tp_asv_new() + * @key: string key + * @value: value + * + * Stores the value in the map. + * + * The value is stored as a slice-allocated GValue. + * + * See Also: tp_asv_new(), tp_asv_get_object_path(), + * tp_g_value_slice_new_take_object_path() + * Since: 0.7.29 + */ +void +tp_asv_take_object_path (GHashTable *asv, + const gchar *key, + gchar *value) +{ + g_return_if_fail (asv != NULL); + g_return_if_fail (key != NULL); + + g_hash_table_insert (asv, (char *) key, + tp_g_value_slice_new_take_object_path (value)); +} + +/** + * tp_asv_set_static_object_path: (skip) + * @asv: a #GHashTable created with tp_asv_new() + * @key: string key + * @value: value + * + * Stores the value in the map. + * + * The value is stored as a slice-allocated GValue. + * + * See Also: tp_asv_new(), tp_asv_get_object_path(), + * tp_g_value_slice_new_static_object_path() + * Since: 0.7.29 + */ +void +tp_asv_set_static_object_path (GHashTable *asv, + const gchar *key, + const gchar *value) +{ + g_return_if_fail (asv != NULL); + g_return_if_fail (key != NULL); + + g_hash_table_insert (asv, (char *) key, + tp_g_value_slice_new_static_object_path (value)); +} + +/** + * tp_asv_get_boxed: + * @asv: (element-type utf8 GObject.Value): A GHashTable where the keys are + * strings and the values are GValues + * @key: The key to look up + * @type: The type that the key's value should have, which must be derived + * from %G_TYPE_BOXED + * + * If a value for @key in @asv is present and is of the desired type, + * return it. + * + * Otherwise return %NULL. + * + * The returned value is not copied, and is only valid as long as the value + * for @key in @asv is not removed or altered. Copy it, for instance with + * g_boxed_copy(), if you need to keep it for longer. + * + * Returns: (transfer none) (allow-none): the value of @key, or %NULL + * Since: 0.7.9 + */ +gpointer +tp_asv_get_boxed (const GHashTable *asv, + const gchar *key, + GType type) +{ + GValue *value; + + g_return_val_if_fail (asv != NULL, NULL); + g_return_val_if_fail (key != NULL, NULL); + g_return_val_if_fail (G_TYPE_FUNDAMENTAL (type) == G_TYPE_BOXED, NULL); + + value = g_hash_table_lookup ((GHashTable *) asv, key); + + if (value == NULL || !G_VALUE_HOLDS (value, type)) + return NULL; + + return g_value_get_boxed (value); +} + +/** + * tp_asv_set_boxed: (skip) + * @asv: a #GHashTable created with tp_asv_new() + * @key: string key + * @type: the type of the key's value, which must be derived from %G_TYPE_BOXED + * @value: value + * + * Stores the value in the map. + * + * The value is stored as a slice-allocated GValue. + * + * See Also: tp_asv_new(), tp_asv_get_boxed(), tp_g_value_slice_new_boxed() + * Since: 0.7.29 + */ +void +tp_asv_set_boxed (GHashTable *asv, + const gchar *key, + GType type, + gconstpointer value) +{ + g_return_if_fail (asv != NULL); + g_return_if_fail (key != NULL); + g_return_if_fail (G_TYPE_FUNDAMENTAL (type) == G_TYPE_BOXED); + + g_hash_table_insert (asv, (char *) key, + tp_g_value_slice_new_boxed (type, value)); +} + +/** + * tp_asv_take_boxed: (skip) + * @asv: a #GHashTable created with tp_asv_new() + * @key: string key + * @type: the type of the key's value, which must be derived from %G_TYPE_BOXED + * @value: value + * + * Stores the value in the map. + * + * The value is stored as a slice-allocated GValue. + * + * See Also: tp_asv_new(), tp_asv_get_boxed(), tp_g_value_slice_new_take_boxed() + * Since: 0.7.29 + */ +void +tp_asv_take_boxed (GHashTable *asv, + const gchar *key, + GType type, + gpointer value) +{ + g_return_if_fail (asv != NULL); + g_return_if_fail (key != NULL); + g_return_if_fail (G_TYPE_FUNDAMENTAL (type) == G_TYPE_BOXED); + + g_hash_table_insert (asv, (char *) key, + tp_g_value_slice_new_take_boxed (type, value)); +} + +/** + * tp_asv_set_static_boxed: (skip) + * @asv: a #GHashTable created with tp_asv_new() + * @key: string key + * @type: the type of the key's value, which must be derived from %G_TYPE_BOXED + * @value: value + * + * Stores the value in the map. + * + * The value is stored as a slice-allocated GValue. + * + * See Also: tp_asv_new(), tp_asv_get_boxed(), + * tp_g_value_slice_new_static_boxed() + * Since: 0.7.29 + */ +void +tp_asv_set_static_boxed (GHashTable *asv, + const gchar *key, + GType type, + gconstpointer value) +{ + g_return_if_fail (asv != NULL); + g_return_if_fail (key != NULL); + g_return_if_fail (G_TYPE_FUNDAMENTAL (type) == G_TYPE_BOXED); + + g_hash_table_insert (asv, (char *) key, + tp_g_value_slice_new_static_boxed (type, value)); +} + +/** + * tp_asv_get_strv: + * @asv: (element-type utf8 GObject.Value): A GHashTable where the keys are + * strings and the values are GValues + * @key: The key to look up + * + * If a value for @key in @asv is present and is an array of strings (strv), + * return it. + * + * Otherwise return %NULL. + * + * The returned value is not copied, and is only valid as long as the value + * for @key in @asv is not removed or altered. Copy it with g_strdupv() if you + * need to keep it for longer. + * + * Returns: (transfer none) (allow-none): the %NULL-terminated string-array + * value of @key, or %NULL + * Since: 0.7.9 + */ +const gchar * const * +tp_asv_get_strv (const GHashTable *asv, + const gchar *key) +{ + GValue *value; + + g_return_val_if_fail (asv != NULL, NULL); + g_return_val_if_fail (key != NULL, NULL); + + value = g_hash_table_lookup ((GHashTable *) asv, key); + + if (value == NULL || !G_VALUE_HOLDS (value, G_TYPE_STRV)) + return NULL; + + return g_value_get_boxed (value); +} + +/** + * tp_asv_set_strv: (skip) + * @asv: a #GHashTable created with tp_asv_new() + * @key: string key + * @value: a %NULL-terminated string array + * + * Stores the value in the map. + * + * The value is stored as a slice-allocated GValue. + * + * See Also: tp_asv_new(), tp_asv_get_strv() + * Since: 0.7.29 + */ +void +tp_asv_set_strv (GHashTable *asv, + const gchar *key, + gchar **value) +{ + g_return_if_fail (asv != NULL); + g_return_if_fail (key != NULL); + + g_hash_table_insert (asv, (char *) key, + tp_g_value_slice_new_boxed (G_TYPE_STRV, value)); +} + +/** + * tp_asv_lookup: (skip) + * @asv: A GHashTable where the keys are strings and the values are GValues + * @key: The key to look up + * + * If a value for @key in @asv is present, return it. Otherwise return %NULL. + * + * The returned value is not copied, and is only valid as long as the value + * for @key in @asv is not removed or altered. Copy it with (for instance) + * g_value_copy() if you need to keep it for longer. + * + * Returns: the value of @key, or %NULL + * Since: 0.7.9 + */ +const GValue * +tp_asv_lookup (const GHashTable *asv, + const gchar *key) +{ + g_return_val_if_fail (asv != NULL, NULL); + g_return_val_if_fail (key != NULL, NULL); + + return g_hash_table_lookup ((GHashTable *) asv, key); +} + +/** + * tp_asv_dump: (skip) + * @asv: a #GHashTable created with tp_asv_new() + * + * Dumps the a{sv} map to the debugging console. + * + * The purpose of this function is give the programmer the ability to easily + * inspect the contents of an a{sv} map for debugging purposes. + */ +void +tp_asv_dump (GHashTable *asv) +{ + GHashTableIter iter; + char *key; + GValue *value; + + g_return_if_fail (asv != NULL); + + g_debug ("{"); + + g_hash_table_iter_init (&iter, asv); + while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &value)) + { + char *str = g_strdup_value_contents (value); + g_debug (" '%s' : %s", key, str); + g_free (str); + } + + g_debug ("}"); +} diff --git a/telepathy-glib/asv.h b/telepathy-glib/asv.h new file mode 100644 index 000000000..7d937222e --- /dev/null +++ b/telepathy-glib/asv.h @@ -0,0 +1,97 @@ +/* + * asv.h - GHashTable<gchar *,GValue *> utilities + * + * Copyright © 2005-2010 Collabora Ltd. <http://www.collabora.co.uk/> + * Copyright © 2005-2009 Nokia Corporation + * + * 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_GLIB_DBUS_H_INSIDE) && !defined (_TP_COMPILATION) +#error "Only <telepathy-glib/telepathy-glib-dbus.h> can be included directly." +#endif + +#ifndef __TP_ASV_H__ +#define __TP_ASV_H__ + +#include <telepathy-glib/telepathy-glib.h> + +G_BEGIN_DECLS + +#define tp_asv_size(asv) _tp_asv_size_inline (asv) + +static inline guint +_tp_asv_size_inline (const GHashTable *asv) +{ + /* The empty comment here is to stop gtkdoc thinking g_hash_table_size is + * a declaration. */ + return g_hash_table_size /* */ ((GHashTable *) asv); +} + +GHashTable *tp_asv_new (const gchar *first_key, ...) + G_GNUC_NULL_TERMINATED G_GNUC_WARN_UNUSED_RESULT; +gboolean tp_asv_get_boolean (const GHashTable *asv, const gchar *key, + gboolean *valid); +void tp_asv_set_boolean (GHashTable *asv, const gchar *key, gboolean value); +gpointer tp_asv_get_boxed (const GHashTable *asv, const gchar *key, + GType type); +void tp_asv_set_boxed (GHashTable *asv, const gchar *key, GType type, + gconstpointer value); +void tp_asv_take_boxed (GHashTable *asv, const gchar *key, GType type, + gpointer value); +void tp_asv_set_static_boxed (GHashTable *asv, const gchar *key, GType type, + gconstpointer value); +const GArray *tp_asv_get_bytes (const GHashTable *asv, const gchar *key); +void tp_asv_set_bytes (GHashTable *asv, const gchar *key, guint length, + gconstpointer bytes); +void tp_asv_take_bytes (GHashTable *asv, const gchar *key, GArray *value); +gdouble tp_asv_get_double (const GHashTable *asv, const gchar *key, + gboolean *valid); +void tp_asv_set_double (GHashTable *asv, const gchar *key, gdouble value); +gint32 tp_asv_get_int32 (const GHashTable *asv, const gchar *key, + gboolean *valid); +void tp_asv_set_int32 (GHashTable *asv, const gchar *key, gint32 value); +gint64 tp_asv_get_int64 (const GHashTable *asv, const gchar *key, + gboolean *valid); +void tp_asv_set_int64 (GHashTable *asv, const gchar *key, gint64 value); +const gchar *tp_asv_get_object_path (const GHashTable *asv, const gchar *key); +void tp_asv_set_object_path (GHashTable *asv, const gchar *key, + const gchar *value); +void tp_asv_take_object_path (GHashTable *asv, const gchar *key, + gchar *value); +void tp_asv_set_static_object_path (GHashTable *asv, const gchar *key, + const gchar *value); +const gchar *tp_asv_get_string (const GHashTable *asv, const gchar *key); +void tp_asv_set_string (GHashTable *asv, const gchar *key, const gchar *value); +void tp_asv_take_string (GHashTable *asv, const gchar *key, gchar *value); +void tp_asv_set_static_string (GHashTable *asv, const gchar *key, + const gchar *value); +guint32 tp_asv_get_uint32 (const GHashTable *asv, const gchar *key, + gboolean *valid); +void tp_asv_set_uint32 (GHashTable *asv, const gchar *key, guint32 value); +guint64 tp_asv_get_uint64 (const GHashTable *asv, const gchar *key, + gboolean *valid); +void tp_asv_set_uint64 (GHashTable *asv, const gchar *key, guint64 value); +const GValue *tp_asv_lookup (const GHashTable *asv, const gchar *key); + +const gchar * const * +/* this comment stops gtkdoc denying that this function exists */ +tp_asv_get_strv (const GHashTable *asv, const gchar *key); +void tp_asv_set_strv (GHashTable *asv, const gchar *key, gchar **value); +void tp_asv_dump (GHashTable *asv); + +G_END_DECLS + +#endif /* single-inclusion guard */ diff --git a/telepathy-glib/base-call-channel.c b/telepathy-glib/base-call-channel.c index b87d4d6d0..8d4af7e52 100644 --- a/telepathy-glib/base-call-channel.c +++ b/telepathy-glib/base-call-channel.c @@ -104,6 +104,7 @@ #define DEBUG_FLAG TP_DEBUG_CALL +#include <telepathy-glib/asv.h> #include "telepathy-glib/base-call-content.h" #include "telepathy-glib/base-call-internal.h" #include "telepathy-glib/base-media-call-stream.h" diff --git a/telepathy-glib/base-client.c b/telepathy-glib/base-client.c index 436df35a9..01365757d 100644 --- a/telepathy-glib/base-client.c +++ b/telepathy-glib/base-client.c @@ -174,6 +174,7 @@ #include <dbus/dbus.h> #include <dbus/dbus-glib-lowlevel.h> +#include <telepathy-glib/asv.h> #include <telepathy-glib/add-dispatch-operation-context-internal.h> #include <telepathy-glib/automatic-client-factory.h> #include <telepathy-glib/channel-dispatcher.h> diff --git a/telepathy-glib/base-connection.c b/telepathy-glib/base-connection.c index 757973f7d..82f1123b8 100644 --- a/telepathy-glib/base-connection.c +++ b/telepathy-glib/base-connection.c @@ -238,6 +238,7 @@ #include <dbus/dbus-glib-lowlevel.h> +#include <telepathy-glib/asv.h> #include <telepathy-glib/channel-manager.h> #include <telepathy-glib/channel-manager-request-internal.h> #include <telepathy-glib/connection-manager.h> diff --git a/telepathy-glib/base-media-call-content.c b/telepathy-glib/base-media-call-content.c index fc511566c..fd871c14a 100644 --- a/telepathy-glib/base-media-call-content.c +++ b/telepathy-glib/base-media-call-content.c @@ -58,6 +58,7 @@ #include <string.h> #define DEBUG_FLAG TP_DEBUG_CALL +#include <telepathy-glib/asv.h> #include "telepathy-glib/base-call-internal.h" #include "telepathy-glib/base-call-channel.h" #include "telepathy-glib/base-channel.h" diff --git a/telepathy-glib/base-password-channel.c b/telepathy-glib/base-password-channel.c index 3bdd12021..76e7e9857 100644 --- a/telepathy-glib/base-password-channel.c +++ b/telepathy-glib/base-password-channel.c @@ -56,6 +56,7 @@ #include "telepathy-glib/base-password-channel.h" +#include <telepathy-glib/asv.h> #include <telepathy-glib/dbus.h> #include <telepathy-glib/gtypes.h> #include <telepathy-glib/interfaces.h> diff --git a/telepathy-glib/base-protocol.c b/telepathy-glib/base-protocol.c index 847d3ee1a..a133db8eb 100644 --- a/telepathy-glib/base-protocol.c +++ b/telepathy-glib/base-protocol.c @@ -24,6 +24,8 @@ #include <telepathy-glib/base-protocol-internal.h> #include <dbus/dbus-protocol.h> + +#include <telepathy-glib/asv.h> #include <telepathy-glib/channel-manager.h> #include <telepathy-glib/gtypes.h> #include <telepathy-glib/interfaces.h> diff --git a/telepathy-glib/call-channel.c b/telepathy-glib/call-channel.c index e5670a025..2e922440f 100644 --- a/telepathy-glib/call-channel.c +++ b/telepathy-glib/call-channel.c @@ -49,6 +49,7 @@ #include <config.h> +#include <telepathy-glib/asv.h> #include <telepathy-glib/call-content.h> #include <telepathy-glib/call-stream.h> #include <telepathy-glib/cli-channel.h> diff --git a/telepathy-glib/call-content-media-description.c b/telepathy-glib/call-content-media-description.c index 09baa59f5..ee33da6d6 100644 --- a/telepathy-glib/call-content-media-description.c +++ b/telepathy-glib/call-content-media-description.c @@ -53,6 +53,7 @@ #include "call-content-media-description.h" #define DEBUG_FLAG TP_DEBUG_CALL +#include <telepathy-glib/asv.h> #include "telepathy-glib/base-call-internal.h" #include "telepathy-glib/debug-internal.h" #include "telepathy-glib/dbus.h" diff --git a/telepathy-glib/call-content.c b/telepathy-glib/call-content.c index e1f073425..0e6a5f71a 100644 --- a/telepathy-glib/call-content.c +++ b/telepathy-glib/call-content.c @@ -47,6 +47,7 @@ #include "telepathy-glib/call-content.h" +#include <telepathy-glib/asv.h> #include <telepathy-glib/call-channel.h> #include <telepathy-glib/call-stream.h> #include <telepathy-glib/cli-call.h> diff --git a/telepathy-glib/call-stream.c b/telepathy-glib/call-stream.c index b07247a75..b9f2a0b56 100644 --- a/telepathy-glib/call-stream.c +++ b/telepathy-glib/call-stream.c @@ -47,6 +47,7 @@ #include "telepathy-glib/call-stream.h" +#include <telepathy-glib/asv.h> #include <telepathy-glib/call-content.h> #include <telepathy-glib/cli-call.h> #include <telepathy-glib/cli-misc.h> diff --git a/telepathy-glib/capabilities.c b/telepathy-glib/capabilities.c index d6206962d..ec4e0347c 100644 --- a/telepathy-glib/capabilities.c +++ b/telepathy-glib/capabilities.c @@ -22,6 +22,7 @@ #include "telepathy-glib/capabilities.h" #include "telepathy-glib/capabilities-internal.h" +#include <telepathy-glib/asv.h> #include <telepathy-glib/dbus.h> #include <telepathy-glib/dbus-internal.h> #include <telepathy-glib/enums.h> diff --git a/telepathy-glib/channel-dispatch-operation.c b/telepathy-glib/channel-dispatch-operation.c index 82bad84cb..62b7f0c94 100644 --- a/telepathy-glib/channel-dispatch-operation.c +++ b/telepathy-glib/channel-dispatch-operation.c @@ -25,6 +25,7 @@ #include <dbus/dbus-glib.h> +#include <telepathy-glib/asv.h> #include <telepathy-glib/base-client-internal.h> #include <telepathy-glib/channel.h> #include <telepathy-glib/cli-misc.h> diff --git a/telepathy-glib/channel-filter.c b/telepathy-glib/channel-filter.c index bb2ce0233..88a3be9e0 100644 --- a/telepathy-glib/channel-filter.c +++ b/telepathy-glib/channel-filter.c @@ -26,6 +26,8 @@ #include "debug-internal.h" #include <dbus/dbus-glib.h> + +#include <telepathy-glib/asv.h> #include <telepathy-glib/interfaces.h> #include <telepathy-glib/util.h> #include <telepathy-glib/variant-util.h> diff --git a/telepathy-glib/channel-group.c b/telepathy-glib/channel-group.c index df09cd8cd..7e1272f4c 100644 --- a/telepathy-glib/channel-group.c +++ b/telepathy-glib/channel-group.c @@ -24,6 +24,7 @@ #include <dbus/dbus-glib.h> +#include <telepathy-glib/asv.h> #include <telepathy-glib/cli-channel.h> #include <telepathy-glib/cli-misc.h> #include <telepathy-glib/client-factory.h> diff --git a/telepathy-glib/channel.c b/telepathy-glib/channel.c index 17e281da6..ffaca6a86 100644 --- a/telepathy-glib/channel.c +++ b/telepathy-glib/channel.c @@ -23,6 +23,7 @@ #include "telepathy-glib/channel-internal.h" +#include <telepathy-glib/asv.h> #include <telepathy-glib/channel-iface.h> #include <telepathy-glib/cli-channel.h> #include <telepathy-glib/cli-misc.h> diff --git a/telepathy-glib/connection-aliasing.c b/telepathy-glib/connection-aliasing.c index 5d56442ac..fd576c156 100644 --- a/telepathy-glib/connection-aliasing.c +++ b/telepathy-glib/connection-aliasing.c @@ -22,6 +22,7 @@ #include "telepathy-glib/connection.h" +#include <telepathy-glib/asv.h> #include <telepathy-glib/cli-connection.h> #include <telepathy-glib/cli-misc.h> #include <telepathy-glib/dbus.h> diff --git a/telepathy-glib/connection-avatars.c b/telepathy-glib/connection-avatars.c index f2ca3f2a0..be814c633 100644 --- a/telepathy-glib/connection-avatars.c +++ b/telepathy-glib/connection-avatars.c @@ -23,6 +23,7 @@ #include "telepathy-glib/connection.h" +#include <telepathy-glib/asv.h> #include <telepathy-glib/cli-misc.h> #include <telepathy-glib/dbus.h> #include <telepathy-glib/interfaces.h> diff --git a/telepathy-glib/connection-contact-info.c b/telepathy-glib/connection-contact-info.c index 87b7e1192..d34945cb8 100644 --- a/telepathy-glib/connection-contact-info.c +++ b/telepathy-glib/connection-contact-info.c @@ -26,6 +26,7 @@ #include <dbus/dbus-protocol.h> +#include <telepathy-glib/asv.h> #include <telepathy-glib/cli-connection.h> #include <telepathy-glib/cli-misc.h> #include <telepathy-glib/dbus.h> diff --git a/telepathy-glib/connection-contact-list.c b/telepathy-glib/connection-contact-list.c index 6b4554295..3ee2b8f9f 100644 --- a/telepathy-glib/connection-contact-list.c +++ b/telepathy-glib/connection-contact-list.c @@ -22,6 +22,7 @@ #include "telepathy-glib/connection-contact-list.h" +#include <telepathy-glib/asv.h> #include <telepathy-glib/cli-connection.h> #include <telepathy-glib/cli-misc.h> #include <telepathy-glib/dbus.h> diff --git a/telepathy-glib/connection-manager.c b/telepathy-glib/connection-manager.c index ab8efeb4f..925dc7295 100644 --- a/telepathy-glib/connection-manager.c +++ b/telepathy-glib/connection-manager.c @@ -27,6 +27,7 @@ #include <dbus/dbus-glib.h> +#include <telepathy-glib/asv.h> #include <telepathy-glib/cli-misc.h> #include "telepathy-glib/defs.h" #include "telepathy-glib/enums.h" diff --git a/telepathy-glib/connection.c b/telepathy-glib/connection.c index 6a14838dd..9c74988b7 100644 --- a/telepathy-glib/connection.c +++ b/telepathy-glib/connection.c @@ -27,6 +27,7 @@ #include <dbus/dbus-protocol.h> +#include <telepathy-glib/asv.h> #include <telepathy-glib/cli-connection.h> #include <telepathy-glib/cli-misc.h> #include <telepathy-glib/connection-manager.h> diff --git a/telepathy-glib/contact-search.c b/telepathy-glib/contact-search.c index c5e6aebd0..44da22bef 100644 --- a/telepathy-glib/contact-search.c +++ b/telepathy-glib/contact-search.c @@ -22,6 +22,7 @@ #include "telepathy-glib/contact-search.h" +#include <telepathy-glib/asv.h> #include <telepathy-glib/cli-channel.h> #include <telepathy-glib/contact-search-result.h> #include <telepathy-glib/contact-search-internal.h> diff --git a/telepathy-glib/contact.c b/telepathy-glib/contact.c index d72d4b9e7..7ce988499 100644 --- a/telepathy-glib/contact.c +++ b/telepathy-glib/contact.c @@ -25,6 +25,7 @@ #include <errno.h> #include <string.h> +#include <telepathy-glib/asv.h> #include <telepathy-glib/capabilities-internal.h> #include <telepathy-glib/cli-connection.h> #include <telepathy-glib/client-factory.h> diff --git a/telepathy-glib/dbus-tube-channel.c b/telepathy-glib/dbus-tube-channel.c index 4c30cbceb..471f29e57 100644 --- a/telepathy-glib/dbus-tube-channel.c +++ b/telepathy-glib/dbus-tube-channel.c @@ -83,6 +83,7 @@ #include "telepathy-glib/dbus-tube-channel.h" +#include <telepathy-glib/asv.h> #include <telepathy-glib/cli-channel.h> #include <telepathy-glib/cli-misc.h> #include <telepathy-glib/contact.h> diff --git a/telepathy-glib/dbus.c b/telepathy-glib/dbus.c index 8916da024..726f46a3b 100644 --- a/telepathy-glib/dbus.c +++ b/telepathy-glib/dbus.c @@ -27,32 +27,7 @@ * D-Bus utility functions used in telepathy-glib. */ -/** - * SECTION:asv - * @title: Manipulating a{sv} mappings - * @short_description: Functions to manipulate mappings from string to - * variant, as represented in dbus-glib by a #GHashTable from string - * to #GValue - * - * Mappings from string to variant (D-Bus signature a{sv}) are commonly used - * to provide extensibility, but in dbus-glib they're somewhat awkward to deal - * with. - * - * These functions provide convenient access to the values in such - * a mapping. - * - * They also work around the fact that none of the #GHashTable public API - * takes a const pointer to a #GHashTable, even the read-only methods that - * logically ought to. - * - * Parts of telepathy-glib return const pointers to #GHashTable, to encourage - * the use of this API. - * - * Since: 0.7.9 - */ - #include "config.h" - #include <telepathy-glib/dbus.h> #include <telepathy-glib/dbus-internal.h> @@ -62,8 +37,6 @@ #include <dbus/dbus.h> #include <dbus/dbus-glib.h> -#include <gobject/gvaluecollector.h> - #include <telepathy-glib/errors.h> #include <telepathy-glib/gtypes.h> #include <telepathy-glib/proxy.h> @@ -75,19 +48,6 @@ #include "debug-internal.h" /** - * tp_asv_size: (skip) - * @asv: a GHashTable - * - * Return the size of @asv as if via g_hash_table_size(). - * - * The only difference is that this version takes a const #GHashTable and - * casts it. - * - * Since: 0.7.12 - */ -/* (#define + static inline in dbus.h) */ - -/** * TpDBusNameType: * @TP_DBUS_NAME_TYPE_UNIQUE: accept unique names like :1.123 * (not including the name of the bus daemon itself) @@ -509,1242 +469,6 @@ tp_dbus_check_valid_object_path (const gchar *path, GError **error) return TRUE; } -/** - * tp_asv_new: (skip) - * @first_key: the name of the first key (or NULL) - * @...: type and value for the first key, followed by a NULL-terminated list - * of (key, type, value) tuples - * - * Creates a new #GHashTable for use with a{sv} maps, containing the values - * passed in as parameters. - * - * The #GHashTable is synonymous with: - * <informalexample><programlisting> - * GHashTable *asv = g_hash_table_new_full (g_str_hash, g_str_equal, - * NULL, (GDestroyNotify) tp_g_value_slice_free); - * </programlisting></informalexample> - * Followed by manual insertion of each of the parameters. - * - * Parameters are stored in slice-allocated GValues and should be set using - * tp_asv_set_*() and retrieved using tp_asv_get_*(). - * - * tp_g_value_slice_new() and tp_g_value_slice_dup() may also be used to insert - * into the map if required. - * <informalexample><programlisting> - * g_hash_table_insert (parameters, "account", - * tp_g_value_slice_new_string ("bob@mcbadgers.com")); - * </programlisting></informalexample> - * - * <example> - * <title>Using tp_asv_new()</title> - * <programlisting> - * GHashTable *parameters = tp_asv_new ( - * "answer", G_TYPE_INT, 42, - * "question", G_TYPE_STRING, "We just don't know", - * NULL);</programlisting> - * </example> - * - * Allocated values will be automatically free'd when overwritten, removed or - * the hash table destroyed with g_hash_table_unref(). - * - * Returns: a newly created #GHashTable for storing a{sv} maps, free with - * g_hash_table_unref(). - * Since: 0.7.29 - */ -GHashTable * -tp_asv_new (const gchar *first_key, ...) -{ - va_list var_args; - char *key; - GType type; - GValue *value; - char *error = NULL; /* NB: not a GError! */ - - /* create a GHashTable */ - GHashTable *asv = g_hash_table_new_full (g_str_hash, g_str_equal, - NULL, (GDestroyNotify) tp_g_value_slice_free); - - va_start (var_args, first_key); - - for (key = (char *) first_key; key != NULL; key = va_arg (var_args, char *)) - { - type = va_arg (var_args, GType); - - value = tp_g_value_slice_new (type); - G_VALUE_COLLECT (value, var_args, 0, &error); - - if (error != NULL) - { - CRITICAL ("key %s: %s", key, error); - g_free (error); - error = NULL; - tp_g_value_slice_free (value); - continue; - } - - g_hash_table_insert (asv, key, value); - } - - va_end (var_args); - - return asv; -} - -/** - * tp_asv_get_boolean: - * @asv: (element-type utf8 GObject.Value): A GHashTable where the keys are - * strings and the values are GValues - * @key: The key to look up - * @valid: (out): Either %NULL, or a location to store %TRUE if the key actually - * exists and has a boolean value - * - * If a value for @key in @asv is present and boolean, return it, - * and set *@valid to %TRUE if @valid is not %NULL. - * - * Otherwise return %FALSE, and set *@valid to %FALSE if @valid is not %NULL. - * - * Returns: a boolean value for @key - * Since: 0.7.9 - */ -gboolean -tp_asv_get_boolean (const GHashTable *asv, - const gchar *key, - gboolean *valid) -{ - GValue *value; - - g_return_val_if_fail (asv != NULL, FALSE); - g_return_val_if_fail (key != NULL, FALSE); - - value = g_hash_table_lookup ((GHashTable *) asv, key); - - if (value == NULL || !G_VALUE_HOLDS_BOOLEAN (value)) - { - if (valid != NULL) - *valid = FALSE; - - return FALSE; - } - - if (valid != NULL) - *valid = TRUE; - - return g_value_get_boolean (value); -} - -/** - * tp_asv_set_boolean: (skip) - * @asv: a #GHashTable created with tp_asv_new() - * @key: string key - * @value: value - * - * Stores the value in the map. - * - * The value is stored as a slice-allocated GValue. - * - * See Also: tp_asv_new(), tp_asv_get_boolean(), tp_g_value_slice_new_boolean() - * Since: 0.7.29 - */ -void -tp_asv_set_boolean (GHashTable *asv, - const gchar *key, - gboolean value) -{ - g_return_if_fail (asv != NULL); - g_return_if_fail (key != NULL); - - g_hash_table_insert (asv, (char *) key, tp_g_value_slice_new_boolean (value)); -} - -/** - * tp_asv_get_bytes: - * @asv: (element-type utf8 GObject.Value): A GHashTable where the keys are - * strings and the values are GValues - * @key: The key to look up - * - * If a value for @key in @asv is present and is an array of bytes - * (its GType is %DBUS_TYPE_G_UCHAR_ARRAY), return it. - * - * Otherwise return %NULL. - * - * The returned value is not copied, and is only valid as long as the value - * for @key in @asv is not removed or altered. Copy it with - * g_boxed_copy (DBUS_TYPE_G_UCHAR_ARRAY, ...) if you need to keep - * it for longer. - * - * Returns: (transfer none) (allow-none) (element-type guint8): the string value - * of @key, or %NULL - * Since: 0.7.9 - */ -const GArray * -tp_asv_get_bytes (const GHashTable *asv, - const gchar *key) -{ - GValue *value; - - g_return_val_if_fail (asv != NULL, NULL); - g_return_val_if_fail (key != NULL, NULL); - - value = g_hash_table_lookup ((GHashTable *) asv, key); - - if (value == NULL || !G_VALUE_HOLDS (value, DBUS_TYPE_G_UCHAR_ARRAY)) - return NULL; - - return g_value_get_boxed (value); -} - -/** - * tp_asv_set_bytes: (skip) - * @asv: a #GHashTable created with tp_asv_new() - * @key: string key - * @length: the number of bytes to copy - * @bytes: location of an array of bytes to be copied (this may be %NULL - * if and only if length is 0) - * - * Stores the value in the map. - * - * The value is stored as a slice-allocated GValue. - * - * See Also: tp_asv_new(), tp_asv_get_bytes(), tp_g_value_slice_new_bytes() - * Since: 0.7.29 - */ -void -tp_asv_set_bytes (GHashTable *asv, - const gchar *key, - guint length, - gconstpointer bytes) -{ - g_return_if_fail (asv != NULL); - g_return_if_fail (key != NULL); - g_return_if_fail (!(length > 0 && bytes == NULL)); - - g_hash_table_insert (asv, (char *) key, - tp_g_value_slice_new_bytes (length, bytes)); -} - -/** - * tp_asv_take_bytes: (skip) - * @asv: a #GHashTable created with tp_asv_new() - * @key: string key - * @value: a non-NULL #GArray of %guchar, ownership of which will be taken by - * the #GValue - * - * Stores the value in the map. - * - * The value is stored as a slice-allocated GValue. - * - * See Also: tp_asv_new(), tp_asv_get_bytes(), tp_g_value_slice_new_take_bytes() - * Since: 0.7.29 - */ -void -tp_asv_take_bytes (GHashTable *asv, - const gchar *key, - GArray *value) -{ - g_return_if_fail (asv != NULL); - g_return_if_fail (key != NULL); - g_return_if_fail (value != NULL); - - g_hash_table_insert (asv, (char *) key, - tp_g_value_slice_new_take_bytes (value)); -} - -/** - * tp_asv_get_string: - * @asv: (element-type utf8 GObject.Value): A GHashTable where the keys are - * strings and the values are GValues - * @key: The key to look up - * - * If a value for @key in @asv is present and is a string, return it. - * - * Otherwise return %NULL. - * - * The returned value is not copied, and is only valid as long as the value - * for @key in @asv is not removed or altered. Copy it with g_strdup() if you - * need to keep it for longer. - * - * Returns: (transfer none) (allow-none): the string value of @key, or %NULL - * Since: 0.7.9 - */ -const gchar * -tp_asv_get_string (const GHashTable *asv, - const gchar *key) -{ - GValue *value; - - g_return_val_if_fail (asv != NULL, NULL); - g_return_val_if_fail (key != NULL, NULL); - - value = g_hash_table_lookup ((GHashTable *) asv, key); - - if (value == NULL || !G_VALUE_HOLDS_STRING (value)) - return NULL; - - return g_value_get_string (value); -} - -/** - * tp_asv_set_string: (skip) - * @asv: a #GHashTable created with tp_asv_new() - * @key: string key - * @value: value - * - * Stores the value in the map. - * - * The value is stored as a slice-allocated GValue. - * - * See Also: tp_asv_new(), tp_asv_get_string(), tp_g_value_slice_new_string() - * Since: 0.7.29 - */ -void -tp_asv_set_string (GHashTable *asv, - const gchar *key, - const gchar *value) -{ - g_return_if_fail (asv != NULL); - g_return_if_fail (key != NULL); - - g_hash_table_insert (asv, (char *) key, tp_g_value_slice_new_string (value)); -} - -/** - * tp_asv_take_string: (skip) - * @asv: a #GHashTable created with tp_asv_new() - * @key: string key - * @value: value - * - * Stores the value in the map. - * - * The value is stored as a slice-allocated GValue. - * - * See Also: tp_asv_new(), tp_asv_get_string(), - * tp_g_value_slice_new_take_string() - * Since: 0.7.29 - */ -void -tp_asv_take_string (GHashTable *asv, - const gchar *key, - gchar *value) -{ - g_return_if_fail (asv != NULL); - g_return_if_fail (key != NULL); - - g_hash_table_insert (asv, (char *) key, - tp_g_value_slice_new_take_string (value)); -} - -/** - * tp_asv_set_static_string: (skip) - * @asv: a #GHashTable created with tp_asv_new() - * @key: string key - * @value: value - * - * Stores the value in the map. - * - * The value is stored as a slice-allocated GValue. - * - * See Also: tp_asv_new(), tp_asv_get_string(), - * tp_g_value_slice_new_static_string() - * Since: 0.7.29 - */ -void -tp_asv_set_static_string (GHashTable *asv, - const gchar *key, - const gchar *value) -{ - g_return_if_fail (asv != NULL); - g_return_if_fail (key != NULL); - - g_hash_table_insert (asv, (char *) key, - tp_g_value_slice_new_static_string (value)); -} - -/** - * tp_asv_get_int32: - * @asv: (element-type utf8 GObject.Value): A GHashTable where the keys are - * strings and the values are GValues - * @key: The key to look up - * @valid: (out): Either %NULL, or a location in which to store %TRUE on success - * or %FALSE on failure - * - * If a value for @key in @asv is present, has an integer type used by - * dbus-glib (guchar, gint, guint, gint64 or guint64) and fits in the - * range of a gint32, return it, and if @valid is not %NULL, set *@valid to - * %TRUE. - * - * Otherwise, return 0, and if @valid is not %NULL, set *@valid to %FALSE. - * - * Returns: the 32-bit signed integer value of @key, or 0 - * Since: 0.7.9 - */ -gint32 -tp_asv_get_int32 (const GHashTable *asv, - const gchar *key, - gboolean *valid) -{ - gint64 i; - guint64 u; - gint32 ret; - GValue *value; - - g_return_val_if_fail (asv != NULL, 0); - g_return_val_if_fail (key != NULL, 0); - - value = g_hash_table_lookup ((GHashTable *) asv, key); - - if (value == NULL) - goto return_invalid; - - switch (G_VALUE_TYPE (value)) - { - case G_TYPE_UCHAR: - ret = g_value_get_uchar (value); - break; - - case G_TYPE_UINT: - u = g_value_get_uint (value); - - if (G_UNLIKELY (u > G_MAXINT32)) - goto return_invalid; - - ret = u; - break; - - case G_TYPE_INT: - ret = g_value_get_int (value); - break; - - case G_TYPE_INT64: - i = g_value_get_int64 (value); - - if (G_UNLIKELY (i < G_MININT32 || i > G_MAXINT32)) - goto return_invalid; - - ret = i; - break; - - case G_TYPE_UINT64: - u = g_value_get_uint64 (value); - - if (G_UNLIKELY (u > G_MAXINT32)) - goto return_invalid; - - ret = u; - break; - - default: - goto return_invalid; - } - - if (valid != NULL) - *valid = TRUE; - - return ret; - -return_invalid: - if (valid != NULL) - *valid = FALSE; - - return 0; -} - -/** - * tp_asv_set_int32: (skip) - * @asv: a #GHashTable created with tp_asv_new() - * @key: string key - * @value: value - * - * Stores the value in the map. - * - * The value is stored as a slice-allocated GValue. - * - * See Also: tp_asv_new(), tp_asv_get_int32(), tp_g_value_slice_new_int() - * Since: 0.7.29 - */ -void -tp_asv_set_int32 (GHashTable *asv, - const gchar *key, - gint32 value) -{ - g_return_if_fail (asv != NULL); - g_return_if_fail (key != NULL); - - g_hash_table_insert (asv, (char *) key, tp_g_value_slice_new_int (value)); -} - -/** - * tp_asv_get_uint32: - * @asv: (element-type utf8 GObject.Value): A GHashTable where the keys are - * strings and the values are GValues - * @key: The key to look up - * @valid: (out): Either %NULL, or a location in which to store %TRUE on success - * or %FALSE on failure - * - * If a value for @key in @asv is present, has an integer type used by - * dbus-glib (guchar, gint, guint, gint64 or guint64) and fits in the - * range of a guint32, return it, and if @valid is not %NULL, set *@valid to - * %TRUE. - * - * Otherwise, return 0, and if @valid is not %NULL, set *@valid to %FALSE. - * - * Returns: the 32-bit unsigned integer value of @key, or 0 - * Since: 0.7.9 - */ -guint32 -tp_asv_get_uint32 (const GHashTable *asv, - const gchar *key, - gboolean *valid) -{ - gint64 i; - guint64 u; - guint32 ret; - GValue *value; - - g_return_val_if_fail (asv != NULL, 0); - g_return_val_if_fail (key != NULL, 0); - - value = g_hash_table_lookup ((GHashTable *) asv, key); - - if (value == NULL) - goto return_invalid; - - switch (G_VALUE_TYPE (value)) - { - case G_TYPE_UCHAR: - ret = g_value_get_uchar (value); - break; - - case G_TYPE_UINT: - ret = g_value_get_uint (value); - break; - - case G_TYPE_INT: - i = g_value_get_int (value); - - if (G_UNLIKELY (i < 0)) - goto return_invalid; - - ret = i; - break; - - case G_TYPE_INT64: - i = g_value_get_int64 (value); - - if (G_UNLIKELY (i < 0 || i > G_MAXUINT32)) - goto return_invalid; - - ret = i; - break; - - case G_TYPE_UINT64: - u = g_value_get_uint64 (value); - - if (G_UNLIKELY (u > G_MAXUINT32)) - goto return_invalid; - - ret = u; - break; - - default: - goto return_invalid; - } - - if (valid != NULL) - *valid = TRUE; - - return ret; - -return_invalid: - if (valid != NULL) - *valid = FALSE; - - return 0; -} - -/** - * tp_asv_set_uint32: (skip) - * @asv: a #GHashTable created with tp_asv_new() - * @key: string key - * @value: value - * - * Stores the value in the map. - * - * The value is stored as a slice-allocated GValue. - * - * See Also: tp_asv_new(), tp_asv_get_uint32(), tp_g_value_slice_new_uint() - * Since: 0.7.29 - */ -void -tp_asv_set_uint32 (GHashTable *asv, - const gchar *key, - guint32 value) -{ - g_return_if_fail (asv != NULL); - g_return_if_fail (key != NULL); - - g_hash_table_insert (asv, (char *) key, tp_g_value_slice_new_uint (value)); -} - -/** - * tp_asv_get_int64: - * @asv: (element-type utf8 GObject.Value): A GHashTable where the keys are - * strings and the values are GValues - * @key: The key to look up - * @valid: (out): Either %NULL, or a location in which to store %TRUE on success - * or %FALSE on failure - * - * If a value for @key in @asv is present, has an integer type used by - * dbus-glib (guchar, gint, guint, gint64 or guint64) and fits in the - * range of a gint64, return it, and if @valid is not %NULL, set *@valid to - * %TRUE. - * - * Otherwise, return 0, and if @valid is not %NULL, set *@valid to %FALSE. - * - * Returns: the 64-bit signed integer value of @key, or 0 - * Since: 0.7.9 - */ -gint64 -tp_asv_get_int64 (const GHashTable *asv, - const gchar *key, - gboolean *valid) -{ - gint64 ret; - guint64 u; - GValue *value; - - g_return_val_if_fail (asv != NULL, 0); - g_return_val_if_fail (key != NULL, 0); - - value = g_hash_table_lookup ((GHashTable *) asv, key); - - if (value == NULL) - goto return_invalid; - - switch (G_VALUE_TYPE (value)) - { - case G_TYPE_UCHAR: - ret = g_value_get_uchar (value); - break; - - case G_TYPE_UINT: - ret = g_value_get_uint (value); - break; - - case G_TYPE_INT: - ret = g_value_get_int (value); - break; - - case G_TYPE_INT64: - ret = g_value_get_int64 (value); - break; - - case G_TYPE_UINT64: - u = g_value_get_uint64 (value); - - if (G_UNLIKELY (u > G_MAXINT64)) - goto return_invalid; - - ret = u; - break; - - default: - goto return_invalid; - } - - if (valid != NULL) - *valid = TRUE; - - return ret; - -return_invalid: - if (valid != NULL) - *valid = FALSE; - - return 0; -} - -/** - * tp_asv_set_int64: (skip) - * @asv: a #GHashTable created with tp_asv_new() - * @key: string key - * @value: value - * - * Stores the value in the map. - * - * The value is stored as a slice-allocated GValue. - * - * See Also: tp_asv_new(), tp_asv_get_int64(), tp_g_value_slice_new_int64() - * Since: 0.7.29 - */ -void -tp_asv_set_int64 (GHashTable *asv, - const gchar *key, - gint64 value) -{ - g_return_if_fail (asv != NULL); - g_return_if_fail (key != NULL); - - g_hash_table_insert (asv, (char *) key, tp_g_value_slice_new_int64 (value)); -} - -/** - * tp_asv_get_uint64: - * @asv: (element-type utf8 GObject.Value): A GHashTable where the keys are - * strings and the values are GValues - * @key: The key to look up - * @valid: (out): Either %NULL, or a location in which to store %TRUE on success - * or %FALSE on failure - * - * If a value for @key in @asv is present, has an integer type used by - * dbus-glib (guchar, gint, guint, gint64 or guint64) and is non-negative, - * return it, and if @valid is not %NULL, set *@valid to %TRUE. - * - * Otherwise, return 0, and if @valid is not %NULL, set *@valid to %FALSE. - * - * Returns: the 64-bit unsigned integer value of @key, or 0 - * Since: 0.7.9 - */ -guint64 -tp_asv_get_uint64 (const GHashTable *asv, - const gchar *key, - gboolean *valid) -{ - gint64 tmp; - guint64 ret; - GValue *value; - - g_return_val_if_fail (asv != NULL, 0); - g_return_val_if_fail (key != NULL, 0); - - value = g_hash_table_lookup ((GHashTable *) asv, key); - - if (value == NULL) - goto return_invalid; - - switch (G_VALUE_TYPE (value)) - { - case G_TYPE_UCHAR: - ret = g_value_get_uchar (value); - break; - - case G_TYPE_UINT: - ret = g_value_get_uint (value); - break; - - case G_TYPE_INT: - tmp = g_value_get_int (value); - - if (G_UNLIKELY (tmp < 0)) - goto return_invalid; - - ret = tmp; - break; - - case G_TYPE_INT64: - tmp = g_value_get_int64 (value); - - if (G_UNLIKELY (tmp < 0)) - goto return_invalid; - - ret = tmp; - break; - - case G_TYPE_UINT64: - ret = g_value_get_uint64 (value); - break; - - default: - goto return_invalid; - } - - if (valid != NULL) - *valid = TRUE; - - return ret; - -return_invalid: - if (valid != NULL) - *valid = FALSE; - - return 0; -} - -/** - * tp_asv_set_uint64: (skip) - * @asv: a #GHashTable created with tp_asv_new() - * @key: string key - * @value: value - * - * Stores the value in the map. - * - * The value is stored as a slice-allocated GValue. - * - * See Also: tp_asv_new(), tp_asv_get_uint64(), tp_g_value_slice_new_uint64() - * Since: 0.7.29 - */ -void -tp_asv_set_uint64 (GHashTable *asv, - const gchar *key, - guint64 value) -{ - g_return_if_fail (asv != NULL); - g_return_if_fail (key != NULL); - - g_hash_table_insert (asv, (char *) key, tp_g_value_slice_new_uint64 (value)); -} - -/** - * tp_asv_get_double: - * @asv: (element-type utf8 GObject.Value): A GHashTable where the keys are - * strings and the values are GValues - * @key: The key to look up - * @valid: (out): Either %NULL, or a location in which to store %TRUE on success - * or %FALSE on failure - * - * If a value for @key in @asv is present and has any numeric type used by - * dbus-glib (guchar, gint, guint, gint64, guint64 or gdouble), - * return it as a double, and if @valid is not %NULL, set *@valid to %TRUE. - * - * Otherwise, return 0.0, and if @valid is not %NULL, set *@valid to %FALSE. - * - * Returns: the double precision floating-point value of @key, or 0.0 - * Since: 0.7.9 - */ -gdouble -tp_asv_get_double (const GHashTable *asv, - const gchar *key, - gboolean *valid) -{ - gdouble ret; - GValue *value; - - g_return_val_if_fail (asv != NULL, 0.0); - g_return_val_if_fail (key != NULL, 0.0); - - value = g_hash_table_lookup ((GHashTable *) asv, key); - - if (value == NULL) - goto return_invalid; - - switch (G_VALUE_TYPE (value)) - { - case G_TYPE_DOUBLE: - ret = g_value_get_double (value); - break; - - case G_TYPE_UCHAR: - ret = g_value_get_uchar (value); - break; - - case G_TYPE_UINT: - ret = g_value_get_uint (value); - break; - - case G_TYPE_INT: - ret = g_value_get_int (value); - break; - - case G_TYPE_INT64: - ret = g_value_get_int64 (value); - break; - - case G_TYPE_UINT64: - ret = g_value_get_uint64 (value); - break; - - default: - goto return_invalid; - } - - if (valid != NULL) - *valid = TRUE; - - return ret; - -return_invalid: - if (valid != NULL) - *valid = FALSE; - - return 0; -} - -/** - * tp_asv_set_double: (skip) - * @asv: a #GHashTable created with tp_asv_new() - * @key: string key - * @value: value - * - * Stores the value in the map. - * - * The value is stored as a slice-allocated GValue. - * - * See Also: tp_asv_new(), tp_asv_get_double(), tp_g_value_slice_new_double() - * Since: 0.7.29 - */ -void -tp_asv_set_double (GHashTable *asv, - const gchar *key, - gdouble value) -{ - g_return_if_fail (asv != NULL); - g_return_if_fail (key != NULL); - - g_hash_table_insert (asv, (char *) key, tp_g_value_slice_new_double (value)); -} - -/** - * tp_asv_get_object_path: - * @asv: (element-type utf8 GObject.Value): A GHashTable where the keys are - * strings and the values are GValues - * @key: The key to look up - * - * If a value for @key in @asv is present and is an object path, return it. - * - * Otherwise return %NULL. - * - * The returned value is not copied, and is only valid as long as the value - * for @key in @asv is not removed or altered. Copy it with g_strdup() if you - * need to keep it for longer. - * - * Returns: (transfer none) (allow-none): the object-path value of @key, or - * %NULL - * Since: 0.7.9 - */ -const gchar * -tp_asv_get_object_path (const GHashTable *asv, - const gchar *key) -{ - GValue *value; - - g_return_val_if_fail (asv != NULL, 0); - g_return_val_if_fail (key != NULL, 0); - - value = g_hash_table_lookup ((GHashTable *) asv, key); - - if (value == NULL || !G_VALUE_HOLDS (value, DBUS_TYPE_G_OBJECT_PATH)) - return NULL; - - return g_value_get_boxed (value); -} - -/** - * tp_asv_set_object_path: (skip) - * @asv: a #GHashTable created with tp_asv_new() - * @key: string key - * @value: value - * - * Stores the value in the map. - * - * The value is stored as a slice-allocated GValue. - * - * See Also: tp_asv_new(), tp_asv_get_object_path(), - * tp_g_value_slice_new_object_path() - * Since: 0.7.29 - */ -void -tp_asv_set_object_path (GHashTable *asv, - const gchar *key, - const gchar *value) -{ - g_return_if_fail (asv != NULL); - g_return_if_fail (key != NULL); - - g_hash_table_insert (asv, (char *) key, - tp_g_value_slice_new_object_path (value)); -} - -/** - * tp_asv_take_object_path: (skip) - * @asv: a #GHashTable created with tp_asv_new() - * @key: string key - * @value: value - * - * Stores the value in the map. - * - * The value is stored as a slice-allocated GValue. - * - * See Also: tp_asv_new(), tp_asv_get_object_path(), - * tp_g_value_slice_new_take_object_path() - * Since: 0.7.29 - */ -void -tp_asv_take_object_path (GHashTable *asv, - const gchar *key, - gchar *value) -{ - g_return_if_fail (asv != NULL); - g_return_if_fail (key != NULL); - - g_hash_table_insert (asv, (char *) key, - tp_g_value_slice_new_take_object_path (value)); -} - -/** - * tp_asv_set_static_object_path: (skip) - * @asv: a #GHashTable created with tp_asv_new() - * @key: string key - * @value: value - * - * Stores the value in the map. - * - * The value is stored as a slice-allocated GValue. - * - * See Also: tp_asv_new(), tp_asv_get_object_path(), - * tp_g_value_slice_new_static_object_path() - * Since: 0.7.29 - */ -void -tp_asv_set_static_object_path (GHashTable *asv, - const gchar *key, - const gchar *value) -{ - g_return_if_fail (asv != NULL); - g_return_if_fail (key != NULL); - - g_hash_table_insert (asv, (char *) key, - tp_g_value_slice_new_static_object_path (value)); -} - -/** - * tp_asv_get_boxed: - * @asv: (element-type utf8 GObject.Value): A GHashTable where the keys are - * strings and the values are GValues - * @key: The key to look up - * @type: The type that the key's value should have, which must be derived - * from %G_TYPE_BOXED - * - * If a value for @key in @asv is present and is of the desired type, - * return it. - * - * Otherwise return %NULL. - * - * The returned value is not copied, and is only valid as long as the value - * for @key in @asv is not removed or altered. Copy it, for instance with - * g_boxed_copy(), if you need to keep it for longer. - * - * Returns: (transfer none) (allow-none): the value of @key, or %NULL - * Since: 0.7.9 - */ -gpointer -tp_asv_get_boxed (const GHashTable *asv, - const gchar *key, - GType type) -{ - GValue *value; - - g_return_val_if_fail (asv != NULL, NULL); - g_return_val_if_fail (key != NULL, NULL); - g_return_val_if_fail (G_TYPE_FUNDAMENTAL (type) == G_TYPE_BOXED, NULL); - - value = g_hash_table_lookup ((GHashTable *) asv, key); - - if (value == NULL || !G_VALUE_HOLDS (value, type)) - return NULL; - - return g_value_get_boxed (value); -} - -/** - * tp_asv_set_boxed: (skip) - * @asv: a #GHashTable created with tp_asv_new() - * @key: string key - * @type: the type of the key's value, which must be derived from %G_TYPE_BOXED - * @value: value - * - * Stores the value in the map. - * - * The value is stored as a slice-allocated GValue. - * - * See Also: tp_asv_new(), tp_asv_get_boxed(), tp_g_value_slice_new_boxed() - * Since: 0.7.29 - */ -void -tp_asv_set_boxed (GHashTable *asv, - const gchar *key, - GType type, - gconstpointer value) -{ - g_return_if_fail (asv != NULL); - g_return_if_fail (key != NULL); - g_return_if_fail (G_TYPE_FUNDAMENTAL (type) == G_TYPE_BOXED); - - g_hash_table_insert (asv, (char *) key, - tp_g_value_slice_new_boxed (type, value)); -} - -/** - * tp_asv_take_boxed: (skip) - * @asv: a #GHashTable created with tp_asv_new() - * @key: string key - * @type: the type of the key's value, which must be derived from %G_TYPE_BOXED - * @value: value - * - * Stores the value in the map. - * - * The value is stored as a slice-allocated GValue. - * - * See Also: tp_asv_new(), tp_asv_get_boxed(), tp_g_value_slice_new_take_boxed() - * Since: 0.7.29 - */ -void -tp_asv_take_boxed (GHashTable *asv, - const gchar *key, - GType type, - gpointer value) -{ - g_return_if_fail (asv != NULL); - g_return_if_fail (key != NULL); - g_return_if_fail (G_TYPE_FUNDAMENTAL (type) == G_TYPE_BOXED); - - g_hash_table_insert (asv, (char *) key, - tp_g_value_slice_new_take_boxed (type, value)); -} - -/** - * tp_asv_set_static_boxed: (skip) - * @asv: a #GHashTable created with tp_asv_new() - * @key: string key - * @type: the type of the key's value, which must be derived from %G_TYPE_BOXED - * @value: value - * - * Stores the value in the map. - * - * The value is stored as a slice-allocated GValue. - * - * See Also: tp_asv_new(), tp_asv_get_boxed(), - * tp_g_value_slice_new_static_boxed() - * Since: 0.7.29 - */ -void -tp_asv_set_static_boxed (GHashTable *asv, - const gchar *key, - GType type, - gconstpointer value) -{ - g_return_if_fail (asv != NULL); - g_return_if_fail (key != NULL); - g_return_if_fail (G_TYPE_FUNDAMENTAL (type) == G_TYPE_BOXED); - - g_hash_table_insert (asv, (char *) key, - tp_g_value_slice_new_static_boxed (type, value)); -} - -/** - * tp_asv_get_strv: - * @asv: (element-type utf8 GObject.Value): A GHashTable where the keys are - * strings and the values are GValues - * @key: The key to look up - * - * If a value for @key in @asv is present and is an array of strings (strv), - * return it. - * - * Otherwise return %NULL. - * - * The returned value is not copied, and is only valid as long as the value - * for @key in @asv is not removed or altered. Copy it with g_strdupv() if you - * need to keep it for longer. - * - * Returns: (transfer none) (allow-none): the %NULL-terminated string-array - * value of @key, or %NULL - * Since: 0.7.9 - */ -const gchar * const * -tp_asv_get_strv (const GHashTable *asv, - const gchar *key) -{ - GValue *value; - - g_return_val_if_fail (asv != NULL, NULL); - g_return_val_if_fail (key != NULL, NULL); - - value = g_hash_table_lookup ((GHashTable *) asv, key); - - if (value == NULL || !G_VALUE_HOLDS (value, G_TYPE_STRV)) - return NULL; - - return g_value_get_boxed (value); -} - -/** - * tp_asv_set_strv: (skip) - * @asv: a #GHashTable created with tp_asv_new() - * @key: string key - * @value: a %NULL-terminated string array - * - * Stores the value in the map. - * - * The value is stored as a slice-allocated GValue. - * - * See Also: tp_asv_new(), tp_asv_get_strv() - * Since: 0.7.29 - */ -void -tp_asv_set_strv (GHashTable *asv, - const gchar *key, - gchar **value) -{ - g_return_if_fail (asv != NULL); - g_return_if_fail (key != NULL); - - g_hash_table_insert (asv, (char *) key, - tp_g_value_slice_new_boxed (G_TYPE_STRV, value)); -} - -/** - * tp_asv_lookup: (skip) - * @asv: A GHashTable where the keys are strings and the values are GValues - * @key: The key to look up - * - * If a value for @key in @asv is present, return it. Otherwise return %NULL. - * - * The returned value is not copied, and is only valid as long as the value - * for @key in @asv is not removed or altered. Copy it with (for instance) - * g_value_copy() if you need to keep it for longer. - * - * Returns: the value of @key, or %NULL - * Since: 0.7.9 - */ -const GValue * -tp_asv_lookup (const GHashTable *asv, - const gchar *key) -{ - g_return_val_if_fail (asv != NULL, NULL); - g_return_val_if_fail (key != NULL, NULL); - - return g_hash_table_lookup ((GHashTable *) asv, key); -} - -/** - * tp_asv_dump: (skip) - * @asv: a #GHashTable created with tp_asv_new() - * - * Dumps the a{sv} map to the debugging console. - * - * The purpose of this function is give the programmer the ability to easily - * inspect the contents of an a{sv} map for debugging purposes. - */ -void -tp_asv_dump (GHashTable *asv) -{ - GHashTableIter iter; - char *key; - GValue *value; - - g_return_if_fail (asv != NULL); - - g_debug ("{"); - - g_hash_table_iter_init (&iter, asv); - while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &value)) - { - char *str = g_strdup_value_contents (value); - g_debug (" '%s' : %s", key, str); - g_free (str); - } - - g_debug ("}"); -} - /* for internal use (TpChannel, TpConnection _new convenience functions) */ gboolean _tp_dbus_connection_get_name_owner (GDBusConnection *dbus_connection, diff --git a/telepathy-glib/dbus.h b/telepathy-glib/dbus.h index f3af6c739..831764f9d 100644 --- a/telepathy-glib/dbus.h +++ b/telepathy-glib/dbus.h @@ -58,68 +58,6 @@ gboolean tp_dbus_check_valid_member_name (const gchar *name, gboolean tp_dbus_check_valid_object_path (const gchar *path, GError **error); -#define tp_asv_size(asv) _tp_asv_size_inline (asv) - -static inline guint -_tp_asv_size_inline (const GHashTable *asv) -{ - /* The empty comment here is to stop gtkdoc thinking g_hash_table_size is - * a declaration. */ - return g_hash_table_size /* */ ((GHashTable *) asv); -} - -GHashTable *tp_asv_new (const gchar *first_key, ...) - G_GNUC_NULL_TERMINATED G_GNUC_WARN_UNUSED_RESULT; -gboolean tp_asv_get_boolean (const GHashTable *asv, const gchar *key, - gboolean *valid); -void tp_asv_set_boolean (GHashTable *asv, const gchar *key, gboolean value); -gpointer tp_asv_get_boxed (const GHashTable *asv, const gchar *key, - GType type); -void tp_asv_set_boxed (GHashTable *asv, const gchar *key, GType type, - gconstpointer value); -void tp_asv_take_boxed (GHashTable *asv, const gchar *key, GType type, - gpointer value); -void tp_asv_set_static_boxed (GHashTable *asv, const gchar *key, GType type, - gconstpointer value); -const GArray *tp_asv_get_bytes (const GHashTable *asv, const gchar *key); -void tp_asv_set_bytes (GHashTable *asv, const gchar *key, guint length, - gconstpointer bytes); -void tp_asv_take_bytes (GHashTable *asv, const gchar *key, GArray *value); -gdouble tp_asv_get_double (const GHashTable *asv, const gchar *key, - gboolean *valid); -void tp_asv_set_double (GHashTable *asv, const gchar *key, gdouble value); -gint32 tp_asv_get_int32 (const GHashTable *asv, const gchar *key, - gboolean *valid); -void tp_asv_set_int32 (GHashTable *asv, const gchar *key, gint32 value); -gint64 tp_asv_get_int64 (const GHashTable *asv, const gchar *key, - gboolean *valid); -void tp_asv_set_int64 (GHashTable *asv, const gchar *key, gint64 value); -const gchar *tp_asv_get_object_path (const GHashTable *asv, const gchar *key); -void tp_asv_set_object_path (GHashTable *asv, const gchar *key, - const gchar *value); -void tp_asv_take_object_path (GHashTable *asv, const gchar *key, - gchar *value); -void tp_asv_set_static_object_path (GHashTable *asv, const gchar *key, - const gchar *value); -const gchar *tp_asv_get_string (const GHashTable *asv, const gchar *key); -void tp_asv_set_string (GHashTable *asv, const gchar *key, const gchar *value); -void tp_asv_take_string (GHashTable *asv, const gchar *key, gchar *value); -void tp_asv_set_static_string (GHashTable *asv, const gchar *key, - const gchar *value); -guint32 tp_asv_get_uint32 (const GHashTable *asv, const gchar *key, - gboolean *valid); -void tp_asv_set_uint32 (GHashTable *asv, const gchar *key, guint32 value); -guint64 tp_asv_get_uint64 (const GHashTable *asv, const gchar *key, - gboolean *valid); -void tp_asv_set_uint64 (GHashTable *asv, const gchar *key, guint64 value); -const GValue *tp_asv_lookup (const GHashTable *asv, const gchar *key); - -const gchar * const * -/* this comment stops gtkdoc denying that this function exists */ -tp_asv_get_strv (const GHashTable *asv, const gchar *key); -void tp_asv_set_strv (GHashTable *asv, const gchar *key, gchar **value); -void tp_asv_dump (GHashTable *asv); - gboolean tp_dbus_connection_request_name (GDBusConnection *dbus_connection, const gchar *well_known_name, gboolean idempotent, GError **error); gboolean tp_dbus_connection_release_name (GDBusConnection *dbus_connection, diff --git a/telepathy-glib/file-transfer-channel.c b/telepathy-glib/file-transfer-channel.c index 7e4def777..1e6fcd8a2 100644 --- a/telepathy-glib/file-transfer-channel.c +++ b/telepathy-glib/file-transfer-channel.c @@ -98,6 +98,7 @@ #include "telepathy-glib/file-transfer-channel.h" +#include <telepathy-glib/asv.h> #include <telepathy-glib/cli-channel.h> #include <telepathy-glib/cli-misc.h> #include <telepathy-glib/dbus.h> diff --git a/telepathy-glib/group-mixin.c b/telepathy-glib/group-mixin.c index 1d05e15c2..12f81ebfe 100644 --- a/telepathy-glib/group-mixin.c +++ b/telepathy-glib/group-mixin.c @@ -64,6 +64,7 @@ #include <stdio.h> #include <string.h> +#include <telepathy-glib/asv.h> #include <telepathy-glib/base-channel.h> #include <telepathy-glib/dbus.h> #include <telepathy-glib/errors.h> diff --git a/telepathy-glib/message-mixin.c b/telepathy-glib/message-mixin.c index 5adc0bf0c..180225cff 100644 --- a/telepathy-glib/message-mixin.c +++ b/telepathy-glib/message-mixin.c @@ -66,6 +66,7 @@ #include <dbus/dbus-glib-lowlevel.h> #include <string.h> +#include <telepathy-glib/asv.h> #include <telepathy-glib/base-channel.h> #include <telepathy-glib/cm-message.h> #include <telepathy-glib/cm-message-internal.h> diff --git a/telepathy-glib/message.c b/telepathy-glib/message.c index 1c17e5359..e43ecf77a 100644 --- a/telepathy-glib/message.c +++ b/telepathy-glib/message.c @@ -37,6 +37,7 @@ #include <dbus/dbus-glib.h> +#include <telepathy-glib/asv.h> #include <telepathy-glib/cm-message.h> #include <telepathy-glib/dbus.h> #include <telepathy-glib/gtypes.h> diff --git a/telepathy-glib/observe-channel-context.c b/telepathy-glib/observe-channel-context.c index 68a952ace..5b74a4be2 100644 --- a/telepathy-glib/observe-channel-context.c +++ b/telepathy-glib/observe-channel-context.c @@ -49,6 +49,7 @@ #include "telepathy-glib/observe-channel-context-internal.h" #include "telepathy-glib/observe-channel-context.h" +#include <telepathy-glib/asv.h> #include <telepathy-glib/channel.h> #include <telepathy-glib/channel-request.h> #include <telepathy-glib/dbus.h> diff --git a/telepathy-glib/protocol.c b/telepathy-glib/protocol.c index 3e815b526..ca0902c1c 100644 --- a/telepathy-glib/protocol.c +++ b/telepathy-glib/protocol.c @@ -39,6 +39,7 @@ #include <dbus/dbus-glib.h> +#include <telepathy-glib/asv.h> #include <telepathy-glib/gtypes.h> #include <telepathy-glib/interfaces.h> #include <telepathy-glib/proxy-subclass.h> diff --git a/telepathy-glib/room-info.c b/telepathy-glib/room-info.c index 162e47ddf..87cf02dc8 100644 --- a/telepathy-glib/room-info.c +++ b/telepathy-glib/room-info.c @@ -23,6 +23,7 @@ #include "room-info.h" #include "room-info-internal.h" +#include <telepathy-glib/asv.h> #include <telepathy-glib/gtypes.h> #include <telepathy-glib/dbus.h> #include <telepathy-glib/sliced-gvalue.h> diff --git a/telepathy-glib/room-list.c b/telepathy-glib/room-list.c index 8c7cdbd48..394ae6a34 100644 --- a/telepathy-glib/room-list.c +++ b/telepathy-glib/room-list.c @@ -47,6 +47,7 @@ #include "telepathy-glib/room-list.h" #include <telepathy-glib/room-info-internal.h> +#include <telepathy-glib/asv.h> #include <telepathy-glib/cli-channel.h> #include <telepathy-glib/interfaces.h> #include <telepathy-glib/telepathy-glib.h> diff --git a/telepathy-glib/stream-tube-channel.c b/telepathy-glib/stream-tube-channel.c index a785c75bf..597c7f995 100644 --- a/telepathy-glib/stream-tube-channel.c +++ b/telepathy-glib/stream-tube-channel.c @@ -51,6 +51,7 @@ #include <dbus/dbus-glib.h> +#include <telepathy-glib/asv.h> #include <telepathy-glib/cli-channel.h> #include <telepathy-glib/contact.h> #include <telepathy-glib/dbus.h> diff --git a/telepathy-glib/telepathy-glib-dbus.h b/telepathy-glib/telepathy-glib-dbus.h index 618c1cc9d..e67df277a 100644 --- a/telepathy-glib/telepathy-glib-dbus.h +++ b/telepathy-glib/telepathy-glib-dbus.h @@ -26,6 +26,7 @@ #define _TP_GLIB_DBUS_H_INSIDE /* utilities for the dbus-glib type system */ +#include <telepathy-glib/asv.h> #include <telepathy-glib/sliced-gvalue.h> #include <telepathy-glib/value-array.h> diff --git a/telepathy-glib/text-channel.c b/telepathy-glib/text-channel.c index b07a3e1ed..daf9ac4a7 100644 --- a/telepathy-glib/text-channel.c +++ b/telepathy-glib/text-channel.c @@ -49,6 +49,7 @@ #include <dbus/dbus-glib.h> +#include <telepathy-glib/asv.h> #include <telepathy-glib/cli-channel.h> #include <telepathy-glib/cli-misc.h> #include <telepathy-glib/contact.h> diff --git a/telepathy-glib/tls-certificate.c b/telepathy-glib/tls-certificate.c index ed766f251..4adc5a45b 100644 --- a/telepathy-glib/tls-certificate.c +++ b/telepathy-glib/tls-certificate.c @@ -27,6 +27,7 @@ #include <dbus/dbus-glib.h> +#include <telepathy-glib/asv.h> #include <telepathy-glib/client-factory-internal.h> #include <telepathy-glib/cli-misc.h> #include <telepathy-glib/dbus.h> diff --git a/telepathy-glib/versions/dbus-1.0.abi b/telepathy-glib/versions/dbus-1.0.abi index 3f392bbd7..8e57705f9 100644 --- a/telepathy-glib/versions/dbus-1.0.abi +++ b/telepathy-glib/versions/dbus-1.0.abi @@ -2,6 +2,38 @@ Version: TELEPATHY_GLIB_DBUS_1.0 Extends: - Release: 1.0 +tp_asv_dump +tp_asv_get_boolean +tp_asv_get_boxed +tp_asv_get_bytes +tp_asv_get_double +tp_asv_get_int32 +tp_asv_get_int64 +tp_asv_get_object_path +tp_asv_get_string +tp_asv_get_strv +tp_asv_get_uint32 +tp_asv_get_uint64 +tp_asv_lookup +tp_asv_new +tp_asv_set_boolean +tp_asv_set_boxed +tp_asv_set_bytes +tp_asv_set_double +tp_asv_set_int32 +tp_asv_set_int64 +tp_asv_set_object_path +tp_asv_set_static_boxed +tp_asv_set_static_object_path +tp_asv_set_static_string +tp_asv_set_string +tp_asv_set_strv +tp_asv_set_uint32 +tp_asv_set_uint64 +tp_asv_take_boxed +tp_asv_take_bytes +tp_asv_take_object_path +tp_asv_take_string tp_cli_account_call_reconnect tp_cli_account_call_remove tp_cli_account_call_update_parameters diff --git a/telepathy-glib/versions/main-1.0.abi b/telepathy-glib/versions/main-1.0.abi index 8a9c2055a..901b31860 100644 --- a/telepathy-glib/versions/main-1.0.abi +++ b/telepathy-glib/versions/main-1.0.abi @@ -134,39 +134,7 @@ tp_add_dispatch_operation_context_fail tp_add_dispatch_operation_context_get_type tp_address_g_variant_from_g_socket_address tp_address_variant_from_g_socket_address -tp_asv_dump tp_asv_from_vardict -tp_asv_get_boolean -tp_asv_get_boxed -tp_asv_get_bytes -tp_asv_get_double -tp_asv_get_int32 -tp_asv_get_int64 -tp_asv_get_object_path -tp_asv_get_string -tp_asv_get_strv -tp_asv_get_uint32 -tp_asv_get_uint64 -tp_asv_lookup -tp_asv_new -tp_asv_set_boolean -tp_asv_set_boxed -tp_asv_set_bytes -tp_asv_set_double -tp_asv_set_int32 -tp_asv_set_int64 -tp_asv_set_object_path -tp_asv_set_static_boxed -tp_asv_set_static_object_path -tp_asv_set_static_string -tp_asv_set_string -tp_asv_set_strv -tp_asv_set_uint32 -tp_asv_set_uint64 -tp_asv_take_boxed -tp_asv_take_bytes -tp_asv_take_object_path -tp_asv_take_string tp_asv_to_vardict tp_automatic_client_factory_get_type tp_automatic_client_factory_new diff --git a/tests/capabilities.c b/tests/capabilities.c index 4745609f6..399f66921 100644 --- a/tests/capabilities.c +++ b/tests/capabilities.c @@ -6,6 +6,7 @@ #include "telepathy-glib/capabilities-internal.h" +#include <telepathy-glib/asv.h> #include <telepathy-glib/dbus.h> #include <telepathy-glib/debug.h> #include <telepathy-glib/enums.h> diff --git a/tests/dbus/account-channel-request.c b/tests/dbus/account-channel-request.c index c04ef19ae..953500328 100644 --- a/tests/dbus/account-channel-request.c +++ b/tests/dbus/account-channel-request.c @@ -12,6 +12,7 @@ #include <telepathy-glib/telepathy-glib.h> #include <telepathy-glib/account-channel-request-internal.h> +#include <telepathy-glib/asv.h> #include <telepathy-glib/cli-channel.h> #include <telepathy-glib/cli-misc.h> #include <telepathy-glib/client.h> diff --git a/tests/dbus/account-request.c b/tests/dbus/account-request.c index c2ad76558..5a6ddce76 100644 --- a/tests/dbus/account-request.c +++ b/tests/dbus/account-request.c @@ -11,6 +11,7 @@ #include <string.h> +#include <telepathy-glib/asv.h> #include <telepathy-glib/account-request.h> #include <telepathy-glib/gtypes.h> #include <telepathy-glib/interfaces.h> diff --git a/tests/dbus/account.c b/tests/dbus/account.c index cb78a6d90..d4daf1f0e 100644 --- a/tests/dbus/account.c +++ b/tests/dbus/account.c @@ -11,6 +11,7 @@ #include "config.h" #include <telepathy-glib/account.h> +#include <telepathy-glib/asv.h> #include <telepathy-glib/debug.h> #include <telepathy-glib/defs.h> #include <telepathy-glib/enums.h> diff --git a/tests/dbus/base-client.c b/tests/dbus/base-client.c index b149644d0..baf16741d 100644 --- a/tests/dbus/base-client.c +++ b/tests/dbus/base-client.c @@ -14,6 +14,7 @@ /* We include -internal headers of context to be able to easily access to * their semi-private attributes (connection, account, channels, etc). */ #include <telepathy-glib/add-dispatch-operation-context-internal.h> +#include <telepathy-glib/asv.h> #include <telepathy-glib/base-client.h> #include <telepathy-glib/cli-channel.h> #include <telepathy-glib/cli-misc.h> diff --git a/tests/dbus/call-channel.c b/tests/dbus/call-channel.c index 2e2506728..31f3e8974 100644 --- a/tests/dbus/call-channel.c +++ b/tests/dbus/call-channel.c @@ -20,6 +20,7 @@ #include "config.h" +#include <telepathy-glib/asv.h> #include <telepathy-glib/cli-connection.h> #include <telepathy-glib/cli-call.h> #include <telepathy-glib/cli-misc.h> diff --git a/tests/dbus/channel-introspect.c b/tests/dbus/channel-introspect.c index 0dc5457ed..1c8fc882e 100644 --- a/tests/dbus/channel-introspect.c +++ b/tests/dbus/channel-introspect.c @@ -10,6 +10,7 @@ #include "config.h" +#include <telepathy-glib/asv.h> #include <telepathy-glib/channel.h> #include <telepathy-glib/connection.h> #include <telepathy-glib/dbus.h> diff --git a/tests/dbus/channel-manager-request-properties.c b/tests/dbus/channel-manager-request-properties.c index 1daa2b4e0..65a6b4932 100644 --- a/tests/dbus/channel-manager-request-properties.c +++ b/tests/dbus/channel-manager-request-properties.c @@ -9,6 +9,7 @@ #include "config.h" +#include <telepathy-glib/asv.h> #include <telepathy-glib/channel.h> #include <telepathy-glib/cli-connection.h> #include <telepathy-glib/connection.h> diff --git a/tests/dbus/channel-request.c b/tests/dbus/channel-request.c index 5ed39d59d..988e0a677 100644 --- a/tests/dbus/channel-request.c +++ b/tests/dbus/channel-request.c @@ -10,6 +10,7 @@ #include "config.h" +#include <telepathy-glib/asv.h> #include <telepathy-glib/channel-request.h> #include <telepathy-glib/client-factory-internal.h> #include <telepathy-glib/defs.h> diff --git a/tests/dbus/cli-group.c b/tests/dbus/cli-group.c index e21913884..d3e5b7ce7 100644 --- a/tests/dbus/cli-group.c +++ b/tests/dbus/cli-group.c @@ -12,6 +12,7 @@ #include <string.h> +#include <telepathy-glib/asv.h> #include <telepathy-glib/channel.h> #include <telepathy-glib/cli-channel.h> #include <telepathy-glib/cli-connection.h> diff --git a/tests/dbus/contact-lists.c b/tests/dbus/contact-lists.c index 645c96b00..63b3c6fce 100644 --- a/tests/dbus/contact-lists.c +++ b/tests/dbus/contact-lists.c @@ -10,6 +10,7 @@ #include "config.h" +#include <telepathy-glib/asv.h> #include <telepathy-glib/cli-connection.h> #include <telepathy-glib/connection.h> #include <telepathy-glib/gtypes.h> diff --git a/tests/dbus/contacts-mixin.c b/tests/dbus/contacts-mixin.c index 57d9a1efd..fd5dc7676 100644 --- a/tests/dbus/contacts-mixin.c +++ b/tests/dbus/contacts-mixin.c @@ -10,6 +10,7 @@ #include "config.h" +#include <telepathy-glib/asv.h> #include <telepathy-glib/cli-connection.h> #include <telepathy-glib/connection.h> #include <telepathy-glib/dbus.h> diff --git a/tests/dbus/contacts.c b/tests/dbus/contacts.c index 9b196c1b1..2de2f737c 100644 --- a/tests/dbus/contacts.c +++ b/tests/dbus/contacts.c @@ -25,6 +25,7 @@ #include <dbus/dbus-glib.h> #include <dbus/dbus-glib-lowlevel.h> +#include <telepathy-glib/asv.h> #include <telepathy-glib/cli-connection.h> #include <telepathy-glib/connection.h> #include <telepathy-glib/contact.h> diff --git a/tests/dbus/disconnection.c b/tests/dbus/disconnection.c index 8cabfbb83..508b7a08c 100644 --- a/tests/dbus/disconnection.c +++ b/tests/dbus/disconnection.c @@ -1,5 +1,6 @@ #include "config.h" +#include <telepathy-glib/asv.h> #include <telepathy-glib/cli-misc.h> #include <telepathy-glib/dbus.h> #include <telepathy-glib/debug.h> diff --git a/tests/dbus/group-mixin.c b/tests/dbus/group-mixin.c index e6bad03d0..df94f039e 100644 --- a/tests/dbus/group-mixin.c +++ b/tests/dbus/group-mixin.c @@ -12,6 +12,7 @@ #include <dbus/dbus-glib.h> +#include <telepathy-glib/asv.h> #include <telepathy-glib/channel.h> #include <telepathy-glib/cli-channel.h> #include <telepathy-glib/cli-connection.h> diff --git a/tests/dbus/message-mixin.c b/tests/dbus/message-mixin.c index e09e5d76f..f830ba1de 100644 --- a/tests/dbus/message-mixin.c +++ b/tests/dbus/message-mixin.c @@ -12,6 +12,7 @@ #include <dbus/dbus-glib.h> +#include <telepathy-glib/asv.h> #include <telepathy-glib/channel.h> #include <telepathy-glib/cli-channel.h> #include <telepathy-glib/cli-connection.h> diff --git a/tests/dbus/properties.c b/tests/dbus/properties.c index 6f3bbfd67..9558caac6 100644 --- a/tests/dbus/properties.c +++ b/tests/dbus/properties.c @@ -5,6 +5,7 @@ #include <dbus/dbus-glib.h> #include <dbus/dbus-glib-lowlevel.h> +#include <telepathy-glib/asv.h> #include <telepathy-glib/cli-misc.h> #include <telepathy-glib/dbus.h> #include <telepathy-glib/dbus-properties-mixin.h> diff --git a/tests/dbus/simple-approver.c b/tests/dbus/simple-approver.c index 07db16719..70a787bc9 100644 --- a/tests/dbus/simple-approver.c +++ b/tests/dbus/simple-approver.c @@ -11,6 +11,7 @@ #include <dbus/dbus-glib.h> +#include <telepathy-glib/asv.h> #include <telepathy-glib/simple-approver.h> #include <telepathy-glib/cli-misc.h> #include <telepathy-glib/client.h> diff --git a/tests/dbus/simple-handler.c b/tests/dbus/simple-handler.c index c65d47ee2..3ab58ba0f 100644 --- a/tests/dbus/simple-handler.c +++ b/tests/dbus/simple-handler.c @@ -9,6 +9,7 @@ #include "config.h" +#include <telepathy-glib/asv.h> #include <telepathy-glib/simple-handler.h> #include <telepathy-glib/cli-channel.h> #include <telepathy-glib/cli-misc.h> diff --git a/tests/dbus/simple-observer.c b/tests/dbus/simple-observer.c index 60bb5282b..4259a342f 100644 --- a/tests/dbus/simple-observer.c +++ b/tests/dbus/simple-observer.c @@ -9,6 +9,7 @@ #include "config.h" +#include <telepathy-glib/asv.h> #include <telepathy-glib/simple-observer.h> #include <telepathy-glib/cli-misc.h> #include <telepathy-glib/client.h> diff --git a/tests/dbus/text-channel.c b/tests/dbus/text-channel.c index a8df1d94f..7d2cc7307 100644 --- a/tests/dbus/text-channel.c +++ b/tests/dbus/text-channel.c @@ -11,6 +11,7 @@ #include <string.h> +#include <telepathy-glib/asv.h> #include <telepathy-glib/cli-channel.h> #include <telepathy-glib/telepathy-glib.h> #include <telepathy-glib/message-mixin.h> diff --git a/tests/dbus/text-respawn.c b/tests/dbus/text-respawn.c index 8b4cc1e51..8cc09d729 100644 --- a/tests/dbus/text-respawn.c +++ b/tests/dbus/text-respawn.c @@ -10,6 +10,7 @@ #include "config.h" +#include <telepathy-glib/asv.h> #include <telepathy-glib/channel.h> #include <telepathy-glib/cli-channel.h> #include <telepathy-glib/connection.h> |