diff options
author | Dan Winship <danw@gnome.org> | 2014-08-16 10:09:48 -0400 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2014-09-18 11:51:09 -0400 |
commit | acf86f68b33b14070d9b03a681fe94ffeead66ef (patch) | |
tree | 28069ac74e5bc7ecfc185495969cdeab7ca203a8 /libnm-core/nm-value-transforms.c | |
parent | 4750559548fd1a0fb73cb826fa818dfe1e4f6940 (diff) | |
download | NetworkManager-acf86f68b33b14070d9b03a681fe94ffeead66ef.tar.gz |
libnm-core: change connection hash tables to variants in API
In preparation for porting to GDBus, make nm_connection_to_dbus(),
etc, represent connections as GVariants of type 'a{sa{sv}}' rather
than as GHashTables-of-GHashTables-of-GValues.
This means we're constantly converting back and forth internally, but
this is just a stepping stone on the way to the full GDBus port, and
all of that code will go away again later.
Diffstat (limited to 'libnm-core/nm-value-transforms.c')
-rw-r--r-- | libnm-core/nm-value-transforms.c | 112 |
1 files changed, 0 insertions, 112 deletions
diff --git a/libnm-core/nm-value-transforms.c b/libnm-core/nm-value-transforms.c deleted file mode 100644 index 77d2609741..0000000000 --- a/libnm-core/nm-value-transforms.c +++ /dev/null @@ -1,112 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ - -/* - * 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 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 Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2005 - 2014 Red Hat, Inc. - */ - -#include "config.h" - -#include <string.h> - -#include "nm-utils.h" -#include "nm-utils-private.h" -#include "nm-dbus-glib-types.h" -#include "nm-glib-compat.h" - -static void -_nm_utils_convert_op_to_string (const GValue *src_value, GValue *dest_value) -{ - g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), DBUS_TYPE_G_OBJECT_PATH)); - - g_value_set_string (dest_value, (const char *) g_value_get_boxed (src_value)); -} - -static void -_string_array_to_string (const GPtrArray *strings, GValue *dest_value) -{ - GString *printable; - guint i; - - printable = g_string_new (NULL); - for (i = 0; strings && i < strings->len; i++) { - if (i > 0) - g_string_append_c (printable, ','); - g_string_append (printable, strings->pdata[i]); - } - - g_value_take_string (dest_value, g_string_free (printable, FALSE)); -} - -static void -_nm_utils_convert_op_array_to_string (const GValue *src_value, GValue *dest_value) -{ - const GPtrArray *strings; - - g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH)); - - strings = (const GPtrArray *) g_value_get_boxed (src_value); - _string_array_to_string (strings, dest_value); -} - -static void -convert_one_gvalue_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), DBUS_TYPE_G_MAP_OF_VARIANT)); - - hash = (GHashTable *) g_value_get_boxed (src_value); - - printable = g_string_new ("["); - g_hash_table_foreach (hash, convert_one_gvalue_hash_entry, printable); - g_string_append (printable, " ]"); - - g_value_take_string (dest_value, printable->str); - g_string_free (printable, FALSE); -} - -void -_nm_value_transforms_register (void) -{ - static gboolean registered = FALSE; - - if (G_UNLIKELY (!registered)) { - g_value_register_transform_func (DBUS_TYPE_G_OBJECT_PATH, - G_TYPE_STRING, - _nm_utils_convert_op_to_string); - g_value_register_transform_func (DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH, - G_TYPE_STRING, - _nm_utils_convert_op_array_to_string); - g_value_register_transform_func (DBUS_TYPE_G_MAP_OF_VARIANT, - G_TYPE_STRING, - _nm_utils_convert_gvalue_hash_to_string); - registered = TRUE; - } -} |