From df6714102c3968bd2d5516bd8441435cee2fc689 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 22 Sep 2019 15:33:42 +0200 Subject: [PATCH 01/12] shared: add NM_G_VARIANT_TYPE() macro Like G_VARIANT_TYPE(), but this one can be used to initialize a static variable. --- shared/nm-glib-aux/nm-macros-internal.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/shared/nm-glib-aux/nm-macros-internal.h b/shared/nm-glib-aux/nm-macros-internal.h index 9292f3699d..09f96ef6ba 100644 --- a/shared/nm-glib-aux/nm-macros-internal.h +++ b/shared/nm-glib-aux/nm-macros-internal.h @@ -1262,6 +1262,14 @@ nm_clear_g_cancellable_disconnect (GCancellable *cancellable, gulong *cancellabl /*****************************************************************************/ +/* GVariantType is basically a C string. But G_VARIANT_TYPE() is not suitable + * to initialize a static variable (because it evaluates a function check that + * the string is valid). Add an alternative macro that does the plain cast. + * + * Here you loose the assertion check that G_VARIANT_TYPE() to ensure the + * string is valid. */ +#define NM_G_VARIANT_TYPE(fmt) ((const GVariantType *) (""fmt"")) + static inline GVariant * nm_g_variant_ref (GVariant *v) { From f36a0d408b1ffa7609fb53de8680cdf26153ba12 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 22 Sep 2019 13:33:23 +0200 Subject: [PATCH 02/12] libnm: avoid heap allocation in _nm_utils_strdict_to_dbus() --- libnm-core/nm-utils.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index ae48b16af4..e62bd8d097 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -825,9 +825,15 @@ _nm_utils_strdict_to_dbus (const GValue *prop_value) if (len == 1) g_variant_builder_add (&builder, "{ss}", key, value); else { - gs_free NMUtilsNamedValue *idx = NULL; + gs_free NMUtilsNamedValue *idx_free = NULL; + NMUtilsNamedValue *idx; + + if (len > 300 / sizeof (NMUtilsNamedValue)) { + idx_free = g_new (NMUtilsNamedValue, len); + idx = idx_free; + } else + idx = g_alloca (sizeof (NMUtilsNamedValue) * len); - idx = g_new (NMUtilsNamedValue, len); i = 0; do { idx[i].name = key; From 3f36f6915629d9a98f52fb266f82274785bb49c6 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 22 Sep 2019 08:53:06 +0200 Subject: [PATCH 03/12] libnm: refactor NMSettInfoProperty to save memory for simple properties In total, we register 447 property informations. Out of these, 326 are plain, GObject property based without special implementations. The NMSettInfoProperty had all function pointers directly embedded, currently this amounts to 5 function pointers and the "dbus_type" field. That means, at runtime we have 326 times trivial implementations with waste 326*6*8 bytes of NULL pointers. We can compact these by moving them to a separate structure. Before: 447 * 5 function pointers 447 * "dbus_type" pointer = 2682 pointers After: 447 * 1 pointers (for NMSettInfoProperty.property_type) 89 * 6 pointers (for the distinct NMSettInfoPropertType data) = 981 pointers So, in total this saves 13608 byes of runtime memory (on 64 bit arch). The 89 NMSettInfoPropertType instances are the remaining distinct instances. Note that every NMSettInfoProperty has a "property_type" pointer, but most of them are shared. That is because the underlying type and the operations are the same. Also nice is that the NMSettInfoPropertType are actually constant, static fields and initialized very early. This change also makes sense form a design point of view. Previously, NMSettInfoProperty contained both per-property data (the "name") but also the behavior. Now, the "behavioral" part is moved to a separate structure (where it is also shared). That means, the parts that are concerned with the type of the property (the behavior) are separate from the actual data of the property. --- libnm-core/nm-core-internal.h | 13 +- libnm-core/nm-setting-bond.c | 2 +- libnm-core/nm-setting-bridge-port.c | 2 +- libnm-core/nm-setting-bridge.c | 2 +- libnm-core/nm-setting-dcb.c | 12 +- libnm-core/nm-setting-ip-config.c | 2 +- libnm-core/nm-setting-ip4-config.c | 10 +- libnm-core/nm-setting-ip6-config.c | 10 +- libnm-core/nm-setting-private.h | 144 +++++++++++++-- libnm-core/nm-setting-sriov.c | 2 +- libnm-core/nm-setting-tc-config.c | 4 +- libnm-core/nm-setting-team-port.c | 10 +- libnm-core/nm-setting-team.c | 10 +- libnm-core/nm-setting-user.c | 2 +- libnm-core/nm-setting-vpn.c | 4 +- libnm-core/nm-setting-wired.c | 2 +- libnm-core/nm-setting-wireguard.c | 2 +- libnm-core/nm-setting.c | 273 +++++++++------------------- libnm-core/tests/test-setting.c | 8 +- 19 files changed, 265 insertions(+), 249 deletions(-) diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h index 9f4f19839f..97c7f94546 100644 --- a/libnm-core/nm-core-internal.h +++ b/libnm-core/nm-core-internal.h @@ -712,10 +712,7 @@ typedef void (*NMSettInfoPropGPropFromDBusFcn) (GVariant *from, const NMSettInfoSetting *nmtst_sett_info_settings (void); -struct _NMSettInfoProperty { - const char *name; - GParamSpec *param_spec; - +typedef struct { const GVariantType *dbus_type; NMSettInfoPropToDBusFcn to_dbus_fcn; @@ -726,6 +723,14 @@ struct _NMSettInfoProperty { * on the GValue value of the GObject property. */ NMSettInfoPropGPropToDBusFcn gprop_to_dbus_fcn; NMSettInfoPropGPropFromDBusFcn gprop_from_dbus_fcn; +} NMSettInfoPropertType; + +struct _NMSettInfoProperty { + const char *name; + + GParamSpec *param_spec; + + const NMSettInfoPropertType *property_type; }; typedef struct { diff --git a/libnm-core/nm-setting-bond.c b/libnm-core/nm-setting-bond.c index 100951d86a..672acd4e31 100644 --- a/libnm-core/nm-setting-bond.c +++ b/libnm-core/nm-setting-bond.c @@ -973,7 +973,7 @@ nm_setting_bond_class_init (NMSettingBondClass *klass) _properties_override_add_transform (properties_override, obj_properties[PROP_OPTIONS], - G_VARIANT_TYPE ("a{ss}"), + NM_G_VARIANT_TYPE ("a{ss}"), _nm_utils_strdict_to_dbus, _nm_utils_strdict_from_dbus); diff --git a/libnm-core/nm-setting-bridge-port.c b/libnm-core/nm-setting-bridge-port.c index 1e4112496d..aa2d9bf2a3 100644 --- a/libnm-core/nm-setting-bridge-port.c +++ b/libnm-core/nm-setting-bridge-port.c @@ -576,7 +576,7 @@ nm_setting_bridge_port_class_init (NMSettingBridgePortClass *klass) _properties_override_add_override (properties_override, obj_properties[PROP_VLANS], - G_VARIANT_TYPE ("aa{sv}"), + NM_G_VARIANT_TYPE ("aa{sv}"), _nm_utils_bridge_vlans_to_dbus, _nm_utils_bridge_vlans_from_dbus, NULL); diff --git a/libnm-core/nm-setting-bridge.c b/libnm-core/nm-setting-bridge.c index ab4d227888..d819e0a6f5 100644 --- a/libnm-core/nm-setting-bridge.c +++ b/libnm-core/nm-setting-bridge.c @@ -1469,7 +1469,7 @@ nm_setting_bridge_class_init (NMSettingBridgeClass *klass) _properties_override_add_override (properties_override, obj_properties[PROP_VLANS], - G_VARIANT_TYPE ("aa{sv}"), + NM_G_VARIANT_TYPE ("aa{sv}"), _nm_utils_bridge_vlans_to_dbus, _nm_utils_bridge_vlans_from_dbus, NULL); diff --git a/libnm-core/nm-setting-dcb.c b/libnm-core/nm-setting-dcb.c index aa45668ff5..e1eb748466 100644 --- a/libnm-core/nm-setting-dcb.c +++ b/libnm-core/nm-setting-dcb.c @@ -1100,7 +1100,7 @@ nm_setting_dcb_class_init (NMSettingDcbClass *klass) _properties_override_add_transform (properties_override, obj_properties[PROP_PRIORITY_FLOW_CONTROL], - G_VARIANT_TYPE ("au"), + NM_G_VARIANT_TYPE ("au"), _nm_setting_dcb_uint_array_to_dbus, _nm_setting_dcb_uint_array_from_dbus); @@ -1148,7 +1148,7 @@ nm_setting_dcb_class_init (NMSettingDcbClass *klass) _properties_override_add_transform (properties_override, obj_properties[PROP_PRIORITY_GROUP_ID], - G_VARIANT_TYPE ("au"), + NM_G_VARIANT_TYPE ("au"), _nm_setting_dcb_uint_array_to_dbus, _nm_setting_dcb_uint_array_from_dbus); @@ -1175,7 +1175,7 @@ nm_setting_dcb_class_init (NMSettingDcbClass *klass) _properties_override_add_transform (properties_override, obj_properties[PROP_PRIORITY_GROUP_BANDWIDTH], - G_VARIANT_TYPE ("au"), + NM_G_VARIANT_TYPE ("au"), _nm_setting_dcb_uint_array_to_dbus, _nm_setting_dcb_uint_array_from_dbus); @@ -1204,7 +1204,7 @@ nm_setting_dcb_class_init (NMSettingDcbClass *klass) _properties_override_add_transform (properties_override, obj_properties[PROP_PRIORITY_BANDWIDTH], - G_VARIANT_TYPE ("au"), + NM_G_VARIANT_TYPE ("au"), _nm_setting_dcb_uint_array_to_dbus, _nm_setting_dcb_uint_array_from_dbus); @@ -1231,7 +1231,7 @@ nm_setting_dcb_class_init (NMSettingDcbClass *klass) _properties_override_add_transform (properties_override, obj_properties[PROP_PRIORITY_STRICT_BANDWIDTH], - G_VARIANT_TYPE ("au"), + NM_G_VARIANT_TYPE ("au"), _nm_setting_dcb_uint_array_to_dbus, _nm_setting_dcb_uint_array_from_dbus); @@ -1257,7 +1257,7 @@ nm_setting_dcb_class_init (NMSettingDcbClass *klass) _properties_override_add_transform (properties_override, obj_properties[PROP_PRIORITY_TRAFFIC_CLASS], - G_VARIANT_TYPE ("au"), + NM_G_VARIANT_TYPE ("au"), _nm_setting_dcb_uint_array_to_dbus, _nm_setting_dcb_uint_array_from_dbus); diff --git a/libnm-core/nm-setting-ip-config.c b/libnm-core/nm-setting-ip-config.c index de367b2d31..8a3fb5cf9b 100644 --- a/libnm-core/nm-setting-ip-config.c +++ b/libnm-core/nm-setting-ip-config.c @@ -5209,7 +5209,7 @@ _nm_sett_info_property_override_create_array_ip_config (void) */ _properties_override_add_dbus_only (properties_override, NM_SETTING_IP_CONFIG_ROUTING_RULES, - G_VARIANT_TYPE ("aa{sv}"), + NM_G_VARIANT_TYPE ("aa{sv}"), _routing_rules_dbus_only_synth, _routing_rules_dbus_only_set); diff --git a/libnm-core/nm-setting-ip4-config.c b/libnm-core/nm-setting-ip4-config.c index 9df80d1f04..cbfe3c4600 100644 --- a/libnm-core/nm-setting-ip4-config.c +++ b/libnm-core/nm-setting-ip4-config.c @@ -799,7 +799,7 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *klass) _properties_override_add_transform (properties_override, g_object_class_find_property (G_OBJECT_CLASS (setting_class), NM_SETTING_IP_CONFIG_DNS), - G_VARIANT_TYPE ("au"), + NM_G_VARIANT_TYPE ("au"), ip4_dns_to_dbus, ip4_dns_from_dbus); @@ -821,7 +821,7 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *klass) _properties_override_add_override (properties_override, g_object_class_find_property (G_OBJECT_CLASS (setting_class), NM_SETTING_IP_CONFIG_ADDRESSES), - G_VARIANT_TYPE ("aau"), + NM_G_VARIANT_TYPE ("aau"), ip4_addresses_get, ip4_addresses_set, NULL); @@ -843,7 +843,7 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *klass) */ _properties_override_add_dbus_only (properties_override, "address-data", - G_VARIANT_TYPE ("aa{sv}"), + NM_G_VARIANT_TYPE ("aa{sv}"), ip4_address_data_get, ip4_address_data_set); @@ -867,7 +867,7 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *klass) _properties_override_add_override (properties_override, g_object_class_find_property (G_OBJECT_CLASS (setting_class), NM_SETTING_IP_CONFIG_ROUTES), - G_VARIANT_TYPE ("aau"), + NM_G_VARIANT_TYPE ("aau"), ip4_routes_get, ip4_routes_set, NULL); @@ -887,7 +887,7 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *klass) */ _properties_override_add_dbus_only (properties_override, "route-data", - G_VARIANT_TYPE ("aa{sv}"), + NM_G_VARIANT_TYPE ("aa{sv}"), ip4_route_data_get, ip4_route_data_set); diff --git a/libnm-core/nm-setting-ip6-config.c b/libnm-core/nm-setting-ip6-config.c index b19ec126ed..18b87081c6 100644 --- a/libnm-core/nm-setting-ip6-config.c +++ b/libnm-core/nm-setting-ip6-config.c @@ -883,7 +883,7 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *klass) _properties_override_add_transform (properties_override, g_object_class_find_property (G_OBJECT_CLASS (setting_class), NM_SETTING_IP_CONFIG_DNS), - G_VARIANT_TYPE ("aay"), + NM_G_VARIANT_TYPE ("aay"), ip6_dns_to_dbus, ip6_dns_from_dbus); @@ -904,7 +904,7 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *klass) _properties_override_add_override (properties_override, g_object_class_find_property (G_OBJECT_CLASS (setting_class), NM_SETTING_IP_CONFIG_ADDRESSES), - G_VARIANT_TYPE ("a(ayuay)"), + NM_G_VARIANT_TYPE ("a(ayuay)"), ip6_addresses_get, ip6_addresses_set, NULL); @@ -920,7 +920,7 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *klass) */ _properties_override_add_dbus_only (properties_override, "address-data", - G_VARIANT_TYPE ("aa{sv}"), + NM_G_VARIANT_TYPE ("aa{sv}"), ip6_address_data_get, ip6_address_data_set); @@ -941,7 +941,7 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *klass) _properties_override_add_override (properties_override, g_object_class_find_property (G_OBJECT_CLASS (setting_class), NM_SETTING_IP_CONFIG_ROUTES), - G_VARIANT_TYPE ("a(ayuayu)"), + NM_G_VARIANT_TYPE ("a(ayuayu)"), ip6_routes_get, ip6_routes_set, NULL); @@ -961,7 +961,7 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *klass) */ _properties_override_add_dbus_only (properties_override, "route-data", - G_VARIANT_TYPE ("aa{sv}"), + NM_G_VARIANT_TYPE ("aa{sv}"), ip6_route_data_get, ip6_route_data_set); diff --git a/libnm-core/nm-setting-private.h b/libnm-core/nm-setting-private.h index deb82c17d2..c9e9e02de6 100644 --- a/libnm-core/nm-setting-private.h +++ b/libnm-core/nm-setting-private.h @@ -143,6 +143,15 @@ _nm_setting_class_commit (NMSettingClass *setting_class, __VA_ARGS__ \ })) +#define NM_SETT_INFO_PROPERT_TYPE(...) \ + ({ \ + static const NMSettInfoPropertType _g = { \ + __VA_ARGS__ \ + }; \ + \ + &_g; \ + }) + #define NM_SETT_INFO_PROPERTY(...) \ (&((const NMSettInfoProperty) { \ __VA_ARGS__ \ @@ -151,32 +160,129 @@ _nm_setting_class_commit (NMSettingClass *setting_class, void _properties_override_add_struct (GArray *properties_override, const NMSettInfoProperty *prop_info); -void _properties_override_add__helper (GArray *properties_override, - NMSettInfoProperty *prop_info); - #define _properties_override_add(properties_override, \ ...) \ (_properties_override_add_struct (properties_override, \ NM_SETT_INFO_PROPERTY (__VA_ARGS__))) -void _properties_override_add_dbus_only (GArray *properties_override, - const char *property_name, - const GVariantType *dbus_type, - NMSettInfoPropToDBusFcn to_dbus_fcn, - NMSettInfoPropFromDBusFcn from_dbus_fcn); +/** + * _properties_override_add_dbus_only: + * @properties_override: an array collecting the overrides + * @p_property_name: the name of the property to override + * @p_dbus_type: the type of the property (in its D-Bus representation) + * @p_to_dbus_fcn: (allow-none): function to call to synthesize a value for the property + * @p_from_dbus_fcn: (allow-none): function to call to set the value of the property + * + * Registers a property named @p_property_name, which will be used in the D-Bus + * serialization of objects of this setting type, but which does not correspond to + * a #GObject property. + * + * When serializing a setting to D-Bus, @p_to_dbus_fcn will be called to synthesize + * a value for the property. (If it returns %NULL, no value will be added to the + * serialization. If @p_to_dbus_fcn is %NULL, the property will always be omitted + * in the serialization.) + * + * When deserializing a D-Bus representation into a setting, if @p_property_name + * is present, then @p_from_dbus_fcn will be called to set it. (If @p_from_dbus_fcn is %NULL + * then the property will be ignored when deserializing.) + */ +#define _properties_override_add_dbus_only(properties_override, \ + p_property_name, \ + p_dbus_type, \ + p_to_dbus_fcn, \ + p_from_dbus_fcn) \ + _properties_override_add ((properties_override), \ + .name = (p_property_name), \ + .property_type = NM_SETT_INFO_PROPERT_TYPE ( \ + .dbus_type = (p_dbus_type), \ + .to_dbus_fcn = (p_to_dbus_fcn), \ + .from_dbus_fcn = (p_from_dbus_fcn), \ + )) -void _properties_override_add_override (GArray *properties_override, - GParamSpec *param_spec, - const GVariantType *dbus_type, - NMSettInfoPropToDBusFcn to_dbus_fcn, - NMSettInfoPropFromDBusFcn from_dbus_fcn, - NMSettInfoPropMissingFromDBusFcn missing_from_dbus_fcn); +/** + * _properties_override_add_override: + * @properties_override: an array collecting the overrides + * @p_param_spec: the name of the property to override + * @p_dbus_type: the type of the property (in its D-Bus representation) + * @p_to_dbus_fcn: (allow-none): function to call to get the value of the property + * @p_from_dbus_fcn: (allow-none): function to call to set the value of the property + * @p_missing_from_dbus_fcn: (allow-none): function to call to indicate the property was not set + * + * Overrides the D-Bus representation of the #GObject property that shares the + * same name as @p_param_spec. + * + * When serializing a setting to D-Bus, if @p_to_dbus_fcn is non-%NULL, then it will + * be called to get the property's value. If it returns a #GVariant, the + * property will be added to the hash, and if it returns %NULL, the property + * will be omitted. (If @p_to_dbus_fcn is %NULL, the property will be read normally + * with g_object_get_property(), and added to the hash if it is not the default + * value.) + * + * When deserializing a D-Bus representation into a setting, if a value with + * the name of @p_param_spec is present, then @p_from_dbus_fcn will be called to set it. + * (If @p_from_dbus_fcn is %NULL then the property will be set normally with + * g_object_set_property().) + * + * If @p_missing_from_dbus_fcn is non-%NULL, then it will be called when deserializing a + * representation that does NOT contain a value for the property. This can be used, + * eg, if a new property needs to be initialized from some older deprecated property + * when it is not present. + */ +#define _properties_override_add_override(properties_override, \ + p_param_spec, \ + p_dbus_type, \ + p_to_dbus_fcn, \ + p_from_dbus_fcn, \ + p_missing_from_dbus_fcn) \ + ({ \ + GParamSpec *const _param_spec = (p_param_spec); \ + \ + nm_assert (_param_spec); \ + \ + _properties_override_add ((properties_override), \ + .param_spec = (_param_spec), \ + .property_type = NM_SETT_INFO_PROPERT_TYPE ( \ + .dbus_type = (p_dbus_type), \ + .to_dbus_fcn = (p_to_dbus_fcn), \ + .from_dbus_fcn = (p_from_dbus_fcn), \ + .missing_from_dbus_fcn = (p_missing_from_dbus_fcn), \ + )); \ + }) -void _properties_override_add_transform (GArray *properties_override, - GParamSpec *param_spec, - const GVariantType *dbus_type, - NMSettInfoPropGPropToDBusFcn gprop_to_dbus_fcn, - NMSettInfoPropGPropFromDBusFcn gprop_from_dbus_fcn); +/** + * _properties_override_add_transform: + * @properties_override: an array collecting the overrides + * @p_param_spec: the param spec of the property to transform. + * @p_dbus_type: the type of the property (in its D-Bus representation) + * @p_gprop_to_dbus_fcn: function to convert from object to D-Bus format + * @p_gprop_from_dbus_fcn: function to convert from D-Bus to object format + * + * Indicates that @property on @setting_class does not have the same format as + * its corresponding D-Bus representation, and so must be transformed when + * serializing/deserializing. + * + * The transformation will also be used by nm_setting_compare(), meaning that + * the underlying object property does not need to be of a type that + * nm_property_compare() recognizes, as long as it recognizes @p_dbus_type. + */ +#define _properties_override_add_transform(properties_override, \ + p_param_spec, \ + p_dbus_type, \ + p_gprop_to_dbus_fcn, \ + p_gprop_from_dbus_fcn) \ + ({ \ + GParamSpec *const _param_spec = (p_param_spec); \ + \ + nm_assert (_param_spec); \ + \ + _properties_override_add ((properties_override), \ + .param_spec = (_param_spec), \ + .property_type = NM_SETT_INFO_PROPERT_TYPE ( \ + .dbus_type = (p_dbus_type), \ + .gprop_to_dbus_fcn = (p_gprop_to_dbus_fcn), \ + .gprop_from_dbus_fcn = (p_gprop_from_dbus_fcn), \ + )); \ + }) /*****************************************************************************/ diff --git a/libnm-core/nm-setting-sriov.c b/libnm-core/nm-setting-sriov.c index b9ac21bfcc..0aa2cc6022 100644 --- a/libnm-core/nm-setting-sriov.c +++ b/libnm-core/nm-setting-sriov.c @@ -1329,7 +1329,7 @@ nm_setting_sriov_class_init (NMSettingSriovClass *klass) _properties_override_add_override (properties_override, obj_properties[PROP_VFS], - G_VARIANT_TYPE ("aa{sv}"), + NM_G_VARIANT_TYPE ("aa{sv}"), vfs_to_dbus, vfs_from_dbus, NULL); diff --git a/libnm-core/nm-setting-tc-config.c b/libnm-core/nm-setting-tc-config.c index be5b4dbcf2..57df75b0d1 100644 --- a/libnm-core/nm-setting-tc-config.c +++ b/libnm-core/nm-setting-tc-config.c @@ -1803,7 +1803,7 @@ nm_setting_tc_config_class_init (NMSettingTCConfigClass *klass) _properties_override_add_override (properties_override, obj_properties[PROP_QDISCS], - G_VARIANT_TYPE ("aa{sv}"), + NM_G_VARIANT_TYPE ("aa{sv}"), tc_qdiscs_get, tc_qdiscs_set, NULL); @@ -1829,7 +1829,7 @@ nm_setting_tc_config_class_init (NMSettingTCConfigClass *klass) _properties_override_add_override (properties_override, obj_properties[PROP_TFILTERS], - G_VARIANT_TYPE ("aa{sv}"), + NM_G_VARIANT_TYPE ("aa{sv}"), tc_tfilters_get, tc_tfilters_set, NULL); diff --git a/libnm-core/nm-setting-team-port.c b/libnm-core/nm-setting-team-port.c index 8fead27820..5fb2966b78 100644 --- a/libnm-core/nm-setting-team-port.c +++ b/libnm-core/nm-setting-team-port.c @@ -538,10 +538,12 @@ nm_setting_team_port_class_init (NMSettingTeamPortClass *klass) #define _property_override(_properties_override, _param_spec, _variant_type, _is_link_watcher) \ _properties_override_add ((_properties_override), \ - .param_spec = (_param_spec), \ - .dbus_type = G_VARIANT_TYPE (""_variant_type""), \ - .to_dbus_fcn = _nm_team_settings_property_to_dbus, \ - .gprop_from_dbus_fcn = ((_is_link_watcher) ? _nm_team_settings_property_from_dbus_link_watchers : NULL)) + .param_spec = (_param_spec), \ + .property_type = NM_SETT_INFO_PROPERT_TYPE ( \ + .dbus_type = NM_G_VARIANT_TYPE (""_variant_type""), \ + .to_dbus_fcn = _nm_team_settings_property_to_dbus, \ + .gprop_from_dbus_fcn = ((_is_link_watcher) ? _nm_team_settings_property_from_dbus_link_watchers : NULL), \ + )) /** * NMSettingTeamPort:config: diff --git a/libnm-core/nm-setting-team.c b/libnm-core/nm-setting-team.c index 4f9b571a8d..4325abfc8b 100644 --- a/libnm-core/nm-setting-team.c +++ b/libnm-core/nm-setting-team.c @@ -1485,10 +1485,12 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) #define _property_override(_properties_override, _param_spec, _variant_type, _is_link_watcher) \ _properties_override_add ((_properties_override), \ - .param_spec = (_param_spec), \ - .dbus_type = G_VARIANT_TYPE (""_variant_type""), \ - .to_dbus_fcn = _nm_team_settings_property_to_dbus, \ - .gprop_from_dbus_fcn = ((_is_link_watcher) ? _nm_team_settings_property_from_dbus_link_watchers : NULL)) + .param_spec = (_param_spec), \ + .property_type = NM_SETT_INFO_PROPERT_TYPE ( \ + .dbus_type = NM_G_VARIANT_TYPE (""_variant_type""), \ + .to_dbus_fcn = _nm_team_settings_property_to_dbus, \ + .gprop_from_dbus_fcn = ((_is_link_watcher) ? _nm_team_settings_property_from_dbus_link_watchers : NULL), \ + )) /** * NMSettingTeam:config: diff --git a/libnm-core/nm-setting-user.c b/libnm-core/nm-setting-user.c index 2852888f5a..b252a1591b 100644 --- a/libnm-core/nm-setting-user.c +++ b/libnm-core/nm-setting-user.c @@ -574,7 +574,7 @@ nm_setting_user_class_init (NMSettingUserClass *klass) _properties_override_add_transform (properties_override, obj_properties[PROP_DATA], - G_VARIANT_TYPE ("a{ss}"), + NM_G_VARIANT_TYPE ("a{ss}"), _nm_utils_strdict_to_dbus, _nm_utils_strdict_from_dbus); diff --git a/libnm-core/nm-setting-vpn.c b/libnm-core/nm-setting-vpn.c index a337d857cf..da1b8e2cad 100644 --- a/libnm-core/nm-setting-vpn.c +++ b/libnm-core/nm-setting-vpn.c @@ -1132,7 +1132,7 @@ nm_setting_vpn_class_init (NMSettingVpnClass *klass) _properties_override_add_transform (properties_override, obj_properties[PROP_DATA], - G_VARIANT_TYPE ("a{ss}"), + NM_G_VARIANT_TYPE ("a{ss}"), _nm_utils_strdict_to_dbus, _nm_utils_strdict_from_dbus); @@ -1159,7 +1159,7 @@ nm_setting_vpn_class_init (NMSettingVpnClass *klass) _properties_override_add_override (properties_override, obj_properties[PROP_SECRETS], - G_VARIANT_TYPE ("a{ss}"), + NM_G_VARIANT_TYPE ("a{ss}"), vpn_secrets_to_dbus, vpn_secrets_from_dbus, NULL); diff --git a/libnm-core/nm-setting-wired.c b/libnm-core/nm-setting-wired.c index fee069883e..2b16acaa8f 100644 --- a/libnm-core/nm-setting-wired.c +++ b/libnm-core/nm-setting-wired.c @@ -1591,7 +1591,7 @@ nm_setting_wired_class_init (NMSettingWiredClass *klass) _properties_override_add_transform (properties_override, obj_properties[PROP_S390_OPTIONS], - G_VARIANT_TYPE ("a{ss}"), + NM_G_VARIANT_TYPE ("a{ss}"), _nm_utils_strdict_to_dbus, _nm_utils_strdict_from_dbus); diff --git a/libnm-core/nm-setting-wireguard.c b/libnm-core/nm-setting-wireguard.c index baceb4d064..b03d527f4a 100644 --- a/libnm-core/nm-setting-wireguard.c +++ b/libnm-core/nm-setting-wireguard.c @@ -2573,7 +2573,7 @@ nm_setting_wireguard_class_init (NMSettingWireGuardClass *klass) */ _properties_override_add_dbus_only (properties_override, NM_SETTING_WIREGUARD_PEERS, - G_VARIANT_TYPE ("aa{sv}"), + NM_G_VARIANT_TYPE ("aa{sv}"), _peers_dbus_only_synth, _peers_dbus_only_set); diff --git a/libnm-core/nm-setting.c b/libnm-core/nm-setting.c index dac2df82e8..23b9d09505 100644 --- a/libnm-core/nm-setting.c +++ b/libnm-core/nm-setting.c @@ -206,150 +206,31 @@ void _properties_override_add_struct (GArray *properties_override, const NMSettInfoProperty *prop_info) { - NMSettInfoProperty *p; - nm_assert (properties_override); nm_assert (prop_info); - nm_assert (prop_info->name || prop_info->param_spec); + nm_assert ((!!prop_info->name) != (!!prop_info->param_spec)); nm_assert (!prop_info->param_spec || !prop_info->name || nm_streq0 (prop_info->name, prop_info->param_spec->name)); - nm_assert (!_nm_sett_info_property_find_in_array ((NMSettInfoProperty *) properties_override->data, - properties_override->len, - prop_info->name ?: prop_info->param_spec->name)); - nm_assert (!prop_info->gprop_from_dbus_fcn || prop_info->dbus_type); - nm_assert (!prop_info->from_dbus_fcn || prop_info->dbus_type); - nm_assert (!prop_info->to_dbus_fcn || prop_info->dbus_type); +#define _PROPERT_EXTRA(prop_info, member) \ + ({ \ + const NMSettInfoProperty *_prop_info = (prop_info); \ + \ + (_prop_info->property_type ? _prop_info->property_type->member : 0); \ + }) - nm_assert (!prop_info->to_dbus_fcn || !prop_info->gprop_to_dbus_fcn); - nm_assert (!prop_info->from_dbus_fcn || !prop_info->gprop_from_dbus_fcn); + nm_assert (!_PROPERT_EXTRA (prop_info, gprop_from_dbus_fcn) || _PROPERT_EXTRA (prop_info, dbus_type)); + nm_assert (!_PROPERT_EXTRA (prop_info, from_dbus_fcn) || _PROPERT_EXTRA (prop_info, dbus_type)); + nm_assert (!_PROPERT_EXTRA (prop_info, to_dbus_fcn) || _PROPERT_EXTRA (prop_info, dbus_type)); - nm_assert (!prop_info->gprop_to_dbus_fcn || prop_info->param_spec); - nm_assert (!prop_info->gprop_from_dbus_fcn || prop_info->param_spec); + nm_assert (!_PROPERT_EXTRA (prop_info, to_dbus_fcn) || !_PROPERT_EXTRA (prop_info, gprop_to_dbus_fcn)); + nm_assert (!_PROPERT_EXTRA (prop_info, from_dbus_fcn) || !_PROPERT_EXTRA (prop_info, gprop_from_dbus_fcn)); + + nm_assert (!_PROPERT_EXTRA (prop_info, gprop_to_dbus_fcn) || prop_info->param_spec); + nm_assert (!_PROPERT_EXTRA (prop_info, gprop_from_dbus_fcn) || prop_info->param_spec); + +#undef _PROPERT_EXTRA g_array_append_vals (properties_override, prop_info, 1); - - if (!prop_info->name) { - /* for convenience, allow omitting "name" if "param_spec" is given. */ - p = &g_array_index (properties_override, - NMSettInfoProperty, - properties_override->len - 1); - nm_assert (p->param_spec); - p->name = p->param_spec->name; - } -} - -/** - * _properties_override_add_dbus_only: - * @properties_override: an array collecting the overrides - * @property_name: the name of the property to override - * @dbus_type: the type of the property (in its D-Bus representation) - * @to_dbus_fcn: (allow-none): function to call to synthesize a value for the property - * @from_dbus_fcn: (allow-none): function to call to set the value of the property - * - * Registers a property named @property_name, which will be used in the D-Bus - * serialization of objects of this setting type, but which does not correspond to - * a #GObject property. - * - * When serializing a setting to D-Bus, @to_dbus_fcn will be called to synthesize - * a value for the property. (If it returns %NULL, no value will be added to the - * serialization. If @to_dbus_fcn is %NULL, the property will always be omitted - * in the serialization.) - * - * When deserializing a D-Bus representation into a setting, if @property_name - * is present, then @from_dbus_fcn will be called to set it. (If @from_dbus_fcn is %NULL - * then the property will be ignored when deserializing.) - */ -void -_properties_override_add_dbus_only (GArray *properties_override, - const char *property_name, - const GVariantType *dbus_type, - NMSettInfoPropToDBusFcn to_dbus_fcn, - NMSettInfoPropFromDBusFcn from_dbus_fcn) -{ - _properties_override_add (properties_override, - .name = property_name, - .dbus_type = dbus_type, - .to_dbus_fcn = to_dbus_fcn, - .from_dbus_fcn = from_dbus_fcn); -} - -/** - * _properties_override_add_override: - * @properties_override: an array collecting the overrides - * @param_spec: the name of the property to override - * @dbus_type: the type of the property (in its D-Bus representation) - * @to_dbus_fcn: (allow-none): function to call to get the value of the property - * @from_dbus_fcn: (allow-none): function to call to set the value of the property - * @missing_from_dbus_fcn: (allow-none): function to call to indicate the property was not set - * - * Overrides the D-Bus representation of the #GObject property that shares the - * same name as @param_spec. - * - * When serializing a setting to D-Bus, if @to_dbus_fcn is non-%NULL, then it will - * be called to get the property's value. If it returns a #GVariant, the - * property will be added to the hash, and if it returns %NULL, the property - * will be omitted. (If @to_dbus_fcn is %NULL, the property will be read normally - * with g_object_get_property(), and added to the hash if it is not the default - * value.) - * - * When deserializing a D-Bus representation into a setting, if a value with - * the name of @param_spec is present, then @from_dbus_fcn will be called to set it. - * (If @from_dbus_fcn is %NULL then the property will be set normally with - * g_object_set_property().) - * - * If @missing_from_dbus_fcn is non-%NULL, then it will be called when deserializing a - * representation that does NOT contain a value for the property. This can be used, - * eg, if a new property needs to be initialized from some older deprecated property - * when it is not present. - */ -void -_properties_override_add_override (GArray *properties_override, - GParamSpec *param_spec, - const GVariantType *dbus_type, - NMSettInfoPropToDBusFcn to_dbus_fcn, - NMSettInfoPropFromDBusFcn from_dbus_fcn, - NMSettInfoPropMissingFromDBusFcn missing_from_dbus_fcn) -{ - nm_assert (param_spec); - - _properties_override_add (properties_override, - .param_spec = param_spec, - .dbus_type = dbus_type, - .to_dbus_fcn = to_dbus_fcn, - .from_dbus_fcn = from_dbus_fcn, - .missing_from_dbus_fcn = missing_from_dbus_fcn); -} - -/** - * _properties_override_add_transform: - * @properties_override: an array collecting the overrides - * @param_spec: the param spec of the property to transform. - * @dbus_type: the type of the property (in its D-Bus representation) - * @gprop_to_dbus_fcn: function to convert from object to D-Bus format - * @gprop_from_dbus_fcn: function to convert from D-Bus to object format - * - * Indicates that @property on @setting_class does not have the same format as - * its corresponding D-Bus representation, and so must be transformed when - * serializing/deserializing. - * - * The transformation will also be used by nm_setting_compare(), meaning that - * the underlying object property does not need to be of a type that - * nm_property_compare() recognizes, as long as it recognizes @dbus_type. - */ -void -_properties_override_add_transform (GArray *properties_override, - GParamSpec *param_spec, - const GVariantType *dbus_type, - NMSettInfoPropGPropToDBusFcn gprop_to_dbus_fcn, - NMSettInfoPropGPropFromDBusFcn gprop_from_dbus_fcn) -{ - nm_assert (param_spec); - - _properties_override_add (properties_override, - .param_spec = param_spec, - .dbus_type = dbus_type, - .gprop_to_dbus_fcn = gprop_to_dbus_fcn, - .gprop_from_dbus_fcn = gprop_from_dbus_fcn); } static NMSettInfoSetting _sett_info_settings[_NM_META_SETTING_TYPE_NUM]; @@ -461,6 +342,18 @@ _nm_setting_class_commit_full (NMSettingClass *setting_class, property_specs = g_object_class_list_properties (G_OBJECT_CLASS (setting_class), &n_property_specs); + for (i = 0; i < properties_override->len; i++) { + NMSettInfoProperty *p = &g_array_index (properties_override, NMSettInfoProperty, i); + + nm_assert ((!!p->name) != (!!p->param_spec)); + + if (!p->name) { + nm_assert (p->param_spec); + p->name = p->param_spec->name; + } else + nm_assert (!p->param_spec); + } + #if NM_MORE_ASSERTS > 10 /* assert that properties_override is constructed consistently. */ for (i = 0; i < override_len; i++) { @@ -502,43 +395,46 @@ _nm_setting_class_commit_full (NMSettingClass *setting_class, NMSettInfoProperty *p = &g_array_index (properties_override, NMSettInfoProperty, i); GType vtype; - if (p->dbus_type) - continue; + if (p->property_type) + goto has_property_type; nm_assert (p->param_spec); - nm_assert (!p->gprop_to_dbus_fcn); vtype = p->param_spec->value_type; if (vtype == G_TYPE_BOOLEAN) - p->dbus_type = G_VARIANT_TYPE_BOOLEAN; + p->property_type = NM_SETT_INFO_PROPERT_TYPE (.dbus_type = G_VARIANT_TYPE_BOOLEAN); else if (vtype == G_TYPE_UCHAR) - p->dbus_type = G_VARIANT_TYPE_BYTE; + p->property_type = NM_SETT_INFO_PROPERT_TYPE (.dbus_type = G_VARIANT_TYPE_BYTE); else if (vtype == G_TYPE_INT) - p->dbus_type = G_VARIANT_TYPE_INT32; + p->property_type = NM_SETT_INFO_PROPERT_TYPE (.dbus_type = G_VARIANT_TYPE_INT32); else if (vtype == G_TYPE_UINT) - p->dbus_type = G_VARIANT_TYPE_UINT32; + p->property_type = NM_SETT_INFO_PROPERT_TYPE (.dbus_type = G_VARIANT_TYPE_UINT32); else if (vtype == G_TYPE_INT64) - p->dbus_type = G_VARIANT_TYPE_INT64; + p->property_type = NM_SETT_INFO_PROPERT_TYPE (.dbus_type = G_VARIANT_TYPE_INT64); else if (vtype == G_TYPE_UINT64) - p->dbus_type = G_VARIANT_TYPE_UINT64; + p->property_type = NM_SETT_INFO_PROPERT_TYPE (.dbus_type = G_VARIANT_TYPE_UINT64); else if (vtype == G_TYPE_STRING) - p->dbus_type = G_VARIANT_TYPE_STRING; + p->property_type = NM_SETT_INFO_PROPERT_TYPE (.dbus_type = G_VARIANT_TYPE_STRING); else if (vtype == G_TYPE_DOUBLE) - p->dbus_type = G_VARIANT_TYPE_DOUBLE; + p->property_type = NM_SETT_INFO_PROPERT_TYPE (.dbus_type = G_VARIANT_TYPE_DOUBLE); else if (vtype == G_TYPE_STRV) - p->dbus_type = G_VARIANT_TYPE_STRING_ARRAY; + p->property_type = NM_SETT_INFO_PROPERT_TYPE (.dbus_type = G_VARIANT_TYPE_STRING_ARRAY); else if (vtype == G_TYPE_BYTES) { - p->dbus_type = G_VARIANT_TYPE_BYTESTRING; - p->gprop_to_dbus_fcn = _gprop_to_dbus_fcn_bytes; + p->property_type = NM_SETT_INFO_PROPERT_TYPE (.dbus_type = G_VARIANT_TYPE_BYTESTRING, + .gprop_to_dbus_fcn = _gprop_to_dbus_fcn_bytes); } else if (g_type_is_a (vtype, G_TYPE_ENUM)) { - p->dbus_type = G_VARIANT_TYPE_INT32; - p->gprop_to_dbus_fcn = _gprop_to_dbus_fcn_enum; + p->property_type = NM_SETT_INFO_PROPERT_TYPE (.dbus_type = G_VARIANT_TYPE_INT32, + .gprop_to_dbus_fcn = _gprop_to_dbus_fcn_enum); } else if (g_type_is_a (vtype, G_TYPE_FLAGS)) { - p->dbus_type = G_VARIANT_TYPE_UINT32; - p->gprop_to_dbus_fcn = _gprop_to_dbus_fcn_flags; - } + p->property_type = NM_SETT_INFO_PROPERT_TYPE (.dbus_type = G_VARIANT_TYPE_UINT32, + .gprop_to_dbus_fcn = _gprop_to_dbus_fcn_flags); + } else + nm_assert_not_reached (); - nm_assert (p->dbus_type); +has_property_type: + nm_assert (p->property_type); + nm_assert (p->property_type->dbus_type); + nm_assert (g_variant_type_string_is_valid ((const char *) p->property_type->dbus_type)); } G_STATIC_ASSERT_EXPR (G_STRUCT_OFFSET (NMSettInfoProperty, name) == 0); @@ -685,10 +581,10 @@ property_to_dbus (const NMSettInfoSetting *sett_info, const NMSettInfoProperty *property = &sett_info->property_infos[property_idx]; GVariant *variant; - nm_assert (property->dbus_type); + nm_assert (property->property_type->dbus_type); if (!property->param_spec) { - if (!property->to_dbus_fcn) + if (!property->property_type->to_dbus_fcn) return NULL; } else if (!ignore_flags) { if (!NM_FLAGS_HAS (property->param_spec->flags, G_PARAM_WRITABLE)) @@ -726,8 +622,8 @@ property_to_dbus (const NMSettInfoSetting *sett_info, } } - if (property->to_dbus_fcn) { - variant = property->to_dbus_fcn (sett_info, property_idx, connection, setting, flags, options); + if (property->property_type->to_dbus_fcn) { + variant = property->property_type->to_dbus_fcn (sett_info, property_idx, connection, setting, flags, options); nm_g_variant_take_ref (variant); } else { nm_auto_unset_gvalue GValue prop_value = { 0, }; @@ -742,15 +638,15 @@ property_to_dbus (const NMSettInfoSetting *sett_info, && g_param_value_defaults (property->param_spec, &prop_value)) return NULL; - if (property->gprop_to_dbus_fcn) { - variant = property->gprop_to_dbus_fcn (&prop_value); + if (property->property_type->gprop_to_dbus_fcn) { + variant = property->property_type->gprop_to_dbus_fcn (&prop_value); nm_g_variant_take_ref (variant); } else - variant = g_dbus_gvalue_to_gvariant (&prop_value, property->dbus_type); + variant = g_dbus_gvalue_to_gvariant (&prop_value, property->property_type->dbus_type); } nm_assert (!variant || !g_variant_is_floating (variant)); - nm_assert (!variant || g_variant_is_of_type (variant, property->dbus_type)); + nm_assert (!variant || g_variant_is_of_type (variant, property->property_type->dbus_type)); return variant; } @@ -761,12 +657,12 @@ set_property_from_dbus (const NMSettInfoProperty *property, GValue *dst_value) { nm_assert (property->param_spec); - nm_assert (property->dbus_type); + nm_assert (property->property_type->dbus_type); - if (property->gprop_from_dbus_fcn) { - if (!g_variant_type_equal (g_variant_get_type (src_value), property->dbus_type)) + if (property->property_type->gprop_from_dbus_fcn) { + if (!g_variant_type_equal (g_variant_get_type (src_value), property->property_type->dbus_type)) return FALSE; - property->gprop_from_dbus_fcn (src_value, dst_value); + property->property_type->gprop_from_dbus_fcn (src_value, dst_value); } else if (dst_value->g_type == G_TYPE_BYTES) { if (!g_variant_is_of_type (src_value, G_VARIANT_TYPE_BYTESTRING)) return FALSE; @@ -1002,16 +898,16 @@ init_from_dbus (NMSetting *setting, g_hash_table_remove (keys, property_info->name); if ( value - && property_info->from_dbus_fcn) { + && property_info->property_type->from_dbus_fcn) { - if (!g_variant_type_equal (g_variant_get_type (value), property_info->dbus_type)) { + if (!g_variant_type_equal (g_variant_get_type (value), property_info->property_type->dbus_type)) { /* for backward behavior, fail unless best-effort is chosen. */ if (NM_FLAGS_HAS (parse_flags, NM_SETTING_PARSE_FLAGS_BEST_EFFORT)) continue; g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, _("can't set property of type '%s' from value of type '%s'"), - property_info->dbus_type ? - g_variant_type_peek_string (property_info->dbus_type) : + property_info->property_type->dbus_type ? + g_variant_type_peek_string (property_info->property_type->dbus_type) : property_info->param_spec ? g_type_name (property_info->param_spec->value_type) : "(unknown)", g_variant_get_type_string (value)); @@ -1019,12 +915,12 @@ init_from_dbus (NMSetting *setting, return FALSE; } - if (!property_info->from_dbus_fcn (setting, - connection_dict, - property_info->name, - value, - parse_flags, - &local)) { + if (!property_info->property_type->from_dbus_fcn (setting, + connection_dict, + property_info->name, + value, + parse_flags, + &local)) { if (!NM_FLAGS_HAS (parse_flags, NM_SETTING_PARSE_FLAGS_STRICT)) continue; g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, @@ -1034,12 +930,12 @@ init_from_dbus (NMSetting *setting, return FALSE; } } else if ( !value - && property_info->missing_from_dbus_fcn) { - if (!property_info->missing_from_dbus_fcn (setting, - connection_dict, - property_info->name, - parse_flags, - &local)) { + && property_info->property_type->missing_from_dbus_fcn) { + if (!property_info->property_type->missing_from_dbus_fcn (setting, + connection_dict, + property_info->name, + parse_flags, + &local)) { if (!NM_FLAGS_HAS (parse_flags, NM_SETTING_PARSE_FLAGS_STRICT)) continue; g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, @@ -1059,8 +955,8 @@ init_from_dbus (NMSetting *setting, continue; g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, _("can't set property of type '%s' from value of type '%s'"), - property_info->dbus_type - ? g_variant_type_peek_string (property_info->dbus_type) + property_info->property_type->dbus_type + ? g_variant_type_peek_string (property_info->property_type->dbus_type) : ( property_info->param_spec ? g_type_name (property_info->param_spec->value_type) : "(unknown)"), @@ -1107,9 +1003,10 @@ nm_setting_get_dbus_property_type (NMSetting *setting, g_return_val_if_fail (property != NULL, NULL); - nm_assert (property->dbus_type); + nm_assert (property->property_type); + nm_assert (g_variant_type_string_is_valid ((const char *) property->property_type->dbus_type)); - return property->dbus_type; + return property->property_type->dbus_type; } gboolean diff --git a/libnm-core/tests/test-setting.c b/libnm-core/tests/test-setting.c index ee0caa3d19..d843f58774 100644 --- a/libnm-core/tests/test-setting.c +++ b/libnm-core/tests/test-setting.c @@ -3387,8 +3387,12 @@ test_setting_metadata (void) if (prop_idx > 0) g_assert_cmpint (strcmp (sis->property_infos[prop_idx - 1].name, sip->name), <, 0); - g_assert (sip->dbus_type); - g_assert (g_variant_type_string_is_valid ((const char *) sip->dbus_type)); + g_assert (sip->property_type); + g_assert (sip->property_type->dbus_type); + g_assert (g_variant_type_string_is_valid ((const char *) sip->property_type->dbus_type)); + + g_assert (!sip->property_type->to_dbus_fcn || !sip->property_type->gprop_to_dbus_fcn); + g_assert (!sip->property_type->from_dbus_fcn || !sip->property_type->gprop_from_dbus_fcn); if (!g_hash_table_insert (h_properties, (char *) sip->name, sip->param_spec)) g_assert_not_reached (); From d534b6d07a235199af3044a6f156d2965dc0ddc0 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 22 Sep 2019 10:57:57 +0200 Subject: [PATCH 04/12] libnm: deduplicate NMSettInfoPropertType instances There is no need to keep duplicate instances. Before we had 89 distinct property types, now there are 49. --- libnm-core/nm-setting-bluetooth.c | 7 +- libnm-core/nm-setting-bond.c | 13 +--- libnm-core/nm-setting-bridge-port.c | 9 +-- libnm-core/nm-setting-bridge.c | 21 +----- libnm-core/nm-setting-dcb.c | 48 ++++--------- libnm-core/nm-setting-gsm.c | 13 +--- libnm-core/nm-setting-infiniband.c | 7 +- libnm-core/nm-setting-olpc-mesh.c | 7 +- libnm-core/nm-setting-private.h | 18 +++-- libnm-core/nm-setting-team-port.c | 23 ++---- libnm-core/nm-setting-team.c | 47 +++++------- libnm-core/nm-setting-user.c | 7 +- libnm-core/nm-setting-vlan.c | 6 +- libnm-core/nm-setting-vpn.c | 8 +-- libnm-core/nm-setting-wimax.c | 7 +- libnm-core/nm-setting-wired.c | 28 ++------ libnm-core/nm-setting-wireless.c | 28 ++------ libnm-core/nm-setting.c | 29 +++++++- libnm-core/nm-team-utils.c | 30 +++++++- libnm-core/nm-team-utils.h | 18 ++--- libnm-core/nm-utils-private.h | 54 +++----------- libnm-core/nm-utils.c | 51 ++++++++++--- libnm-core/tests/test-setting.c | 107 ++++++++++++++++++++++++++++ 23 files changed, 287 insertions(+), 299 deletions(-) diff --git a/libnm-core/nm-setting-bluetooth.c b/libnm-core/nm-setting-bluetooth.c index 2d9e72c100..10f52878e9 100644 --- a/libnm-core/nm-setting-bluetooth.c +++ b/libnm-core/nm-setting-bluetooth.c @@ -295,12 +295,7 @@ nm_setting_bluetooth_class_init (NMSettingBluetoothClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_transform (properties_override, - obj_properties[PROP_BDADDR], - G_VARIANT_TYPE_BYTESTRING, - _nm_utils_hwaddr_to_dbus, - _nm_utils_hwaddr_from_dbus); + _properties_override_add_gobj (properties_override, obj_properties[PROP_BDADDR], &nm_sett_info_propert_type_mac_addrees); /** * NMSettingBluetooth:type: diff --git a/libnm-core/nm-setting-bond.c b/libnm-core/nm-setting-bond.c index 672acd4e31..04d653cc0e 100644 --- a/libnm-core/nm-setting-bond.c +++ b/libnm-core/nm-setting-bond.c @@ -970,12 +970,7 @@ nm_setting_bond_class_init (NMSettingBondClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_transform (properties_override, - obj_properties[PROP_OPTIONS], - NM_G_VARIANT_TYPE ("a{ss}"), - _nm_utils_strdict_to_dbus, - _nm_utils_strdict_from_dbus); + _properties_override_add_gobj (properties_override, obj_properties[PROP_OPTIONS], &nm_sett_info_propert_type_strdict); /* ---dbus--- * property: interface-name @@ -985,11 +980,7 @@ nm_setting_bond_class_init (NMSettingBondClass *klass) * bond's interface name. * ---end--- */ - _properties_override_add_dbus_only (properties_override, - "interface-name", - G_VARIANT_TYPE_STRING, - _nm_setting_get_deprecated_virtual_interface_name, - NULL); + _properties_override_add_virt (properties_override, "interface-name", &nm_sett_info_propert_type_deprecated_interface_name); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/libnm-core/nm-setting-bridge-port.c b/libnm-core/nm-setting-bridge-port.c index aa2d9bf2a3..fd3dc98e92 100644 --- a/libnm-core/nm-setting-bridge-port.c +++ b/libnm-core/nm-setting-bridge-port.c @@ -573,17 +573,10 @@ nm_setting_bridge_port_class_init (NMSettingBridgePortClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_override (properties_override, - obj_properties[PROP_VLANS], - NM_G_VARIANT_TYPE ("aa{sv}"), - _nm_utils_bridge_vlans_to_dbus, - _nm_utils_bridge_vlans_from_dbus, - NULL); + _properties_override_add_gobj (properties_override, obj_properties[PROP_VLANS], &nm_sett_info_propert_type_bridge_vlans); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); _nm_setting_class_commit_full (setting_class, NM_META_SETTING_TYPE_BRIDGE_PORT, NULL, properties_override); - } diff --git a/libnm-core/nm-setting-bridge.c b/libnm-core/nm-setting-bridge.c index d819e0a6f5..9a0e31c79d 100644 --- a/libnm-core/nm-setting-bridge.c +++ b/libnm-core/nm-setting-bridge.c @@ -1209,12 +1209,7 @@ nm_setting_bridge_class_init (NMSettingBridgeClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_transform (properties_override, - obj_properties[PROP_MAC_ADDRESS], - G_VARIANT_TYPE_BYTESTRING, - _nm_utils_hwaddr_to_dbus, - _nm_utils_hwaddr_from_dbus); + _properties_override_add_gobj (properties_override, obj_properties[PROP_MAC_ADDRESS], &nm_sett_info_propert_type_mac_addrees); /** * NMSettingBridge:stp: @@ -1466,13 +1461,7 @@ nm_setting_bridge_class_init (NMSettingBridgeClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_override (properties_override, - obj_properties[PROP_VLANS], - NM_G_VARIANT_TYPE ("aa{sv}"), - _nm_utils_bridge_vlans_to_dbus, - _nm_utils_bridge_vlans_from_dbus, - NULL); + _properties_override_add_gobj (properties_override, obj_properties[PROP_VLANS], &nm_sett_info_propert_type_bridge_vlans); /* ---dbus--- * property: interface-name @@ -1482,11 +1471,7 @@ nm_setting_bridge_class_init (NMSettingBridgeClass *klass) * bridge's interface name. * ---end--- */ - _properties_override_add_dbus_only (properties_override, - "interface-name", - G_VARIANT_TYPE_STRING, - _nm_setting_get_deprecated_virtual_interface_name, - NULL); + _properties_override_add_virt (properties_override, "interface-name", &nm_sett_info_propert_type_deprecated_interface_name); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/libnm-core/nm-setting-dcb.c b/libnm-core/nm-setting-dcb.c index e1eb748466..a7d081131b 100644 --- a/libnm-core/nm-setting-dcb.c +++ b/libnm-core/nm-setting-dcb.c @@ -743,6 +743,12 @@ _nm_setting_dcb_uint_array_from_dbus (GVariant *dbus_value, set_gvalue_from_array (prop_value, (guint *) array, length); } +static const NMSettInfoPropertType nm_sett_info_propert_type_dcb_au = { + .dbus_type = NM_G_VARIANT_TYPE ("au"), + .gprop_to_dbus_fcn = _nm_setting_dcb_uint_array_to_dbus, + .gprop_from_dbus_fcn = _nm_setting_dcb_uint_array_from_dbus, +}; + /*****************************************************************************/ static void @@ -1097,12 +1103,7 @@ nm_setting_dcb_class_init (NMSettingDcbClass *klass) G_TYPE_ARRAY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_transform (properties_override, - obj_properties[PROP_PRIORITY_FLOW_CONTROL], - NM_G_VARIANT_TYPE ("au"), - _nm_setting_dcb_uint_array_to_dbus, - _nm_setting_dcb_uint_array_from_dbus); + _properties_override_add_gobj (properties_override, obj_properties[PROP_PRIORITY_FLOW_CONTROL], &nm_sett_info_propert_type_dcb_au); /** * NMSettingDcb:priority-group-flags: @@ -1145,12 +1146,7 @@ nm_setting_dcb_class_init (NMSettingDcbClass *klass) G_TYPE_ARRAY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_transform (properties_override, - obj_properties[PROP_PRIORITY_GROUP_ID], - NM_G_VARIANT_TYPE ("au"), - _nm_setting_dcb_uint_array_to_dbus, - _nm_setting_dcb_uint_array_from_dbus); + _properties_override_add_gobj (properties_override, obj_properties[PROP_PRIORITY_GROUP_ID], &nm_sett_info_propert_type_dcb_au); /** * NMSettingDcb:priority-group-bandwidth: (type GArray(guint)) @@ -1172,12 +1168,7 @@ nm_setting_dcb_class_init (NMSettingDcbClass *klass) G_TYPE_ARRAY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_transform (properties_override, - obj_properties[PROP_PRIORITY_GROUP_BANDWIDTH], - NM_G_VARIANT_TYPE ("au"), - _nm_setting_dcb_uint_array_to_dbus, - _nm_setting_dcb_uint_array_from_dbus); + _properties_override_add_gobj (properties_override, obj_properties[PROP_PRIORITY_GROUP_BANDWIDTH], &nm_sett_info_propert_type_dcb_au); /** * NMSettingDcb:priority-bandwidth: (type GArray(guint)) @@ -1201,12 +1192,7 @@ nm_setting_dcb_class_init (NMSettingDcbClass *klass) G_TYPE_ARRAY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_transform (properties_override, - obj_properties[PROP_PRIORITY_BANDWIDTH], - NM_G_VARIANT_TYPE ("au"), - _nm_setting_dcb_uint_array_to_dbus, - _nm_setting_dcb_uint_array_from_dbus); + _properties_override_add_gobj (properties_override, obj_properties[PROP_PRIORITY_BANDWIDTH], &nm_sett_info_propert_type_dcb_au); /** * NMSettingDcb:priority-strict-bandwidth: (type GArray(gboolean)) @@ -1228,12 +1214,7 @@ nm_setting_dcb_class_init (NMSettingDcbClass *klass) G_TYPE_ARRAY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_transform (properties_override, - obj_properties[PROP_PRIORITY_STRICT_BANDWIDTH], - NM_G_VARIANT_TYPE ("au"), - _nm_setting_dcb_uint_array_to_dbus, - _nm_setting_dcb_uint_array_from_dbus); + _properties_override_add_gobj (properties_override, obj_properties[PROP_PRIORITY_STRICT_BANDWIDTH], &nm_sett_info_propert_type_dcb_au); /** * NMSettingDcb:priority-traffic-class: (type GArray(guint)) @@ -1254,12 +1235,7 @@ nm_setting_dcb_class_init (NMSettingDcbClass *klass) G_TYPE_ARRAY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_transform (properties_override, - obj_properties[PROP_PRIORITY_TRAFFIC_CLASS], - NM_G_VARIANT_TYPE ("au"), - _nm_setting_dcb_uint_array_to_dbus, - _nm_setting_dcb_uint_array_from_dbus); + _properties_override_add_gobj (properties_override, obj_properties[PROP_PRIORITY_TRAFFIC_CLASS], &nm_sett_info_propert_type_dcb_au); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/libnm-core/nm-setting-gsm.c b/libnm-core/nm-setting-gsm.c index b4ca97e6d8..bd118a9210 100644 --- a/libnm-core/nm-setting-gsm.c +++ b/libnm-core/nm-setting-gsm.c @@ -847,17 +847,8 @@ nm_setting_gsm_class_init (NMSettingGsmClass *klass) G_PARAM_STATIC_STRINGS); /* Ignore incoming deprecated properties */ - _properties_override_add_dbus_only (properties_override, - "allowed-bands", - G_VARIANT_TYPE_UINT32, - NULL, - NULL); - - _properties_override_add_dbus_only (properties_override, - "network-type", - G_VARIANT_TYPE_INT32, - NULL, - NULL); + _properties_override_add_virt (properties_override, "allowed-bands", &nm_sett_info_propert_type_deprecated_ignore_u); + _properties_override_add_virt (properties_override, "network-type", &nm_sett_info_propert_type_deprecated_ignore_i); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/libnm-core/nm-setting-infiniband.c b/libnm-core/nm-setting-infiniband.c index ddfdc8ab75..9b3884dd02 100644 --- a/libnm-core/nm-setting-infiniband.c +++ b/libnm-core/nm-setting-infiniband.c @@ -414,12 +414,7 @@ nm_setting_infiniband_class_init (NMSettingInfinibandClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_transform (properties_override, - obj_properties[PROP_MAC_ADDRESS], - G_VARIANT_TYPE_BYTESTRING, - _nm_utils_hwaddr_to_dbus, - _nm_utils_hwaddr_from_dbus); + _properties_override_add_gobj (properties_override, obj_properties[PROP_MAC_ADDRESS], &nm_sett_info_propert_type_mac_addrees); /** * NMSettingInfiniband:mtu: diff --git a/libnm-core/nm-setting-olpc-mesh.c b/libnm-core/nm-setting-olpc-mesh.c index b88b458f3a..2247dd5bbb 100644 --- a/libnm-core/nm-setting-olpc-mesh.c +++ b/libnm-core/nm-setting-olpc-mesh.c @@ -250,12 +250,7 @@ nm_setting_olpc_mesh_class_init (NMSettingOlpcMeshClass *klass) NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_transform (properties_override, - obj_properties[PROP_DHCP_ANYCAST_ADDRESS], - G_VARIANT_TYPE_BYTESTRING, - _nm_utils_hwaddr_to_dbus, - _nm_utils_hwaddr_from_dbus); + _properties_override_add_gobj (properties_override, obj_properties[PROP_DHCP_ANYCAST_ADDRESS], &nm_sett_info_propert_type_mac_addrees); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/libnm-core/nm-setting-private.h b/libnm-core/nm-setting-private.h index c9e9e02de6..747818df9c 100644 --- a/libnm-core/nm-setting-private.h +++ b/libnm-core/nm-setting-private.h @@ -69,12 +69,12 @@ gboolean _nm_setting_clear_secrets (NMSetting *setting, #define NM_SETTING_PARAM_GENDATA_BACKED (1 << (7 + G_PARAM_USER_SHIFT)) -GVariant *_nm_setting_get_deprecated_virtual_interface_name (const NMSettInfoSetting *sett_info, - guint property_idx, - NMConnection *connection, - NMSetting *setting, - NMConnectionSerializationFlags flags, - const NMConnectionSerializationOptions *options); +extern const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_interface_name; +extern const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_ignore_i; +extern const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_ignore_u; + +extern const NMSettInfoPropertType nm_sett_info_propert_type_plain_i; +extern const NMSettInfoPropertType nm_sett_info_propert_type_plain_u; NMSettingVerifyResult _nm_setting_verify (NMSetting *setting, NMConnection *connection, @@ -165,6 +165,12 @@ void _properties_override_add_struct (GArray *properties_override, (_properties_override_add_struct (properties_override, \ NM_SETT_INFO_PROPERTY (__VA_ARGS__))) +#define _properties_override_add_gobj(properties_override, p_param_spec, p_property_type) \ + _properties_override_add ((properties_override), .param_spec = (p_param_spec), .property_type = (p_property_type)) + +#define _properties_override_add_virt(properties_override, p_name, p_property_type) \ + _properties_override_add ((properties_override), .name = (p_name), .property_type = (p_property_type)) + /** * _properties_override_add_dbus_only: * @properties_override: an array collecting the overrides diff --git a/libnm-core/nm-setting-team-port.c b/libnm-core/nm-setting-team-port.c index 5fb2966b78..aff9c94067 100644 --- a/libnm-core/nm-setting-team-port.c +++ b/libnm-core/nm-setting-team-port.c @@ -536,15 +536,6 @@ nm_setting_team_port_class_init (NMSettingTeamPortClass *klass) setting_class->duplicate_copy_properties = duplicate_copy_properties; setting_class->init_from_dbus = init_from_dbus; -#define _property_override(_properties_override, _param_spec, _variant_type, _is_link_watcher) \ - _properties_override_add ((_properties_override), \ - .param_spec = (_param_spec), \ - .property_type = NM_SETT_INFO_PROPERT_TYPE ( \ - .dbus_type = NM_G_VARIANT_TYPE (""_variant_type""), \ - .to_dbus_fcn = _nm_team_settings_property_to_dbus, \ - .gprop_from_dbus_fcn = ((_is_link_watcher) ? _nm_team_settings_property_from_dbus_link_watchers : NULL), \ - )) - /** * NMSettingTeamPort:config: * @@ -565,7 +556,7 @@ nm_setting_team_port_class_init (NMSettingTeamPortClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_CONFIG], "s", FALSE); + _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_CONFIG], &nm_sett_info_propert_type_team_s); /** * NMSettingTeamPort:queue-id: @@ -580,7 +571,7 @@ nm_setting_team_port_class_init (NMSettingTeamPortClass *klass) G_MININT32, G_MAXINT32, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_PORT_QUEUE_ID], "i", FALSE); + _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_PORT_QUEUE_ID], &nm_sett_info_propert_type_team_i); /** * NMSettingTeamPort:prio: @@ -594,7 +585,7 @@ nm_setting_team_port_class_init (NMSettingTeamPortClass *klass) G_MININT32, G_MAXINT32, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_PORT_PRIO], "i", FALSE); + _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_PORT_PRIO], &nm_sett_info_propert_type_team_i); /** * NMSettingTeamPort:sticky: @@ -608,7 +599,7 @@ nm_setting_team_port_class_init (NMSettingTeamPortClass *klass) FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_PORT_STICKY], "b", FALSE); + _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_PORT_STICKY], &nm_sett_info_propert_type_team_b); /** * NMSettingTeamPort:lacp-prio: @@ -622,7 +613,7 @@ nm_setting_team_port_class_init (NMSettingTeamPortClass *klass) G_MININT32, G_MAXINT32, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_PORT_LACP_PRIO], "i", FALSE); + _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_PORT_LACP_PRIO], &nm_sett_info_propert_type_team_i); /** * NMSettingTeamPort:lacp-key: @@ -636,7 +627,7 @@ nm_setting_team_port_class_init (NMSettingTeamPortClass *klass) G_MININT32, G_MAXINT32, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_PORT_LACP_KEY], "i", FALSE); + _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_PORT_LACP_KEY], &nm_sett_info_propert_type_team_i); /** * NMSettingTeamPort:link-watchers: (type GPtrArray(NMTeamLinkWatcher)) @@ -657,7 +648,7 @@ nm_setting_team_port_class_init (NMSettingTeamPortClass *klass) G_TYPE_PTR_ARRAY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_LINK_WATCHERS], "aa{sv}", TRUE); + _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_LINK_WATCHERS], &nm_sett_info_propert_type_team_link_watchers); g_object_class_install_properties (object_class, G_N_ELEMENTS (obj_properties), obj_properties); diff --git a/libnm-core/nm-setting-team.c b/libnm-core/nm-setting-team.c index 4325abfc8b..56bdc280ae 100644 --- a/libnm-core/nm-setting-team.c +++ b/libnm-core/nm-setting-team.c @@ -1483,15 +1483,6 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) setting_class->duplicate_copy_properties = duplicate_copy_properties; setting_class->init_from_dbus = init_from_dbus; -#define _property_override(_properties_override, _param_spec, _variant_type, _is_link_watcher) \ - _properties_override_add ((_properties_override), \ - .param_spec = (_param_spec), \ - .property_type = NM_SETT_INFO_PROPERT_TYPE ( \ - .dbus_type = NM_G_VARIANT_TYPE (""_variant_type""), \ - .to_dbus_fcn = _nm_team_settings_property_to_dbus, \ - .gprop_from_dbus_fcn = ((_is_link_watcher) ? _nm_team_settings_property_from_dbus_link_watchers : NULL), \ - )) - /** * NMSettingTeam:config: * @@ -1512,7 +1503,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_CONFIG], "s", FALSE); + _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_CONFIG], &nm_sett_info_propert_type_team_s); /** * NMSettingTeam:notify-peers-count: @@ -1526,7 +1517,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) G_MININT32, G_MAXINT32, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_NOTIFY_PEERS_COUNT], "i", FALSE); + _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_NOTIFY_PEERS_COUNT], &nm_sett_info_propert_type_team_i); /** * NMSettingTeam:notify-peers-interval: @@ -1540,7 +1531,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) G_MININT32, G_MAXINT32, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_NOTIFY_PEERS_INTERVAL], "i", FALSE); + _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_NOTIFY_PEERS_INTERVAL], &nm_sett_info_propert_type_team_i); /** * NMSettingTeam:mcast-rejoin-count: @@ -1554,7 +1545,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) G_MININT32, G_MAXINT32, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_MCAST_REJOIN_COUNT], "i", FALSE); + _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_MCAST_REJOIN_COUNT], &nm_sett_info_propert_type_team_i); /** * NMSettingTeam:mcast-rejoin-interval: @@ -1568,7 +1559,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) G_MININT32, G_MAXINT32, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_MCAST_REJOIN_INTERVAL], "i", FALSE); + _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_MCAST_REJOIN_INTERVAL], &nm_sett_info_propert_type_team_i); /** * NMSettingTeam:runner: @@ -1584,7 +1575,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER], "s", FALSE); + _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER], &nm_sett_info_propert_type_team_s); /** * NMSettingTeam:runner-hwaddr-policy: @@ -1598,7 +1589,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_HWADDR_POLICY], "s", FALSE); + _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_HWADDR_POLICY], &nm_sett_info_propert_type_team_s); /** * NMSettingTeam:runner-tx-hash: @@ -1613,7 +1604,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_TX_HASH], "as", FALSE); + _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_TX_HASH], &nm_sett_info_propert_type_team_as); /** * NMSettingTeam:runner-tx-balancer: @@ -1627,7 +1618,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_TX_BALANCER], "s", FALSE); + _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_TX_BALANCER], &nm_sett_info_propert_type_team_s); /** * NMSettingTeam:runner-tx-balancer-interval: @@ -1641,7 +1632,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) G_MININT32, G_MAXINT32, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_TX_BALANCER_INTERVAL], "i", FALSE); + _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_TX_BALANCER_INTERVAL], &nm_sett_info_propert_type_team_i); /** * NMSettingTeam:runner-active: @@ -1655,7 +1646,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) TRUE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_ACTIVE], "b", FALSE); + _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_ACTIVE], &nm_sett_info_propert_type_team_b); /** * NMSettingTeam:runner-fast-rate: @@ -1669,7 +1660,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_FAST_RATE], "b", FALSE); + _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_FAST_RATE], &nm_sett_info_propert_type_team_b); /** * NMSettingTeam:runner-sys-prio: @@ -1683,7 +1674,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) G_MININT32, G_MAXINT32, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_SYS_PRIO], "i", FALSE); + _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_SYS_PRIO], &nm_sett_info_propert_type_team_i); /** * NMSettingTeam:runner-min-ports: @@ -1697,7 +1688,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) G_MININT32, G_MAXINT32, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_MIN_PORTS], "i", FALSE); + _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_MIN_PORTS], &nm_sett_info_propert_type_team_i); /** * NMSettingTeam:runner-agg-select-policy: @@ -1711,7 +1702,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_AGG_SELECT_POLICY], "s", FALSE); + _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_AGG_SELECT_POLICY], &nm_sett_info_propert_type_team_s); /** * NMSettingTeam:link-watchers: (type GPtrArray(NMTeamLinkWatcher)) @@ -1732,7 +1723,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) G_TYPE_PTR_ARRAY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _property_override (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_LINK_WATCHERS], "aa{sv}", TRUE); + _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_LINK_WATCHERS], &nm_sett_info_propert_type_team_link_watchers); /* ---dbus--- * property: interface-name @@ -1742,11 +1733,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) * team's interface name. * ---end--- */ - _properties_override_add_dbus_only (properties_override, - "interface-name", - G_VARIANT_TYPE_STRING, - _nm_setting_get_deprecated_virtual_interface_name, - NULL); + _properties_override_add_virt (properties_override, "interface-name", &nm_sett_info_propert_type_deprecated_interface_name); g_object_class_install_properties (object_class, G_N_ELEMENTS (obj_properties), obj_properties); diff --git a/libnm-core/nm-setting-user.c b/libnm-core/nm-setting-user.c index b252a1591b..1763df5ea6 100644 --- a/libnm-core/nm-setting-user.c +++ b/libnm-core/nm-setting-user.c @@ -571,12 +571,7 @@ nm_setting_user_class_init (NMSettingUserClass *klass) G_TYPE_HASH_TABLE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_transform (properties_override, - obj_properties[PROP_DATA], - NM_G_VARIANT_TYPE ("a{ss}"), - _nm_utils_strdict_to_dbus, - _nm_utils_strdict_from_dbus); + _properties_override_add_gobj (properties_override, obj_properties[PROP_DATA], &nm_sett_info_propert_type_strdict); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/libnm-core/nm-setting-vlan.c b/libnm-core/nm-setting-vlan.c index c57d8536a8..111e15ccfe 100644 --- a/libnm-core/nm-setting-vlan.c +++ b/libnm-core/nm-setting-vlan.c @@ -974,11 +974,7 @@ nm_setting_vlan_class_init (NMSettingVlanClass *klass) * vlan's interface name. * ---end--- */ - _properties_override_add_dbus_only (properties_override, - "interface-name", - G_VARIANT_TYPE_STRING, - _nm_setting_get_deprecated_virtual_interface_name, - NULL); + _properties_override_add_virt (properties_override, "interface-name", &nm_sett_info_propert_type_deprecated_interface_name); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/libnm-core/nm-setting-vpn.c b/libnm-core/nm-setting-vpn.c index da1b8e2cad..d51843339f 100644 --- a/libnm-core/nm-setting-vpn.c +++ b/libnm-core/nm-setting-vpn.c @@ -1129,12 +1129,7 @@ nm_setting_vpn_class_init (NMSettingVpnClass *klass) G_TYPE_HASH_TABLE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_transform (properties_override, - obj_properties[PROP_DATA], - NM_G_VARIANT_TYPE ("a{ss}"), - _nm_utils_strdict_to_dbus, - _nm_utils_strdict_from_dbus); + _properties_override_add_gobj (properties_override, obj_properties[PROP_DATA], &nm_sett_info_propert_type_strdict); /** * NMSettingVpn:secrets: (type GHashTable(utf8,utf8)): @@ -1156,7 +1151,6 @@ nm_setting_vpn_class_init (NMSettingVpnClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_SECRET | G_PARAM_STATIC_STRINGS); - _properties_override_add_override (properties_override, obj_properties[PROP_SECRETS], NM_G_VARIANT_TYPE ("a{ss}"), diff --git a/libnm-core/nm-setting-wimax.c b/libnm-core/nm-setting-wimax.c index 13ada1f56e..52f7d827bb 100644 --- a/libnm-core/nm-setting-wimax.c +++ b/libnm-core/nm-setting-wimax.c @@ -236,12 +236,7 @@ nm_setting_wimax_class_init (NMSettingWimaxClass *klass) NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_transform (properties_override, - obj_properties[PROP_MAC_ADDRESS], - G_VARIANT_TYPE_BYTESTRING, - _nm_utils_hwaddr_to_dbus, - _nm_utils_hwaddr_from_dbus); + _properties_override_add_gobj (properties_override, obj_properties[PROP_MAC_ADDRESS], &nm_sett_info_propert_type_mac_addrees); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/libnm-core/nm-setting-wired.c b/libnm-core/nm-setting-wired.c index 2b16acaa8f..fdd4dd36f6 100644 --- a/libnm-core/nm-setting-wired.c +++ b/libnm-core/nm-setting-wired.c @@ -1344,12 +1344,7 @@ nm_setting_wired_class_init (NMSettingWiredClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_transform (properties_override, - obj_properties[PROP_MAC_ADDRESS], - G_VARIANT_TYPE_BYTESTRING, - _nm_utils_hwaddr_to_dbus, - _nm_utils_hwaddr_from_dbus); + _properties_override_add_gobj (properties_override, obj_properties[PROP_MAC_ADDRESS], &nm_sett_info_propert_type_mac_addrees); /** * NMSettingWired:cloned-mac-address: @@ -1400,13 +1395,7 @@ nm_setting_wired_class_init (NMSettingWiredClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_override (properties_override, - obj_properties[PROP_CLONED_MAC_ADDRESS], - G_VARIANT_TYPE_BYTESTRING, - _nm_utils_hwaddr_cloned_get, - _nm_utils_hwaddr_cloned_set, - _nm_utils_hwaddr_cloned_not_set); + _properties_override_add_gobj (properties_override, obj_properties[PROP_CLONED_MAC_ADDRESS], &nm_sett_info_propert_type_cloned_mac_address); /* ---dbus--- * property: assigned-mac-address @@ -1420,11 +1409,7 @@ nm_setting_wired_class_init (NMSettingWiredClass *klass) * "cloned-mac-address". * ---end--- */ - _properties_override_add_dbus_only (properties_override, - "assigned-mac-address", - G_VARIANT_TYPE_STRING, - _nm_utils_hwaddr_cloned_data_synth, - _nm_utils_hwaddr_cloned_data_set); + _properties_override_add_virt (properties_override, "assigned-mac-address", &nm_sett_info_propert_type_assigned_mac_address); /** * NMSettingWired:generate-mac-address-mask: @@ -1588,12 +1573,7 @@ nm_setting_wired_class_init (NMSettingWiredClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_transform (properties_override, - obj_properties[PROP_S390_OPTIONS], - NM_G_VARIANT_TYPE ("a{ss}"), - _nm_utils_strdict_to_dbus, - _nm_utils_strdict_from_dbus); + _properties_override_add_gobj (properties_override, obj_properties[PROP_S390_OPTIONS], &nm_sett_info_propert_type_strdict); /** * NMSettingWired:wake-on-lan: diff --git a/libnm-core/nm-setting-wireless.c b/libnm-core/nm-setting-wireless.c index f72e1677aa..43fa7b80d7 100644 --- a/libnm-core/nm-setting-wireless.c +++ b/libnm-core/nm-setting-wireless.c @@ -1376,12 +1376,7 @@ nm_setting_wireless_class_init (NMSettingWirelessClass *klass) NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_transform (properties_override, - obj_properties[PROP_BSSID], - G_VARIANT_TYPE_BYTESTRING, - _nm_utils_hwaddr_to_dbus, - _nm_utils_hwaddr_from_dbus); + _properties_override_add_gobj (properties_override, obj_properties[PROP_BSSID], &nm_sett_info_propert_type_mac_addrees); /** * NMSettingWireless:rate: @@ -1455,12 +1450,7 @@ nm_setting_wireless_class_init (NMSettingWirelessClass *klass) NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_transform (properties_override, - obj_properties[PROP_MAC_ADDRESS], - G_VARIANT_TYPE_BYTESTRING, - _nm_utils_hwaddr_to_dbus, - _nm_utils_hwaddr_from_dbus); + _properties_override_add_gobj (properties_override, obj_properties[PROP_MAC_ADDRESS], &nm_sett_info_propert_type_mac_addrees); /** * NMSettingWireless:cloned-mac-address: @@ -1510,13 +1500,7 @@ nm_setting_wireless_class_init (NMSettingWirelessClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_override (properties_override, - obj_properties[PROP_CLONED_MAC_ADDRESS], - G_VARIANT_TYPE_BYTESTRING, - _nm_utils_hwaddr_cloned_get, - _nm_utils_hwaddr_cloned_set, - _nm_utils_hwaddr_cloned_not_set); + _properties_override_add_gobj (properties_override, obj_properties[PROP_CLONED_MAC_ADDRESS], &nm_sett_info_propert_type_cloned_mac_address); /* ---dbus--- * property: assigned-mac-address @@ -1530,11 +1514,7 @@ nm_setting_wireless_class_init (NMSettingWirelessClass *klass) * "cloned-mac-address". * ---end--- */ - _properties_override_add_dbus_only (properties_override, - "assigned-mac-address", - G_VARIANT_TYPE_STRING, - _nm_utils_hwaddr_cloned_data_synth, - _nm_utils_hwaddr_cloned_data_set); + _properties_override_add_virt (properties_override, "assigned-mac-address", &nm_sett_info_propert_type_assigned_mac_address); /** * NMSettingWireless:generate-mac-address-mask: diff --git a/libnm-core/nm-setting.c b/libnm-core/nm-setting.c index 23b9d09505..0b63c29a16 100644 --- a/libnm-core/nm-setting.c +++ b/libnm-core/nm-setting.c @@ -406,9 +406,9 @@ _nm_setting_class_commit_full (NMSettingClass *setting_class, else if (vtype == G_TYPE_UCHAR) p->property_type = NM_SETT_INFO_PROPERT_TYPE (.dbus_type = G_VARIANT_TYPE_BYTE); else if (vtype == G_TYPE_INT) - p->property_type = NM_SETT_INFO_PROPERT_TYPE (.dbus_type = G_VARIANT_TYPE_INT32); + p->property_type = &nm_sett_info_propert_type_plain_i; else if (vtype == G_TYPE_UINT) - p->property_type = NM_SETT_INFO_PROPERT_TYPE (.dbus_type = G_VARIANT_TYPE_UINT32); + p->property_type = &nm_sett_info_propert_type_plain_u; else if (vtype == G_TYPE_INT64) p->property_type = NM_SETT_INFO_PROPERT_TYPE (.dbus_type = G_VARIANT_TYPE_INT64); else if (vtype == G_TYPE_UINT64) @@ -2301,7 +2301,7 @@ nm_setting_to_string (NMSetting *setting) return g_string_free (string, FALSE); } -GVariant * +static GVariant * _nm_setting_get_deprecated_virtual_interface_name (const NMSettInfoSetting *sett_info, guint property_idx, NMConnection *connection, @@ -2324,6 +2324,29 @@ _nm_setting_get_deprecated_virtual_interface_name (const NMSettInfoSetting *sett return NULL; } +const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_interface_name = { + .dbus_type = G_VARIANT_TYPE_STRING, + .to_dbus_fcn = _nm_setting_get_deprecated_virtual_interface_name, +}; + +const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_ignore_i = { + .dbus_type = G_VARIANT_TYPE_INT32, + /* No functions set. This property type is to silently ignore the value on D-Bus. */ +}; + +const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_ignore_u = { + .dbus_type = G_VARIANT_TYPE_UINT32, + /* No functions set. This property type is to silently ignore the value on D-Bus. */ +}; + +const NMSettInfoPropertType nm_sett_info_propert_type_plain_i = { + .dbus_type = G_VARIANT_TYPE_INT32, +}; + +const NMSettInfoPropertType nm_sett_info_propert_type_plain_u = { + .dbus_type = G_VARIANT_TYPE_UINT32, +}; + /*****************************************************************************/ static GenData * diff --git a/libnm-core/nm-team-utils.c b/libnm-core/nm-team-utils.c index 78c9182609..0be33b0383 100644 --- a/libnm-core/nm-team-utils.c +++ b/libnm-core/nm-team-utils.c @@ -2420,7 +2420,7 @@ _nm_setting_get_team_setting (struct _NMSetting *setting) return _nm_setting_team_port_get_team_setting (NM_SETTING_TEAM_PORT (setting)); } -GVariant * +static GVariant * _nm_team_settings_property_to_dbus (const NMSettInfoSetting *sett_info, guint property_idx, NMConnection *connection, @@ -2467,7 +2467,7 @@ _nm_team_settings_property_to_dbus (const NMSettInfoSetting *sett_info, return NULL; } -void +static void _nm_team_settings_property_from_dbus_link_watchers (GVariant *dbus_value, GValue *prop_value) { @@ -2475,6 +2475,32 @@ _nm_team_settings_property_from_dbus_link_watchers (GVariant *dbus_value, _nm_utils_team_link_watchers_from_variant (dbus_value, FALSE, NULL)); } +const NMSettInfoPropertType nm_sett_info_propert_type_team_b = { + .dbus_type = G_VARIANT_TYPE_BOOLEAN, + .to_dbus_fcn = _nm_team_settings_property_to_dbus, +}; + +const NMSettInfoPropertType nm_sett_info_propert_type_team_i = { + .dbus_type = G_VARIANT_TYPE_INT32, + .to_dbus_fcn = _nm_team_settings_property_to_dbus, +}; + +const NMSettInfoPropertType nm_sett_info_propert_type_team_s = { + .dbus_type = G_VARIANT_TYPE_STRING, + .to_dbus_fcn = _nm_team_settings_property_to_dbus, +}; + +const NMSettInfoPropertType nm_sett_info_propert_type_team_as = { + .dbus_type = NM_G_VARIANT_TYPE ("as"), + .to_dbus_fcn = _nm_team_settings_property_to_dbus, +}; + +const NMSettInfoPropertType nm_sett_info_propert_type_team_link_watchers = { + .dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"), + .to_dbus_fcn = _nm_team_settings_property_to_dbus, + .gprop_from_dbus_fcn = _nm_team_settings_property_from_dbus_link_watchers, +}; + /*****************************************************************************/ NMTeamSetting * diff --git a/libnm-core/nm-team-utils.h b/libnm-core/nm-team-utils.h index 8d6b9985e9..6cab42d46a 100644 --- a/libnm-core/nm-team-utils.h +++ b/libnm-core/nm-team-utils.h @@ -11,6 +11,7 @@ #endif #include "nm-glib-aux/nm-value-type.h" +#include "nm-core-internal.h" struct _NMSetting; @@ -277,17 +278,10 @@ NMTeamSetting *_nm_setting_get_team_setting (struct _NMSetting *setting); /*****************************************************************************/ -#include "nm-connection.h" -#include "nm-core-internal.h" - -GVariant *_nm_team_settings_property_to_dbus (const NMSettInfoSetting *sett_info, - guint property_idx, - NMConnection *connection, - NMSetting *setting, - NMConnectionSerializationFlags flags, - const NMConnectionSerializationOptions *options); - -void _nm_team_settings_property_from_dbus_link_watchers (GVariant *dbus_value, - GValue *prop_value); +extern const NMSettInfoPropertType nm_sett_info_propert_type_team_b; +extern const NMSettInfoPropertType nm_sett_info_propert_type_team_i; +extern const NMSettInfoPropertType nm_sett_info_propert_type_team_s; +extern const NMSettInfoPropertType nm_sett_info_propert_type_team_as; +extern const NMSettInfoPropertType nm_sett_info_propert_type_team_link_watchers; #endif /* __NM_TEAM_UITLS_H__ */ diff --git a/libnm-core/nm-utils-private.h b/libnm-core/nm-utils-private.h index 8bda7a5583..72833c2650 100644 --- a/libnm-core/nm-utils-private.h +++ b/libnm-core/nm-utils-private.h @@ -47,41 +47,16 @@ gboolean _nm_utils_wps_method_validate (NMSettingWirelessSecurityWpsMethod wps_m /* D-Bus transform funcs */ -GVariant *_nm_utils_hwaddr_cloned_get (const NMSettInfoSetting *sett_info, - guint property_idx, - NMConnection *connection, - NMSetting *setting, - NMConnectionSerializationFlags flags, - const NMConnectionSerializationOptions *options); -gboolean _nm_utils_hwaddr_cloned_set (NMSetting *setting, - GVariant *connection_dict, - const char *property, - GVariant *value, - NMSettingParseFlags parse_flags, - GError **error); -gboolean _nm_utils_hwaddr_cloned_not_set (NMSetting *setting, - GVariant *connection_dict, - const char *property, - NMSettingParseFlags parse_flags, - GError **error); -GVariant * _nm_utils_hwaddr_cloned_data_synth (const NMSettInfoSetting *sett_info, - guint property_idx, - NMConnection *connection, - NMSetting *setting, - NMConnectionSerializationFlags flags, - const NMConnectionSerializationOptions *options); -gboolean _nm_utils_hwaddr_cloned_data_set (NMSetting *setting, - GVariant *connection_dict, - const char *property, - GVariant *value, - NMSettingParseFlags parse_flags, - GError **error); +extern const NMSettInfoPropertType nm_sett_info_propert_type_strdict; -GVariant * _nm_utils_hwaddr_to_dbus (const GValue *prop_value); -void _nm_utils_hwaddr_from_dbus (GVariant *dbus_value, - GValue *prop_value); +extern const NMSettInfoPropertType nm_sett_info_propert_type_mac_addrees; + +extern const NMSettInfoPropertType nm_sett_info_propert_type_cloned_mac_address; + +extern const NMSettInfoPropertType nm_sett_info_propert_type_assigned_mac_address; + +extern const NMSettInfoPropertType nm_sett_info_propert_type_bridge_vlans; -GVariant * _nm_utils_strdict_to_dbus (const GValue *prop_value); void _nm_utils_strdict_from_dbus (GVariant *dbus_value, GValue *prop_value); @@ -97,19 +72,6 @@ void _nm_utils_format_variant_attributes_full (GString *str, char key_value_separator); gboolean _nm_sriov_vf_parse_vlans (NMSriovVF *vf, const char *str, GError **error); -GVariant * _nm_utils_bridge_vlans_to_dbus (const NMSettInfoSetting *sett_info, - guint property_idx, - NMConnection *connection, - NMSetting *setting, - NMConnectionSerializationFlags flags, - const NMConnectionSerializationOptions *options); - -gboolean _nm_utils_bridge_vlans_from_dbus (NMSetting *setting, - GVariant *connection_dict, - const char *property, - GVariant *value, - NMSettingParseFlags parse_flags, - GError **error); gboolean _nm_utils_bridge_vlan_verify_list (GPtrArray *vlans, gboolean check_normalizable, GError **error, diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index e62bd8d097..a73deda72f 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -800,7 +800,7 @@ _nm_utils_hash_values_to_slist (GHashTable *hash) return list; } -GVariant * +static GVariant * _nm_utils_strdict_to_dbus (const GValue *prop_value) { GHashTable *hash; @@ -868,6 +868,12 @@ _nm_utils_strdict_from_dbus (GVariant *dbus_value, g_value_take_boxed (prop_value, hash); } +const NMSettInfoPropertType nm_sett_info_propert_type_strdict = { + .dbus_type = NM_G_VARIANT_TYPE ("a{ss}"), + .gprop_to_dbus_fcn = _nm_utils_strdict_to_dbus, + .gprop_from_dbus_fcn = _nm_utils_strdict_from_dbus, +}; + GHashTable * _nm_utils_copy_strdict (GHashTable *strdict) { @@ -4311,7 +4317,7 @@ _nm_utils_hwaddr_to_dbus_impl (const char *str) return g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, buf, len, 1); } -GVariant * +static GVariant * _nm_utils_hwaddr_cloned_get (const NMSettInfoSetting *sett_info, guint property_idx, NMConnection *connection, @@ -4327,7 +4333,7 @@ _nm_utils_hwaddr_cloned_get (const NMSettInfoSetting *sett_info, return _nm_utils_hwaddr_to_dbus_impl (addr); } -gboolean +static gboolean _nm_utils_hwaddr_cloned_set (NMSetting *setting, GVariant *connection_dict, const char *property, @@ -4359,7 +4365,7 @@ _nm_utils_hwaddr_cloned_set (NMSetting *setting, return TRUE; } -gboolean +static gboolean _nm_utils_hwaddr_cloned_not_set (NMSetting *setting, GVariant *connection_dict, const char *property, @@ -4370,7 +4376,14 @@ _nm_utils_hwaddr_cloned_not_set (NMSetting *setting, return TRUE; } -GVariant * +const NMSettInfoPropertType nm_sett_info_propert_type_cloned_mac_address = { + .dbus_type = G_VARIANT_TYPE_BYTESTRING, + .to_dbus_fcn = _nm_utils_hwaddr_cloned_get, + .from_dbus_fcn = _nm_utils_hwaddr_cloned_set, + .missing_from_dbus_fcn = _nm_utils_hwaddr_cloned_not_set, +}; + +static GVariant * _nm_utils_hwaddr_cloned_data_synth (const NMSettInfoSetting *sett_info, guint property_idx, NMConnection *connection, @@ -4409,7 +4422,7 @@ _nm_utils_hwaddr_cloned_data_synth (const NMSettInfoSetting *sett_info, : NULL; } -gboolean +static gboolean _nm_utils_hwaddr_cloned_data_set (NMSetting *setting, GVariant *connection_dict, const char *property, @@ -4429,13 +4442,19 @@ _nm_utils_hwaddr_cloned_data_set (NMSetting *setting, return TRUE; } -GVariant * +const NMSettInfoPropertType nm_sett_info_propert_type_assigned_mac_address = { + .dbus_type = G_VARIANT_TYPE_STRING, + .to_dbus_fcn = _nm_utils_hwaddr_cloned_data_synth, + .from_dbus_fcn = _nm_utils_hwaddr_cloned_data_set, +}; + +static GVariant * _nm_utils_hwaddr_to_dbus (const GValue *prop_value) { return _nm_utils_hwaddr_to_dbus_impl (g_value_get_string (prop_value)); } -void +static void _nm_utils_hwaddr_from_dbus (GVariant *dbus_value, GValue *prop_value) { @@ -4447,6 +4466,12 @@ _nm_utils_hwaddr_from_dbus (GVariant *dbus_value, g_value_take_string (prop_value, str); } +const NMSettInfoPropertType nm_sett_info_propert_type_mac_addrees = { + .dbus_type = G_VARIANT_TYPE_BYTESTRING, + .gprop_to_dbus_fcn = _nm_utils_hwaddr_to_dbus, + .gprop_from_dbus_fcn = _nm_utils_hwaddr_from_dbus, +}; + /*****************************************************************************/ /* Validate secret-flags. Most settings don't validate them, which is a bug. @@ -5895,7 +5920,7 @@ nm_utils_base64secret_normalize (const char *base64_key, return TRUE; } -GVariant * +static GVariant * _nm_utils_bridge_vlans_to_dbus (const NMSettInfoSetting *sett_info, guint property_idx, NMConnection *connection, @@ -5937,7 +5962,7 @@ _nm_utils_bridge_vlans_to_dbus (const NMSettInfoSetting *sett_info, return g_variant_builder_end (&builder); } -gboolean +static gboolean _nm_utils_bridge_vlans_from_dbus (NMSetting *setting, GVariant *connection_dict, const char *property, @@ -5991,6 +6016,12 @@ _nm_utils_bridge_vlans_from_dbus (NMSetting *setting, return TRUE; } +const NMSettInfoPropertType nm_sett_info_propert_type_bridge_vlans = { + .dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"), + .to_dbus_fcn = _nm_utils_bridge_vlans_to_dbus, + .from_dbus_fcn = _nm_utils_bridge_vlans_from_dbus, +}; + gboolean _nm_utils_bridge_vlan_verify_list (GPtrArray *vlans, gboolean check_normalizable, diff --git a/libnm-core/tests/test-setting.c b/libnm-core/tests/test-setting.c index d843f58774..e6a7e900b2 100644 --- a/libnm-core/tests/test-setting.c +++ b/libnm-core/tests/test-setting.c @@ -3318,14 +3318,63 @@ test_empty_setting (void) /*****************************************************************************/ +static guint +_PROP_IDX_PACK (NMMetaSettingType meta_type, + guint idx) +{ + return (((guint) meta_type) & 0xFFu) + | (idx << 8); +} + +static const char * +_PROP_IDX_OWNER (GHashTable *h_property_types, + const NMSettInfoPropertType *property_type) +{ + const NMSettInfoSetting *sett_info_settings = nmtst_sett_info_settings (); + const NMSettInfoSetting *sis; + const NMMetaSettingInfo *msi; + GArray *arr; + guint idx; + NMMetaSettingType meta_type; + guint prop_idx; + char sbuf[300]; + + g_assert (h_property_types); + g_assert (property_type); + + arr = g_hash_table_lookup (h_property_types, property_type); + + g_assert (arr); + g_assert (arr->len > 0); + + idx = g_array_index (arr, guint, 0); + + meta_type = (idx & 0xFFu); + prop_idx = idx >> 8; + + g_assert (meta_type < _NM_META_SETTING_TYPE_NUM); + + sis = &sett_info_settings[meta_type]; + msi = &nm_meta_setting_infos[meta_type]; + + g_assert (prop_idx < sis->property_infos_len); + + nm_sprintf_buf (sbuf, "%s.%s", msi->setting_name, sis->property_infos[prop_idx].name); + + return g_intern_string (sbuf); +} + static void test_setting_metadata (void) { const NMSettInfoSetting *sett_info_settings = nmtst_sett_info_settings (); NMMetaSettingType meta_type; + gs_unref_hashtable GHashTable *h_property_types = NULL; G_STATIC_ASSERT (_NM_META_SETTING_TYPE_NUM == NM_META_SETTING_TYPE_UNKNOWN); + h_property_types = g_hash_table_new_full (nm_direct_hash, NULL, NULL, (GDestroyNotify) g_array_unref); + for (meta_type = 0; meta_type < _NM_META_SETTING_TYPE_NUM; meta_type++) { const NMMetaSettingInfo *msi = &nm_meta_setting_infos[meta_type]; nm_auto_unref_gtypeclass NMSettingClass *klass = NULL; @@ -3348,6 +3397,8 @@ test_setting_metadata (void) klass = g_type_class_ref (gtype); g_assert (klass); g_assert (NM_IS_SETTING_CLASS (klass)); + + g_assert (msi == klass->setting_info); } g_assert (sett_info_settings); @@ -3381,6 +3432,8 @@ test_setting_metadata (void) for (prop_idx = 0; prop_idx < sis->property_infos_len; prop_idx++) { const NMSettInfoProperty *sip = &sis->property_infos[prop_idx]; + GArray *property_types_data; + guint prop_idx_val; g_assert (sip->name); @@ -3397,6 +3450,15 @@ test_setting_metadata (void) if (!g_hash_table_insert (h_properties, (char *) sip->name, sip->param_spec)) g_assert_not_reached (); + property_types_data = g_hash_table_lookup (h_property_types, sip->property_type); + if (!property_types_data) { + property_types_data = g_array_new (FALSE, FALSE, sizeof (guint)); + if (!g_hash_table_insert (h_property_types, (gpointer) sip->property_type, property_types_data)) + g_assert_not_reached (); + } + prop_idx_val = _PROP_IDX_PACK (meta_type, prop_idx); + g_array_append_val (property_types_data, prop_idx_val); + if (sip->param_spec) { nm_auto_unset_gvalue GValue val = G_VALUE_INIT; @@ -3473,6 +3535,51 @@ test_setting_metadata (void) } else g_assert_cmpint (meta_type, !=, NM_META_SETTING_TYPE_ETHTOOL); } + + { + gs_free NMSettInfoPropertType **a_property_types = NULL; + guint a_property_types_len; + guint prop_idx; + guint prop_idx_2; + + a_property_types = (NMSettInfoPropertType **) g_hash_table_get_keys_as_array (h_property_types, &a_property_types_len); + + for (prop_idx = 0; prop_idx < a_property_types_len; prop_idx++) { + const NMSettInfoPropertType *pt = a_property_types[prop_idx]; + + for (prop_idx_2 = prop_idx + 1; prop_idx_2 < a_property_types_len; prop_idx_2++) { + const NMSettInfoPropertType *pt_2 = a_property_types[prop_idx_2]; + + if ( !g_variant_type_equal (pt->dbus_type, pt_2->dbus_type) + || pt->to_dbus_fcn != pt_2->to_dbus_fcn + || pt->from_dbus_fcn != pt_2->from_dbus_fcn + || pt->missing_from_dbus_fcn != pt_2->missing_from_dbus_fcn + || pt->gprop_to_dbus_fcn != pt_2->gprop_to_dbus_fcn + || pt->gprop_from_dbus_fcn != pt_2->gprop_from_dbus_fcn) + continue; + + if ( (pt == &nm_sett_info_propert_type_plain_i && pt_2 == &nm_sett_info_propert_type_deprecated_ignore_i) + || (pt_2 == &nm_sett_info_propert_type_plain_i && pt == &nm_sett_info_propert_type_deprecated_ignore_i) + || (pt == &nm_sett_info_propert_type_plain_u && pt_2 == &nm_sett_info_propert_type_deprecated_ignore_u) + || (pt_2 == &nm_sett_info_propert_type_plain_u && pt == &nm_sett_info_propert_type_deprecated_ignore_u)) { + /* These are known to be duplicated. This is the case for + * "gsm.network-type" and plain properies like "802-11-wireless-security.fils" ("i" D-Bus type) + * "gsm.allowed-bands" and plain properies like "802-11-olpc-mesh.channel" ("u" D-Bus type) + * While the content/behaviour of the property types are identical, their purpose + * is different. So allowe them. + */ + continue; + } + + /* the property-types with same content should all be shared. Here we have two that + * are the same content, but different instances. Bug. */ + g_error ("The identical property type for D-Bus type \"%s\" is used by: %s and %s", + (const char *) pt->dbus_type, + _PROP_IDX_OWNER (h_property_types, pt), + _PROP_IDX_OWNER (h_property_types, pt_2)); + } + } + } } /*****************************************************************************/ From 0129954203fcd7b4c0837d76a94aa63956b06e31 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 22 Sep 2019 14:30:41 +0200 Subject: [PATCH 05/12] libnm: replace _properties_override_add_dbus_only() with _properties_override_add_virt() We have too many _properties_override_add*() variants. They basically are all the same. Drop _properties_override_add_dbus_only() and use _properties_override_add_virt() instead. Also, I am always confused by the term "synth". We shouldn't treat non-GObject-based properties as somehow odd that need to be synthesized. --- libnm-core/nm-setting-ip-config.c | 12 +++++----- libnm-core/nm-setting-ip4-config.c | 36 +++++++++++++++++------------- libnm-core/nm-setting-ip6-config.c | 24 +++++++++++--------- libnm-core/nm-setting-private.h | 34 ---------------------------- libnm-core/nm-setting-wireguard.c | 12 +++++----- libnm-core/nm-setting-wireless.c | 11 ++++----- 6 files changed, 54 insertions(+), 75 deletions(-) diff --git a/libnm-core/nm-setting-ip-config.c b/libnm-core/nm-setting-ip-config.c index 8a3fb5cf9b..6883baef2c 100644 --- a/libnm-core/nm-setting-ip-config.c +++ b/libnm-core/nm-setting-ip-config.c @@ -5207,11 +5207,13 @@ _nm_sett_info_property_override_create_array_ip_config (void) * description: Array of dictionaries for routing rules. * ---end--- */ - _properties_override_add_dbus_only (properties_override, - NM_SETTING_IP_CONFIG_ROUTING_RULES, - NM_G_VARIANT_TYPE ("aa{sv}"), - _routing_rules_dbus_only_synth, - _routing_rules_dbus_only_set); + _properties_override_add_virt (properties_override, + NM_SETTING_IP_CONFIG_ROUTING_RULES, + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"), + .to_dbus_fcn = _routing_rules_dbus_only_synth, + .from_dbus_fcn = _routing_rules_dbus_only_set, + )); return properties_override; } diff --git a/libnm-core/nm-setting-ip4-config.c b/libnm-core/nm-setting-ip4-config.c index cbfe3c4600..b32ff6ee2c 100644 --- a/libnm-core/nm-setting-ip4-config.c +++ b/libnm-core/nm-setting-ip4-config.c @@ -825,12 +825,12 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *klass) ip4_addresses_get, ip4_addresses_set, NULL); - - _properties_override_add_dbus_only (properties_override, - "address-labels", - G_VARIANT_TYPE_STRING_ARRAY, - ip4_address_labels_get, - NULL); + _properties_override_add_virt (properties_override, + "address-labels", + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = G_VARIANT_TYPE_STRING_ARRAY, + .to_dbus_fcn = ip4_address_labels_get, + )); /* ---dbus--- * property: address-data @@ -841,11 +841,13 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *klass) * also exist on some addresses. * ---end--- */ - _properties_override_add_dbus_only (properties_override, - "address-data", - NM_G_VARIANT_TYPE ("aa{sv}"), - ip4_address_data_get, - ip4_address_data_set); + _properties_override_add_virt (properties_override, + "address-data", + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"), + .to_dbus_fcn = ip4_address_data_get, + .from_dbus_fcn = ip4_address_data_set, + )); /* ---dbus--- * property: routes @@ -885,11 +887,13 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *klass) * also exist on some routes. * ---end--- */ - _properties_override_add_dbus_only (properties_override, - "route-data", - NM_G_VARIANT_TYPE ("aa{sv}"), - ip4_route_data_get, - ip4_route_data_set); + _properties_override_add_virt (properties_override, + "route-data", + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"), + .to_dbus_fcn = ip4_route_data_get, + .from_dbus_fcn = ip4_route_data_set, + )); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/libnm-core/nm-setting-ip6-config.c b/libnm-core/nm-setting-ip6-config.c index 18b87081c6..556a25905c 100644 --- a/libnm-core/nm-setting-ip6-config.c +++ b/libnm-core/nm-setting-ip6-config.c @@ -918,11 +918,13 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *klass) * also exist on some addresses. * ---end--- */ - _properties_override_add_dbus_only (properties_override, - "address-data", - NM_G_VARIANT_TYPE ("aa{sv}"), - ip6_address_data_get, - ip6_address_data_set); + _properties_override_add_virt (properties_override, + "address-data", + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"), + .to_dbus_fcn = ip6_address_data_get, + .from_dbus_fcn = ip6_address_data_set, + )); /* ---dbus--- * property: routes @@ -959,11 +961,13 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *klass) * also exist on some routes. * ---end--- */ - _properties_override_add_dbus_only (properties_override, - "route-data", - NM_G_VARIANT_TYPE ("aa{sv}"), - ip6_route_data_get, - ip6_route_data_set); + _properties_override_add_virt (properties_override, + "route-data", + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"), + .to_dbus_fcn = ip6_route_data_get, + .from_dbus_fcn = ip6_route_data_set, + )); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/libnm-core/nm-setting-private.h b/libnm-core/nm-setting-private.h index 747818df9c..e9ba4b8ce5 100644 --- a/libnm-core/nm-setting-private.h +++ b/libnm-core/nm-setting-private.h @@ -171,40 +171,6 @@ void _properties_override_add_struct (GArray *properties_override, #define _properties_override_add_virt(properties_override, p_name, p_property_type) \ _properties_override_add ((properties_override), .name = (p_name), .property_type = (p_property_type)) -/** - * _properties_override_add_dbus_only: - * @properties_override: an array collecting the overrides - * @p_property_name: the name of the property to override - * @p_dbus_type: the type of the property (in its D-Bus representation) - * @p_to_dbus_fcn: (allow-none): function to call to synthesize a value for the property - * @p_from_dbus_fcn: (allow-none): function to call to set the value of the property - * - * Registers a property named @p_property_name, which will be used in the D-Bus - * serialization of objects of this setting type, but which does not correspond to - * a #GObject property. - * - * When serializing a setting to D-Bus, @p_to_dbus_fcn will be called to synthesize - * a value for the property. (If it returns %NULL, no value will be added to the - * serialization. If @p_to_dbus_fcn is %NULL, the property will always be omitted - * in the serialization.) - * - * When deserializing a D-Bus representation into a setting, if @p_property_name - * is present, then @p_from_dbus_fcn will be called to set it. (If @p_from_dbus_fcn is %NULL - * then the property will be ignored when deserializing.) - */ -#define _properties_override_add_dbus_only(properties_override, \ - p_property_name, \ - p_dbus_type, \ - p_to_dbus_fcn, \ - p_from_dbus_fcn) \ - _properties_override_add ((properties_override), \ - .name = (p_property_name), \ - .property_type = NM_SETT_INFO_PROPERT_TYPE ( \ - .dbus_type = (p_dbus_type), \ - .to_dbus_fcn = (p_to_dbus_fcn), \ - .from_dbus_fcn = (p_from_dbus_fcn), \ - )) - /** * _properties_override_add_override: * @properties_override: an array collecting the overrides diff --git a/libnm-core/nm-setting-wireguard.c b/libnm-core/nm-setting-wireguard.c index b03d527f4a..ff4cf93839 100644 --- a/libnm-core/nm-setting-wireguard.c +++ b/libnm-core/nm-setting-wireguard.c @@ -2571,11 +2571,13 @@ nm_setting_wireguard_class_init (NMSettingWireGuardClass *klass) * description: Array of dictionaries for the WireGuard peers. * ---end--- */ - _properties_override_add_dbus_only (properties_override, - NM_SETTING_WIREGUARD_PEERS, - NM_G_VARIANT_TYPE ("aa{sv}"), - _peers_dbus_only_synth, - _peers_dbus_only_set); + _properties_override_add_virt (properties_override, + NM_SETTING_WIREGUARD_PEERS, + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"), + .to_dbus_fcn = _peers_dbus_only_synth, + .from_dbus_fcn = _peers_dbus_only_set, + )); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/libnm-core/nm-setting-wireless.c b/libnm-core/nm-setting-wireless.c index 43fa7b80d7..f753b688dc 100644 --- a/libnm-core/nm-setting-wireless.c +++ b/libnm-core/nm-setting-wireless.c @@ -1735,11 +1735,12 @@ nm_setting_wireless_class_init (NMSettingWirelessClass *klass) * NetworkManager daemons. * ---end--- */ - _properties_override_add_dbus_only (properties_override, - "security", - G_VARIANT_TYPE_STRING, - nm_setting_wireless_get_security, - NULL); + _properties_override_add_virt (properties_override, + "security", + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = G_VARIANT_TYPE_STRING, + .to_dbus_fcn = nm_setting_wireless_get_security, + )); /** * NMSettingWireless:wake-on-wlan: From 6ecd4bed2a46e7c9e0684a1702182628bacbac3d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 22 Sep 2019 14:30:41 +0200 Subject: [PATCH 06/12] libnm: replace _properties_override_add_transform() with _properties_override_add_gobj() --- libnm-core/nm-setting-ip4-config.c | 14 +++++---- libnm-core/nm-setting-ip6-config.c | 14 +++++---- libnm-core/nm-setting-private.h | 35 ----------------------- libnm-core/nm-setting-serial.c | 13 +++++---- libnm-core/nm-setting-wireless-security.c | 11 +++---- 5 files changed, 29 insertions(+), 58 deletions(-) diff --git a/libnm-core/nm-setting-ip4-config.c b/libnm-core/nm-setting-ip4-config.c index b32ff6ee2c..a14a452d30 100644 --- a/libnm-core/nm-setting-ip4-config.c +++ b/libnm-core/nm-setting-ip4-config.c @@ -796,12 +796,14 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *klass) * integers) * ---end--- */ - _properties_override_add_transform (properties_override, - g_object_class_find_property (G_OBJECT_CLASS (setting_class), - NM_SETTING_IP_CONFIG_DNS), - NM_G_VARIANT_TYPE ("au"), - ip4_dns_to_dbus, - ip4_dns_from_dbus); + _properties_override_add_gobj (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_IP_CONFIG_DNS), + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("au"), + .gprop_to_dbus_fcn = ip4_dns_to_dbus, + .gprop_from_dbus_fcn = ip4_dns_from_dbus, + )); /* ---dbus--- * property: addresses diff --git a/libnm-core/nm-setting-ip6-config.c b/libnm-core/nm-setting-ip6-config.c index 556a25905c..938e5e1cee 100644 --- a/libnm-core/nm-setting-ip6-config.c +++ b/libnm-core/nm-setting-ip6-config.c @@ -880,12 +880,14 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *klass) * description: Array of IP addresses of DNS servers (in network byte order) * ---end--- */ - _properties_override_add_transform (properties_override, - g_object_class_find_property (G_OBJECT_CLASS (setting_class), - NM_SETTING_IP_CONFIG_DNS), - NM_G_VARIANT_TYPE ("aay"), - ip6_dns_to_dbus, - ip6_dns_from_dbus); + _properties_override_add_gobj (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_IP_CONFIG_DNS), + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("aay"), + .gprop_to_dbus_fcn = ip6_dns_to_dbus, + .gprop_from_dbus_fcn = ip6_dns_from_dbus, + )); /* ---dbus--- * property: addresses diff --git a/libnm-core/nm-setting-private.h b/libnm-core/nm-setting-private.h index e9ba4b8ce5..aa5302a9be 100644 --- a/libnm-core/nm-setting-private.h +++ b/libnm-core/nm-setting-private.h @@ -221,41 +221,6 @@ void _properties_override_add_struct (GArray *properties_override, )); \ }) -/** - * _properties_override_add_transform: - * @properties_override: an array collecting the overrides - * @p_param_spec: the param spec of the property to transform. - * @p_dbus_type: the type of the property (in its D-Bus representation) - * @p_gprop_to_dbus_fcn: function to convert from object to D-Bus format - * @p_gprop_from_dbus_fcn: function to convert from D-Bus to object format - * - * Indicates that @property on @setting_class does not have the same format as - * its corresponding D-Bus representation, and so must be transformed when - * serializing/deserializing. - * - * The transformation will also be used by nm_setting_compare(), meaning that - * the underlying object property does not need to be of a type that - * nm_property_compare() recognizes, as long as it recognizes @p_dbus_type. - */ -#define _properties_override_add_transform(properties_override, \ - p_param_spec, \ - p_dbus_type, \ - p_gprop_to_dbus_fcn, \ - p_gprop_from_dbus_fcn) \ - ({ \ - GParamSpec *const _param_spec = (p_param_spec); \ - \ - nm_assert (_param_spec); \ - \ - _properties_override_add ((properties_override), \ - .param_spec = (_param_spec), \ - .property_type = NM_SETT_INFO_PROPERT_TYPE ( \ - .dbus_type = (p_dbus_type), \ - .gprop_to_dbus_fcn = (p_gprop_to_dbus_fcn), \ - .gprop_from_dbus_fcn = (p_gprop_from_dbus_fcn), \ - )); \ - }) - /*****************************************************************************/ gboolean _nm_setting_use_legacy_property (NMSetting *setting, diff --git a/libnm-core/nm-setting-serial.c b/libnm-core/nm-setting-serial.c index 1f7f3c3c62..723071ca4e 100644 --- a/libnm-core/nm-setting-serial.c +++ b/libnm-core/nm-setting-serial.c @@ -288,12 +288,13 @@ nm_setting_serial_class_init (NMSettingSerialClass *klass) G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS); - - _properties_override_add_transform (properties_override, - obj_properties[PROP_PARITY], - G_VARIANT_TYPE_BYTE, - parity_to_dbus, - parity_from_dbus); + _properties_override_add_gobj (properties_override, + obj_properties[PROP_PARITY], + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = G_VARIANT_TYPE_BYTE, + .gprop_to_dbus_fcn = parity_to_dbus, + .gprop_from_dbus_fcn = parity_from_dbus, + )); /** * NMSettingSerial:stopbits: diff --git a/libnm-core/nm-setting-wireless-security.c b/libnm-core/nm-setting-wireless-security.c index c58ba1e380..4074b26693 100644 --- a/libnm-core/nm-setting-wireless-security.c +++ b/libnm-core/nm-setting-wireless-security.c @@ -1811,12 +1811,13 @@ nm_setting_wireless_security_class_init (NMSettingWirelessSecurityClass *klass) G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS); + _properties_override_add_gobj (properties_override, + obj_properties[PROP_WEP_KEY_TYPE], + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = G_VARIANT_TYPE_UINT32, + .gprop_to_dbus_fcn = wep_key_type_to_dbus, + )); - _properties_override_add_transform (properties_override, - obj_properties[PROP_WEP_KEY_TYPE], - G_VARIANT_TYPE_UINT32, - wep_key_type_to_dbus, - NULL); /** * NMSettingWirelessSecurity:wps-method: * From 275d850d1b0b58088e42c031b2128634db5e9b9e Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 22 Sep 2019 15:05:35 +0200 Subject: [PATCH 07/12] libnm: replace _properties_override_add_override() with _properties_override_add_gobj() --- libnm-core/nm-setting-connection.c | 27 ++++++++-------- libnm-core/nm-setting-ip-config.c | 12 +++---- libnm-core/nm-setting-ip4-config.c | 30 +++++++++--------- libnm-core/nm-setting-ip6-config.c | 30 +++++++++--------- libnm-core/nm-setting-private.h | 50 ------------------------------ libnm-core/nm-setting-sriov.c | 14 ++++----- libnm-core/nm-setting-tc-config.c | 28 ++++++++--------- libnm-core/nm-setting-vlan.c | 14 ++++----- libnm-core/nm-setting-vpn.c | 13 ++++---- libnm-core/nm-setting-wired.c | 13 ++++---- libnm-core/nm-setting-wireless.c | 13 ++++---- 11 files changed, 98 insertions(+), 146 deletions(-) diff --git a/libnm-core/nm-setting-connection.c b/libnm-core/nm-setting-connection.c index d1e58b1fde..84c8cac327 100644 --- a/libnm-core/nm-setting-connection.c +++ b/libnm-core/nm-setting-connection.c @@ -1735,13 +1735,13 @@ nm_setting_connection_class_init (NMSettingConnectionClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_override (properties_override, - obj_properties[PROP_INTERFACE_NAME], - G_VARIANT_TYPE_STRING, - NULL, - nm_setting_connection_set_interface_name, - nm_setting_connection_no_interface_name); + _properties_override_add_gobj (properties_override, + obj_properties[PROP_INTERFACE_NAME], + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = G_VARIANT_TYPE_STRING, + .from_dbus_fcn = nm_setting_connection_set_interface_name, + .missing_from_dbus_fcn = nm_setting_connection_no_interface_name, + )); /** * NMSettingConnection:type: @@ -1920,13 +1920,12 @@ nm_setting_connection_class_init (NMSettingConnectionClass *klass) G_PARAM_CONSTRUCT | NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_override (properties_override, - obj_properties[PROP_TIMESTAMP], - G_VARIANT_TYPE_UINT64, - _to_dbus_fcn_timestamp, - NULL, - NULL); + _properties_override_add_gobj (properties_override, + obj_properties[PROP_TIMESTAMP], + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = G_VARIANT_TYPE_UINT64, + .to_dbus_fcn = _to_dbus_fcn_timestamp, + )); /** * NMSettingConnection:read-only: diff --git a/libnm-core/nm-setting-ip-config.c b/libnm-core/nm-setting-ip-config.c index 6883baef2c..072339f150 100644 --- a/libnm-core/nm-setting-ip-config.c +++ b/libnm-core/nm-setting-ip-config.c @@ -5194,12 +5194,12 @@ _nm_sett_info_property_override_create_array_ip_config (void) { GArray *properties_override = _nm_sett_info_property_override_create_array (); - _properties_override_add_override (properties_override, - obj_properties[PROP_GATEWAY], - G_VARIANT_TYPE_STRING, - NULL, - ip_gateway_set, - NULL); + _properties_override_add_gobj (properties_override, + obj_properties[PROP_GATEWAY], + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = G_VARIANT_TYPE_STRING, + .from_dbus_fcn = ip_gateway_set, + )); /* ---dbus--- * property: routing-rules diff --git a/libnm-core/nm-setting-ip4-config.c b/libnm-core/nm-setting-ip4-config.c index a14a452d30..1ed3ef5155 100644 --- a/libnm-core/nm-setting-ip4-config.c +++ b/libnm-core/nm-setting-ip4-config.c @@ -820,13 +820,14 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *klass) * for that subnet. * ---end--- */ - _properties_override_add_override (properties_override, - g_object_class_find_property (G_OBJECT_CLASS (setting_class), - NM_SETTING_IP_CONFIG_ADDRESSES), - NM_G_VARIANT_TYPE ("aau"), - ip4_addresses_get, - ip4_addresses_set, - NULL); + _properties_override_add_gobj (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_IP_CONFIG_ADDRESSES), + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("aau"), + .to_dbus_fcn = ip4_addresses_get, + .from_dbus_fcn = ip4_addresses_set, + )); _properties_override_add_virt (properties_override, "address-labels", NM_SETT_INFO_PROPERT_TYPE ( @@ -868,13 +869,14 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *klass) * property.) * ---end--- */ - _properties_override_add_override (properties_override, - g_object_class_find_property (G_OBJECT_CLASS (setting_class), - NM_SETTING_IP_CONFIG_ROUTES), - NM_G_VARIANT_TYPE ("aau"), - ip4_routes_get, - ip4_routes_set, - NULL); + _properties_override_add_gobj (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_IP_CONFIG_ROUTES), + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("aau"), + .to_dbus_fcn = ip4_routes_get, + .from_dbus_fcn = ip4_routes_set, + )); /* ---dbus--- * property: route-data diff --git a/libnm-core/nm-setting-ip6-config.c b/libnm-core/nm-setting-ip6-config.c index 938e5e1cee..ee05acdc4b 100644 --- a/libnm-core/nm-setting-ip6-config.c +++ b/libnm-core/nm-setting-ip6-config.c @@ -903,13 +903,14 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *klass) * that subnet. * ---end--- */ - _properties_override_add_override (properties_override, - g_object_class_find_property (G_OBJECT_CLASS (setting_class), - NM_SETTING_IP_CONFIG_ADDRESSES), - NM_G_VARIANT_TYPE ("a(ayuay)"), - ip6_addresses_get, - ip6_addresses_set, - NULL); + _properties_override_add_gobj (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_IP_CONFIG_ADDRESSES), + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("a(ayuay)"), + .to_dbus_fcn = ip6_addresses_get, + .from_dbus_fcn = ip6_addresses_set, + )); /* ---dbus--- * property: address-data @@ -942,13 +943,14 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *klass) * default metric for the device. * ---end--- */ - _properties_override_add_override (properties_override, - g_object_class_find_property (G_OBJECT_CLASS (setting_class), - NM_SETTING_IP_CONFIG_ROUTES), - NM_G_VARIANT_TYPE ("a(ayuayu)"), - ip6_routes_get, - ip6_routes_set, - NULL); + _properties_override_add_gobj (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_IP_CONFIG_ROUTES), + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("a(ayuayu)"), + .to_dbus_fcn = ip6_routes_get, + .from_dbus_fcn = ip6_routes_set, + )); /* ---dbus--- * property: route-data diff --git a/libnm-core/nm-setting-private.h b/libnm-core/nm-setting-private.h index aa5302a9be..7ebd58bfab 100644 --- a/libnm-core/nm-setting-private.h +++ b/libnm-core/nm-setting-private.h @@ -171,56 +171,6 @@ void _properties_override_add_struct (GArray *properties_override, #define _properties_override_add_virt(properties_override, p_name, p_property_type) \ _properties_override_add ((properties_override), .name = (p_name), .property_type = (p_property_type)) -/** - * _properties_override_add_override: - * @properties_override: an array collecting the overrides - * @p_param_spec: the name of the property to override - * @p_dbus_type: the type of the property (in its D-Bus representation) - * @p_to_dbus_fcn: (allow-none): function to call to get the value of the property - * @p_from_dbus_fcn: (allow-none): function to call to set the value of the property - * @p_missing_from_dbus_fcn: (allow-none): function to call to indicate the property was not set - * - * Overrides the D-Bus representation of the #GObject property that shares the - * same name as @p_param_spec. - * - * When serializing a setting to D-Bus, if @p_to_dbus_fcn is non-%NULL, then it will - * be called to get the property's value. If it returns a #GVariant, the - * property will be added to the hash, and if it returns %NULL, the property - * will be omitted. (If @p_to_dbus_fcn is %NULL, the property will be read normally - * with g_object_get_property(), and added to the hash if it is not the default - * value.) - * - * When deserializing a D-Bus representation into a setting, if a value with - * the name of @p_param_spec is present, then @p_from_dbus_fcn will be called to set it. - * (If @p_from_dbus_fcn is %NULL then the property will be set normally with - * g_object_set_property().) - * - * If @p_missing_from_dbus_fcn is non-%NULL, then it will be called when deserializing a - * representation that does NOT contain a value for the property. This can be used, - * eg, if a new property needs to be initialized from some older deprecated property - * when it is not present. - */ -#define _properties_override_add_override(properties_override, \ - p_param_spec, \ - p_dbus_type, \ - p_to_dbus_fcn, \ - p_from_dbus_fcn, \ - p_missing_from_dbus_fcn) \ - ({ \ - GParamSpec *const _param_spec = (p_param_spec); \ - \ - nm_assert (_param_spec); \ - \ - _properties_override_add ((properties_override), \ - .param_spec = (_param_spec), \ - .property_type = NM_SETT_INFO_PROPERT_TYPE ( \ - .dbus_type = (p_dbus_type), \ - .to_dbus_fcn = (p_to_dbus_fcn), \ - .from_dbus_fcn = (p_from_dbus_fcn), \ - .missing_from_dbus_fcn = (p_missing_from_dbus_fcn), \ - )); \ - }) - /*****************************************************************************/ gboolean _nm_setting_use_legacy_property (NMSetting *setting, diff --git a/libnm-core/nm-setting-sriov.c b/libnm-core/nm-setting-sriov.c index 0aa2cc6022..f5bf5b3c7e 100644 --- a/libnm-core/nm-setting-sriov.c +++ b/libnm-core/nm-setting-sriov.c @@ -1326,13 +1326,13 @@ nm_setting_sriov_class_init (NMSettingSriovClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_override (properties_override, - obj_properties[PROP_VFS], - NM_G_VARIANT_TYPE ("aa{sv}"), - vfs_to_dbus, - vfs_from_dbus, - NULL); + _properties_override_add_gobj (properties_override, + obj_properties[PROP_VFS], + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"), + .to_dbus_fcn = vfs_to_dbus, + .from_dbus_fcn = vfs_from_dbus, + )); /** * NMSettingSriov:autoprobe-drivers diff --git a/libnm-core/nm-setting-tc-config.c b/libnm-core/nm-setting-tc-config.c index 57df75b0d1..5c81c45395 100644 --- a/libnm-core/nm-setting-tc-config.c +++ b/libnm-core/nm-setting-tc-config.c @@ -1800,13 +1800,13 @@ nm_setting_tc_config_class_init (NMSettingTCConfigClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_override (properties_override, - obj_properties[PROP_QDISCS], - NM_G_VARIANT_TYPE ("aa{sv}"), - tc_qdiscs_get, - tc_qdiscs_set, - NULL); + _properties_override_add_gobj (properties_override, + obj_properties[PROP_QDISCS], + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"), + .to_dbus_fcn = tc_qdiscs_get, + .from_dbus_fcn = tc_qdiscs_set, + )); /** * NMSettingTCConfig:tfilters: (type GPtrArray(NMTCTfilter)) @@ -1826,13 +1826,13 @@ nm_setting_tc_config_class_init (NMSettingTCConfigClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_override (properties_override, - obj_properties[PROP_TFILTERS], - NM_G_VARIANT_TYPE ("aa{sv}"), - tc_tfilters_get, - tc_tfilters_set, - NULL); + _properties_override_add_gobj (properties_override, + obj_properties[PROP_TFILTERS], + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"), + .to_dbus_fcn = tc_tfilters_get, + .from_dbus_fcn = tc_tfilters_set, + )); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/libnm-core/nm-setting-vlan.c b/libnm-core/nm-setting-vlan.c index 111e15ccfe..6b8f870f13 100644 --- a/libnm-core/nm-setting-vlan.c +++ b/libnm-core/nm-setting-vlan.c @@ -908,13 +908,13 @@ nm_setting_vlan_class_init (NMSettingVlanClass *klass) G_PARAM_CONSTRUCT | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_override (properties_override, - obj_properties[PROP_FLAGS], - G_VARIANT_TYPE_UINT32, - _override_flags_get, - NULL, - _override_flags_not_set); + _properties_override_add_gobj (properties_override, + obj_properties[PROP_FLAGS], + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = G_VARIANT_TYPE_UINT32, + .to_dbus_fcn = _override_flags_get, + .missing_from_dbus_fcn = _override_flags_not_set, + )); /** * NMSettingVlan:ingress-priority-map: diff --git a/libnm-core/nm-setting-vpn.c b/libnm-core/nm-setting-vpn.c index d51843339f..0c06c3b32d 100644 --- a/libnm-core/nm-setting-vpn.c +++ b/libnm-core/nm-setting-vpn.c @@ -1151,12 +1151,13 @@ nm_setting_vpn_class_init (NMSettingVpnClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_SECRET | G_PARAM_STATIC_STRINGS); - _properties_override_add_override (properties_override, - obj_properties[PROP_SECRETS], - NM_G_VARIANT_TYPE ("a{ss}"), - vpn_secrets_to_dbus, - vpn_secrets_from_dbus, - NULL); + _properties_override_add_gobj (properties_override, + obj_properties[PROP_SECRETS], + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("a{ss}"), + .to_dbus_fcn = vpn_secrets_to_dbus, + .from_dbus_fcn = vpn_secrets_from_dbus, + )); /** * NMSettingVpn:timeout: diff --git a/libnm-core/nm-setting-wired.c b/libnm-core/nm-setting-wired.c index fdd4dd36f6..20f41cb355 100644 --- a/libnm-core/nm-setting-wired.c +++ b/libnm-core/nm-setting-wired.c @@ -1306,13 +1306,12 @@ nm_setting_wired_class_init (NMSettingWiredClass *klass) G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS); - - _properties_override_add_override (properties_override, - obj_properties[PROP_AUTO_NEGOTIATE], - G_VARIANT_TYPE_BOOLEAN, - _override_autoneg_get, - NULL, - NULL); + _properties_override_add_gobj (properties_override, + obj_properties[PROP_AUTO_NEGOTIATE], + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = G_VARIANT_TYPE_BOOLEAN, + .to_dbus_fcn = _override_autoneg_get, + )); /** * NMSettingWired:mac-address: diff --git a/libnm-core/nm-setting-wireless.c b/libnm-core/nm-setting-wireless.c index f753b688dc..0fa0f692b0 100644 --- a/libnm-core/nm-setting-wireless.c +++ b/libnm-core/nm-setting-wireless.c @@ -1611,13 +1611,12 @@ nm_setting_wireless_class_init (NMSettingWirelessClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_STATIC_STRINGS); - - _properties_override_add_override (properties_override, - obj_properties[PROP_SEEN_BSSIDS], - G_VARIANT_TYPE_STRING_ARRAY, - _to_dbus_fcn_seen_bssids, - NULL, - NULL); + _properties_override_add_gobj (properties_override, + obj_properties[PROP_SEEN_BSSIDS], + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = G_VARIANT_TYPE_STRING_ARRAY, + .to_dbus_fcn = _to_dbus_fcn_seen_bssids, + )); /** * NMSettingWireless:mtu: From e5495c482fb3a935660ca70e8a0c241d63402541 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 22 Sep 2019 15:23:41 +0200 Subject: [PATCH 08/12] libnm: cleanup _properties_override_add*() functions --- libnm-core/nm-setting-private.h | 27 +++++++++++++++++++-------- libnm-core/nm-setting.c | 8 +++----- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/libnm-core/nm-setting-private.h b/libnm-core/nm-setting-private.h index 7ebd58bfab..85b7e728e3 100644 --- a/libnm-core/nm-setting-private.h +++ b/libnm-core/nm-setting-private.h @@ -157,19 +157,30 @@ _nm_setting_class_commit (NMSettingClass *setting_class, __VA_ARGS__ \ })) -void _properties_override_add_struct (GArray *properties_override, - const NMSettInfoProperty *prop_info); +gboolean _properties_override_add_assert (const NMSettInfoProperty *prop_info); -#define _properties_override_add(properties_override, \ - ...) \ - (_properties_override_add_struct (properties_override, \ - NM_SETT_INFO_PROPERTY (__VA_ARGS__))) +static inline void +_properties_override_add (GArray *properties_override, + const NMSettInfoProperty *prop_info) +{ + nm_assert (properties_override); + nm_assert (_properties_override_add_assert (prop_info)); + g_array_append_vals (properties_override, prop_info, 1); +} #define _properties_override_add_gobj(properties_override, p_param_spec, p_property_type) \ - _properties_override_add ((properties_override), .param_spec = (p_param_spec), .property_type = (p_property_type)) + _properties_override_add ((properties_override), \ + NM_SETT_INFO_PROPERTY ( \ + .param_spec = (p_param_spec), \ + .property_type = (p_property_type), \ + )) #define _properties_override_add_virt(properties_override, p_name, p_property_type) \ - _properties_override_add ((properties_override), .name = (p_name), .property_type = (p_property_type)) + _properties_override_add ((properties_override), \ + NM_SETT_INFO_PROPERTY ( \ + .name = (""p_name""), \ + .property_type = (p_property_type), \ + )) /*****************************************************************************/ diff --git a/libnm-core/nm-setting.c b/libnm-core/nm-setting.c index 0b63c29a16..096a6546d7 100644 --- a/libnm-core/nm-setting.c +++ b/libnm-core/nm-setting.c @@ -202,11 +202,9 @@ _gprop_to_dbus_fcn_flags (const GValue *val) return g_variant_new_uint32 (g_value_get_flags (val)); } -void -_properties_override_add_struct (GArray *properties_override, - const NMSettInfoProperty *prop_info) +gboolean +_properties_override_add_assert (const NMSettInfoProperty *prop_info) { - nm_assert (properties_override); nm_assert (prop_info); nm_assert ((!!prop_info->name) != (!!prop_info->param_spec)); nm_assert (!prop_info->param_spec || !prop_info->name || nm_streq0 (prop_info->name, prop_info->param_spec->name)); @@ -230,7 +228,7 @@ _properties_override_add_struct (GArray *properties_override, #undef _PROPERT_EXTRA - g_array_append_vals (properties_override, prop_info, 1); + return TRUE; } static NMSettInfoSetting _sett_info_settings[_NM_META_SETTING_TYPE_NUM]; From a1b575b07b7408c94fa62a8e166ccd548b60cbe1 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 22 Sep 2019 15:32:04 +0200 Subject: [PATCH 09/12] libnm/trivial: rename _properties_override_add_*() to _nm_properties_override_*() These macros/functions are in a header file. Everything in a header file should have an "nm" prefix. Rename. --- libnm-core/nm-setting-bluetooth.c | 2 +- libnm-core/nm-setting-bond.c | 4 +- libnm-core/nm-setting-bridge-port.c | 2 +- libnm-core/nm-setting-bridge.c | 6 +- libnm-core/nm-setting-connection.c | 26 +++---- libnm-core/nm-setting-dcb.c | 12 ++-- libnm-core/nm-setting-gsm.c | 4 +- libnm-core/nm-setting-infiniband.c | 2 +- libnm-core/nm-setting-ip-config.c | 26 +++---- libnm-core/nm-setting-ip4-config.c | 88 +++++++++++------------ libnm-core/nm-setting-ip6-config.c | 76 ++++++++++---------- libnm-core/nm-setting-olpc-mesh.c | 2 +- libnm-core/nm-setting-private.h | 32 ++++----- libnm-core/nm-setting-serial.c | 14 ++-- libnm-core/nm-setting-sriov.c | 14 ++-- libnm-core/nm-setting-tc-config.c | 28 ++++---- libnm-core/nm-setting-team-port.c | 14 ++-- libnm-core/nm-setting-team.c | 34 ++++----- libnm-core/nm-setting-user.c | 2 +- libnm-core/nm-setting-vlan.c | 16 ++--- libnm-core/nm-setting-vpn.c | 16 ++--- libnm-core/nm-setting-wimax.c | 2 +- libnm-core/nm-setting-wired.c | 20 +++--- libnm-core/nm-setting-wireguard.c | 14 ++-- libnm-core/nm-setting-wireless-security.c | 12 ++-- libnm-core/nm-setting-wireless.c | 32 ++++----- libnm-core/nm-setting.c | 2 +- 27 files changed, 251 insertions(+), 251 deletions(-) diff --git a/libnm-core/nm-setting-bluetooth.c b/libnm-core/nm-setting-bluetooth.c index 10f52878e9..2b93494e6a 100644 --- a/libnm-core/nm-setting-bluetooth.c +++ b/libnm-core/nm-setting-bluetooth.c @@ -295,7 +295,7 @@ nm_setting_bluetooth_class_init (NMSettingBluetoothClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[PROP_BDADDR], &nm_sett_info_propert_type_mac_addrees); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_BDADDR], &nm_sett_info_propert_type_mac_addrees); /** * NMSettingBluetooth:type: diff --git a/libnm-core/nm-setting-bond.c b/libnm-core/nm-setting-bond.c index 04d653cc0e..fad09f4314 100644 --- a/libnm-core/nm-setting-bond.c +++ b/libnm-core/nm-setting-bond.c @@ -970,7 +970,7 @@ nm_setting_bond_class_init (NMSettingBondClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[PROP_OPTIONS], &nm_sett_info_propert_type_strdict); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_OPTIONS], &nm_sett_info_propert_type_strdict); /* ---dbus--- * property: interface-name @@ -980,7 +980,7 @@ nm_setting_bond_class_init (NMSettingBondClass *klass) * bond's interface name. * ---end--- */ - _properties_override_add_virt (properties_override, "interface-name", &nm_sett_info_propert_type_deprecated_interface_name); + _nm_properties_override_dbus (properties_override, "interface-name", &nm_sett_info_propert_type_deprecated_interface_name); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/libnm-core/nm-setting-bridge-port.c b/libnm-core/nm-setting-bridge-port.c index fd3dc98e92..f5f6da248a 100644 --- a/libnm-core/nm-setting-bridge-port.c +++ b/libnm-core/nm-setting-bridge-port.c @@ -573,7 +573,7 @@ nm_setting_bridge_port_class_init (NMSettingBridgePortClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[PROP_VLANS], &nm_sett_info_propert_type_bridge_vlans); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_VLANS], &nm_sett_info_propert_type_bridge_vlans); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/libnm-core/nm-setting-bridge.c b/libnm-core/nm-setting-bridge.c index 9a0e31c79d..a8cd4a1b43 100644 --- a/libnm-core/nm-setting-bridge.c +++ b/libnm-core/nm-setting-bridge.c @@ -1209,7 +1209,7 @@ nm_setting_bridge_class_init (NMSettingBridgeClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[PROP_MAC_ADDRESS], &nm_sett_info_propert_type_mac_addrees); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_MAC_ADDRESS], &nm_sett_info_propert_type_mac_addrees); /** * NMSettingBridge:stp: @@ -1461,7 +1461,7 @@ nm_setting_bridge_class_init (NMSettingBridgeClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[PROP_VLANS], &nm_sett_info_propert_type_bridge_vlans); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_VLANS], &nm_sett_info_propert_type_bridge_vlans); /* ---dbus--- * property: interface-name @@ -1471,7 +1471,7 @@ nm_setting_bridge_class_init (NMSettingBridgeClass *klass) * bridge's interface name. * ---end--- */ - _properties_override_add_virt (properties_override, "interface-name", &nm_sett_info_propert_type_deprecated_interface_name); + _nm_properties_override_dbus (properties_override, "interface-name", &nm_sett_info_propert_type_deprecated_interface_name); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/libnm-core/nm-setting-connection.c b/libnm-core/nm-setting-connection.c index 84c8cac327..d29a189b26 100644 --- a/libnm-core/nm-setting-connection.c +++ b/libnm-core/nm-setting-connection.c @@ -1735,13 +1735,13 @@ nm_setting_connection_class_init (NMSettingConnectionClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, - obj_properties[PROP_INTERFACE_NAME], - NM_SETT_INFO_PROPERT_TYPE ( - .dbus_type = G_VARIANT_TYPE_STRING, - .from_dbus_fcn = nm_setting_connection_set_interface_name, - .missing_from_dbus_fcn = nm_setting_connection_no_interface_name, - )); + _nm_properties_override_gobj (properties_override, + obj_properties[PROP_INTERFACE_NAME], + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = G_VARIANT_TYPE_STRING, + .from_dbus_fcn = nm_setting_connection_set_interface_name, + .missing_from_dbus_fcn = nm_setting_connection_no_interface_name, + )); /** * NMSettingConnection:type: @@ -1920,12 +1920,12 @@ nm_setting_connection_class_init (NMSettingConnectionClass *klass) G_PARAM_CONSTRUCT | NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, - obj_properties[PROP_TIMESTAMP], - NM_SETT_INFO_PROPERT_TYPE ( - .dbus_type = G_VARIANT_TYPE_UINT64, - .to_dbus_fcn = _to_dbus_fcn_timestamp, - )); + _nm_properties_override_gobj (properties_override, + obj_properties[PROP_TIMESTAMP], + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = G_VARIANT_TYPE_UINT64, + .to_dbus_fcn = _to_dbus_fcn_timestamp, + )); /** * NMSettingConnection:read-only: diff --git a/libnm-core/nm-setting-dcb.c b/libnm-core/nm-setting-dcb.c index a7d081131b..c3b512ce17 100644 --- a/libnm-core/nm-setting-dcb.c +++ b/libnm-core/nm-setting-dcb.c @@ -1103,7 +1103,7 @@ nm_setting_dcb_class_init (NMSettingDcbClass *klass) G_TYPE_ARRAY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[PROP_PRIORITY_FLOW_CONTROL], &nm_sett_info_propert_type_dcb_au); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_PRIORITY_FLOW_CONTROL], &nm_sett_info_propert_type_dcb_au); /** * NMSettingDcb:priority-group-flags: @@ -1146,7 +1146,7 @@ nm_setting_dcb_class_init (NMSettingDcbClass *klass) G_TYPE_ARRAY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[PROP_PRIORITY_GROUP_ID], &nm_sett_info_propert_type_dcb_au); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_PRIORITY_GROUP_ID], &nm_sett_info_propert_type_dcb_au); /** * NMSettingDcb:priority-group-bandwidth: (type GArray(guint)) @@ -1168,7 +1168,7 @@ nm_setting_dcb_class_init (NMSettingDcbClass *klass) G_TYPE_ARRAY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[PROP_PRIORITY_GROUP_BANDWIDTH], &nm_sett_info_propert_type_dcb_au); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_PRIORITY_GROUP_BANDWIDTH], &nm_sett_info_propert_type_dcb_au); /** * NMSettingDcb:priority-bandwidth: (type GArray(guint)) @@ -1192,7 +1192,7 @@ nm_setting_dcb_class_init (NMSettingDcbClass *klass) G_TYPE_ARRAY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[PROP_PRIORITY_BANDWIDTH], &nm_sett_info_propert_type_dcb_au); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_PRIORITY_BANDWIDTH], &nm_sett_info_propert_type_dcb_au); /** * NMSettingDcb:priority-strict-bandwidth: (type GArray(gboolean)) @@ -1214,7 +1214,7 @@ nm_setting_dcb_class_init (NMSettingDcbClass *klass) G_TYPE_ARRAY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[PROP_PRIORITY_STRICT_BANDWIDTH], &nm_sett_info_propert_type_dcb_au); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_PRIORITY_STRICT_BANDWIDTH], &nm_sett_info_propert_type_dcb_au); /** * NMSettingDcb:priority-traffic-class: (type GArray(guint)) @@ -1235,7 +1235,7 @@ nm_setting_dcb_class_init (NMSettingDcbClass *klass) G_TYPE_ARRAY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[PROP_PRIORITY_TRAFFIC_CLASS], &nm_sett_info_propert_type_dcb_au); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_PRIORITY_TRAFFIC_CLASS], &nm_sett_info_propert_type_dcb_au); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/libnm-core/nm-setting-gsm.c b/libnm-core/nm-setting-gsm.c index bd118a9210..07906d0336 100644 --- a/libnm-core/nm-setting-gsm.c +++ b/libnm-core/nm-setting-gsm.c @@ -847,8 +847,8 @@ nm_setting_gsm_class_init (NMSettingGsmClass *klass) G_PARAM_STATIC_STRINGS); /* Ignore incoming deprecated properties */ - _properties_override_add_virt (properties_override, "allowed-bands", &nm_sett_info_propert_type_deprecated_ignore_u); - _properties_override_add_virt (properties_override, "network-type", &nm_sett_info_propert_type_deprecated_ignore_i); + _nm_properties_override_dbus (properties_override, "allowed-bands", &nm_sett_info_propert_type_deprecated_ignore_u); + _nm_properties_override_dbus (properties_override, "network-type", &nm_sett_info_propert_type_deprecated_ignore_i); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/libnm-core/nm-setting-infiniband.c b/libnm-core/nm-setting-infiniband.c index 9b3884dd02..f06c616fd7 100644 --- a/libnm-core/nm-setting-infiniband.c +++ b/libnm-core/nm-setting-infiniband.c @@ -414,7 +414,7 @@ nm_setting_infiniband_class_init (NMSettingInfinibandClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[PROP_MAC_ADDRESS], &nm_sett_info_propert_type_mac_addrees); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_MAC_ADDRESS], &nm_sett_info_propert_type_mac_addrees); /** * NMSettingInfiniband:mtu: diff --git a/libnm-core/nm-setting-ip-config.c b/libnm-core/nm-setting-ip-config.c index 072339f150..9fc2206f8c 100644 --- a/libnm-core/nm-setting-ip-config.c +++ b/libnm-core/nm-setting-ip-config.c @@ -5194,12 +5194,12 @@ _nm_sett_info_property_override_create_array_ip_config (void) { GArray *properties_override = _nm_sett_info_property_override_create_array (); - _properties_override_add_gobj (properties_override, - obj_properties[PROP_GATEWAY], - NM_SETT_INFO_PROPERT_TYPE ( - .dbus_type = G_VARIANT_TYPE_STRING, - .from_dbus_fcn = ip_gateway_set, - )); + _nm_properties_override_gobj (properties_override, + obj_properties[PROP_GATEWAY], + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = G_VARIANT_TYPE_STRING, + .from_dbus_fcn = ip_gateway_set, + )); /* ---dbus--- * property: routing-rules @@ -5207,13 +5207,13 @@ _nm_sett_info_property_override_create_array_ip_config (void) * description: Array of dictionaries for routing rules. * ---end--- */ - _properties_override_add_virt (properties_override, - NM_SETTING_IP_CONFIG_ROUTING_RULES, - NM_SETT_INFO_PROPERT_TYPE ( - .dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"), - .to_dbus_fcn = _routing_rules_dbus_only_synth, - .from_dbus_fcn = _routing_rules_dbus_only_set, - )); + _nm_properties_override_dbus (properties_override, + NM_SETTING_IP_CONFIG_ROUTING_RULES, + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"), + .to_dbus_fcn = _routing_rules_dbus_only_synth, + .from_dbus_fcn = _routing_rules_dbus_only_set, + )); return properties_override; } diff --git a/libnm-core/nm-setting-ip4-config.c b/libnm-core/nm-setting-ip4-config.c index 1ed3ef5155..1a92019b34 100644 --- a/libnm-core/nm-setting-ip4-config.c +++ b/libnm-core/nm-setting-ip4-config.c @@ -796,14 +796,14 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *klass) * integers) * ---end--- */ - _properties_override_add_gobj (properties_override, - g_object_class_find_property (G_OBJECT_CLASS (setting_class), - NM_SETTING_IP_CONFIG_DNS), - NM_SETT_INFO_PROPERT_TYPE ( - .dbus_type = NM_G_VARIANT_TYPE ("au"), - .gprop_to_dbus_fcn = ip4_dns_to_dbus, - .gprop_from_dbus_fcn = ip4_dns_from_dbus, - )); + _nm_properties_override_gobj (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_IP_CONFIG_DNS), + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("au"), + .gprop_to_dbus_fcn = ip4_dns_to_dbus, + .gprop_from_dbus_fcn = ip4_dns_from_dbus, + )); /* ---dbus--- * property: addresses @@ -820,20 +820,20 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *klass) * for that subnet. * ---end--- */ - _properties_override_add_gobj (properties_override, - g_object_class_find_property (G_OBJECT_CLASS (setting_class), - NM_SETTING_IP_CONFIG_ADDRESSES), - NM_SETT_INFO_PROPERT_TYPE ( - .dbus_type = NM_G_VARIANT_TYPE ("aau"), - .to_dbus_fcn = ip4_addresses_get, - .from_dbus_fcn = ip4_addresses_set, - )); - _properties_override_add_virt (properties_override, - "address-labels", - NM_SETT_INFO_PROPERT_TYPE ( - .dbus_type = G_VARIANT_TYPE_STRING_ARRAY, - .to_dbus_fcn = ip4_address_labels_get, - )); + _nm_properties_override_gobj (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_IP_CONFIG_ADDRESSES), + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("aau"), + .to_dbus_fcn = ip4_addresses_get, + .from_dbus_fcn = ip4_addresses_set, + )); + _nm_properties_override_dbus (properties_override, + "address-labels", + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = G_VARIANT_TYPE_STRING_ARRAY, + .to_dbus_fcn = ip4_address_labels_get, + )); /* ---dbus--- * property: address-data @@ -844,13 +844,13 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *klass) * also exist on some addresses. * ---end--- */ - _properties_override_add_virt (properties_override, - "address-data", - NM_SETT_INFO_PROPERT_TYPE ( - .dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"), - .to_dbus_fcn = ip4_address_data_get, - .from_dbus_fcn = ip4_address_data_set, - )); + _nm_properties_override_dbus (properties_override, + "address-data", + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"), + .to_dbus_fcn = ip4_address_data_get, + .from_dbus_fcn = ip4_address_data_set, + )); /* ---dbus--- * property: routes @@ -869,14 +869,14 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *klass) * property.) * ---end--- */ - _properties_override_add_gobj (properties_override, - g_object_class_find_property (G_OBJECT_CLASS (setting_class), - NM_SETTING_IP_CONFIG_ROUTES), - NM_SETT_INFO_PROPERT_TYPE ( - .dbus_type = NM_G_VARIANT_TYPE ("aau"), - .to_dbus_fcn = ip4_routes_get, - .from_dbus_fcn = ip4_routes_set, - )); + _nm_properties_override_gobj (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_IP_CONFIG_ROUTES), + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("aau"), + .to_dbus_fcn = ip4_routes_get, + .from_dbus_fcn = ip4_routes_set, + )); /* ---dbus--- * property: route-data @@ -891,13 +891,13 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *klass) * also exist on some routes. * ---end--- */ - _properties_override_add_virt (properties_override, - "route-data", - NM_SETT_INFO_PROPERT_TYPE ( - .dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"), - .to_dbus_fcn = ip4_route_data_get, - .from_dbus_fcn = ip4_route_data_set, - )); + _nm_properties_override_dbus (properties_override, + "route-data", + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"), + .to_dbus_fcn = ip4_route_data_get, + .from_dbus_fcn = ip4_route_data_set, + )); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/libnm-core/nm-setting-ip6-config.c b/libnm-core/nm-setting-ip6-config.c index ee05acdc4b..b326b83ced 100644 --- a/libnm-core/nm-setting-ip6-config.c +++ b/libnm-core/nm-setting-ip6-config.c @@ -880,14 +880,14 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *klass) * description: Array of IP addresses of DNS servers (in network byte order) * ---end--- */ - _properties_override_add_gobj (properties_override, - g_object_class_find_property (G_OBJECT_CLASS (setting_class), - NM_SETTING_IP_CONFIG_DNS), - NM_SETT_INFO_PROPERT_TYPE ( - .dbus_type = NM_G_VARIANT_TYPE ("aay"), - .gprop_to_dbus_fcn = ip6_dns_to_dbus, - .gprop_from_dbus_fcn = ip6_dns_from_dbus, - )); + _nm_properties_override_gobj (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_IP_CONFIG_DNS), + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("aay"), + .gprop_to_dbus_fcn = ip6_dns_to_dbus, + .gprop_from_dbus_fcn = ip6_dns_from_dbus, + )); /* ---dbus--- * property: addresses @@ -903,14 +903,14 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *klass) * that subnet. * ---end--- */ - _properties_override_add_gobj (properties_override, - g_object_class_find_property (G_OBJECT_CLASS (setting_class), - NM_SETTING_IP_CONFIG_ADDRESSES), - NM_SETT_INFO_PROPERT_TYPE ( - .dbus_type = NM_G_VARIANT_TYPE ("a(ayuay)"), - .to_dbus_fcn = ip6_addresses_get, - .from_dbus_fcn = ip6_addresses_set, - )); + _nm_properties_override_gobj (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_IP_CONFIG_ADDRESSES), + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("a(ayuay)"), + .to_dbus_fcn = ip6_addresses_get, + .from_dbus_fcn = ip6_addresses_set, + )); /* ---dbus--- * property: address-data @@ -921,13 +921,13 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *klass) * also exist on some addresses. * ---end--- */ - _properties_override_add_virt (properties_override, - "address-data", - NM_SETT_INFO_PROPERT_TYPE ( - .dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"), - .to_dbus_fcn = ip6_address_data_get, - .from_dbus_fcn = ip6_address_data_set, - )); + _nm_properties_override_dbus (properties_override, + "address-data", + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"), + .to_dbus_fcn = ip6_address_data_get, + .from_dbus_fcn = ip6_address_data_set, + )); /* ---dbus--- * property: routes @@ -943,14 +943,14 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *klass) * default metric for the device. * ---end--- */ - _properties_override_add_gobj (properties_override, - g_object_class_find_property (G_OBJECT_CLASS (setting_class), - NM_SETTING_IP_CONFIG_ROUTES), - NM_SETT_INFO_PROPERT_TYPE ( - .dbus_type = NM_G_VARIANT_TYPE ("a(ayuayu)"), - .to_dbus_fcn = ip6_routes_get, - .from_dbus_fcn = ip6_routes_set, - )); + _nm_properties_override_gobj (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_IP_CONFIG_ROUTES), + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("a(ayuayu)"), + .to_dbus_fcn = ip6_routes_get, + .from_dbus_fcn = ip6_routes_set, + )); /* ---dbus--- * property: route-data @@ -965,13 +965,13 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *klass) * also exist on some routes. * ---end--- */ - _properties_override_add_virt (properties_override, - "route-data", - NM_SETT_INFO_PROPERT_TYPE ( - .dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"), - .to_dbus_fcn = ip6_route_data_get, - .from_dbus_fcn = ip6_route_data_set, - )); + _nm_properties_override_dbus (properties_override, + "route-data", + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"), + .to_dbus_fcn = ip6_route_data_get, + .from_dbus_fcn = ip6_route_data_set, + )); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/libnm-core/nm-setting-olpc-mesh.c b/libnm-core/nm-setting-olpc-mesh.c index 2247dd5bbb..b104b352dc 100644 --- a/libnm-core/nm-setting-olpc-mesh.c +++ b/libnm-core/nm-setting-olpc-mesh.c @@ -250,7 +250,7 @@ nm_setting_olpc_mesh_class_init (NMSettingOlpcMeshClass *klass) NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[PROP_DHCP_ANYCAST_ADDRESS], &nm_sett_info_propert_type_mac_addrees); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_DHCP_ANYCAST_ADDRESS], &nm_sett_info_propert_type_mac_addrees); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/libnm-core/nm-setting-private.h b/libnm-core/nm-setting-private.h index 85b7e728e3..d4444039b7 100644 --- a/libnm-core/nm-setting-private.h +++ b/libnm-core/nm-setting-private.h @@ -157,30 +157,30 @@ _nm_setting_class_commit (NMSettingClass *setting_class, __VA_ARGS__ \ })) -gboolean _properties_override_add_assert (const NMSettInfoProperty *prop_info); +gboolean _nm_properties_override_assert (const NMSettInfoProperty *prop_info); static inline void -_properties_override_add (GArray *properties_override, - const NMSettInfoProperty *prop_info) +_nm_properties_override (GArray *properties_override, + const NMSettInfoProperty *prop_info) { nm_assert (properties_override); - nm_assert (_properties_override_add_assert (prop_info)); + nm_assert (_nm_properties_override_assert (prop_info)); g_array_append_vals (properties_override, prop_info, 1); } -#define _properties_override_add_gobj(properties_override, p_param_spec, p_property_type) \ - _properties_override_add ((properties_override), \ - NM_SETT_INFO_PROPERTY ( \ - .param_spec = (p_param_spec), \ - .property_type = (p_property_type), \ - )) +#define _nm_properties_override_gobj(properties_override, p_param_spec, p_property_type) \ + _nm_properties_override ((properties_override), \ + NM_SETT_INFO_PROPERTY ( \ + .param_spec = (p_param_spec), \ + .property_type = (p_property_type), \ + )) -#define _properties_override_add_virt(properties_override, p_name, p_property_type) \ - _properties_override_add ((properties_override), \ - NM_SETT_INFO_PROPERTY ( \ - .name = (""p_name""), \ - .property_type = (p_property_type), \ - )) +#define _nm_properties_override_dbus(properties_override, p_name, p_property_type) \ + _nm_properties_override ((properties_override), \ + NM_SETT_INFO_PROPERTY ( \ + .name = (""p_name""), \ + .property_type = (p_property_type), \ + )) /*****************************************************************************/ diff --git a/libnm-core/nm-setting-serial.c b/libnm-core/nm-setting-serial.c index 723071ca4e..8b10323838 100644 --- a/libnm-core/nm-setting-serial.c +++ b/libnm-core/nm-setting-serial.c @@ -288,13 +288,13 @@ nm_setting_serial_class_init (NMSettingSerialClass *klass) G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, - obj_properties[PROP_PARITY], - NM_SETT_INFO_PROPERT_TYPE ( - .dbus_type = G_VARIANT_TYPE_BYTE, - .gprop_to_dbus_fcn = parity_to_dbus, - .gprop_from_dbus_fcn = parity_from_dbus, - )); + _nm_properties_override_gobj (properties_override, + obj_properties[PROP_PARITY], + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = G_VARIANT_TYPE_BYTE, + .gprop_to_dbus_fcn = parity_to_dbus, + .gprop_from_dbus_fcn = parity_from_dbus, + )); /** * NMSettingSerial:stopbits: diff --git a/libnm-core/nm-setting-sriov.c b/libnm-core/nm-setting-sriov.c index f5bf5b3c7e..e7f8632e41 100644 --- a/libnm-core/nm-setting-sriov.c +++ b/libnm-core/nm-setting-sriov.c @@ -1326,13 +1326,13 @@ nm_setting_sriov_class_init (NMSettingSriovClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, - obj_properties[PROP_VFS], - NM_SETT_INFO_PROPERT_TYPE ( - .dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"), - .to_dbus_fcn = vfs_to_dbus, - .from_dbus_fcn = vfs_from_dbus, - )); + _nm_properties_override_gobj (properties_override, + obj_properties[PROP_VFS], + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"), + .to_dbus_fcn = vfs_to_dbus, + .from_dbus_fcn = vfs_from_dbus, + )); /** * NMSettingSriov:autoprobe-drivers diff --git a/libnm-core/nm-setting-tc-config.c b/libnm-core/nm-setting-tc-config.c index 5c81c45395..92c658ff36 100644 --- a/libnm-core/nm-setting-tc-config.c +++ b/libnm-core/nm-setting-tc-config.c @@ -1800,13 +1800,13 @@ nm_setting_tc_config_class_init (NMSettingTCConfigClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, - obj_properties[PROP_QDISCS], - NM_SETT_INFO_PROPERT_TYPE ( - .dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"), - .to_dbus_fcn = tc_qdiscs_get, - .from_dbus_fcn = tc_qdiscs_set, - )); + _nm_properties_override_gobj (properties_override, + obj_properties[PROP_QDISCS], + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"), + .to_dbus_fcn = tc_qdiscs_get, + .from_dbus_fcn = tc_qdiscs_set, + )); /** * NMSettingTCConfig:tfilters: (type GPtrArray(NMTCTfilter)) @@ -1826,13 +1826,13 @@ nm_setting_tc_config_class_init (NMSettingTCConfigClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, - obj_properties[PROP_TFILTERS], - NM_SETT_INFO_PROPERT_TYPE ( - .dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"), - .to_dbus_fcn = tc_tfilters_get, - .from_dbus_fcn = tc_tfilters_set, - )); + _nm_properties_override_gobj (properties_override, + obj_properties[PROP_TFILTERS], + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"), + .to_dbus_fcn = tc_tfilters_get, + .from_dbus_fcn = tc_tfilters_set, + )); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/libnm-core/nm-setting-team-port.c b/libnm-core/nm-setting-team-port.c index aff9c94067..49c59f69b8 100644 --- a/libnm-core/nm-setting-team-port.c +++ b/libnm-core/nm-setting-team-port.c @@ -556,7 +556,7 @@ nm_setting_team_port_class_init (NMSettingTeamPortClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_CONFIG], &nm_sett_info_propert_type_team_s); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_CONFIG], &nm_sett_info_propert_type_team_s); /** * NMSettingTeamPort:queue-id: @@ -571,7 +571,7 @@ nm_setting_team_port_class_init (NMSettingTeamPortClass *klass) G_MININT32, G_MAXINT32, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_PORT_QUEUE_ID], &nm_sett_info_propert_type_team_i); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_PORT_QUEUE_ID], &nm_sett_info_propert_type_team_i); /** * NMSettingTeamPort:prio: @@ -585,7 +585,7 @@ nm_setting_team_port_class_init (NMSettingTeamPortClass *klass) G_MININT32, G_MAXINT32, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_PORT_PRIO], &nm_sett_info_propert_type_team_i); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_PORT_PRIO], &nm_sett_info_propert_type_team_i); /** * NMSettingTeamPort:sticky: @@ -599,7 +599,7 @@ nm_setting_team_port_class_init (NMSettingTeamPortClass *klass) FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_PORT_STICKY], &nm_sett_info_propert_type_team_b); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_PORT_STICKY], &nm_sett_info_propert_type_team_b); /** * NMSettingTeamPort:lacp-prio: @@ -613,7 +613,7 @@ nm_setting_team_port_class_init (NMSettingTeamPortClass *klass) G_MININT32, G_MAXINT32, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_PORT_LACP_PRIO], &nm_sett_info_propert_type_team_i); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_PORT_LACP_PRIO], &nm_sett_info_propert_type_team_i); /** * NMSettingTeamPort:lacp-key: @@ -627,7 +627,7 @@ nm_setting_team_port_class_init (NMSettingTeamPortClass *klass) G_MININT32, G_MAXINT32, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_PORT_LACP_KEY], &nm_sett_info_propert_type_team_i); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_PORT_LACP_KEY], &nm_sett_info_propert_type_team_i); /** * NMSettingTeamPort:link-watchers: (type GPtrArray(NMTeamLinkWatcher)) @@ -648,7 +648,7 @@ nm_setting_team_port_class_init (NMSettingTeamPortClass *klass) G_TYPE_PTR_ARRAY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_LINK_WATCHERS], &nm_sett_info_propert_type_team_link_watchers); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_LINK_WATCHERS], &nm_sett_info_propert_type_team_link_watchers); g_object_class_install_properties (object_class, G_N_ELEMENTS (obj_properties), obj_properties); diff --git a/libnm-core/nm-setting-team.c b/libnm-core/nm-setting-team.c index 56bdc280ae..27f11dcf9b 100644 --- a/libnm-core/nm-setting-team.c +++ b/libnm-core/nm-setting-team.c @@ -1503,7 +1503,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_CONFIG], &nm_sett_info_propert_type_team_s); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_CONFIG], &nm_sett_info_propert_type_team_s); /** * NMSettingTeam:notify-peers-count: @@ -1517,7 +1517,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) G_MININT32, G_MAXINT32, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_NOTIFY_PEERS_COUNT], &nm_sett_info_propert_type_team_i); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_NOTIFY_PEERS_COUNT], &nm_sett_info_propert_type_team_i); /** * NMSettingTeam:notify-peers-interval: @@ -1531,7 +1531,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) G_MININT32, G_MAXINT32, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_NOTIFY_PEERS_INTERVAL], &nm_sett_info_propert_type_team_i); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_NOTIFY_PEERS_INTERVAL], &nm_sett_info_propert_type_team_i); /** * NMSettingTeam:mcast-rejoin-count: @@ -1545,7 +1545,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) G_MININT32, G_MAXINT32, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_MCAST_REJOIN_COUNT], &nm_sett_info_propert_type_team_i); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_MCAST_REJOIN_COUNT], &nm_sett_info_propert_type_team_i); /** * NMSettingTeam:mcast-rejoin-interval: @@ -1559,7 +1559,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) G_MININT32, G_MAXINT32, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_MCAST_REJOIN_INTERVAL], &nm_sett_info_propert_type_team_i); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_MCAST_REJOIN_INTERVAL], &nm_sett_info_propert_type_team_i); /** * NMSettingTeam:runner: @@ -1575,7 +1575,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER], &nm_sett_info_propert_type_team_s); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER], &nm_sett_info_propert_type_team_s); /** * NMSettingTeam:runner-hwaddr-policy: @@ -1589,7 +1589,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_HWADDR_POLICY], &nm_sett_info_propert_type_team_s); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_HWADDR_POLICY], &nm_sett_info_propert_type_team_s); /** * NMSettingTeam:runner-tx-hash: @@ -1604,7 +1604,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_TX_HASH], &nm_sett_info_propert_type_team_as); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_TX_HASH], &nm_sett_info_propert_type_team_as); /** * NMSettingTeam:runner-tx-balancer: @@ -1618,7 +1618,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_TX_BALANCER], &nm_sett_info_propert_type_team_s); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_TX_BALANCER], &nm_sett_info_propert_type_team_s); /** * NMSettingTeam:runner-tx-balancer-interval: @@ -1632,7 +1632,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) G_MININT32, G_MAXINT32, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_TX_BALANCER_INTERVAL], &nm_sett_info_propert_type_team_i); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_TX_BALANCER_INTERVAL], &nm_sett_info_propert_type_team_i); /** * NMSettingTeam:runner-active: @@ -1646,7 +1646,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) TRUE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_ACTIVE], &nm_sett_info_propert_type_team_b); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_ACTIVE], &nm_sett_info_propert_type_team_b); /** * NMSettingTeam:runner-fast-rate: @@ -1660,7 +1660,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_FAST_RATE], &nm_sett_info_propert_type_team_b); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_FAST_RATE], &nm_sett_info_propert_type_team_b); /** * NMSettingTeam:runner-sys-prio: @@ -1674,7 +1674,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) G_MININT32, G_MAXINT32, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_SYS_PRIO], &nm_sett_info_propert_type_team_i); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_SYS_PRIO], &nm_sett_info_propert_type_team_i); /** * NMSettingTeam:runner-min-ports: @@ -1688,7 +1688,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) G_MININT32, G_MAXINT32, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_MIN_PORTS], &nm_sett_info_propert_type_team_i); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_MIN_PORTS], &nm_sett_info_propert_type_team_i); /** * NMSettingTeam:runner-agg-select-policy: @@ -1702,7 +1702,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_AGG_SELECT_POLICY], &nm_sett_info_propert_type_team_s); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_MASTER_RUNNER_AGG_SELECT_POLICY], &nm_sett_info_propert_type_team_s); /** * NMSettingTeam:link-watchers: (type GPtrArray(NMTeamLinkWatcher)) @@ -1723,7 +1723,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) G_TYPE_PTR_ARRAY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_LINK_WATCHERS], &nm_sett_info_propert_type_team_link_watchers); + _nm_properties_override_gobj (properties_override, obj_properties[NM_TEAM_ATTRIBUTE_LINK_WATCHERS], &nm_sett_info_propert_type_team_link_watchers); /* ---dbus--- * property: interface-name @@ -1733,7 +1733,7 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) * team's interface name. * ---end--- */ - _properties_override_add_virt (properties_override, "interface-name", &nm_sett_info_propert_type_deprecated_interface_name); + _nm_properties_override_dbus (properties_override, "interface-name", &nm_sett_info_propert_type_deprecated_interface_name); g_object_class_install_properties (object_class, G_N_ELEMENTS (obj_properties), obj_properties); diff --git a/libnm-core/nm-setting-user.c b/libnm-core/nm-setting-user.c index 1763df5ea6..2e9ad3cf86 100644 --- a/libnm-core/nm-setting-user.c +++ b/libnm-core/nm-setting-user.c @@ -571,7 +571,7 @@ nm_setting_user_class_init (NMSettingUserClass *klass) G_TYPE_HASH_TABLE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[PROP_DATA], &nm_sett_info_propert_type_strdict); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_DATA], &nm_sett_info_propert_type_strdict); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/libnm-core/nm-setting-vlan.c b/libnm-core/nm-setting-vlan.c index 6b8f870f13..3c48c865dc 100644 --- a/libnm-core/nm-setting-vlan.c +++ b/libnm-core/nm-setting-vlan.c @@ -908,13 +908,13 @@ nm_setting_vlan_class_init (NMSettingVlanClass *klass) G_PARAM_CONSTRUCT | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, - obj_properties[PROP_FLAGS], - NM_SETT_INFO_PROPERT_TYPE ( - .dbus_type = G_VARIANT_TYPE_UINT32, - .to_dbus_fcn = _override_flags_get, - .missing_from_dbus_fcn = _override_flags_not_set, - )); + _nm_properties_override_gobj (properties_override, + obj_properties[PROP_FLAGS], + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = G_VARIANT_TYPE_UINT32, + .to_dbus_fcn = _override_flags_get, + .missing_from_dbus_fcn = _override_flags_not_set, + )); /** * NMSettingVlan:ingress-priority-map: @@ -974,7 +974,7 @@ nm_setting_vlan_class_init (NMSettingVlanClass *klass) * vlan's interface name. * ---end--- */ - _properties_override_add_virt (properties_override, "interface-name", &nm_sett_info_propert_type_deprecated_interface_name); + _nm_properties_override_dbus (properties_override, "interface-name", &nm_sett_info_propert_type_deprecated_interface_name); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/libnm-core/nm-setting-vpn.c b/libnm-core/nm-setting-vpn.c index 0c06c3b32d..4adc0bc8ca 100644 --- a/libnm-core/nm-setting-vpn.c +++ b/libnm-core/nm-setting-vpn.c @@ -1129,7 +1129,7 @@ nm_setting_vpn_class_init (NMSettingVpnClass *klass) G_TYPE_HASH_TABLE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[PROP_DATA], &nm_sett_info_propert_type_strdict); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_DATA], &nm_sett_info_propert_type_strdict); /** * NMSettingVpn:secrets: (type GHashTable(utf8,utf8)): @@ -1151,13 +1151,13 @@ nm_setting_vpn_class_init (NMSettingVpnClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_SECRET | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, - obj_properties[PROP_SECRETS], - NM_SETT_INFO_PROPERT_TYPE ( - .dbus_type = NM_G_VARIANT_TYPE ("a{ss}"), - .to_dbus_fcn = vpn_secrets_to_dbus, - .from_dbus_fcn = vpn_secrets_from_dbus, - )); + _nm_properties_override_gobj (properties_override, + obj_properties[PROP_SECRETS], + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("a{ss}"), + .to_dbus_fcn = vpn_secrets_to_dbus, + .from_dbus_fcn = vpn_secrets_from_dbus, + )); /** * NMSettingVpn:timeout: diff --git a/libnm-core/nm-setting-wimax.c b/libnm-core/nm-setting-wimax.c index 52f7d827bb..0824b66c78 100644 --- a/libnm-core/nm-setting-wimax.c +++ b/libnm-core/nm-setting-wimax.c @@ -236,7 +236,7 @@ nm_setting_wimax_class_init (NMSettingWimaxClass *klass) NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[PROP_MAC_ADDRESS], &nm_sett_info_propert_type_mac_addrees); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_MAC_ADDRESS], &nm_sett_info_propert_type_mac_addrees); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/libnm-core/nm-setting-wired.c b/libnm-core/nm-setting-wired.c index 20f41cb355..7de223d6ce 100644 --- a/libnm-core/nm-setting-wired.c +++ b/libnm-core/nm-setting-wired.c @@ -1306,12 +1306,12 @@ nm_setting_wired_class_init (NMSettingWiredClass *klass) G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, - obj_properties[PROP_AUTO_NEGOTIATE], - NM_SETT_INFO_PROPERT_TYPE ( - .dbus_type = G_VARIANT_TYPE_BOOLEAN, - .to_dbus_fcn = _override_autoneg_get, - )); + _nm_properties_override_gobj (properties_override, + obj_properties[PROP_AUTO_NEGOTIATE], + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = G_VARIANT_TYPE_BOOLEAN, + .to_dbus_fcn = _override_autoneg_get, + )); /** * NMSettingWired:mac-address: @@ -1343,7 +1343,7 @@ nm_setting_wired_class_init (NMSettingWiredClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[PROP_MAC_ADDRESS], &nm_sett_info_propert_type_mac_addrees); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_MAC_ADDRESS], &nm_sett_info_propert_type_mac_addrees); /** * NMSettingWired:cloned-mac-address: @@ -1394,7 +1394,7 @@ nm_setting_wired_class_init (NMSettingWiredClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[PROP_CLONED_MAC_ADDRESS], &nm_sett_info_propert_type_cloned_mac_address); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_CLONED_MAC_ADDRESS], &nm_sett_info_propert_type_cloned_mac_address); /* ---dbus--- * property: assigned-mac-address @@ -1408,7 +1408,7 @@ nm_setting_wired_class_init (NMSettingWiredClass *klass) * "cloned-mac-address". * ---end--- */ - _properties_override_add_virt (properties_override, "assigned-mac-address", &nm_sett_info_propert_type_assigned_mac_address); + _nm_properties_override_dbus (properties_override, "assigned-mac-address", &nm_sett_info_propert_type_assigned_mac_address); /** * NMSettingWired:generate-mac-address-mask: @@ -1572,7 +1572,7 @@ nm_setting_wired_class_init (NMSettingWiredClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[PROP_S390_OPTIONS], &nm_sett_info_propert_type_strdict); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_S390_OPTIONS], &nm_sett_info_propert_type_strdict); /** * NMSettingWired:wake-on-lan: diff --git a/libnm-core/nm-setting-wireguard.c b/libnm-core/nm-setting-wireguard.c index ff4cf93839..a0e3ffcde8 100644 --- a/libnm-core/nm-setting-wireguard.c +++ b/libnm-core/nm-setting-wireguard.c @@ -2571,13 +2571,13 @@ nm_setting_wireguard_class_init (NMSettingWireGuardClass *klass) * description: Array of dictionaries for the WireGuard peers. * ---end--- */ - _properties_override_add_virt (properties_override, - NM_SETTING_WIREGUARD_PEERS, - NM_SETT_INFO_PROPERT_TYPE ( - .dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"), - .to_dbus_fcn = _peers_dbus_only_synth, - .from_dbus_fcn = _peers_dbus_only_set, - )); + _nm_properties_override_dbus (properties_override, + NM_SETTING_WIREGUARD_PEERS, + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"), + .to_dbus_fcn = _peers_dbus_only_synth, + .from_dbus_fcn = _peers_dbus_only_set, + )); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/libnm-core/nm-setting-wireless-security.c b/libnm-core/nm-setting-wireless-security.c index 4074b26693..c4b45d2247 100644 --- a/libnm-core/nm-setting-wireless-security.c +++ b/libnm-core/nm-setting-wireless-security.c @@ -1811,12 +1811,12 @@ nm_setting_wireless_security_class_init (NMSettingWirelessSecurityClass *klass) G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, - obj_properties[PROP_WEP_KEY_TYPE], - NM_SETT_INFO_PROPERT_TYPE ( - .dbus_type = G_VARIANT_TYPE_UINT32, - .gprop_to_dbus_fcn = wep_key_type_to_dbus, - )); + _nm_properties_override_gobj (properties_override, + obj_properties[PROP_WEP_KEY_TYPE], + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = G_VARIANT_TYPE_UINT32, + .gprop_to_dbus_fcn = wep_key_type_to_dbus, + )); /** * NMSettingWirelessSecurity:wps-method: diff --git a/libnm-core/nm-setting-wireless.c b/libnm-core/nm-setting-wireless.c index 0fa0f692b0..339fb3a0a3 100644 --- a/libnm-core/nm-setting-wireless.c +++ b/libnm-core/nm-setting-wireless.c @@ -1376,7 +1376,7 @@ nm_setting_wireless_class_init (NMSettingWirelessClass *klass) NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[PROP_BSSID], &nm_sett_info_propert_type_mac_addrees); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_BSSID], &nm_sett_info_propert_type_mac_addrees); /** * NMSettingWireless:rate: @@ -1450,7 +1450,7 @@ nm_setting_wireless_class_init (NMSettingWirelessClass *klass) NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[PROP_MAC_ADDRESS], &nm_sett_info_propert_type_mac_addrees); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_MAC_ADDRESS], &nm_sett_info_propert_type_mac_addrees); /** * NMSettingWireless:cloned-mac-address: @@ -1500,7 +1500,7 @@ nm_setting_wireless_class_init (NMSettingWirelessClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, obj_properties[PROP_CLONED_MAC_ADDRESS], &nm_sett_info_propert_type_cloned_mac_address); + _nm_properties_override_gobj (properties_override, obj_properties[PROP_CLONED_MAC_ADDRESS], &nm_sett_info_propert_type_cloned_mac_address); /* ---dbus--- * property: assigned-mac-address @@ -1514,7 +1514,7 @@ nm_setting_wireless_class_init (NMSettingWirelessClass *klass) * "cloned-mac-address". * ---end--- */ - _properties_override_add_virt (properties_override, "assigned-mac-address", &nm_sett_info_propert_type_assigned_mac_address); + _nm_properties_override_dbus (properties_override, "assigned-mac-address", &nm_sett_info_propert_type_assigned_mac_address); /** * NMSettingWireless:generate-mac-address-mask: @@ -1611,12 +1611,12 @@ nm_setting_wireless_class_init (NMSettingWirelessClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_STATIC_STRINGS); - _properties_override_add_gobj (properties_override, - obj_properties[PROP_SEEN_BSSIDS], - NM_SETT_INFO_PROPERT_TYPE ( - .dbus_type = G_VARIANT_TYPE_STRING_ARRAY, - .to_dbus_fcn = _to_dbus_fcn_seen_bssids, - )); + _nm_properties_override_gobj (properties_override, + obj_properties[PROP_SEEN_BSSIDS], + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = G_VARIANT_TYPE_STRING_ARRAY, + .to_dbus_fcn = _to_dbus_fcn_seen_bssids, + )); /** * NMSettingWireless:mtu: @@ -1734,12 +1734,12 @@ nm_setting_wireless_class_init (NMSettingWirelessClass *klass) * NetworkManager daemons. * ---end--- */ - _properties_override_add_virt (properties_override, - "security", - NM_SETT_INFO_PROPERT_TYPE ( - .dbus_type = G_VARIANT_TYPE_STRING, - .to_dbus_fcn = nm_setting_wireless_get_security, - )); + _nm_properties_override_dbus (properties_override, + "security", + NM_SETT_INFO_PROPERT_TYPE ( + .dbus_type = G_VARIANT_TYPE_STRING, + .to_dbus_fcn = nm_setting_wireless_get_security, + )); /** * NMSettingWireless:wake-on-wlan: diff --git a/libnm-core/nm-setting.c b/libnm-core/nm-setting.c index 096a6546d7..e3bd1e2fe2 100644 --- a/libnm-core/nm-setting.c +++ b/libnm-core/nm-setting.c @@ -203,7 +203,7 @@ _gprop_to_dbus_fcn_flags (const GValue *val) } gboolean -_properties_override_add_assert (const NMSettInfoProperty *prop_info) +_nm_properties_override_assert (const NMSettInfoProperty *prop_info) { nm_assert (prop_info); nm_assert ((!!prop_info->name) != (!!prop_info->param_spec)); From 133f23d39ed3c20cb14c991983fe670de5dc64a4 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 22 Sep 2019 16:21:00 +0200 Subject: [PATCH 10/12] libnm: copy list of property-infos instead of keeping buffer from GArray We use the "properties_override" GArray to construct the list of property infos. But as we append values to the GArray, the buffer grows exponentially and likely is larger than the actually used number of values. As this data is kept until the end of the program, let's not waste the over-allocated memory and instead copy it to a buffer of the right size. --- libnm-core/nm-setting.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libnm-core/nm-setting.c b/libnm-core/nm-setting.c index e3bd1e2fe2..97e3441385 100644 --- a/libnm-core/nm-setting.c +++ b/libnm-core/nm-setting.c @@ -442,13 +442,15 @@ has_property_type: sett_info->setting_class = setting_class; if (detail) sett_info->detail = *detail; + nm_assert (properties_override->len > 0); sett_info->property_infos_len = properties_override->len; - sett_info->property_infos = (const NMSettInfoProperty *) g_array_free (properties_override, - properties_override->len == 0); + sett_info->property_infos = nm_memdup (properties_override->data, sizeof (NMSettInfoProperty) * properties_override->len); sett_info->property_infos_sorted = _property_infos_sort (sett_info->property_infos, sett_info->property_infos_len, setting_class); + + g_array_free (properties_override, TRUE); } const NMSettInfoProperty * From 5a5e08794e93e3ec250648b7765bdff67c671bce Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 24 Sep 2019 18:27:37 +0200 Subject: [PATCH 11/12] libnm: drop unused NM_SETTING_PARAM_GENDATA_BACKED property flag The idea was that properties that are implemented via GENDATA still could have a GObject property. As such, they would be marked with this flag. Currently, gendata properties are only implemented by NMSettingEthtool, and there are no GObject properties where this flag is used. While it might make sense in theory or in the future, it is unused. Drop it. --- libnm-core/nm-setting-private.h | 2 -- libnm-core/nm-setting.c | 3 --- 2 files changed, 5 deletions(-) diff --git a/libnm-core/nm-setting-private.h b/libnm-core/nm-setting-private.h index d4444039b7..0b7509d8c1 100644 --- a/libnm-core/nm-setting-private.h +++ b/libnm-core/nm-setting-private.h @@ -67,8 +67,6 @@ gboolean _nm_setting_clear_secrets (NMSetting *setting, */ #define NM_SETTING_PARAM_REAPPLY_IMMEDIATELY (1 << (6 + G_PARAM_USER_SHIFT)) -#define NM_SETTING_PARAM_GENDATA_BACKED (1 << (7 + G_PARAM_USER_SHIFT)) - extern const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_interface_name; extern const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_ignore_i; extern const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_ignore_u; diff --git a/libnm-core/nm-setting.c b/libnm-core/nm-setting.c index 97e3441385..d4bd9bc764 100644 --- a/libnm-core/nm-setting.c +++ b/libnm-core/nm-setting.c @@ -590,9 +590,6 @@ property_to_dbus (const NMSettInfoSetting *sett_info, if (!NM_FLAGS_HAS (property->param_spec->flags, G_PARAM_WRITABLE)) return NULL; - if (NM_FLAGS_ANY (property->param_spec->flags, NM_SETTING_PARAM_GENDATA_BACKED)) - return NULL; - if ( NM_FLAGS_HAS (property->param_spec->flags, NM_SETTING_PARAM_LEGACY) && !_nm_utils_is_manager_process) return NULL; From 29a451d33a3630f034c9394ef376dc4887177bfe Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 24 Sep 2019 18:25:00 +0200 Subject: [PATCH 12/12] libnm: don't special case "vpn.secrets" property in property_to_dbus() "nm-setting.c" (and property_to_dbus()) should stay independent of actualy settings implementations. Instead, the property-info should control the behavior. What I like about this change is also that the generic handling is not a flags "handle_secrets_for_vpn", but it just says to skip checking the param-spec flags and directly call the to_dbus_fcn(). It's just a generally useful thing to do, to let the to_dbus_fcn() function also handle checking the property flags. The fact that only vpn.secrets properties uses this for a certain pupose, is abstracted in a way that makes sense. --- libnm-core/nm-setting-private.h | 4 ++++ libnm-core/nm-setting-vpn.c | 4 ++++ libnm-core/nm-setting.c | 11 +++-------- libnm-core/tests/test-setting.c | 3 +++ 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/libnm-core/nm-setting-private.h b/libnm-core/nm-setting-private.h index 0b7509d8c1..a85237e0bb 100644 --- a/libnm-core/nm-setting-private.h +++ b/libnm-core/nm-setting-private.h @@ -67,6 +67,10 @@ gboolean _nm_setting_clear_secrets (NMSetting *setting, */ #define NM_SETTING_PARAM_REAPPLY_IMMEDIATELY (1 << (6 + G_PARAM_USER_SHIFT)) +/* property_to_dbus() should ignore the property flags, and instead always calls to_dbus_fcn() + */ +#define NM_SETTING_PARAM_TO_DBUS_IGNORE_FLAGS (1 << (7 + G_PARAM_USER_SHIFT)) + extern const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_interface_name; extern const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_ignore_i; extern const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_ignore_u; diff --git a/libnm-core/nm-setting-vpn.c b/libnm-core/nm-setting-vpn.c index 4adc0bc8ca..bc30f47641 100644 --- a/libnm-core/nm-setting-vpn.c +++ b/libnm-core/nm-setting-vpn.c @@ -921,6 +921,9 @@ vpn_secrets_to_dbus (const NMSettInfoSetting *sett_info, const char *key, *value; NMSettingSecretFlags secret_flags; + if (NM_FLAGS_HAS (flags, NM_CONNECTION_SERIALIZE_NO_SECRETS)) + return NULL; + g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{ss}")); g_object_get (setting, property_name, &secrets, NULL); @@ -1150,6 +1153,7 @@ nm_setting_vpn_class_init (NMSettingVpnClass *klass) G_TYPE_HASH_TABLE, G_PARAM_READWRITE | NM_SETTING_PARAM_SECRET | + NM_SETTING_PARAM_TO_DBUS_IGNORE_FLAGS | G_PARAM_STATIC_STRINGS); _nm_properties_override_gobj (properties_override, obj_properties[PROP_SECRETS], diff --git a/libnm-core/nm-setting.c b/libnm-core/nm-setting.c index d4bd9bc764..6f77282b70 100644 --- a/libnm-core/nm-setting.c +++ b/libnm-core/nm-setting.c @@ -586,7 +586,8 @@ property_to_dbus (const NMSettInfoSetting *sett_info, if (!property->param_spec) { if (!property->property_type->to_dbus_fcn) return NULL; - } else if (!ignore_flags) { + } else if ( !ignore_flags + && !NM_FLAGS_HAS (property->param_spec->flags, NM_SETTING_PARAM_TO_DBUS_IGNORE_FLAGS)) { if (!NM_FLAGS_HAS (property->param_spec->flags, G_PARAM_WRITABLE)) return NULL; @@ -598,13 +599,7 @@ property_to_dbus (const NMSettInfoSetting *sett_info, if (NM_FLAGS_HAS (flags, NM_CONNECTION_SERIALIZE_NO_SECRETS)) return NULL; - /* Check agent secrets. Secrets in the vpn.secrets property are special as - * the flag for each of them is specified as a separate key in the - * vpn.data property. They are handled separately in the to_dbus_fcn() - * of VPN setting. */ - if ( NM_FLAGS_HAS (flags, NM_CONNECTION_SERIALIZE_WITH_SECRETS_AGENT_OWNED) - && !nm_streq (nm_setting_get_name (setting), NM_SETTING_VPN_SETTING_NAME) - && !nm_streq (property->name, NM_SETTING_VPN_SECRETS)) { + if (NM_FLAGS_HAS (flags, NM_CONNECTION_SERIALIZE_WITH_SECRETS_AGENT_OWNED)) { NMSettingSecretFlags f; /* see also _nm_connection_serialize_secrets() */ diff --git a/libnm-core/tests/test-setting.c b/libnm-core/tests/test-setting.c index e6a7e900b2..1cbdf07cd0 100644 --- a/libnm-core/tests/test-setting.c +++ b/libnm-core/tests/test-setting.c @@ -3487,6 +3487,9 @@ test_setting_metadata (void) else g_assert_cmpstr (g_value_get_string (&val), ==, default_value); } + + if (NM_FLAGS_HAS (sip->param_spec->flags, NM_SETTING_PARAM_TO_DBUS_IGNORE_FLAGS)) + g_assert (sip->property_type->to_dbus_fcn); } }