diff options
author | Thomas Haller <thaller@redhat.com> | 2019-04-23 16:34:59 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-04-25 08:20:03 +0200 |
commit | 020c4c81d82ad314f1998b271a4fdfbf96e1b7c3 (patch) | |
tree | e318f653736e07582a4bd9cda4e0067ac4e10f61 /clients/common | |
parent | e55a45faa25eaa282d8dc96e9d1ffa5d049977d3 (diff) | |
download | NetworkManager-020c4c81d82ad314f1998b271a4fdfbf96e1b7c3.tar.gz |
cli: drop GValue transform functions for strdict and implement it in _get_fcn_gobject_impl()
The only remaining GValue transform function was from GHashTable (of (str,str) type)
to string. Drop that too, and implement the conversion in _get_fcn_gobject_impl().
Note that there are few GObject properties of type GHashTable and most
of them implement their own logic. This only applies to
"802-3-ethernet.s390-options".
Also, always sort the keys. Otherwise, the output is not stable.
Diffstat (limited to 'clients/common')
-rw-r--r-- | clients/common/nm-meta-setting-desc.c | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/clients/common/nm-meta-setting-desc.c b/clients/common/nm-meta-setting-desc.c index 5136d98a2b..98cb50405c 100644 --- a/clients/common/nm-meta-setting-desc.c +++ b/clients/common/nm-meta-setting-desc.c @@ -856,17 +856,11 @@ _get_fcn_gobject_impl (const NMMetaPropertyInfo *property_info, glib_handles_str_transform = !NM_IN_SET (gtype_prop, G_TYPE_BOOLEAN, G_TYPE_STRV, - G_TYPE_BYTES); + G_TYPE_BYTES, + G_TYPE_HASH_TABLE); if (glib_handles_str_transform) { - /* We rely on the type convertion of the gobject property to string. - * - * Note that we register some transformations via nmc_value_transforms_register() - * to make that working for G_TYPE_HASH_TABLE. - * - * FIXME: that is particularly ugly because it's non-obvious which code relies - * on nmc_value_transforms_register(). Also, nmc_value_transforms_register() is - * in clients/cli, while we are here in clients/common. */ + /* We rely on the type convertion of the gobject property to string. */ g_value_init (&val, G_TYPE_STRING); } else g_value_init (&val, gtype_prop); @@ -922,6 +916,29 @@ _get_fcn_gobject_impl (const NMMetaPropertyInfo *property_info, RETURN_STR_TO_FREE (str); } + if (gtype_prop == G_TYPE_HASH_TABLE) { + GHashTable *strdict; + gs_free const char **keys = NULL; + GString *str; + gsize i; + + strdict = g_value_get_boxed (&val); + keys = nm_utils_strdict_get_keys (strdict, TRUE, NULL); + if (!keys) + return NULL; + + str = g_string_new (NULL); + for (i = 0; keys[i]; i++) { + if (str->len > 0) + g_string_append_c (str, ','); + g_string_append_printf (str, + "%s=%s", + keys[i], + (const char *) g_hash_table_lookup (strdict, keys[i])); + } + RETURN_STR_TO_FREE (g_string_free (str, FALSE)); + } + nm_assert_not_reached (); return NULL; } |