From 5ec181c20e35c46edd72fca026f4160736e95362 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Wed, 5 Dec 2007 16:41:09 +0000 Subject: [PATCH] 2007-12-05 Dan Williams * libnm-util/nm-utils.c - (nm_utils_register_value_transformations, nm_utils_convert_gvalue_hash_to_string): better debug output of GHashTables of GValues too git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3136 4912f4e0-d625-0410-9fb7-b9a5a253dbdc --- ChangeLog | 7 +++++++ libnm-util/nm-utils.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/ChangeLog b/ChangeLog index f151d8f89..95f72a138 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2007-12-05 Dan Williams + + * libnm-util/nm-utils.c + - (nm_utils_register_value_transformations, + nm_utils_convert_gvalue_hash_to_string): better debug output of + GHashTables of GValues too + 2007-12-04 Dan Williams * initscript/RedHat/NetworkManager.in diff --git a/libnm-util/nm-utils.c b/libnm-util/nm-utils.c index 695adecf0..4eb3cf399 100644 --- a/libnm-util/nm-utils.c +++ b/libnm-util/nm-utils.c @@ -432,6 +432,7 @@ nm_utils_string_slist_validate (GSList *list, const char **valid_values) #define TYPE_GSLIST_OF_STRINGS dbus_g_type_get_collection ("GSList", G_TYPE_STRING) #define TYPE_ARRAY_OF_IP4ADDR_STRUCTS dbus_g_type_get_collection ("GPtrArray", dbus_g_type_get_collection ("GArray", G_TYPE_UINT)) +#define TYPE_HASH_OF_GVALUES dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE) static void nm_utils_convert_strv_to_slist (const GValue *src_value, GValue *dest_value) @@ -561,6 +562,35 @@ nm_utils_convert_ip4_addr_struct_array_to_string (const GValue *src_value, GValu g_string_free (printable, FALSE); } +static void +convert_one_hash_entry (gpointer key, gpointer value, gpointer user_data) +{ + GString *printable = (GString *) user_data; + char *value_as_string; + + value_as_string = g_strdup_value_contents ((GValue *) value); + g_string_append_printf (printable, " { '%s': %s },", (const char *) key, value_as_string); + g_free (value_as_string); +} + +static void +nm_utils_convert_gvalue_hash_to_string (const GValue *src_value, GValue *dest_value) +{ + GHashTable *hash; + GString *printable; + + g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), TYPE_HASH_OF_GVALUES)); + + hash = (GHashTable *) g_value_get_boxed (src_value); + + printable = g_string_new ("["); + g_hash_table_foreach (hash, convert_one_hash_entry, printable); + g_string_append (printable, " ]"); + + g_value_take_string (dest_value, printable->str); + g_string_free (printable, FALSE); +} + void nm_utils_register_value_transformations (void) { @@ -579,6 +609,9 @@ nm_utils_register_value_transformations (void) g_value_register_transform_func (TYPE_ARRAY_OF_IP4ADDR_STRUCTS, G_TYPE_STRING, nm_utils_convert_ip4_addr_struct_array_to_string); + g_value_register_transform_func (TYPE_HASH_OF_GVALUES, + G_TYPE_STRING, + nm_utils_convert_gvalue_hash_to_string); registered = TRUE; } }