From 52368678d67d7d11ef2c552b6ef1865ba012c0e7 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 21 Jan 2019 08:10:14 +0100 Subject: [PATCH] libnm: extend nm_setting_enumerate_values() to support non-GObject base properties While nm_setting_enumerate_values() should not be used anymore, still extend it to make it workable also for properties that are not based on GObject properties. --- libnm-core/nm-core-internal.h | 7 ++++--- libnm-core/nm-setting.c | 36 +++++++++++++++++++++++--------- libnm-core/nm-setting.h | 39 +++++++++++++++++++++-------------- 3 files changed, 53 insertions(+), 29 deletions(-) diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h index b3d664dcea..9385d505e7 100644 --- a/libnm-core/nm-core-internal.h +++ b/libnm-core/nm-core-internal.h @@ -614,7 +614,8 @@ gboolean _nm_setting_sriov_sort_vfs (NMSettingSriov *setting); /*****************************************************************************/ -typedef struct _NMSettInfoSetting NMSettInfoSetting; +typedef struct _NMSettInfoSetting NMSettInfoSetting; +typedef struct _NMSettInfoProperty NMSettInfoProperty; typedef GVariant *(*NMSettingPropertyGetFunc) (NMSetting *setting, const char *property); @@ -638,7 +639,7 @@ typedef GVariant *(*NMSettingPropertyTransformToFunc) (const GValue *from); typedef void (*NMSettingPropertyTransformFromFunc) (GVariant *from, GValue *to); -typedef struct { +struct _NMSettInfoProperty { const char *name; GParamSpec *param_spec; const GVariantType *dbus_type; @@ -650,7 +651,7 @@ typedef struct { NMSettingPropertyTransformToFunc to_dbus; NMSettingPropertyTransformFromFunc from_dbus; -} NMSettInfoProperty; +}; typedef struct { const GVariantType *(*get_variant_type) (const struct _NMSettInfoSetting *sett_info, diff --git a/libnm-core/nm-setting.c b/libnm-core/nm-setting.c index b26ab6b3d2..bed3a3cf16 100644 --- a/libnm-core/nm-setting.c +++ b/libnm-core/nm-setting.c @@ -1729,6 +1729,27 @@ nm_setting_diff (NMSetting *a, } } +static void +enumerate_values (const NMSettInfoProperty *property_info, + NMSetting *setting, + NMSettingValueIterFn func, + gpointer user_data) +{ + GValue value = G_VALUE_INIT; + + if (!property_info->param_spec) + return; + + g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (property_info->param_spec)); + g_object_get_property (G_OBJECT (setting), property_info->param_spec->name, &value); + func (setting, + property_info->param_spec->name, + &value, + property_info->param_spec->flags, + user_data); + g_value_unset (&value); +} + /** * nm_setting_enumerate_values: * @setting: the #NMSetting @@ -1784,16 +1805,10 @@ nm_setting_enumerate_values (NMSetting *setting, } for (i = 0; i < sett_info->property_infos_len; i++) { - GParamSpec *prop_spec = _nm_sett_info_property_info_get_sorted (sett_info, i)->param_spec; - GValue value = G_VALUE_INIT; - - if (!prop_spec) - continue; - - g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (prop_spec)); - g_object_get_property (G_OBJECT (setting), prop_spec->name, &value); - func (setting, prop_spec->name, &value, prop_spec->flags, user_data); - g_value_unset (&value); + NM_SETTING_GET_CLASS (setting)->enumerate_values (_nm_sett_info_property_info_get_sorted (sett_info, i), + setting, + func, + user_data); } } @@ -2606,6 +2621,7 @@ nm_setting_class_init (NMSettingClass *setting_class) setting_class->compare_property = compare_property; setting_class->clear_secrets = clear_secrets; setting_class->duplicate_copy_properties = duplicate_copy_properties; + setting_class->enumerate_values = enumerate_values; /** * NMSetting:name: diff --git a/libnm-core/nm-setting.h b/libnm-core/nm-setting.h index 0f0ac8f382..0002b80ae6 100644 --- a/libnm-core/nm-setting.h +++ b/libnm-core/nm-setting.h @@ -170,6 +170,22 @@ typedef gboolean (*NMSettingClearSecretsWithFlagsFn) (NMSetting *setting, struct _NMMetaSettingInfo; struct _NMSettInfoSetting; +struct _NMSettInfoProperty; + +/** + * NMSettingValueIterFn: + * @setting: The setting for which properties are being iterated, given to + * nm_setting_enumerate_values() + * @key: The value/property name + * @value: The property's value + * @flags: The property's flags, like %NM_SETTING_PARAM_SECRET + * @user_data: User data passed to nm_setting_enumerate_values() + */ +typedef void (*NMSettingValueIterFn) (NMSetting *setting, + const char *key, + const GValue *value, + GParamFlags flags, + gpointer user_data); typedef struct { GObjectClass parent; @@ -225,28 +241,19 @@ typedef struct { NMSetting *src, NMSetting *dst); + /*< private >*/ + void (*enumerate_values) (const struct _NMSettInfoProperty *property_info, + NMSetting *setting, + NMSettingValueIterFn func, + gpointer user_data); + /*< private >*/ const struct _NMMetaSettingInfo *setting_info; /*< private >*/ - gpointer padding[5]; + gpointer padding[4]; } NMSettingClass; -/** - * NMSettingValueIterFn: - * @setting: The setting for which properties are being iterated, given to - * nm_setting_enumerate_values() - * @key: The value/property name - * @value: The property's value - * @flags: The property's flags, like %NM_SETTING_PARAM_SECRET - * @user_data: User data passed to nm_setting_enumerate_values() - */ -typedef void (*NMSettingValueIterFn) (NMSetting *setting, - const char *key, - const GValue *value, - GParamFlags flags, - gpointer user_data); - GType nm_setting_get_type (void); GType nm_setting_lookup_type (const char *name);