diff options
author | Dan Winship <danw@gnome.org> | 2014-08-04 11:39:33 -0400 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2014-09-03 11:08:14 -0400 |
commit | 2b6d39e589c17afd809c3fe2ffc46e78dee02f58 (patch) | |
tree | 6e84637983b7e483c54fa3d5771e4be913806a85 | |
parent | 5f6313e1d10ee3f97c402d1824ca3dfffa8f311c (diff) | |
download | NetworkManager-2b6d39e589c17afd809c3fe2ffc46e78dee02f58.tar.gz |
libnm-core: reorganize _nm_setting_new_from_dbus()
Reorganize _nm_setting_new_from_dbus() to create an empty NMSetting
first and then set each of its properties, rather than passing all of
the properties to g_object_newv(). We don't need to pass them at
construct time since no NMSetting properties are CONSTRUCT_ONLY, and
organizing the function this way will let us include non-GObject
properties in the hash as well.
-rw-r--r-- | libnm-core/nm-setting.c | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/libnm-core/nm-setting.c b/libnm-core/nm-setting.c index 9e268977e4..e8c8a1224e 100644 --- a/libnm-core/nm-setting.c +++ b/libnm-core/nm-setting.c @@ -462,14 +462,13 @@ _nm_setting_to_dbus (NMSetting *setting, NMConnectionSerializationFlags flags) NMSetting * _nm_setting_new_from_dbus (GType setting_type, GHashTable *hash) { - GHashTableIter iter; NMSetting *setting; - const char *prop_name; - GValue *src_value; GObjectClass *class; - guint n_params = 0; - GParameter *params; - int i; + GHashTableIter iter; + const char *prop_name; + GParamSpec **property_specs; + guint n_property_specs; + guint i; g_return_val_if_fail (G_TYPE_IS_INSTANTIATABLE (setting_type), NULL); g_return_val_if_fail (hash != NULL, NULL); @@ -478,35 +477,36 @@ _nm_setting_new_from_dbus (GType setting_type, GHashTable *hash) * already been used. */ class = g_type_class_ref (setting_type); - params = g_new0 (GParameter, g_hash_table_size (hash)); + /* Check for invalid properties first. */ g_hash_table_iter_init (&iter, hash); - while (g_hash_table_iter_next (&iter, (gpointer) &prop_name, (gpointer) &src_value)) { - GValue *dst_value = ¶ms[n_params].value; - GParamSpec *param_spec; - - param_spec = g_object_class_find_property (class, prop_name); - if (!param_spec) { + while (g_hash_table_iter_next (&iter, (gpointer) &prop_name, NULL)) { + if (!g_object_class_find_property (class, prop_name)) { /* Oh, we're so nice and only warn, maybe it should be a fatal error? */ g_warning ("Ignoring invalid property '%s'", prop_name); continue; } + } - /* 'name' doesn't get deserialized */ - if (strcmp (g_param_spec_get_name (param_spec), NM_SETTING_NAME) == 0) - continue; + /* Now build the setting object from the legitimate properties */ + setting = (NMSetting *) g_object_new (setting_type, NULL); - g_value_init (dst_value, G_VALUE_TYPE (src_value)); - g_value_copy (src_value, dst_value); - params[n_params++].name = prop_name; - } + property_specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (setting), &n_property_specs); + for (i = 0; i < n_property_specs; i++) { + GParamSpec *prop_spec = property_specs[i]; + GValue *value; - setting = (NMSetting *) g_object_newv (setting_type, n_params, params); + /* 'name' doesn't get deserialized */ + if (strcmp (prop_spec->name, NM_SETTING_NAME) == 0) + continue; - for (i = 0; i < n_params; i++) - g_value_unset (¶ms[i].value); + value = g_hash_table_lookup (hash, prop_spec->name); + if (!value) + continue; - g_free (params); + g_object_set_property (G_OBJECT (setting), prop_spec->name, value); + } + g_free (property_specs); g_type_class_unref (class); return setting; |