From b33ba1ef5cb76566a62ad1397f685e1a69758c9d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 17 Jun 2021 22:10:43 +0200 Subject: [PATCH 01/21] glib-aux: add nm_g_variant_singleton_b() helper (cherry picked from commit edb31252cc4d57e8d80b1e1c907b3c37a49a250b) --- src/libnm-glib-aux/nm-shared-utils.c | 45 +++++++++++++++++----------- src/libnm-glib-aux/nm-shared-utils.h | 1 + 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/libnm-glib-aux/nm-shared-utils.c b/src/libnm-glib-aux/nm-shared-utils.c index 936d900618..e2d88af66a 100644 --- a/src/libnm-glib-aux/nm-shared-utils.c +++ b/src/libnm-glib-aux/nm-shared-utils.c @@ -529,24 +529,26 @@ nm_utils_gbytes_to_variant_ay(GBytes *bytes) /*****************************************************************************/ -#define _variant_singleton_get(create_variant) \ - ({ \ - static GVariant *_singleton = NULL; \ - GVariant * _v; \ - \ -again: \ - _v = g_atomic_pointer_get(&_singleton); \ - if (G_UNLIKELY(!_v)) { \ - _v = (create_variant); \ - nm_assert(_v); \ - nm_assert(g_variant_is_floating(_v)); \ - g_variant_ref_sink(_v); \ - if (!g_atomic_pointer_compare_and_exchange(&_singleton, NULL, _v)) { \ - g_variant_unref(_v); \ - goto again; \ - } \ - } \ - _v; \ +#define _variant_singleton_get(create_variant) \ + ({ \ + static GVariant *_singleton = NULL; \ + GVariant * _v; \ + \ + while (TRUE) { \ + _v = g_atomic_pointer_get(&_singleton); \ + if (G_UNLIKELY(!_v)) { \ + _v = (create_variant); \ + nm_assert(_v); \ + nm_assert(g_variant_is_floating(_v)); \ + g_variant_ref_sink(_v); \ + if (!g_atomic_pointer_compare_and_exchange(&_singleton, NULL, _v)) { \ + g_variant_unref(_v); \ + continue; \ + } \ + } \ + break; \ + } \ + _v; \ }) GVariant * @@ -555,6 +557,13 @@ nm_g_variant_singleton_u_0(void) return _variant_singleton_get(g_variant_new_uint32(0)); } +GVariant * +nm_g_variant_singleton_b(gboolean value) +{ + return value ? _variant_singleton_get(g_variant_new_boolean(TRUE)) + : _variant_singleton_get(g_variant_new_boolean(FALSE)); +} + static GVariant * _variant_singleton_get_array_init(GVariant **p_singleton, const char *variant_type) { diff --git a/src/libnm-glib-aux/nm-shared-utils.h b/src/libnm-glib-aux/nm-shared-utils.h index 7887551d96..4b2429255c 100644 --- a/src/libnm-glib-aux/nm-shared-utils.h +++ b/src/libnm-glib-aux/nm-shared-utils.h @@ -1487,6 +1487,7 @@ char *nm_utils_str_utf8safe_unescape_cp(const char *str, NMUtilsStrUtf8SafeFlags char *nm_utils_str_utf8safe_escape_take(char *str, NMUtilsStrUtf8SafeFlags flags); +GVariant *nm_g_variant_singleton_b(gboolean value); GVariant *nm_g_variant_singleton_u_0(void); GVariant *nm_g_variant_singleton_aLsvI(void); GVariant *nm_g_variant_singleton_aLsaLsvII(void); From d99e20e436786a1d9b64461723a3256c4eca4210 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 18 Jun 2021 14:36:41 +0200 Subject: [PATCH 02/21] glib-aux: add nm_g_variant_singleton_s_empty() helper (cherry picked from commit e2defd011571339e974ed53453bcf30daad2fe31) --- src/libnm-glib-aux/nm-shared-utils.c | 6 ++++++ src/libnm-glib-aux/nm-shared-utils.h | 1 + 2 files changed, 7 insertions(+) diff --git a/src/libnm-glib-aux/nm-shared-utils.c b/src/libnm-glib-aux/nm-shared-utils.c index e2d88af66a..e42e0fe590 100644 --- a/src/libnm-glib-aux/nm-shared-utils.c +++ b/src/libnm-glib-aux/nm-shared-utils.c @@ -564,6 +564,12 @@ nm_g_variant_singleton_b(gboolean value) : _variant_singleton_get(g_variant_new_boolean(FALSE)); } +GVariant * +nm_g_variant_singleton_s_empty(void) +{ + return _variant_singleton_get(g_variant_new_string("")); +} + static GVariant * _variant_singleton_get_array_init(GVariant **p_singleton, const char *variant_type) { diff --git a/src/libnm-glib-aux/nm-shared-utils.h b/src/libnm-glib-aux/nm-shared-utils.h index 4b2429255c..40f22354b6 100644 --- a/src/libnm-glib-aux/nm-shared-utils.h +++ b/src/libnm-glib-aux/nm-shared-utils.h @@ -1489,6 +1489,7 @@ char *nm_utils_str_utf8safe_escape_take(char *str, NMUtilsStrUtf8SafeFlags flags GVariant *nm_g_variant_singleton_b(gboolean value); GVariant *nm_g_variant_singleton_u_0(void); +GVariant *nm_g_variant_singleton_s_empty(void); GVariant *nm_g_variant_singleton_aLsvI(void); GVariant *nm_g_variant_singleton_aLsaLsvII(void); GVariant *nm_g_variant_singleton_aaLsvI(void); From 445d01e2c662410498e2bae28201c295805ebede Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 17 Jun 2021 23:41:44 +0200 Subject: [PATCH 03/21] glib-aux: add NM_G_PARAM_SPEC_GET_DEFAULT_STRING() helper (cherry picked from commit 87229b22aec787444d646966937553ffe0852d8d) --- src/libnm-glib-aux/nm-shared-utils.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libnm-glib-aux/nm-shared-utils.h b/src/libnm-glib-aux/nm-shared-utils.h index 40f22354b6..f5b1d00cfb 100644 --- a/src/libnm-glib-aux/nm-shared-utils.h +++ b/src/libnm-glib-aux/nm-shared-utils.h @@ -1425,6 +1425,8 @@ GParamSpec *nm_g_object_class_find_property_from_gtype(GType gtype, const char * _NM_G_PARAM_SPEC_CAST(param_spec, G_TYPE_UINT, GParamSpecUInt) #define NM_G_PARAM_SPEC_CAST_UINT64(param_spec) \ _NM_G_PARAM_SPEC_CAST(param_spec, G_TYPE_UINT64, GParamSpecUInt64) +#define NM_G_PARAM_SPEC_CAST_STRING(param_spec) \ + _NM_G_PARAM_SPEC_CAST(param_spec, G_TYPE_STRING, GParamSpecString) #define NM_G_PARAM_SPEC_GET_DEFAULT_BOOLEAN(param_spec) \ (NM_G_PARAM_SPEC_CAST_BOOLEAN(NM_ENSURE_NOT_NULL(param_spec))->default_value) @@ -1432,6 +1434,8 @@ GParamSpec *nm_g_object_class_find_property_from_gtype(GType gtype, const char * (NM_G_PARAM_SPEC_CAST_UINT(NM_ENSURE_NOT_NULL(param_spec))->default_value) #define NM_G_PARAM_SPEC_GET_DEFAULT_UINT64(param_spec) \ (NM_G_PARAM_SPEC_CAST_UINT64(NM_ENSURE_NOT_NULL(param_spec))->default_value) +#define NM_G_PARAM_SPEC_GET_DEFAULT_STRING(param_spec) \ + (NM_G_PARAM_SPEC_CAST_STRING(NM_ENSURE_NOT_NULL(param_spec))->default_value) /*****************************************************************************/ From d19c0937d4466373af4ce23af63e287859d07437 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 18 Jun 2021 13:18:12 +0200 Subject: [PATCH 04/21] libnm: expose internal helper nm_utils_hwaddr_to_dbus() (cherry picked from commit 8081e39ab680644b0e0a375247b9a95793d9aa94) --- src/libnm-core-impl/nm-utils.c | 8 ++++---- src/libnm-core-intern/nm-core-internal.h | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/libnm-core-impl/nm-utils.c b/src/libnm-core-impl/nm-utils.c index d9956a4dff..391dd1a15e 100644 --- a/src/libnm-core-impl/nm-utils.c +++ b/src/libnm-core-impl/nm-utils.c @@ -3994,8 +3994,8 @@ nm_utils_hwaddr_matches(gconstpointer hwaddr1, /*****************************************************************************/ -static GVariant * -_nm_utils_hwaddr_to_dbus_impl(const char *str) +GVariant * +nm_utils_hwaddr_to_dbus(const char *str) { guint8 buf[NM_UTILS_HWADDR_LEN_MAX]; gsize len; @@ -4021,7 +4021,7 @@ _nm_utils_hwaddr_cloned_get(const NMSettInfoSetting * sett_info, nm_assert(nm_streq(sett_info->property_infos[property_idx].name, "cloned-mac-address")); g_object_get(setting, "cloned-mac-address", &addr, NULL); - return _nm_utils_hwaddr_to_dbus_impl(addr); + return nm_utils_hwaddr_to_dbus(addr); } static gboolean @@ -4140,7 +4140,7 @@ const NMSettInfoPropertType nm_sett_info_propert_type_assigned_mac_address = { static GVariant * _nm_utils_hwaddr_to_dbus(const GValue *prop_value) { - return _nm_utils_hwaddr_to_dbus_impl(g_value_get_string(prop_value)); + return nm_utils_hwaddr_to_dbus(g_value_get_string(prop_value)); } static void diff --git a/src/libnm-core-intern/nm-core-internal.h b/src/libnm-core-intern/nm-core-internal.h index 5ea68ea3bd..eb471a34a1 100644 --- a/src/libnm-core-intern/nm-core-internal.h +++ b/src/libnm-core-intern/nm-core-internal.h @@ -642,6 +642,10 @@ GVariant * nm_ip_routing_rule_to_dbus(const NMIPRoutingRule *self); /*****************************************************************************/ +GVariant *nm_utils_hwaddr_to_dbus(const char *str); + +/*****************************************************************************/ + typedef struct _NMSettInfoSetting NMSettInfoSetting; typedef struct _NMSettInfoProperty NMSettInfoProperty; From 3e58861336c7236b790b5f6a56b9be90498e950b Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 17 Jun 2021 22:01:34 +0200 Subject: [PATCH 05/21] libnm: simplify assertions for valid NMSettInfoProperty (cherry picked from commit 21638c54b0ab811eddd22fcb565fc988e19fad4e) --- src/libnm-core-impl/nm-setting.c | 34 ++++++++++++++------------------ 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index 2e373a5ab0..6e1fb70d25 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -178,33 +178,29 @@ _gprop_to_dbus_fcn_flags(const GValue *val) gboolean _nm_properties_override_assert(const NMSettInfoProperty *prop_info) { +#if NM_MORE_ASSERTS 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)); -#define _PROPERT_EXTRA(prop_info, member) \ - ({ \ - const NMSettInfoProperty *_prop_info = (prop_info); \ - \ - (_prop_info->property_type ? _prop_info->property_type->member : 0); \ - }) + if (prop_info->property_type) { + const NMSettInfoPropertType *property_type = prop_info->property_type; - 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)); + /* we always require a dbus_type. */ + nm_assert(property_type->dbus_type); - 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 + /* {to,from}_dbus_fcn and gprop_{to,from}_dbus_fcn cannot both be set. */ + nm_assert(!property_type->to_dbus_fcn || !property_type->gprop_to_dbus_fcn); + nm_assert(!property_type->from_dbus_fcn || !property_type->gprop_from_dbus_fcn); + if (!prop_info->param_spec) { + /* if we don't have a param_spec, we cannot have gprop_{to,from}_dbus_fcn. */ + nm_assert(!property_type->gprop_to_dbus_fcn); + nm_assert(!property_type->gprop_from_dbus_fcn); + } + } +#endif return TRUE; } From 1ebef5060393dcf063f159a824eb2f0e4379e7f6 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 17 Jun 2021 23:13:09 +0200 Subject: [PATCH 06/21] libnm: drop unused parameter "ignored_default" from property_to_dbus() (cherry picked from commit 4065158491ca4e5e2b419e0d34650a6cf6802a91) --- src/libnm-core-impl/nm-setting.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index 6e1fb70d25..8a3d7d05a6 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -556,8 +556,7 @@ property_to_dbus(const NMSettInfoSetting * sett_info, NMSetting * setting, NMConnectionSerializationFlags flags, const NMConnectionSerializationOptions *options, - gboolean ignore_flags, - gboolean ignore_default) + gboolean ignore_flags) { const NMSettInfoProperty *property = &sett_info->property_infos[property_idx]; GVariant * variant; @@ -611,7 +610,7 @@ property_to_dbus(const NMSettInfoSetting * sett_info, g_object_get_property(G_OBJECT(setting), property->param_spec->name, &prop_value); - if (ignore_default && g_param_value_defaults(property->param_spec, &prop_value)) + if (g_param_value_defaults(property->param_spec, &prop_value)) return NULL; if (property->property_type->gprop_to_dbus_fcn) { @@ -707,8 +706,7 @@ _nm_setting_to_dbus(NMSetting * setting, for (i = 0; i < sett_info->property_infos_len; i++) { gs_unref_variant GVariant *dbus_value = NULL; - dbus_value = - property_to_dbus(sett_info, i, connection, setting, flags, options, FALSE, TRUE); + dbus_value = property_to_dbus(sett_info, i, connection, setting, flags, options, FALSE); if (dbus_value) { g_variant_builder_add(&builder, "{sv}", sett_info->property_infos[i].name, dbus_value); } @@ -1344,7 +1342,6 @@ compare_property(const NMSettInfoSetting *sett_info, set_a, NM_CONNECTION_SERIALIZE_ALL, NULL, - TRUE, TRUE); value2 = property_to_dbus(sett_info, property_idx, @@ -1352,7 +1349,6 @@ compare_property(const NMSettInfoSetting *sett_info, set_b, NM_CONNECTION_SERIALIZE_ALL, NULL, - TRUE, TRUE); if (nm_property_compare(value1, value2) != 0) return NM_TERNARY_FALSE; From e4898f98e0df93854c957a877393a12a806acc65 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 18 Jun 2021 00:01:30 +0200 Subject: [PATCH 07/21] libnm: add NM_SETTING_PARAM_NONE define This completes other NM_SETTING_PARAM_* flags. (cherry picked from commit c54be51f99d6e5080a25bb5f75f1dae442b68d37) --- src/libnm-core-impl/nm-setting-private.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libnm-core-impl/nm-setting-private.h b/src/libnm-core-impl/nm-setting-private.h index e8373f8e63..fc369558a4 100644 --- a/src/libnm-core-impl/nm-setting-private.h +++ b/src/libnm-core-impl/nm-setting-private.h @@ -211,6 +211,10 @@ gboolean _nm_setting_clear_secrets(NMSetting * setting, NMSettingClearSecretsWithFlagsFn func, gpointer user_data); +/*****************************************************************************/ + +#define NM_SETTING_PARAM_NONE 0 + /* The property of the #NMSetting should be considered during comparisons that * use the %NM_SETTING_COMPARE_FLAG_INFERRABLE flag. Properties that don't have * this flag, are ignored when doing an infrerrable comparison. This flag should From db9ae06cfd6829ca1f29bfdcfd291a4c7d1759ff Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 18 Jun 2021 08:59:12 +0200 Subject: [PATCH 08/21] libnm: let all property types implement to_dbus_fcn() handler If a property can be converted to D-Bus, then always set the to_dbus_fcn() handler. The only caller of to_dbus_fcn() is property_to_dbus(), so this means that property_to_dbus() has no more default implementation and always delegates to to_dbus_fcn(). The code is easier to understand if all properties implement to_dbus_fcn() the same way. Also, there is supposed to be a split between NMSettInfoProperty (info about the property) and NMSettInfoPropertType (the type). The idea is that each property (obviously) requires its distinct NMSettInfoProperty, but they can share a common type implementation. With NMSettInfoPropertType.gprop_to_dbus_fcn that is often violated because many properties that implement NMSettInfoPropertType.gprop_to_dbus_fcn require a special type implementation. As such, gprop_to_dbus_fcn should be part of the property info and not the property type. The first step towards that is unifying all properties to use to_dbus_fcn(). (cherry picked from commit c161439b73c4bc7fcb91e45d3bdef1471b03eab0) --- src/libnm-core-impl/nm-setting-connection.c | 6 +- src/libnm-core-impl/nm-setting-dcb.c | 1 + src/libnm-core-impl/nm-setting-ip-config.c | 8 +- src/libnm-core-impl/nm-setting-ip4-config.c | 6 +- src/libnm-core-impl/nm-setting-ip6-config.c | 6 +- src/libnm-core-impl/nm-setting-private.h | 12 ++ src/libnm-core-impl/nm-setting-serial.c | 6 +- .../nm-setting-wireless-security.c | 4 +- src/libnm-core-impl/nm-setting.c | 107 ++++++++++-------- src/libnm-core-impl/nm-utils.c | 2 + src/libnm-core-impl/tests/test-setting.c | 8 +- 11 files changed, 100 insertions(+), 66 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-connection.c b/src/libnm-core-impl/nm-setting-connection.c index 19573db478..e8e6c35ff2 100644 --- a/src/libnm-core-impl/nm-setting-connection.c +++ b/src/libnm-core-impl/nm-setting-connection.c @@ -1995,9 +1995,9 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass) _nm_properties_override_gobj( properties_override, obj_properties[PROP_INTERFACE_NAME], - NM_SETT_INFO_PROPERT_TYPE(.dbus_type = G_VARIANT_TYPE_STRING, - .missing_from_dbus_fcn = - nm_setting_connection_no_interface_name, )); + NM_SETT_INFO_PROPERT_TYPE_GPROP(G_VARIANT_TYPE_STRING, + .missing_from_dbus_fcn = + nm_setting_connection_no_interface_name, )); /** * NMSettingConnection:type: diff --git a/src/libnm-core-impl/nm-setting-dcb.c b/src/libnm-core-impl/nm-setting-dcb.c index 89df5835e8..228a89941c 100644 --- a/src/libnm-core-impl/nm-setting-dcb.c +++ b/src/libnm-core-impl/nm-setting-dcb.c @@ -764,6 +764,7 @@ _nm_setting_dcb_uint_array_from_dbus(GVariant *dbus_value, GValue *prop_value) static const NMSettInfoPropertType nm_sett_info_propert_type_dcb_au = { .dbus_type = NM_G_VARIANT_TYPE("au"), + .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_gprop, .gprop_to_dbus_fcn = _nm_setting_dcb_uint_array_to_dbus, .gprop_from_dbus_fcn = _nm_setting_dcb_uint_array_from_dbus, }; diff --git a/src/libnm-core-impl/nm-setting-ip-config.c b/src/libnm-core-impl/nm-setting-ip-config.c index 5a5f714c8c..abf6afd95d 100644 --- a/src/libnm-core-impl/nm-setting-ip-config.c +++ b/src/libnm-core-impl/nm-setting-ip-config.c @@ -5760,10 +5760,10 @@ _nm_sett_info_property_override_create_array_ip_config(void) { GArray *properties_override = _nm_sett_info_property_override_create_array(); - _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, )); + _nm_properties_override_gobj( + properties_override, + obj_properties[PROP_GATEWAY], + NM_SETT_INFO_PROPERT_TYPE_GPROP(G_VARIANT_TYPE_STRING, .from_dbus_fcn = ip_gateway_set, )); /* ---dbus--- * property: routing-rules diff --git a/src/libnm-core-impl/nm-setting-ip4-config.c b/src/libnm-core-impl/nm-setting-ip4-config.c index 003e8dc131..d5eee5fe42 100644 --- a/src/libnm-core-impl/nm-setting-ip4-config.c +++ b/src/libnm-core-impl/nm-setting-ip4-config.c @@ -943,9 +943,9 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) _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, )); + NM_SETT_INFO_PROPERT_TYPE_GPROP(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/src/libnm-core-impl/nm-setting-ip6-config.c b/src/libnm-core-impl/nm-setting-ip6-config.c index d2a016fe25..bd7bd7aca0 100644 --- a/src/libnm-core-impl/nm-setting-ip6-config.c +++ b/src/libnm-core-impl/nm-setting-ip6-config.c @@ -1012,9 +1012,9 @@ nm_setting_ip6_config_class_init(NMSettingIP6ConfigClass *klass) _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, )); + NM_SETT_INFO_PROPERT_TYPE_GPROP(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/src/libnm-core-impl/nm-setting-private.h b/src/libnm-core-impl/nm-setting-private.h index fc369558a4..19c703de77 100644 --- a/src/libnm-core-impl/nm-setting-private.h +++ b/src/libnm-core-impl/nm-setting-private.h @@ -265,6 +265,13 @@ gboolean _nm_setting_aggregate(NMSetting *setting, NMConnectionAggregateType typ gboolean _nm_setting_slave_type_is_valid(const char *slave_type, const char **out_port_type); +GVariant *_nm_setting_property_to_dbus_fcn_gprop(const NMSettInfoSetting * sett_info, + guint property_idx, + NMConnection * connection, + NMSetting * setting, + NMConnectionSerializationFlags flags, + const NMConnectionSerializationOptions *options); + GVariant *_nm_setting_to_dbus(NMSetting * setting, NMConnection * connection, NMConnectionSerializationFlags flags, @@ -317,6 +324,11 @@ _nm_setting_class_commit(NMSettingClass *setting_class, NMMetaSettingType meta_t &_g; \ }) +#define NM_SETT_INFO_PROPERT_TYPE_GPROP(_dbus_type, ...) \ + NM_SETT_INFO_PROPERT_TYPE(.dbus_type = _dbus_type, \ + .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_gprop, \ + __VA_ARGS__) + #define NM_SETT_INFO_PROPERTY(...) (&((const NMSettInfoProperty){__VA_ARGS__})) gboolean _nm_properties_override_assert(const NMSettInfoProperty *prop_info); diff --git a/src/libnm-core-impl/nm-setting-serial.c b/src/libnm-core-impl/nm-setting-serial.c index 5a3802a3e7..22244c7746 100644 --- a/src/libnm-core-impl/nm-setting-serial.c +++ b/src/libnm-core-impl/nm-setting-serial.c @@ -311,9 +311,9 @@ nm_setting_serial_class_init(NMSettingSerialClass *klass) _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, )); + NM_SETT_INFO_PROPERT_TYPE_GPROP(G_VARIANT_TYPE_BYTE, + .gprop_to_dbus_fcn = parity_to_dbus, + .gprop_from_dbus_fcn = parity_from_dbus, )); /** * NMSettingSerial:stopbits: diff --git a/src/libnm-core-impl/nm-setting-wireless-security.c b/src/libnm-core-impl/nm-setting-wireless-security.c index df618e36d9..39f3a95fc9 100644 --- a/src/libnm-core-impl/nm-setting-wireless-security.c +++ b/src/libnm-core-impl/nm-setting-wireless-security.c @@ -1927,8 +1927,8 @@ nm_setting_wireless_security_class_init(NMSettingWirelessSecurityClass *klass) _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, )); + NM_SETT_INFO_PROPERT_TYPE_GPROP(G_VARIANT_TYPE_UINT32, + .gprop_to_dbus_fcn = wep_key_type_to_dbus, )); /** * NMSettingWirelessSecurity:wps-method: diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index 8a3d7d05a6..00743c2d68 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -190,8 +190,10 @@ _nm_properties_override_assert(const NMSettInfoProperty *prop_info) /* we always require a dbus_type. */ nm_assert(property_type->dbus_type); + if (!property_type->to_dbus_fcn) + nm_assert(!property_type->gprop_to_dbus_fcn); + /* {to,from}_dbus_fcn and gprop_{to,from}_dbus_fcn cannot both be set. */ - nm_assert(!property_type->to_dbus_fcn || !property_type->gprop_to_dbus_fcn); nm_assert(!property_type->from_dbus_fcn || !property_type->gprop_from_dbus_fcn); if (!prop_info->param_spec) { @@ -375,35 +377,35 @@ _nm_setting_class_commit_full(NMSettingClass * setting_class, vtype = p->param_spec->value_type; if (vtype == G_TYPE_BOOLEAN) - p->property_type = NM_SETT_INFO_PROPERT_TYPE(.dbus_type = G_VARIANT_TYPE_BOOLEAN); + p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP(G_VARIANT_TYPE_BOOLEAN); else if (vtype == G_TYPE_UCHAR) - p->property_type = NM_SETT_INFO_PROPERT_TYPE(.dbus_type = G_VARIANT_TYPE_BYTE); + p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP(G_VARIANT_TYPE_BYTE); else if (vtype == G_TYPE_INT) p->property_type = &nm_sett_info_propert_type_plain_i; else if (vtype == G_TYPE_UINT) 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); + p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP(G_VARIANT_TYPE_INT64); else if (vtype == G_TYPE_UINT64) - p->property_type = NM_SETT_INFO_PROPERT_TYPE(.dbus_type = G_VARIANT_TYPE_UINT64); + p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP(G_VARIANT_TYPE_UINT64); else if (vtype == G_TYPE_STRING) - p->property_type = NM_SETT_INFO_PROPERT_TYPE(.dbus_type = G_VARIANT_TYPE_STRING); + p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP(G_VARIANT_TYPE_STRING); else if (vtype == G_TYPE_DOUBLE) - p->property_type = NM_SETT_INFO_PROPERT_TYPE(.dbus_type = G_VARIANT_TYPE_DOUBLE); + p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP(G_VARIANT_TYPE_DOUBLE); else if (vtype == G_TYPE_STRV) - p->property_type = NM_SETT_INFO_PROPERT_TYPE(.dbus_type = G_VARIANT_TYPE_STRING_ARRAY); + p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP(G_VARIANT_TYPE_STRING_ARRAY); else if (vtype == G_TYPE_BYTES) { p->property_type = - NM_SETT_INFO_PROPERT_TYPE(.dbus_type = G_VARIANT_TYPE_BYTESTRING, - .gprop_to_dbus_fcn = _gprop_to_dbus_fcn_bytes); + NM_SETT_INFO_PROPERT_TYPE_GPROP(G_VARIANT_TYPE_BYTESTRING, + .gprop_to_dbus_fcn = _gprop_to_dbus_fcn_bytes); } else if (g_type_is_a(vtype, G_TYPE_ENUM)) { p->property_type = - NM_SETT_INFO_PROPERT_TYPE(.dbus_type = G_VARIANT_TYPE_INT32, - .gprop_to_dbus_fcn = _gprop_to_dbus_fcn_enum); + NM_SETT_INFO_PROPERT_TYPE_GPROP(G_VARIANT_TYPE_INT32, + .gprop_to_dbus_fcn = _gprop_to_dbus_fcn_enum); } else if (g_type_is_a(vtype, G_TYPE_FLAGS)) { p->property_type = - NM_SETT_INFO_PROPERT_TYPE(.dbus_type = G_VARIANT_TYPE_UINT32, - .gprop_to_dbus_fcn = _gprop_to_dbus_fcn_flags); + NM_SETT_INFO_PROPERT_TYPE_GPROP(G_VARIANT_TYPE_UINT32, + .gprop_to_dbus_fcn = _gprop_to_dbus_fcn_flags); } else nm_assert_not_reached(); @@ -549,6 +551,34 @@ _nm_setting_use_legacy_property(NMSetting * setting, /*****************************************************************************/ +GVariant * +_nm_setting_property_to_dbus_fcn_gprop(const NMSettInfoSetting * sett_info, + guint property_idx, + NMConnection * connection, + NMSetting * setting, + NMConnectionSerializationFlags flags, + const NMConnectionSerializationOptions *options) +{ + const NMSettInfoProperty *const property = &sett_info->property_infos[property_idx]; + nm_auto_unset_gvalue GValue prop_value = { + 0, + }; + + nm_assert(property->param_spec); + + g_value_init(&prop_value, property->param_spec->value_type); + + g_object_get_property(G_OBJECT(setting), property->param_spec->name, &prop_value); + + if (g_param_value_defaults(property->param_spec, &prop_value)) + return NULL; + + if (property->property_type->gprop_to_dbus_fcn) + return property->property_type->gprop_to_dbus_fcn(&prop_value); + + return g_dbus_gvalue_to_gvariant(&prop_value, property->property_type->dbus_type); +} + static GVariant * property_to_dbus(const NMSettInfoSetting * sett_info, guint property_idx, @@ -563,12 +593,15 @@ property_to_dbus(const NMSettInfoSetting * sett_info, nm_assert(property->property_type->dbus_type); - if (!property->param_spec) { - if (!property->property_type->to_dbus_fcn) - return NULL; - } else if (!ignore_flags - && !NM_FLAGS_HAS(property->param_spec->flags, - NM_SETTING_PARAM_TO_DBUS_IGNORE_FLAGS)) { + if (!property->property_type->to_dbus_fcn) { + nm_assert(!property->param_spec); + nm_assert(!property->property_type->gprop_to_dbus_fcn); + return NULL; + } + + if (property->param_spec + && (!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; @@ -595,32 +628,10 @@ property_to_dbus(const NMSettInfoSetting * sett_info, } } - 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, - }; + variant = property->property_type + ->to_dbus_fcn(sett_info, property_idx, connection, setting, flags, options); + nm_g_variant_take_ref(variant); - nm_assert(property->param_spec); - - g_value_init(&prop_value, property->param_spec->value_type); - - g_object_get_property(G_OBJECT(setting), property->param_spec->name, &prop_value); - - if (g_param_value_defaults(property->param_spec, &prop_value)) - return NULL; - - 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->property_type->dbus_type); - } - - nm_assert(!variant || !g_variant_is_floating(variant)); nm_assert(!variant || g_variant_is_of_type(variant, property->property_type->dbus_type)); return variant; @@ -2330,11 +2341,13 @@ const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_ignore_u = { }; const NMSettInfoPropertType nm_sett_info_propert_type_plain_i = { - .dbus_type = G_VARIANT_TYPE_INT32, + .dbus_type = G_VARIANT_TYPE_INT32, + .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_gprop, }; const NMSettInfoPropertType nm_sett_info_propert_type_plain_u = { - .dbus_type = G_VARIANT_TYPE_UINT32, + .dbus_type = G_VARIANT_TYPE_UINT32, + .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_gprop, }; /*****************************************************************************/ diff --git a/src/libnm-core-impl/nm-utils.c b/src/libnm-core-impl/nm-utils.c index 391dd1a15e..f42c81d9d2 100644 --- a/src/libnm-core-impl/nm-utils.c +++ b/src/libnm-core-impl/nm-utils.c @@ -781,6 +781,7 @@ _nm_utils_strdict_from_dbus(GVariant *dbus_value, GValue *prop_value) const NMSettInfoPropertType nm_sett_info_propert_type_strdict = { .dbus_type = NM_G_VARIANT_TYPE("a{ss}"), + .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_gprop, .gprop_to_dbus_fcn = _nm_utils_strdict_to_dbus, .gprop_from_dbus_fcn = _nm_utils_strdict_from_dbus, }; @@ -4156,6 +4157,7 @@ _nm_utils_hwaddr_from_dbus(GVariant *dbus_value, GValue *prop_value) const NMSettInfoPropertType nm_sett_info_propert_type_mac_address = { .dbus_type = G_VARIANT_TYPE_BYTESTRING, + .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_gprop, .gprop_to_dbus_fcn = _nm_utils_hwaddr_to_dbus, .gprop_from_dbus_fcn = _nm_utils_hwaddr_from_dbus, }; diff --git a/src/libnm-core-impl/tests/test-setting.c b/src/libnm-core-impl/tests/test-setting.c index 50821bb16c..835dc80d01 100644 --- a/src/libnm-core-impl/tests/test-setting.c +++ b/src/libnm-core-impl/tests/test-setting.c @@ -4368,7 +4368,13 @@ test_setting_metadata(void) 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); + if (!sip->property_type->to_dbus_fcn) { + /* it's allowed to have no to_dbus_fcn(), to ignore a property. But such + * properties must not have a param_spec and no gprop_to_dbus_fcn. */ + g_assert(!sip->param_spec); + g_assert(!sip->property_type->gprop_to_dbus_fcn); + } + g_assert(!sip->property_type->from_dbus_fcn || !sip->property_type->gprop_from_dbus_fcn); From 0d95b3c300e07c4472b3445d90daad24c4e3edc1 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 18 Jun 2021 09:44:46 +0200 Subject: [PATCH 09/21] libnm: add and use NM_SETT_INFO_PROPERT_TYPE_DBUS() macro (cherry picked from commit 69597a67c15cb3a37933eed65db539f8b9d248b0) --- src/libnm-core-impl/nm-setting-connection.c | 4 +-- src/libnm-core-impl/nm-setting-ip-config.c | 6 ++-- src/libnm-core-impl/nm-setting-ip4-config.c | 33 +++++++++++---------- src/libnm-core-impl/nm-setting-ip6-config.c | 29 +++++++++--------- src/libnm-core-impl/nm-setting-private.h | 11 ++++--- src/libnm-core-impl/nm-setting-sriov.c | 6 ++-- src/libnm-core-impl/nm-setting-tc-config.c | 17 ++++++----- src/libnm-core-impl/nm-setting-vlan.c | 6 ++-- src/libnm-core-impl/nm-setting-vpn.c | 6 ++-- src/libnm-core-impl/nm-setting-wired.c | 9 +++--- src/libnm-core-impl/nm-setting-wireguard.c | 6 ++-- src/libnm-core-impl/nm-setting-wireless.c | 8 ++--- 12 files changed, 74 insertions(+), 67 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-connection.c b/src/libnm-core-impl/nm-setting-connection.c index e8e6c35ff2..a8423a6974 100644 --- a/src/libnm-core-impl/nm-setting-connection.c +++ b/src/libnm-core-impl/nm-setting-connection.c @@ -2182,8 +2182,8 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass) _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, )); + NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_UINT64, + .to_dbus_fcn = _to_dbus_fcn_timestamp, )); /** * NMSettingConnection:read-only: diff --git a/src/libnm-core-impl/nm-setting-ip-config.c b/src/libnm-core-impl/nm-setting-ip-config.c index abf6afd95d..26e98a0433 100644 --- a/src/libnm-core-impl/nm-setting-ip-config.c +++ b/src/libnm-core-impl/nm-setting-ip-config.c @@ -5774,9 +5774,9 @@ _nm_sett_info_property_override_create_array_ip_config(void) _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, )); + NM_SETT_INFO_PROPERT_TYPE_DBUS(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/src/libnm-core-impl/nm-setting-ip4-config.c b/src/libnm-core-impl/nm-setting-ip4-config.c index d5eee5fe42..205dd4cc08 100644 --- a/src/libnm-core-impl/nm-setting-ip4-config.c +++ b/src/libnm-core-impl/nm-setting-ip4-config.c @@ -972,14 +972,14 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) _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_SETT_INFO_PROPERT_TYPE_DBUS(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, )); + NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_STRING_ARRAY, + .to_dbus_fcn = ip4_address_labels_get, )); /* ---dbus--- * property: address-data @@ -993,9 +993,9 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) _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, )); + NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aa{sv}"), + .to_dbus_fcn = ip4_address_data_get, + .from_dbus_fcn = ip4_address_data_set, )); /* ---dbus--- * property: routes @@ -1026,9 +1026,9 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) _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, )); + NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aau"), + .to_dbus_fcn = ip4_routes_get, + .from_dbus_fcn = ip4_routes_set, )); /* ---dbus--- * property: route-data @@ -1043,11 +1043,12 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) * also exist on some routes. * ---end--- */ - _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, )); + _nm_properties_override_dbus( + properties_override, + "route-data", + NM_SETT_INFO_PROPERT_TYPE_DBUS(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/src/libnm-core-impl/nm-setting-ip6-config.c b/src/libnm-core-impl/nm-setting-ip6-config.c index bd7bd7aca0..fe171ce884 100644 --- a/src/libnm-core-impl/nm-setting-ip6-config.c +++ b/src/libnm-core-impl/nm-setting-ip6-config.c @@ -1033,9 +1033,9 @@ nm_setting_ip6_config_class_init(NMSettingIP6ConfigClass *klass) _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, )); + NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("a(ayuay)"), + .to_dbus_fcn = ip6_addresses_get, + .from_dbus_fcn = ip6_addresses_set, )); /* ---dbus--- * property: address-data @@ -1049,9 +1049,9 @@ nm_setting_ip6_config_class_init(NMSettingIP6ConfigClass *klass) _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, )); + NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aa{sv}"), + .to_dbus_fcn = ip6_address_data_get, + .from_dbus_fcn = ip6_address_data_set, )); /* ---dbus--- * property: routes @@ -1070,9 +1070,9 @@ nm_setting_ip6_config_class_init(NMSettingIP6ConfigClass *klass) _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, )); + NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("a(ayuayu)"), + .to_dbus_fcn = ip6_routes_get, + .from_dbus_fcn = ip6_routes_set, )); /* ---dbus--- * property: route-data @@ -1087,11 +1087,12 @@ nm_setting_ip6_config_class_init(NMSettingIP6ConfigClass *klass) * also exist on some routes. * ---end--- */ - _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, )); + _nm_properties_override_dbus( + properties_override, + "route-data", + NM_SETT_INFO_PROPERT_TYPE_DBUS(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/src/libnm-core-impl/nm-setting-private.h b/src/libnm-core-impl/nm-setting-private.h index 19c703de77..e3ecdff994 100644 --- a/src/libnm-core-impl/nm-setting-private.h +++ b/src/libnm-core-impl/nm-setting-private.h @@ -324,10 +324,13 @@ _nm_setting_class_commit(NMSettingClass *setting_class, NMMetaSettingType meta_t &_g; \ }) -#define NM_SETT_INFO_PROPERT_TYPE_GPROP(_dbus_type, ...) \ - NM_SETT_INFO_PROPERT_TYPE(.dbus_type = _dbus_type, \ - .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_gprop, \ - __VA_ARGS__) +#define NM_SETT_INFO_PROPERT_TYPE_DBUS(_dbus_type, ...) \ + NM_SETT_INFO_PROPERT_TYPE(.dbus_type = _dbus_type, __VA_ARGS__) + +#define NM_SETT_INFO_PROPERT_TYPE_GPROP(_dbus_type, ...) \ + NM_SETT_INFO_PROPERT_TYPE_DBUS(_dbus_type, \ + .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_gprop, \ + __VA_ARGS__) #define NM_SETT_INFO_PROPERTY(...) (&((const NMSettInfoProperty){__VA_ARGS__})) diff --git a/src/libnm-core-impl/nm-setting-sriov.c b/src/libnm-core-impl/nm-setting-sriov.c index 70e542d1cd..b18d184af8 100644 --- a/src/libnm-core-impl/nm-setting-sriov.c +++ b/src/libnm-core-impl/nm-setting-sriov.c @@ -1325,9 +1325,9 @@ nm_setting_sriov_class_init(NMSettingSriovClass *klass) | G_PARAM_STATIC_STRINGS); _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, )); + NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aa{sv}"), + .to_dbus_fcn = vfs_to_dbus, + .from_dbus_fcn = vfs_from_dbus, )); /** * NMSettingSriov:autoprobe-drivers diff --git a/src/libnm-core-impl/nm-setting-tc-config.c b/src/libnm-core-impl/nm-setting-tc-config.c index 9338e8a52e..f44c89cb09 100644 --- a/src/libnm-core-impl/nm-setting-tc-config.c +++ b/src/libnm-core-impl/nm-setting-tc-config.c @@ -1838,9 +1838,9 @@ nm_setting_tc_config_class_init(NMSettingTCConfigClass *klass) | G_PARAM_STATIC_STRINGS); _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, )); + NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aa{sv}"), + .to_dbus_fcn = tc_qdiscs_get, + .from_dbus_fcn = tc_qdiscs_set, )); /** * NMSettingTCConfig:tfilters: (type GPtrArray(NMTCTfilter)) @@ -1870,11 +1870,12 @@ nm_setting_tc_config_class_init(NMSettingTCConfigClass *klass) "", G_TYPE_PTR_ARRAY, G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - _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, )); + _nm_properties_override_gobj( + properties_override, + obj_properties[PROP_TFILTERS], + NM_SETT_INFO_PROPERT_TYPE_DBUS(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/src/libnm-core-impl/nm-setting-vlan.c b/src/libnm-core-impl/nm-setting-vlan.c index 541186ecf3..e4e07e35dd 100644 --- a/src/libnm-core-impl/nm-setting-vlan.c +++ b/src/libnm-core-impl/nm-setting-vlan.c @@ -926,9 +926,9 @@ nm_setting_vlan_class_init(NMSettingVlanClass *klass) _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, )); + NM_SETT_INFO_PROPERT_TYPE_DBUS(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/src/libnm-core-impl/nm-setting-vpn.c b/src/libnm-core-impl/nm-setting-vpn.c index d4a99d4da0..7b8fdb7644 100644 --- a/src/libnm-core-impl/nm-setting-vpn.c +++ b/src/libnm-core-impl/nm-setting-vpn.c @@ -1226,9 +1226,9 @@ nm_setting_vpn_class_init(NMSettingVpnClass *klass) _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, )); + NM_SETT_INFO_PROPERT_TYPE_DBUS(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/src/libnm-core-impl/nm-setting-wired.c b/src/libnm-core-impl/nm-setting-wired.c index 36d254b3a5..99909bf06a 100644 --- a/src/libnm-core-impl/nm-setting-wired.c +++ b/src/libnm-core-impl/nm-setting-wired.c @@ -1395,10 +1395,11 @@ nm_setting_wired_class_init(NMSettingWiredClass *klass) "", FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _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, )); + _nm_properties_override_gobj( + properties_override, + obj_properties[PROP_AUTO_NEGOTIATE], + NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_BOOLEAN, + .to_dbus_fcn = _override_autoneg_get, )); /** * NMSettingWired:mac-address: diff --git a/src/libnm-core-impl/nm-setting-wireguard.c b/src/libnm-core-impl/nm-setting-wireguard.c index f78d637c93..b5ec0bb88a 100644 --- a/src/libnm-core-impl/nm-setting-wireguard.c +++ b/src/libnm-core-impl/nm-setting-wireguard.c @@ -2594,9 +2594,9 @@ nm_setting_wireguard_class_init(NMSettingWireGuardClass *klass) _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, )); + NM_SETT_INFO_PROPERT_TYPE_DBUS(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/src/libnm-core-impl/nm-setting-wireless.c b/src/libnm-core-impl/nm-setting-wireless.c index 92209aec7f..e73d8eeb21 100644 --- a/src/libnm-core-impl/nm-setting-wireless.c +++ b/src/libnm-core-impl/nm-setting-wireless.c @@ -1743,8 +1743,8 @@ nm_setting_wireless_class_init(NMSettingWirelessClass *klass) _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, )); + NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_STRING_ARRAY, + .to_dbus_fcn = _to_dbus_fcn_seen_bssids, )); /** * NMSettingWireless:mtu: @@ -1871,8 +1871,8 @@ nm_setting_wireless_class_init(NMSettingWirelessClass *klass) _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, )); + NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_STRING, + .to_dbus_fcn = nm_setting_wireless_get_security, )); /** * NMSettingWireless:wake-on-wlan: From d2e0a8cc0ea14aae5cb83dd852f657318bce473e Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 18 Jun 2021 09:59:40 +0200 Subject: [PATCH 10/21] libnm: add and use NM_SETT_INFO_PROPERT_TYPE_*_INIT() macros The advantage is that we use similar macros for initializing the static structs like const NMSettInfoPropertType nm_sett_info_propert_type_cloned_mac_address; and the ad-hoc locations that use NM_SETT_INFO_PROPERT_TYPE(). The former exist for property types that are used more than once. The latter exist for convenience, where a property type is implemented at only one place. Also, there are few direct references to _nm_setting_property_to_dbus_fcn_gprop(). all users use NM_SETT_INFO_PROPERT_TYPE_GPROP() or NM_SETT_INFO_PROPERT_TYPE_GPROP_INIT(). (cherry picked from commit 6fc2e03677b4eccdecfa156939363a150a4014d9) --- src/libnm-core-impl/nm-setting-dcb.c | 11 +++--- src/libnm-core-impl/nm-setting-private.h | 29 +++++++++----- src/libnm-core-impl/nm-setting.c | 38 +++++++++--------- src/libnm-core-impl/nm-team-utils.c | 38 ++++++++---------- src/libnm-core-impl/nm-utils.c | 49 ++++++++++-------------- 5 files changed, 80 insertions(+), 85 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-dcb.c b/src/libnm-core-impl/nm-setting-dcb.c index 228a89941c..57fe1da029 100644 --- a/src/libnm-core-impl/nm-setting-dcb.c +++ b/src/libnm-core-impl/nm-setting-dcb.c @@ -762,12 +762,11 @@ _nm_setting_dcb_uint_array_from_dbus(GVariant *dbus_value, GValue *prop_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"), - .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_gprop, - .gprop_to_dbus_fcn = _nm_setting_dcb_uint_array_to_dbus, - .gprop_from_dbus_fcn = _nm_setting_dcb_uint_array_from_dbus, -}; +static const NMSettInfoPropertType nm_sett_info_propert_type_dcb_au = + NM_SETT_INFO_PROPERT_TYPE_GPROP_INIT(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, ); /*****************************************************************************/ diff --git a/src/libnm-core-impl/nm-setting-private.h b/src/libnm-core-impl/nm-setting-private.h index e3ecdff994..8dc7c4323e 100644 --- a/src/libnm-core-impl/nm-setting-private.h +++ b/src/libnm-core-impl/nm-setting-private.h @@ -317,20 +317,29 @@ _nm_setting_class_commit(NMSettingClass *setting_class, NMMetaSettingType meta_t #define NM_SETT_INFO_SETT_DETAIL(...) (&((const NMSettInfoSettDetail){__VA_ARGS__})) -#define NM_SETT_INFO_PROPERT_TYPE(...) \ - ({ \ - static const NMSettInfoPropertType _g = {__VA_ARGS__}; \ - \ - &_g; \ +#define NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(_dbus_type, ...) \ + { \ + .dbus_type = _dbus_type, __VA_ARGS__ \ + } + +#define NM_SETT_INFO_PROPERT_TYPE_GPROP_INIT(_dbus_type, ...) \ + { \ + .dbus_type = _dbus_type, .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_gprop, \ + __VA_ARGS__ \ + } + +#define NM_SETT_INFO_PROPERT_TYPE(init) \ + ({ \ + static const NMSettInfoPropertType _g = init; \ + \ + &_g; \ }) #define NM_SETT_INFO_PROPERT_TYPE_DBUS(_dbus_type, ...) \ - NM_SETT_INFO_PROPERT_TYPE(.dbus_type = _dbus_type, __VA_ARGS__) + NM_SETT_INFO_PROPERT_TYPE(NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(_dbus_type, __VA_ARGS__)) -#define NM_SETT_INFO_PROPERT_TYPE_GPROP(_dbus_type, ...) \ - NM_SETT_INFO_PROPERT_TYPE_DBUS(_dbus_type, \ - .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_gprop, \ - __VA_ARGS__) +#define NM_SETT_INFO_PROPERT_TYPE_GPROP(_dbus_type, ...) \ + NM_SETT_INFO_PROPERT_TYPE(NM_SETT_INFO_PROPERT_TYPE_GPROP_INIT(_dbus_type, __VA_ARGS__)) #define NM_SETT_INFO_PROPERTY(...) (&((const NMSettInfoProperty){__VA_ARGS__})) diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index 00743c2d68..4593e6fc19 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -2325,30 +2325,28 @@ _nm_setting_get_deprecated_virtual_interface_name(const NMSettInfoSetting * 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_interface_name = + NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(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_i = + NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT( + 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_deprecated_ignore_u = + NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT( + 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, - .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_gprop, -}; +const NMSettInfoPropertType nm_sett_info_propert_type_plain_i = + NM_SETT_INFO_PROPERT_TYPE_GPROP_INIT(G_VARIANT_TYPE_INT32); -const NMSettInfoPropertType nm_sett_info_propert_type_plain_u = { - .dbus_type = G_VARIANT_TYPE_UINT32, - .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_gprop, -}; +const NMSettInfoPropertType nm_sett_info_propert_type_plain_u = + NM_SETT_INFO_PROPERT_TYPE_GPROP_INIT(G_VARIANT_TYPE_UINT32); /*****************************************************************************/ diff --git a/src/libnm-core-impl/nm-team-utils.c b/src/libnm-core-impl/nm-team-utils.c index d369f46a13..bd9ef510cb 100644 --- a/src/libnm-core-impl/nm-team-utils.c +++ b/src/libnm-core-impl/nm-team-utils.c @@ -2786,31 +2786,27 @@ _nm_team_settings_property_from_dbus_link_watchers(GVariant *dbus_value, GValue _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_b = + NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(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_i = + NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(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_s = + NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(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_as = + NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(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, -}; +const NMSettInfoPropertType nm_sett_info_propert_type_team_link_watchers = + NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(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, ); /*****************************************************************************/ diff --git a/src/libnm-core-impl/nm-utils.c b/src/libnm-core-impl/nm-utils.c index f42c81d9d2..8c4d3c6a89 100644 --- a/src/libnm-core-impl/nm-utils.c +++ b/src/libnm-core-impl/nm-utils.c @@ -779,12 +779,10 @@ _nm_utils_strdict_from_dbus(GVariant *dbus_value, GValue *prop_value) g_value_take_boxed(prop_value, hash); } -const NMSettInfoPropertType nm_sett_info_propert_type_strdict = { - .dbus_type = NM_G_VARIANT_TYPE("a{ss}"), - .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_gprop, - .gprop_to_dbus_fcn = _nm_utils_strdict_to_dbus, - .gprop_from_dbus_fcn = _nm_utils_strdict_from_dbus, -}; +const NMSettInfoPropertType nm_sett_info_propert_type_strdict = + NM_SETT_INFO_PROPERT_TYPE_GPROP_INIT(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) @@ -4068,12 +4066,11 @@ _nm_utils_hwaddr_cloned_not_set(NMSetting * setting, return TRUE; } -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, -}; +const NMSettInfoPropertType nm_sett_info_propert_type_cloned_mac_address = + NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(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, @@ -4132,11 +4129,10 @@ _nm_utils_hwaddr_cloned_data_set(NMSetting * setting, return TRUE; } -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, -}; +const NMSettInfoPropertType nm_sett_info_propert_type_assigned_mac_address = + NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(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) @@ -4155,12 +4151,10 @@ _nm_utils_hwaddr_from_dbus(GVariant *dbus_value, GValue *prop_value) g_value_take_string(prop_value, str); } -const NMSettInfoPropertType nm_sett_info_propert_type_mac_address = { - .dbus_type = G_VARIANT_TYPE_BYTESTRING, - .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_gprop, - .gprop_to_dbus_fcn = _nm_utils_hwaddr_to_dbus, - .gprop_from_dbus_fcn = _nm_utils_hwaddr_from_dbus, -}; +const NMSettInfoPropertType nm_sett_info_propert_type_mac_address = + NM_SETT_INFO_PROPERT_TYPE_GPROP_INIT(G_VARIANT_TYPE_BYTESTRING, + .gprop_to_dbus_fcn = _nm_utils_hwaddr_to_dbus, + .gprop_from_dbus_fcn = _nm_utils_hwaddr_from_dbus, ); /*****************************************************************************/ @@ -5560,11 +5554,10 @@ _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, -}; +const NMSettInfoPropertType nm_sett_info_propert_type_bridge_vlans = + NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(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, From 3dfd5636012f305e5ace5cef36dc5efad3df586c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 18 Jun 2021 09:43:20 +0200 Subject: [PATCH 11/21] libnm: add type enum for handling gprop differences in to_dbus_fcn For GBytes, GEnum, GFlags and others, we need special converters from the default GObject properties to GVariant. Previously, those were implemented by providing a special gprop_to_dbus_fcn hook. But gprop_to_dbus_fcn should move from NMSettInfoPropertType to NMSettInfoProperty, because it's usually a per-property meta data, and not a per-property-type meta data. The difference is whether the meta data can be shared between different properties (of the same "type). In these cases, this extra information is indeed part of the type. We want to have a generic NM_SETT_INFO_PROPERT_TYPE_GPROP() property (using _nm_setting_property_to_dbus_fcn_gprop()), but then we would like to distinguish between special cases. So this was fine. However, I find the approach of providing a gprop_to_dbus_fcn in this case cumbersome. It makes it harder to understand what happens. Instead, introduce a new "gprop_type" for the different types that _nm_setting_property_to_dbus_fcn_gprop() can handle. This new "gprop_type" is extra data of the property type, so introduce a new field "typdata_to_dbus". (cherry picked from commit ac090edd87bc63d5b798f8a07cf5a7af1de9e91d) --- src/libnm-core-impl/nm-setting.c | 55 +++++++++++------------- src/libnm-core-impl/tests/test-setting.c | 23 +++++++++- src/libnm-core-intern/nm-core-internal.h | 14 ++++++ 3 files changed, 60 insertions(+), 32 deletions(-) diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index 4593e6fc19..d933f9e581 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -156,25 +156,6 @@ _nm_sett_info_property_find_in_array(const NMSettInfoProperty *properties, return NULL; } -static GVariant * -_gprop_to_dbus_fcn_bytes(const GValue *val) -{ - nm_assert(G_VALUE_HOLDS(val, G_TYPE_BYTES)); - return nm_utils_gbytes_to_variant_ay(g_value_get_boxed(val)); -} - -static GVariant * -_gprop_to_dbus_fcn_enum(const GValue *val) -{ - return g_variant_new_int32(g_value_get_enum(val)); -} - -static GVariant * -_gprop_to_dbus_fcn_flags(const GValue *val) -{ - return g_variant_new_uint32(g_value_get_flags(val)); -} - gboolean _nm_properties_override_assert(const NMSettInfoProperty *prop_info) { @@ -395,17 +376,17 @@ _nm_setting_class_commit_full(NMSettingClass * setting_class, else if (vtype == G_TYPE_STRV) p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP(G_VARIANT_TYPE_STRING_ARRAY); else if (vtype == G_TYPE_BYTES) { - p->property_type = - NM_SETT_INFO_PROPERT_TYPE_GPROP(G_VARIANT_TYPE_BYTESTRING, - .gprop_to_dbus_fcn = _gprop_to_dbus_fcn_bytes); + p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP( + G_VARIANT_TYPE_BYTESTRING, + .typdata_to_dbus.gprop_type = NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_BYTES); } else if (g_type_is_a(vtype, G_TYPE_ENUM)) { - p->property_type = - NM_SETT_INFO_PROPERT_TYPE_GPROP(G_VARIANT_TYPE_INT32, - .gprop_to_dbus_fcn = _gprop_to_dbus_fcn_enum); + p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP( + G_VARIANT_TYPE_INT32, + .typdata_to_dbus.gprop_type = NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_ENUM); } else if (g_type_is_a(vtype, G_TYPE_FLAGS)) { - p->property_type = - NM_SETT_INFO_PROPERT_TYPE_GPROP(G_VARIANT_TYPE_UINT32, - .gprop_to_dbus_fcn = _gprop_to_dbus_fcn_flags); + p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP( + G_VARIANT_TYPE_UINT32, + .typdata_to_dbus.gprop_type = NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_FLAGS); } else nm_assert_not_reached(); @@ -573,10 +554,22 @@ _nm_setting_property_to_dbus_fcn_gprop(const NMSettInfoSetting * s if (g_param_value_defaults(property->param_spec, &prop_value)) return NULL; - if (property->property_type->gprop_to_dbus_fcn) - return property->property_type->gprop_to_dbus_fcn(&prop_value); + switch (property->property_type->typdata_to_dbus.gprop_type) { + case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_DEFAULT: + if (property->property_type->gprop_to_dbus_fcn) + return property->property_type->gprop_to_dbus_fcn(&prop_value); - return g_dbus_gvalue_to_gvariant(&prop_value, property->property_type->dbus_type); + return g_dbus_gvalue_to_gvariant(&prop_value, property->property_type->dbus_type); + case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_BYTES: + nm_assert(G_VALUE_HOLDS(&prop_value, G_TYPE_BYTES)); + return nm_utils_gbytes_to_variant_ay(g_value_get_boxed(&prop_value)); + case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_ENUM: + return g_variant_new_int32(g_value_get_enum(&prop_value)); + case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_FLAGS: + return g_variant_new_uint32(g_value_get_flags(&prop_value)); + } + + return nm_assert_unreachable_val(NULL); } static GVariant * diff --git a/src/libnm-core-impl/tests/test-setting.c b/src/libnm-core-impl/tests/test-setting.c index 835dc80d01..6ee3c19508 100644 --- a/src/libnm-core-impl/tests/test-setting.c +++ b/src/libnm-core-impl/tests/test-setting.c @@ -4373,6 +4373,23 @@ test_setting_metadata(void) * properties must not have a param_spec and no gprop_to_dbus_fcn. */ g_assert(!sip->param_spec); g_assert(!sip->property_type->gprop_to_dbus_fcn); + } else if (sip->property_type->to_dbus_fcn == _nm_setting_property_to_dbus_fcn_gprop) { + g_assert(sip->param_spec); + switch (sip->property_type->typdata_to_dbus.gprop_type) { + case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_BYTES: + g_assert(sip->param_spec->value_type == G_TYPE_BYTES); + goto check_done; + case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_ENUM: + g_assert(g_type_is_a (sip->param_spec->value_type, G_TYPE_ENUM)); + goto check_done; + case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_FLAGS: + g_assert(g_type_is_a (sip->param_spec->value_type, G_TYPE_FLAGS)); + goto check_done; + case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_DEFAULT: + goto check_done; + } + g_assert_not_reached(); +check_done:; } g_assert(!sip->property_type->from_dbus_fcn @@ -4493,7 +4510,11 @@ test_setting_metadata(void) || 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) + || pt->gprop_from_dbus_fcn != pt_2->gprop_from_dbus_fcn + || memcmp(&pt->typdata_to_dbus, + &pt_2->typdata_to_dbus, + sizeof(pt->typdata_to_dbus)) + != 0) continue; if ((pt == &nm_sett_info_propert_type_plain_i diff --git a/src/libnm-core-intern/nm-core-internal.h b/src/libnm-core-intern/nm-core-internal.h index eb471a34a1..bf40869270 100644 --- a/src/libnm-core-intern/nm-core-internal.h +++ b/src/libnm-core-intern/nm-core-internal.h @@ -671,6 +671,13 @@ typedef void (*NMSettInfoPropGPropFromDBusFcn)(GVariant *from, GValue *to); const NMSettInfoSetting *nmtst_sett_info_settings(void); +typedef enum _nm_packed { + NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_DEFAULT = 0, + NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_BYTES, + NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_ENUM, + NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_FLAGS, +} NMSettingPropertyToDBusFcnGPropType; + typedef struct { const GVariantType *dbus_type; @@ -682,6 +689,13 @@ typedef struct { * on the GValue value of the GObject property. */ NMSettInfoPropGPropToDBusFcn gprop_to_dbus_fcn; NMSettInfoPropGPropFromDBusFcn gprop_from_dbus_fcn; + + struct { + union { + NMSettingPropertyToDBusFcnGPropType gprop_type; + }; + } typdata_to_dbus; + } NMSettInfoPropertType; struct _NMSettInfoProperty { From 97a25c5965a1accfe4407209fa03bc60c55eebde Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 18 Jun 2021 11:04:03 +0200 Subject: [PATCH 12/21] libnm: change "nm_sett_info_propert_type_dcb_au" to use gprop_type for to_dbus_fcn() (cherry picked from commit 8c0a8a6d9bfaa9299eca9a019589f0459b5142f7) --- src/libnm-core-impl/nm-setting-dcb.c | 16 ++++------------ src/libnm-core-impl/nm-setting.c | 7 +++++++ src/libnm-core-impl/tests/test-setting.c | 3 +++ src/libnm-core-intern/nm-core-internal.h | 1 + 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-dcb.c b/src/libnm-core-impl/nm-setting-dcb.c index 57fe1da029..f9602c3bbf 100644 --- a/src/libnm-core-impl/nm-setting-dcb.c +++ b/src/libnm-core-impl/nm-setting-dcb.c @@ -744,14 +744,6 @@ set_gvalue_from_array(GValue *v, uint *a, size_t len) #define SET_GVALUE_FROM_ARRAY(v, a) set_gvalue_from_array(v, a, G_N_ELEMENTS(a)) -static GVariant * -_nm_setting_dcb_uint_array_to_dbus(const GValue *prop_value) -{ - GArray *src = g_value_get_boxed(prop_value); - - return nm_g_variant_new_au((const guint32 *) src->data, src->len); -} - static void _nm_setting_dcb_uint_array_from_dbus(GVariant *dbus_value, GValue *prop_value) { @@ -763,10 +755,10 @@ _nm_setting_dcb_uint_array_from_dbus(GVariant *dbus_value, GValue *prop_value) } static const NMSettInfoPropertType nm_sett_info_propert_type_dcb_au = - NM_SETT_INFO_PROPERT_TYPE_GPROP_INIT(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, ); + NM_SETT_INFO_PROPERT_TYPE_GPROP_INIT( + NM_G_VARIANT_TYPE("au"), + .typdata_to_dbus.gprop_type = NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_GARRAY_UINT, + .gprop_from_dbus_fcn = _nm_setting_dcb_uint_array_from_dbus, ); /*****************************************************************************/ diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index d933f9e581..69dad203eb 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -544,6 +544,7 @@ _nm_setting_property_to_dbus_fcn_gprop(const NMSettInfoSetting * s nm_auto_unset_gvalue GValue prop_value = { 0, }; + GArray *tmp_array; nm_assert(property->param_spec); @@ -567,6 +568,12 @@ _nm_setting_property_to_dbus_fcn_gprop(const NMSettInfoSetting * s return g_variant_new_int32(g_value_get_enum(&prop_value)); case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_FLAGS: return g_variant_new_uint32(g_value_get_flags(&prop_value)); + case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_GARRAY_UINT: + G_STATIC_ASSERT_EXPR(sizeof(guint) == sizeof(guint32)); + nm_assert(G_VALUE_HOLDS(&prop_value, G_TYPE_ARRAY)); + tmp_array = g_value_get_boxed(&prop_value); + nm_assert(tmp_array); + return nm_g_variant_new_au((const guint32 *) tmp_array->data, tmp_array->len); } return nm_assert_unreachable_val(NULL); diff --git a/src/libnm-core-impl/tests/test-setting.c b/src/libnm-core-impl/tests/test-setting.c index 6ee3c19508..4231539bfb 100644 --- a/src/libnm-core-impl/tests/test-setting.c +++ b/src/libnm-core-impl/tests/test-setting.c @@ -4385,6 +4385,9 @@ test_setting_metadata(void) case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_FLAGS: g_assert(g_type_is_a (sip->param_spec->value_type, G_TYPE_FLAGS)); goto check_done; + case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_GARRAY_UINT: + g_assert(sip->param_spec->value_type == G_TYPE_ARRAY); + goto check_done; case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_DEFAULT: goto check_done; } diff --git a/src/libnm-core-intern/nm-core-internal.h b/src/libnm-core-intern/nm-core-internal.h index bf40869270..6a5cd64076 100644 --- a/src/libnm-core-intern/nm-core-internal.h +++ b/src/libnm-core-intern/nm-core-internal.h @@ -676,6 +676,7 @@ typedef enum _nm_packed { NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_BYTES, NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_ENUM, NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_FLAGS, + NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_GARRAY_UINT, } NMSettingPropertyToDBusFcnGPropType; typedef struct { From 7f21fbad31005653e09a16ebf978b36f5d061e59 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 18 Jun 2021 12:27:12 +0200 Subject: [PATCH 13/21] libnm: change "nm_sett_info_propert_type_strdict" to use gprop_type for to_dbus_fcn() (cherry picked from commit 6d390146604d55e6ce51202962631008f8057222) --- src/libnm-core-impl/nm-setting.c | 3 +++ src/libnm-core-impl/nm-utils.c | 11 +++-------- src/libnm-core-impl/tests/test-setting.c | 3 +++ src/libnm-core-intern/nm-core-internal.h | 1 + 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index 69dad203eb..4066d663d0 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -574,6 +574,9 @@ _nm_setting_property_to_dbus_fcn_gprop(const NMSettInfoSetting * s tmp_array = g_value_get_boxed(&prop_value); nm_assert(tmp_array); return nm_g_variant_new_au((const guint32 *) tmp_array->data, tmp_array->len); + case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_STRDICT: + nm_assert(G_VALUE_HOLDS(&prop_value, G_TYPE_HASH_TABLE)); + return nm_utils_strdict_to_variant_ass(g_value_get_boxed(&prop_value)); } return nm_assert_unreachable_val(NULL); diff --git a/src/libnm-core-impl/nm-utils.c b/src/libnm-core-impl/nm-utils.c index 8c4d3c6a89..2fd10c2500 100644 --- a/src/libnm-core-impl/nm-utils.c +++ b/src/libnm-core-impl/nm-utils.c @@ -758,12 +758,6 @@ _nm_utils_hash_values_to_slist(GHashTable *hash) return list; } -static GVariant * -_nm_utils_strdict_to_dbus(const GValue *prop_value) -{ - return nm_utils_strdict_to_variant_ass(g_value_get_boxed(prop_value)); -} - void _nm_utils_strdict_from_dbus(GVariant *dbus_value, GValue *prop_value) { @@ -781,8 +775,9 @@ _nm_utils_strdict_from_dbus(GVariant *dbus_value, GValue *prop_value) const NMSettInfoPropertType nm_sett_info_propert_type_strdict = NM_SETT_INFO_PROPERT_TYPE_GPROP_INIT(NM_G_VARIANT_TYPE("a{ss}"), - .gprop_to_dbus_fcn = _nm_utils_strdict_to_dbus, - .gprop_from_dbus_fcn = _nm_utils_strdict_from_dbus, ); + .gprop_from_dbus_fcn = _nm_utils_strdict_from_dbus, + .typdata_to_dbus.gprop_type = + NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_STRDICT); GHashTable * _nm_utils_copy_strdict(GHashTable *strdict) diff --git a/src/libnm-core-impl/tests/test-setting.c b/src/libnm-core-impl/tests/test-setting.c index 4231539bfb..6f3ffc54eb 100644 --- a/src/libnm-core-impl/tests/test-setting.c +++ b/src/libnm-core-impl/tests/test-setting.c @@ -4388,6 +4388,9 @@ test_setting_metadata(void) case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_GARRAY_UINT: g_assert(sip->param_spec->value_type == G_TYPE_ARRAY); goto check_done; + case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_STRDICT: + g_assert(sip->param_spec->value_type == G_TYPE_HASH_TABLE); + goto check_done; case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_DEFAULT: goto check_done; } diff --git a/src/libnm-core-intern/nm-core-internal.h b/src/libnm-core-intern/nm-core-internal.h index 6a5cd64076..f36bf573bf 100644 --- a/src/libnm-core-intern/nm-core-internal.h +++ b/src/libnm-core-intern/nm-core-internal.h @@ -677,6 +677,7 @@ typedef enum _nm_packed { NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_ENUM, NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_FLAGS, NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_GARRAY_UINT, + NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_STRDICT, } NMSettingPropertyToDBusFcnGPropType; typedef struct { From 7af962b330d4ee74b18d969a7813a45376891a57 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 18 Jun 2021 12:27:12 +0200 Subject: [PATCH 14/21] libnm: change "nm_sett_info_propert_type_mac_address" to use gprop_type for to_dbus_fcn() (cherry picked from commit ed57990b58682aff0b0d71a4684cd9819f03baea) --- src/libnm-core-impl/nm-setting.c | 2 ++ src/libnm-core-impl/nm-utils.c | 15 +++++---------- src/libnm-core-impl/tests/test-setting.c | 3 +++ src/libnm-core-intern/nm-core-internal.h | 1 + 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index 4066d663d0..95338892af 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -577,6 +577,8 @@ _nm_setting_property_to_dbus_fcn_gprop(const NMSettInfoSetting * s case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_STRDICT: nm_assert(G_VALUE_HOLDS(&prop_value, G_TYPE_HASH_TABLE)); return nm_utils_strdict_to_variant_ass(g_value_get_boxed(&prop_value)); + case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_MAC_ADDRESS: + return nm_utils_hwaddr_to_dbus(g_value_get_string(&prop_value)); } return nm_assert_unreachable_val(NULL); diff --git a/src/libnm-core-impl/nm-utils.c b/src/libnm-core-impl/nm-utils.c index 2fd10c2500..12e3bd40f4 100644 --- a/src/libnm-core-impl/nm-utils.c +++ b/src/libnm-core-impl/nm-utils.c @@ -4085,7 +4085,7 @@ _nm_utils_hwaddr_cloned_data_synth(const NMSettInfoSetting * sett_ g_object_get(setting, "cloned-mac-address", &addr, NULL); /* Before introducing the extended "cloned-mac-address" (and its D-Bus - * field "assigned-mac-address"), libnm's _nm_utils_hwaddr_to_dbus() + * field "assigned-mac-address"), libnm's nm_utils_hwaddr_to_dbus() * would drop invalid values as it was unable to serialize them. * * Now, we would like to send invalid values as "assigned-mac-address" @@ -4129,12 +4129,6 @@ const NMSettInfoPropertType nm_sett_info_propert_type_assigned_mac_address = .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(g_value_get_string(prop_value)); -} - static void _nm_utils_hwaddr_from_dbus(GVariant *dbus_value, GValue *prop_value) { @@ -4147,9 +4141,10 @@ _nm_utils_hwaddr_from_dbus(GVariant *dbus_value, GValue *prop_value) } const NMSettInfoPropertType nm_sett_info_propert_type_mac_address = - NM_SETT_INFO_PROPERT_TYPE_GPROP_INIT(G_VARIANT_TYPE_BYTESTRING, - .gprop_to_dbus_fcn = _nm_utils_hwaddr_to_dbus, - .gprop_from_dbus_fcn = _nm_utils_hwaddr_from_dbus, ); + NM_SETT_INFO_PROPERT_TYPE_GPROP_INIT( + G_VARIANT_TYPE_BYTESTRING, + .gprop_from_dbus_fcn = _nm_utils_hwaddr_from_dbus, + .typdata_to_dbus.gprop_type = NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_MAC_ADDRESS); /*****************************************************************************/ diff --git a/src/libnm-core-impl/tests/test-setting.c b/src/libnm-core-impl/tests/test-setting.c index 6f3ffc54eb..567eb81df4 100644 --- a/src/libnm-core-impl/tests/test-setting.c +++ b/src/libnm-core-impl/tests/test-setting.c @@ -4391,6 +4391,9 @@ test_setting_metadata(void) case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_STRDICT: g_assert(sip->param_spec->value_type == G_TYPE_HASH_TABLE); goto check_done; + case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_MAC_ADDRESS: + g_assert(sip->param_spec->value_type == G_TYPE_STRING); + goto check_done; case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_DEFAULT: goto check_done; } diff --git a/src/libnm-core-intern/nm-core-internal.h b/src/libnm-core-intern/nm-core-internal.h index f36bf573bf..7678bcef80 100644 --- a/src/libnm-core-intern/nm-core-internal.h +++ b/src/libnm-core-intern/nm-core-internal.h @@ -678,6 +678,7 @@ typedef enum _nm_packed { NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_FLAGS, NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_GARRAY_UINT, NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_STRDICT, + NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_MAC_ADDRESS, } NMSettingPropertyToDBusFcnGPropType; typedef struct { From 8416c42b9da075b38bf10c658aa929d7813ba4e3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 18 Jun 2021 10:36:17 +0200 Subject: [PATCH 15/21] libnm: move gprop_to_dbus_fcn hook to NMSettInfoProperty For each property we have meta data in form of NMSettInfoProperty. Each meta data also has a NMSettInfoProperty.property_type (NMSettInfoPropertType). The property type is supposed to define common behaviors for properties, while the property meta data has individual properties. The idea is that several properties can share the same property-type, and that per-property meta data is part of NMSettInfoProperty. The distinction is not very strong, but note that all remaining uses of NMSettInfoPropertType.gprop_to_dbus_fcn were part of a property type that was only used for one single property. That lack of reusability hints to a wrong use. Move gprop_to_dbus_fcn to the property meta data as a new field NMSettInfoProperty.to_dbus_data. Note that NMSettInfoPropertType.gprop_from_dbus_fcn still suffers from the same problem. But the from-dbus side is not yet addressed. (cherry picked from commit 54cab39ac99fc6d5ad7378a93bcdb6dc8c340330) --- src/libnm-core-impl/nm-setting-ip4-config.c | 4 ++-- src/libnm-core-impl/nm-setting-ip6-config.c | 4 ++-- src/libnm-core-impl/nm-setting-private.h | 10 ++++++---- src/libnm-core-impl/nm-setting-serial.c | 4 ++-- .../nm-setting-wireless-security.c | 9 ++++----- src/libnm-core-impl/nm-setting.c | 18 +++++++++--------- src/libnm-core-impl/tests/test-setting.c | 10 +++++++--- src/libnm-core-intern/nm-core-internal.h | 10 ++++++++-- 8 files changed, 40 insertions(+), 29 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-ip4-config.c b/src/libnm-core-impl/nm-setting-ip4-config.c index 205dd4cc08..336e59640d 100644 --- a/src/libnm-core-impl/nm-setting-ip4-config.c +++ b/src/libnm-core-impl/nm-setting-ip4-config.c @@ -944,8 +944,8 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) properties_override, g_object_class_find_property(G_OBJECT_CLASS(setting_class), NM_SETTING_IP_CONFIG_DNS), NM_SETT_INFO_PROPERT_TYPE_GPROP(NM_G_VARIANT_TYPE("au"), - .gprop_to_dbus_fcn = ip4_dns_to_dbus, - .gprop_from_dbus_fcn = ip4_dns_from_dbus, )); + .gprop_from_dbus_fcn = ip4_dns_from_dbus, ), + .to_dbus_data.gprop_to_dbus_fcn = ip4_dns_to_dbus); /* ---dbus--- * property: addresses diff --git a/src/libnm-core-impl/nm-setting-ip6-config.c b/src/libnm-core-impl/nm-setting-ip6-config.c index fe171ce884..2bea668150 100644 --- a/src/libnm-core-impl/nm-setting-ip6-config.c +++ b/src/libnm-core-impl/nm-setting-ip6-config.c @@ -1013,8 +1013,8 @@ nm_setting_ip6_config_class_init(NMSettingIP6ConfigClass *klass) properties_override, g_object_class_find_property(G_OBJECT_CLASS(setting_class), NM_SETTING_IP_CONFIG_DNS), NM_SETT_INFO_PROPERT_TYPE_GPROP(NM_G_VARIANT_TYPE("aay"), - .gprop_to_dbus_fcn = ip6_dns_to_dbus, - .gprop_from_dbus_fcn = ip6_dns_from_dbus, )); + .gprop_from_dbus_fcn = ip6_dns_from_dbus, ), + .to_dbus_data.gprop_to_dbus_fcn = ip6_dns_to_dbus); /* ---dbus--- * property: addresses diff --git a/src/libnm-core-impl/nm-setting-private.h b/src/libnm-core-impl/nm-setting-private.h index 8dc7c4323e..f7b6b546c5 100644 --- a/src/libnm-core-impl/nm-setting-private.h +++ b/src/libnm-core-impl/nm-setting-private.h @@ -353,10 +353,12 @@ _nm_properties_override(GArray *properties_override, const NMSettInfoProperty *p g_array_append_vals(properties_override, prop_info, 1); } -#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 _nm_properties_override_gobj(properties_override, p_param_spec, p_property_type, ...) \ + _nm_properties_override((properties_override), \ + NM_SETT_INFO_PROPERTY(.name = NULL, \ + .param_spec = (p_param_spec), \ + .property_type = (p_property_type), \ + __VA_ARGS__)) #define _nm_properties_override_dbus(properties_override, p_name, p_property_type) \ _nm_properties_override( \ diff --git a/src/libnm-core-impl/nm-setting-serial.c b/src/libnm-core-impl/nm-setting-serial.c index 22244c7746..c87de166ac 100644 --- a/src/libnm-core-impl/nm-setting-serial.c +++ b/src/libnm-core-impl/nm-setting-serial.c @@ -312,8 +312,8 @@ nm_setting_serial_class_init(NMSettingSerialClass *klass) properties_override, obj_properties[PROP_PARITY], NM_SETT_INFO_PROPERT_TYPE_GPROP(G_VARIANT_TYPE_BYTE, - .gprop_to_dbus_fcn = parity_to_dbus, - .gprop_from_dbus_fcn = parity_from_dbus, )); + .gprop_from_dbus_fcn = parity_from_dbus, ), + .to_dbus_data.gprop_to_dbus_fcn = parity_to_dbus, ); /** * NMSettingSerial:stopbits: diff --git a/src/libnm-core-impl/nm-setting-wireless-security.c b/src/libnm-core-impl/nm-setting-wireless-security.c index 39f3a95fc9..9e3c8d819f 100644 --- a/src/libnm-core-impl/nm-setting-wireless-security.c +++ b/src/libnm-core-impl/nm-setting-wireless-security.c @@ -1924,11 +1924,10 @@ nm_setting_wireless_security_class_init(NMSettingWirelessSecurityClass *klass) NM_TYPE_WEP_KEY_TYPE, NM_WEP_KEY_TYPE_UNKNOWN, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _nm_properties_override_gobj( - properties_override, - obj_properties[PROP_WEP_KEY_TYPE], - NM_SETT_INFO_PROPERT_TYPE_GPROP(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_plain_u, + .to_dbus_data.gprop_to_dbus_fcn = wep_key_type_to_dbus, ); /** * NMSettingWirelessSecurity:wps-method: diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index 95338892af..af826b0928 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -171,15 +171,11 @@ _nm_properties_override_assert(const NMSettInfoProperty *prop_info) /* we always require a dbus_type. */ nm_assert(property_type->dbus_type); - if (!property_type->to_dbus_fcn) - nm_assert(!property_type->gprop_to_dbus_fcn); - - /* {to,from}_dbus_fcn and gprop_{to,from}_dbus_fcn cannot both be set. */ + /* from_dbus_fcn and gprop_from_dbus_fcn cannot both be set. */ nm_assert(!property_type->from_dbus_fcn || !property_type->gprop_from_dbus_fcn); if (!prop_info->param_spec) { - /* if we don't have a param_spec, we cannot have gprop_{to,from}_dbus_fcn. */ - nm_assert(!property_type->gprop_to_dbus_fcn); + /* if we don't have a param_spec, we cannot have gprop_from_dbus_fcn. */ nm_assert(!property_type->gprop_from_dbus_fcn); } } @@ -547,6 +543,10 @@ _nm_setting_property_to_dbus_fcn_gprop(const NMSettInfoSetting * s GArray *tmp_array; nm_assert(property->param_spec); + nm_assert(property->property_type->to_dbus_fcn == _nm_setting_property_to_dbus_fcn_gprop); + nm_assert(property->property_type->typdata_to_dbus.gprop_type + == NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_DEFAULT + || !property->to_dbus_data.gprop_to_dbus_fcn); g_value_init(&prop_value, property->param_spec->value_type); @@ -557,8 +557,8 @@ _nm_setting_property_to_dbus_fcn_gprop(const NMSettInfoSetting * s switch (property->property_type->typdata_to_dbus.gprop_type) { case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_DEFAULT: - if (property->property_type->gprop_to_dbus_fcn) - return property->property_type->gprop_to_dbus_fcn(&prop_value); + if (property->to_dbus_data.gprop_to_dbus_fcn) + return property->to_dbus_data.gprop_to_dbus_fcn(&prop_value); return g_dbus_gvalue_to_gvariant(&prop_value, property->property_type->dbus_type); case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_BYTES: @@ -600,7 +600,7 @@ property_to_dbus(const NMSettInfoSetting * sett_info, if (!property->property_type->to_dbus_fcn) { nm_assert(!property->param_spec); - nm_assert(!property->property_type->gprop_to_dbus_fcn); + nm_assert(!property->to_dbus_data.none); return NULL; } diff --git a/src/libnm-core-impl/tests/test-setting.c b/src/libnm-core-impl/tests/test-setting.c index 567eb81df4..6a342bcca8 100644 --- a/src/libnm-core-impl/tests/test-setting.c +++ b/src/libnm-core-impl/tests/test-setting.c @@ -4372,7 +4372,7 @@ test_setting_metadata(void) /* it's allowed to have no to_dbus_fcn(), to ignore a property. But such * properties must not have a param_spec and no gprop_to_dbus_fcn. */ g_assert(!sip->param_spec); - g_assert(!sip->property_type->gprop_to_dbus_fcn); + g_assert(!sip->to_dbus_data.none); } else if (sip->property_type->to_dbus_fcn == _nm_setting_property_to_dbus_fcn_gprop) { g_assert(sip->param_spec); switch (sip->property_type->typdata_to_dbus.gprop_type) { @@ -4399,6 +4399,9 @@ test_setting_metadata(void) } g_assert_not_reached(); check_done:; + if (sip->property_type->typdata_to_dbus.gprop_type + != NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_DEFAULT) + g_assert(!sip->to_dbus_data.gprop_to_dbus_fcn); } g_assert(!sip->property_type->from_dbus_fcn @@ -4518,7 +4521,6 @@ check_done:; || 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 || memcmp(&pt->typdata_to_dbus, &pt_2->typdata_to_dbus, @@ -4545,7 +4547,9 @@ check_done:; /* 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", + g_error("The identical property type for D-Bus type \"%s\" is used by: %s and %s. " + "If a NMSettInfoPropertType is identical, it should be shared by creating " + "a common instance of the property type", (const char *) pt->dbus_type, _PROP_IDX_OWNER(h_property_types, pt), _PROP_IDX_OWNER(h_property_types, pt_2)); diff --git a/src/libnm-core-intern/nm-core-internal.h b/src/libnm-core-intern/nm-core-internal.h index 7678bcef80..657c66d683 100644 --- a/src/libnm-core-intern/nm-core-internal.h +++ b/src/libnm-core-intern/nm-core-internal.h @@ -688,9 +688,8 @@ typedef struct { NMSettInfoPropFromDBusFcn from_dbus_fcn; NMSettInfoPropMissingFromDBusFcn missing_from_dbus_fcn; - /* Simpler variants of @to_dbus_fcn/@from_dbus_fcn that operate solely + /* Simpler variants of @from_dbus_fcn that operate solely * on the GValue value of the GObject property. */ - NMSettInfoPropGPropToDBusFcn gprop_to_dbus_fcn; NMSettInfoPropGPropFromDBusFcn gprop_from_dbus_fcn; struct { @@ -707,6 +706,13 @@ struct _NMSettInfoProperty { GParamSpec *param_spec; const NMSettInfoPropertType *property_type; + + struct { + union { + gpointer none; + NMSettInfoPropGPropToDBusFcn gprop_to_dbus_fcn; + }; + } to_dbus_data; }; typedef struct { From 7598eb6228b9deed354dfb8ab0b0d21debdddb6e Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 17 Jun 2021 22:10:48 +0200 Subject: [PATCH 16/21] libnm: extend to_dbus_fcn() property type for efficiently converting boolean property Most of our NMSetting properties are based around GObject properties, and thus the tooling to convert a NMSetting to/from GVariant consists of getting/setting a GValue. We can do better. For most of such properties we also define a C getter function, which we can call with less overhead. All we need is to hook the C getter with the property meta data. As example, implement it for "connection.autoconnect". The immediate goal of this is to reduce the overhead of to_dbus. But note that also for comparison of two properties, there is the default implementation which is used by the majority of properties. This implementation converts the properties first to GVariant (via to_dbus_fcn) and then compares the variants. What this commit also does, is to hook up the property meta data with the C-getters. This is one step towards also more efficiently compare properties using the naive C getters. Likewise, the keyfile writer use g_object_get_property(). It also could do better. (cherry picked from commit a832781a8a64c96cd8bca8b2e591a1fd2b3bad8e) --- src/libnm-core-impl/nm-setting-connection.c | 13 ++-- src/libnm-core-impl/nm-setting-private.h | 73 +++++++++++++++++++++ src/libnm-core-impl/nm-setting.c | 23 ++++++- src/libnm-core-impl/tests/test-setting.c | 5 ++ src/libnm-core-intern/nm-core-internal.h | 1 + 5 files changed, 108 insertions(+), 7 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-connection.c b/src/libnm-core-impl/nm-setting-connection.c index a8423a6974..df792a9883 100644 --- a/src/libnm-core-impl/nm-setting-connection.c +++ b/src/libnm-core-impl/nm-setting-connection.c @@ -2075,12 +2075,13 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass) * description: Whether the connection should be autoconnected (not only while booting). * ---end--- */ - obj_properties[PROP_AUTOCONNECT] = g_param_spec_boolean( - NM_SETTING_CONNECTION_AUTOCONNECT, - "", - "", - TRUE, - G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_CONNECTION_AUTOCONNECT, + PROP_AUTOCONNECT, + TRUE, + NM_SETTING_PARAM_FUZZY_IGNORE, + nm_setting_connection_get_autoconnect); /** * NMSettingConnection:autoconnect-priority: diff --git a/src/libnm-core-impl/nm-setting-private.h b/src/libnm-core-impl/nm-setting-private.h index f7b6b546c5..bb006b88c0 100644 --- a/src/libnm-core-impl/nm-setting-private.h +++ b/src/libnm-core-impl/nm-setting-private.h @@ -253,6 +253,8 @@ 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; +extern const NMSettInfoPropertType nm_sett_info_propert_type_boolean; + NMSettingVerifyResult _nm_setting_verify(NMSetting *setting, NMConnection *connection, GError **error); @@ -272,6 +274,14 @@ GVariant *_nm_setting_property_to_dbus_fcn_gprop(const NMSettInfoSetting * NMConnectionSerializationFlags flags, const NMConnectionSerializationOptions *options); +GVariant * +_nm_setting_property_to_dbus_fcn_get_boolean(const NMSettInfoSetting * sett_info, + guint property_idx, + NMConnection * connection, + NMSetting * setting, + NMConnectionSerializationFlags flags, + const NMConnectionSerializationOptions *options); + GVariant *_nm_setting_to_dbus(NMSetting * setting, NMConnection * connection, NMConnectionSerializationFlags flags, @@ -367,6 +377,69 @@ _nm_properties_override(GArray *properties_override, const NMSettInfoProperty *p /*****************************************************************************/ +#define _nm_setting_property_define_boolean_full(properties_override, \ + obj_properties, \ + prop_name, \ + prop_id, \ + default_value, \ + param_flags, \ + property_type, \ + get_fcn, \ + ...) \ + G_STMT_START \ + { \ + const gboolean _default_value = (default_value); \ + GParamSpec * _param_spec; \ + const NMSettInfoPropertType *const _property_type = (property_type); \ + \ + G_STATIC_ASSERT( \ + !NM_FLAGS_ANY((param_flags), \ + ~(NM_SETTING_PARAM_FUZZY_IGNORE | NM_SETTING_PARAM_INFERRABLE \ + | NM_SETTING_PARAM_REAPPLY_IMMEDIATELY))); \ + \ + nm_assert(_property_type); \ + nm_assert(_property_type->to_dbus_fcn == _nm_setting_property_to_dbus_fcn_get_boolean); \ + \ + nm_assert(NM_IN_SET(_default_value, 0, 1)); \ + \ + _param_spec = \ + g_param_spec_boolean("" prop_name "", \ + "", \ + "", \ + _default_value, \ + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | (param_flags)); \ + \ + (obj_properties)[(prop_id)] = _param_spec; \ + \ + _nm_properties_override_gobj((properties_override), \ + _param_spec, \ + _property_type, \ + .to_dbus_data.get_boolean = \ + (gboolean(*)(NMSetting *)) (get_fcn), \ + __VA_ARGS__); \ + } \ + G_STMT_END + +#define _nm_setting_property_define_boolean(properties_override, \ + obj_properties, \ + prop_name, \ + prop_id, \ + default_value, \ + param_flags, \ + get_fcn, \ + ...) \ + _nm_setting_property_define_boolean_full((properties_override), \ + (obj_properties), \ + prop_name, \ + (prop_id), \ + (default_value), \ + (param_flags), \ + &nm_sett_info_propert_type_boolean, \ + (get_fcn), \ + __VA_ARGS__) + +/*****************************************************************************/ + gboolean _nm_setting_use_legacy_property(NMSetting * setting, GVariant * connection_dict, const char *legacy_property, diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index af826b0928..c0c75a420d 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -176,7 +176,7 @@ _nm_properties_override_assert(const NMSettInfoProperty *prop_info) if (!prop_info->param_spec) { /* if we don't have a param_spec, we cannot have gprop_from_dbus_fcn. */ - nm_assert(!property_type->gprop_from_dbus_fcn); + nm_assert(property_type->from_dbus_fcn || !property_type->gprop_from_dbus_fcn); } } #endif @@ -528,6 +528,23 @@ _nm_setting_use_legacy_property(NMSetting * setting, /*****************************************************************************/ +GVariant * +_nm_setting_property_to_dbus_fcn_get_boolean(const NMSettInfoSetting * sett_info, + guint property_idx, + NMConnection * connection, + NMSetting * setting, + NMConnectionSerializationFlags flags, + const NMConnectionSerializationOptions *options) +{ + const NMSettInfoProperty *property_info = &sett_info->property_infos[property_idx]; + gboolean val; + + val = !!property_info->to_dbus_data.get_boolean(setting); + if (val == NM_G_PARAM_SPEC_GET_DEFAULT_BOOLEAN(property_info->param_spec)) + return NULL; + return g_variant_ref(nm_g_variant_singleton_b(val)); +} + GVariant * _nm_setting_property_to_dbus_fcn_gprop(const NMSettInfoSetting * sett_info, guint property_idx, @@ -2353,6 +2370,10 @@ const NMSettInfoPropertType nm_sett_info_propert_type_plain_i = const NMSettInfoPropertType nm_sett_info_propert_type_plain_u = NM_SETT_INFO_PROPERT_TYPE_GPROP_INIT(G_VARIANT_TYPE_UINT32); +const NMSettInfoPropertType nm_sett_info_propert_type_boolean = NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT( + G_VARIANT_TYPE_BOOLEAN, + .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_get_boolean); + /*****************************************************************************/ static GenData * diff --git a/src/libnm-core-impl/tests/test-setting.c b/src/libnm-core-impl/tests/test-setting.c index 6a342bcca8..0572de1412 100644 --- a/src/libnm-core-impl/tests/test-setting.c +++ b/src/libnm-core-impl/tests/test-setting.c @@ -4402,6 +4402,11 @@ check_done:; if (sip->property_type->typdata_to_dbus.gprop_type != NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_DEFAULT) g_assert(!sip->to_dbus_data.gprop_to_dbus_fcn); + } else if (sip->property_type->to_dbus_fcn + == _nm_setting_property_to_dbus_fcn_get_boolean) { + g_assert(sip->param_spec); + g_assert(sip->param_spec->value_type == G_TYPE_BOOLEAN); + g_assert(sip->to_dbus_data.get_boolean); } g_assert(!sip->property_type->from_dbus_fcn diff --git a/src/libnm-core-intern/nm-core-internal.h b/src/libnm-core-intern/nm-core-internal.h index 657c66d683..1fde5d455d 100644 --- a/src/libnm-core-intern/nm-core-internal.h +++ b/src/libnm-core-intern/nm-core-internal.h @@ -711,6 +711,7 @@ struct _NMSettInfoProperty { union { gpointer none; NMSettInfoPropGPropToDBusFcn gprop_to_dbus_fcn; + gboolean (*get_boolean)(NMSetting *); }; } to_dbus_data; }; From b20941215e204ec53f624a9038447d48723945b5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 17 Jun 2021 23:41:19 +0200 Subject: [PATCH 17/21] libnm: extend to_dbus_fcn() property type for efficiently converting string property (cherry picked from commit e435fdfedf56ca83b44f2be76a069d3540a83355) --- src/libnm-core-impl/nm-setting-connection.c | 12 ++-- src/libnm-core-impl/nm-setting-private.h | 65 +++++++++++++++++++++ src/libnm-core-impl/nm-setting.c | 25 ++++++++ src/libnm-core-impl/tests/test-setting.c | 5 ++ src/libnm-core-intern/nm-core-internal.h | 1 + 5 files changed, 102 insertions(+), 6 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-connection.c b/src/libnm-core-impl/nm-setting-connection.c index df792a9883..1df5823121 100644 --- a/src/libnm-core-impl/nm-setting-connection.c +++ b/src/libnm-core-impl/nm-setting-connection.c @@ -1956,12 +1956,12 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass) * description: Token to generate stable IDs. * ---end--- */ - obj_properties[PROP_STABLE_ID] = g_param_spec_string( - NM_SETTING_CONNECTION_STABLE_ID, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_string(properties_override, + obj_properties, + NM_SETTING_CONNECTION_STABLE_ID, + PROP_STABLE_ID, + NM_SETTING_PARAM_FUZZY_IGNORE, + nm_setting_connection_get_stable_id); /** * NMSettingConnection:interface-name: diff --git a/src/libnm-core-impl/nm-setting-private.h b/src/libnm-core-impl/nm-setting-private.h index bb006b88c0..061fc901ff 100644 --- a/src/libnm-core-impl/nm-setting-private.h +++ b/src/libnm-core-impl/nm-setting-private.h @@ -254,6 +254,7 @@ extern const NMSettInfoPropertType nm_sett_info_propert_type_plain_i; extern const NMSettInfoPropertType nm_sett_info_propert_type_plain_u; extern const NMSettInfoPropertType nm_sett_info_propert_type_boolean; +extern const NMSettInfoPropertType nm_sett_info_propert_type_string; NMSettingVerifyResult _nm_setting_verify(NMSetting *setting, NMConnection *connection, GError **error); @@ -282,6 +283,14 @@ _nm_setting_property_to_dbus_fcn_get_boolean(const NMSettInfoSetting * NMConnectionSerializationFlags flags, const NMConnectionSerializationOptions *options); +GVariant * +_nm_setting_property_to_dbus_fcn_get_string(const NMSettInfoSetting * sett_info, + guint property_idx, + NMConnection * connection, + NMSetting * setting, + NMConnectionSerializationFlags flags, + const NMConnectionSerializationOptions *options); + GVariant *_nm_setting_to_dbus(NMSetting * setting, NMConnection * connection, NMConnectionSerializationFlags flags, @@ -440,6 +449,62 @@ _nm_properties_override(GArray *properties_override, const NMSettInfoProperty *p /*****************************************************************************/ +#define _nm_setting_property_define_string_full(properties_override, \ + obj_properties, \ + prop_name, \ + prop_id, \ + param_flags, \ + property_type, \ + get_fcn, \ + ...) \ + G_STMT_START \ + { \ + GParamSpec * _param_spec; \ + const NMSettInfoPropertType *const _property_type = (property_type); \ + \ + G_STATIC_ASSERT(!NM_FLAGS_ANY((param_flags), \ + ~(NM_SETTING_PARAM_SECRET | NM_SETTING_PARAM_FUZZY_IGNORE \ + | NM_SETTING_PARAM_INFERRABLE \ + | NM_SETTING_PARAM_REAPPLY_IMMEDIATELY))); \ + nm_assert(_property_type); \ + nm_assert(_property_type->to_dbus_fcn == _nm_setting_property_to_dbus_fcn_get_string); \ + \ + _param_spec = \ + g_param_spec_string("" prop_name "", \ + "", \ + "", \ + NULL, \ + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | (param_flags)); \ + \ + (obj_properties)[(prop_id)] = _param_spec; \ + \ + _nm_properties_override_gobj((properties_override), \ + _param_spec, \ + _property_type, \ + .to_dbus_data.get_string = \ + (const char *(*) (NMSetting *) ) (get_fcn), \ + __VA_ARGS__); \ + } \ + G_STMT_END + +#define _nm_setting_property_define_string(properties_override, \ + obj_properties, \ + prop_name, \ + prop_id, \ + param_flags, \ + get_fcn, \ + ...) \ + _nm_setting_property_define_string_full((properties_override), \ + (obj_properties), \ + prop_name, \ + (prop_id), \ + (param_flags), \ + &nm_sett_info_propert_type_string, \ + (get_fcn), \ + __VA_ARGS__) + +/*****************************************************************************/ + gboolean _nm_setting_use_legacy_property(NMSetting * setting, GVariant * connection_dict, const char *legacy_property, diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index c0c75a420d..765ecea0ec 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -545,6 +545,27 @@ _nm_setting_property_to_dbus_fcn_get_boolean(const NMSettInfoSetting * return g_variant_ref(nm_g_variant_singleton_b(val)); } +GVariant * +_nm_setting_property_to_dbus_fcn_get_string(const NMSettInfoSetting * sett_info, + guint property_idx, + NMConnection * connection, + NMSetting * setting, + NMConnectionSerializationFlags flags, + const NMConnectionSerializationOptions *options) +{ + const NMSettInfoProperty *property_info = &sett_info->property_infos[property_idx]; + const char * val; + + nm_assert(!NM_G_PARAM_SPEC_GET_DEFAULT_STRING(property_info->param_spec)); + + val = property_info->to_dbus_data.get_string(setting); + if (!val) + return NULL; + if (!val[0]) + return g_variant_ref(nm_g_variant_singleton_s_empty()); + return g_variant_new_string(val); +} + GVariant * _nm_setting_property_to_dbus_fcn_gprop(const NMSettInfoSetting * sett_info, guint property_idx, @@ -2374,6 +2395,10 @@ const NMSettInfoPropertType nm_sett_info_propert_type_boolean = NM_SETT_INFO_PRO G_VARIANT_TYPE_BOOLEAN, .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_get_boolean); +const NMSettInfoPropertType nm_sett_info_propert_type_string = + NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_STRING, + .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_get_string); + /*****************************************************************************/ static GenData * diff --git a/src/libnm-core-impl/tests/test-setting.c b/src/libnm-core-impl/tests/test-setting.c index 0572de1412..77edf4afa4 100644 --- a/src/libnm-core-impl/tests/test-setting.c +++ b/src/libnm-core-impl/tests/test-setting.c @@ -4407,6 +4407,11 @@ check_done:; g_assert(sip->param_spec); g_assert(sip->param_spec->value_type == G_TYPE_BOOLEAN); g_assert(sip->to_dbus_data.get_boolean); + } else if (sip->property_type->to_dbus_fcn + == _nm_setting_property_to_dbus_fcn_get_string) { + g_assert(sip->param_spec); + g_assert(sip->param_spec->value_type == G_TYPE_STRING); + g_assert(sip->to_dbus_data.get_string); } g_assert(!sip->property_type->from_dbus_fcn diff --git a/src/libnm-core-intern/nm-core-internal.h b/src/libnm-core-intern/nm-core-internal.h index 1fde5d455d..c4e420f0d8 100644 --- a/src/libnm-core-intern/nm-core-internal.h +++ b/src/libnm-core-intern/nm-core-internal.h @@ -712,6 +712,7 @@ struct _NMSettInfoProperty { gpointer none; NMSettInfoPropGPropToDBusFcn gprop_to_dbus_fcn; gboolean (*get_boolean)(NMSetting *); + const char *(*get_string)(NMSetting *); }; } to_dbus_data; }; From 4cea3e4f443d6fa02aa7e881962fbeb9fac72660 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 18 Jun 2021 16:36:40 +0200 Subject: [PATCH 18/21] libnm: add flag to control whether to_dbus_fcn() should handle default values Usually, properties that are set to their default are not serialized on D-Bus. That is, to_dbus_fcn() returns NULL. In some cases, we explicitly want to always serialize the property. For example, if we changed behavior and the libnm default value changed. Then we want that the message on D-Bus is always clear about the used value and not rely on the default value on the receiving side. (cherry picked from commit acc3a66bf2ef60458b87e9965f89b26d2e35e480) --- src/libnm-core-impl/nm-setting.c | 12 ++++++++++-- src/libnm-core-impl/tests/test-setting.c | 6 ++++++ src/libnm-core-intern/nm-core-internal.h | 6 ++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index 765ecea0ec..54e1a176c1 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -540,7 +540,8 @@ _nm_setting_property_to_dbus_fcn_get_boolean(const NMSettInfoSetting * gboolean val; val = !!property_info->to_dbus_data.get_boolean(setting); - if (val == NM_G_PARAM_SPEC_GET_DEFAULT_BOOLEAN(property_info->param_spec)) + if (!property_info->to_dbus_data.including_default + && val == NM_G_PARAM_SPEC_GET_DEFAULT_BOOLEAN(property_info->param_spec)) return NULL; return g_variant_ref(nm_g_variant_singleton_b(val)); } @@ -556,7 +557,13 @@ _nm_setting_property_to_dbus_fcn_get_string(const NMSettInfoSetting * const NMSettInfoProperty *property_info = &sett_info->property_infos[property_idx]; const char * val; + /* For string properties that are implemented via this function, the default is always NULL. + * In general, having strings default to NULL is most advisable. + * + * Setting "including_default" for a string makes no sense because a + * GVariant of type "s" cannot express NULL. */ nm_assert(!NM_G_PARAM_SPEC_GET_DEFAULT_STRING(property_info->param_spec)); + nm_assert(!property_info->to_dbus_data.including_default); val = property_info->to_dbus_data.get_string(setting); if (!val) @@ -590,7 +597,8 @@ _nm_setting_property_to_dbus_fcn_gprop(const NMSettInfoSetting * s g_object_get_property(G_OBJECT(setting), property->param_spec->name, &prop_value); - if (g_param_value_defaults(property->param_spec, &prop_value)) + if (!property->to_dbus_data.including_default + && g_param_value_defaults(property->param_spec, &prop_value)) return NULL; switch (property->property_type->typdata_to_dbus.gprop_type) { diff --git a/src/libnm-core-impl/tests/test-setting.c b/src/libnm-core-impl/tests/test-setting.c index 77edf4afa4..066cdb24d9 100644 --- a/src/libnm-core-impl/tests/test-setting.c +++ b/src/libnm-core-impl/tests/test-setting.c @@ -4358,6 +4358,7 @@ test_setting_metadata(void) const NMSettInfoProperty *sip = &sis->property_infos[prop_idx]; GArray * property_types_data; guint prop_idx_val; + gboolean can_set_including_default = FALSE; g_assert(sip->name); @@ -4402,11 +4403,13 @@ check_done:; if (sip->property_type->typdata_to_dbus.gprop_type != NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_DEFAULT) g_assert(!sip->to_dbus_data.gprop_to_dbus_fcn); + can_set_including_default = TRUE; } else if (sip->property_type->to_dbus_fcn == _nm_setting_property_to_dbus_fcn_get_boolean) { g_assert(sip->param_spec); g_assert(sip->param_spec->value_type == G_TYPE_BOOLEAN); g_assert(sip->to_dbus_data.get_boolean); + can_set_including_default = TRUE; } else if (sip->property_type->to_dbus_fcn == _nm_setting_property_to_dbus_fcn_get_string) { g_assert(sip->param_spec); @@ -4414,6 +4417,9 @@ check_done:; g_assert(sip->to_dbus_data.get_string); } + if (!can_set_including_default) + g_assert(!sip->to_dbus_data.including_default); + g_assert(!sip->property_type->from_dbus_fcn || !sip->property_type->gprop_from_dbus_fcn); diff --git a/src/libnm-core-intern/nm-core-internal.h b/src/libnm-core-intern/nm-core-internal.h index c4e420f0d8..2ef2520956 100644 --- a/src/libnm-core-intern/nm-core-internal.h +++ b/src/libnm-core-intern/nm-core-internal.h @@ -714,6 +714,12 @@ struct _NMSettInfoProperty { gboolean (*get_boolean)(NMSetting *); const char *(*get_string)(NMSetting *); }; + + /* Usually, properties that are set to the default value for the GParamSpec + * are not serialized to GVariant (and NULL is returned by to_dbus_data(). + * Set this flag to force always converting the property even if the value + * is the default. */ + bool including_default : 1; } to_dbus_data; }; From 1cc3b9c75365cfb4ca1e25a0f83f3bde3981e824 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 18 Jun 2021 16:48:12 +0200 Subject: [PATCH 19/21] libnm: use new including_default flag and boolean getter for "ethernet.auto-negotiate" property (cherry picked from commit d5c4378cdf732a75862e81c8c85c23012cf080b2) --- src/libnm-core-impl/nm-setting-wired.c | 30 +++++++------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-wired.c b/src/libnm-core-impl/nm-setting-wired.c index 99909bf06a..c325413b22 100644 --- a/src/libnm-core-impl/nm-setting-wired.c +++ b/src/libnm-core-impl/nm-setting-wired.c @@ -995,17 +995,6 @@ compare_property(const NMSettInfoSetting *sett_info, ->compare_property(sett_info, property_idx, con_a, set_a, con_b, set_b, flags); } -static GVariant * -_override_autoneg_get(const NMSettInfoSetting * sett_info, - guint property_idx, - NMConnection * connection, - NMSetting * setting, - NMConnectionSerializationFlags flags, - const NMConnectionSerializationOptions *options) -{ - return g_variant_new_boolean(nm_setting_wired_get_auto_negotiate((NMSettingWired *) setting)); -} - /*****************************************************************************/ static void @@ -1389,17 +1378,14 @@ nm_setting_wired_class_init(NMSettingWiredClass *klass) * "speed" and "duplex" parameters (skips link configuration). * ---end--- */ - obj_properties[PROP_AUTO_NEGOTIATE] = - g_param_spec_boolean(NM_SETTING_WIRED_AUTO_NEGOTIATE, - "", - "", - FALSE, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _nm_properties_override_gobj( - properties_override, - obj_properties[PROP_AUTO_NEGOTIATE], - NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_BOOLEAN, - .to_dbus_fcn = _override_autoneg_get, )); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_WIRED_AUTO_NEGOTIATE, + PROP_AUTO_NEGOTIATE, + FALSE, + NM_SETTING_PARAM_NONE, + nm_setting_wired_get_auto_negotiate, + .to_dbus_data.including_default = TRUE); /** * NMSettingWired:mac-address: From 2e93f82746d1e14c5522151e1246b0f824d2fba1 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 17 Jun 2021 22:53:52 +0200 Subject: [PATCH 20/21] libnm: use _nm_setting_property_define_boolean() for boolean NMSetting properties (cherry picked from commit 22edf34ba3b794c8d6b7fbf6b9743e2898a98a27) --- src/libnm-core-impl/nm-setting-8021x.c | 36 ++-- src/libnm-core-impl/nm-setting-bridge-port.c | 13 +- src/libnm-core-impl/nm-setting-bridge.c | 78 ++++---- src/libnm-core-impl/nm-setting-connection.c | 13 +- src/libnm-core-impl/nm-setting-gsm.c | 26 +-- src/libnm-core-impl/nm-setting-ip-config.c | 30 ++++ src/libnm-core-impl/nm-setting-ip-tunnel.c | 23 ++- src/libnm-core-impl/nm-setting-macsec.c | 35 ++-- src/libnm-core-impl/nm-setting-macvlan.c | 36 ++-- src/libnm-core-impl/nm-setting-ovs-bridge.c | 49 ++--- src/libnm-core-impl/nm-setting-ppp.c | 177 ++++++++++--------- src/libnm-core-impl/nm-setting-proxy.c | 23 ++- src/libnm-core-impl/nm-setting-tun.c | 49 ++--- src/libnm-core-impl/nm-setting-vpn.c | 13 +- src/libnm-core-impl/nm-setting-vxlan.c | 77 ++++---- src/libnm-core-impl/nm-setting-wireguard.c | 13 +- src/libnm-core-impl/nm-setting-wireless.c | 12 +- 17 files changed, 410 insertions(+), 293 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-8021x.c b/src/libnm-core-impl/nm-setting-8021x.c index 78a31e9c39..6ddbd68066 100644 --- a/src/libnm-core-impl/nm-setting-8021x.c +++ b/src/libnm-core-impl/nm-setting-8021x.c @@ -3513,8 +3513,9 @@ finalize(GObject *object) static void nm_setting_802_1x_class_init(NMSetting8021xClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); - NMSettingClass *setting_class = NM_SETTING_CLASS(klass); + GObjectClass * object_class = G_OBJECT_CLASS(klass); + NMSettingClass *setting_class = NM_SETTING_CLASS(klass); + GArray * properties_override = _nm_sett_info_property_override_create_array(); g_type_class_add_private(klass, sizeof(NMSetting8021xPrivate)); @@ -4587,12 +4588,13 @@ nm_setting_802_1x_class_init(NMSetting8021xClass *klass) * description: a boolean value. * ---end--- */ - obj_properties[PROP_SYSTEM_CA_CERTS] = - g_param_spec_boolean(NM_SETTING_802_1X_SYSTEM_CA_CERTS, - "", - "", - FALSE, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_802_1X_SYSTEM_CA_CERTS, + PROP_SYSTEM_CA_CERTS, + FALSE, + NM_SETTING_PARAM_NONE, + nm_setting_802_1x_get_system_ca_certs); /** * NMSetting8021x:auth-timeout: @@ -4636,14 +4638,18 @@ nm_setting_802_1x_class_init(NMSetting8021xClass *klass) * description: whether the 802.1X authentication is optional * ---end--- */ - obj_properties[PROP_OPTIONAL] = - g_param_spec_boolean(NM_SETTING_802_1X_OPTIONAL, - "", - "", - FALSE, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_802_1X_OPTIONAL, + PROP_OPTIONAL, + FALSE, + NM_SETTING_PARAM_NONE, + nm_setting_802_1x_get_optional); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_802_1X); + _nm_setting_class_commit_full(setting_class, + NM_META_SETTING_TYPE_802_1X, + NULL, + properties_override); } diff --git a/src/libnm-core-impl/nm-setting-bridge-port.c b/src/libnm-core-impl/nm-setting-bridge-port.c index 9efb1563c3..33d0c00915 100644 --- a/src/libnm-core-impl/nm-setting-bridge-port.c +++ b/src/libnm-core-impl/nm-setting-bridge-port.c @@ -564,12 +564,13 @@ nm_setting_bridge_port_class_init(NMSettingBridgePortClass *klass) * description: Hairpin mode of the bridge port. * ---end--- */ - obj_properties[PROP_HAIRPIN_MODE] = g_param_spec_boolean( - NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE, - "", - "", - FALSE, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE, + PROP_HAIRPIN_MODE, + FALSE, + NM_SETTING_PARAM_INFERRABLE, + nm_setting_bridge_port_get_hairpin_mode); /** * NMSettingBridgePort:vlans: (type GPtrArray(NMBridgeVlan)) diff --git a/src/libnm-core-impl/nm-setting-bridge.c b/src/libnm-core-impl/nm-setting-bridge.c index e606432afe..e987310f6f 100644 --- a/src/libnm-core-impl/nm-setting-bridge.c +++ b/src/libnm-core-impl/nm-setting-bridge.c @@ -1672,12 +1672,13 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) * description: Span tree protocol participation. * ---end--- */ - obj_properties[PROP_STP] = g_param_spec_boolean(NM_SETTING_BRIDGE_STP, - "", - "", - NM_BRIDGE_STP_DEF, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE - | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_BRIDGE_STP, + PROP_STP, + NM_BRIDGE_STP_DEF, + NM_SETTING_PARAM_INFERRABLE, + nm_setting_bridge_get_stp); /** * NMSettingBridge:priority: @@ -1830,12 +1831,13 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) * description: IGMP snooping support. * ---end--- */ - obj_properties[PROP_MULTICAST_SNOOPING] = g_param_spec_boolean( - NM_SETTING_BRIDGE_MULTICAST_SNOOPING, - "", - "", - NM_BRIDGE_MULTICAST_SNOOPING_DEF, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_BRIDGE_MULTICAST_SNOOPING, + PROP_MULTICAST_SNOOPING, + NM_BRIDGE_MULTICAST_SNOOPING_DEF, + NM_SETTING_PARAM_INFERRABLE, + nm_setting_bridge_get_multicast_snooping); /** * NMSettingBridge:vlan-filtering: @@ -1852,12 +1854,13 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) * description: VLAN filtering support. * ---end--- */ - obj_properties[PROP_VLAN_FILTERING] = g_param_spec_boolean( - NM_SETTING_BRIDGE_VLAN_FILTERING, - "", - "", - FALSE, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_BRIDGE_VLAN_FILTERING, + PROP_VLAN_FILTERING, + FALSE, + NM_SETTING_PARAM_INFERRABLE, + nm_setting_bridge_get_vlan_filtering); /** * NMSettingBridge:vlan-default-pvid: @@ -1998,12 +2001,13 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) * * Since: 1.24 */ - obj_properties[PROP_VLAN_STATS_ENABLED] = g_param_spec_boolean( - NM_SETTING_BRIDGE_VLAN_STATS_ENABLED, - "", - "", - NM_BRIDGE_VLAN_STATS_ENABLED_DEF, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_BRIDGE_VLAN_STATS_ENABLED, + PROP_VLAN_STATS_ENABLED, + NM_BRIDGE_VLAN_STATS_ENABLED_DEF, + NM_SETTING_PARAM_INFERRABLE, + nm_setting_bridge_get_vlan_stats_enabled); /** * NMSettingBridge:multicast-router: @@ -2048,12 +2052,13 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) * * Since: 1.24 */ - obj_properties[PROP_MULTICAST_QUERY_USE_IFADDR] = g_param_spec_boolean( - NM_SETTING_BRIDGE_MULTICAST_QUERY_USE_IFADDR, - "", - "", - NM_BRIDGE_MULTICAST_QUERY_USE_IFADDR_DEF, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_BRIDGE_MULTICAST_QUERY_USE_IFADDR, + PROP_MULTICAST_QUERY_USE_IFADDR, + NM_BRIDGE_MULTICAST_QUERY_USE_IFADDR_DEF, + NM_SETTING_PARAM_INFERRABLE, + nm_setting_bridge_get_multicast_query_use_ifaddr); /** * NMSettingBridge:multicast-querier: @@ -2070,12 +2075,13 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) * * Since: 1.24 */ - obj_properties[PROP_MULTICAST_QUERIER] = g_param_spec_boolean( - NM_SETTING_BRIDGE_MULTICAST_QUERIER, - "", - "", - NM_BRIDGE_MULTICAST_QUERIER_DEF, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_BRIDGE_MULTICAST_QUERIER, + PROP_MULTICAST_QUERIER, + NM_BRIDGE_MULTICAST_QUERIER_DEF, + NM_SETTING_PARAM_INFERRABLE, + nm_setting_bridge_get_multicast_querier); /** * NMSettingBridge:multicast-hash-max: diff --git a/src/libnm-core-impl/nm-setting-connection.c b/src/libnm-core-impl/nm-setting-connection.c index 1df5823121..fc89467b47 100644 --- a/src/libnm-core-impl/nm-setting-connection.c +++ b/src/libnm-core-impl/nm-setting-connection.c @@ -2193,12 +2193,13 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass) * service's D-Bus interface with the right privileges, or %TRUE if the * connection is read-only and cannot be modified. **/ - obj_properties[PROP_READ_ONLY] = g_param_spec_boolean( - NM_SETTING_CONNECTION_READ_ONLY, - "", - "", - FALSE, - G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_CONNECTION_READ_ONLY, + PROP_READ_ONLY, + FALSE, + NM_SETTING_PARAM_FUZZY_IGNORE, + nm_setting_connection_get_read_only); /** * NMSettingConnection:zone: diff --git a/src/libnm-core-impl/nm-setting-gsm.c b/src/libnm-core-impl/nm-setting-gsm.c index a1f0500e4d..a177f7fb8c 100644 --- a/src/libnm-core-impl/nm-setting-gsm.c +++ b/src/libnm-core-impl/nm-setting-gsm.c @@ -667,12 +667,13 @@ nm_setting_gsm_class_init(NMSettingGsmClass *klass) * * Since: 1.22 **/ - obj_properties[PROP_AUTO_CONFIG] = - g_param_spec_boolean(NM_SETTING_GSM_AUTO_CONFIG, - "", - "", - FALSE, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_GSM_AUTO_CONFIG, + PROP_AUTO_CONFIG, + FALSE, + NM_SETTING_PARAM_NONE, + nm_setting_gsm_get_auto_config); /** * NMSettingGsm:number: @@ -793,12 +794,13 @@ nm_setting_gsm_class_init(NMSettingGsmClass *klass) * When %TRUE, only connections to the home network will be allowed. * Connections to roaming networks will not be made. **/ - obj_properties[PROP_HOME_ONLY] = - g_param_spec_boolean(NM_SETTING_GSM_HOME_ONLY, - "", - "", - FALSE, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_GSM_HOME_ONLY, + PROP_HOME_ONLY, + FALSE, + NM_SETTING_PARAM_NONE, + nm_setting_gsm_get_home_only); /** * NMSettingGsm:device-id: diff --git a/src/libnm-core-impl/nm-setting-ip-config.c b/src/libnm-core-impl/nm-setting-ip-config.c index 26e98a0433..b95eb8eeb4 100644 --- a/src/libnm-core-impl/nm-setting-ip-config.c +++ b/src/libnm-core-impl/nm-setting-ip-config.c @@ -5778,6 +5778,36 @@ _nm_sett_info_property_override_create_array_ip_config(void) .to_dbus_fcn = _routing_rules_dbus_only_synth, .from_dbus_fcn = _routing_rules_dbus_only_set, )); + _nm_properties_override_gobj(properties_override, + obj_properties[PROP_IGNORE_AUTO_ROUTES], + &nm_sett_info_propert_type_boolean, + .to_dbus_data.get_boolean = (gboolean(*)( + NMSetting *)) nm_setting_ip_config_get_ignore_auto_routes); + + _nm_properties_override_gobj(properties_override, + obj_properties[PROP_IGNORE_AUTO_DNS], + &nm_sett_info_propert_type_boolean, + .to_dbus_data.get_boolean = (gboolean(*)( + NMSetting *)) nm_setting_ip_config_get_ignore_auto_dns); + + _nm_properties_override_gobj(properties_override, + obj_properties[PROP_DHCP_SEND_HOSTNAME], + &nm_sett_info_propert_type_boolean, + .to_dbus_data.get_boolean = (gboolean(*)( + NMSetting *)) nm_setting_ip_config_get_dhcp_send_hostname); + + _nm_properties_override_gobj(properties_override, + obj_properties[PROP_NEVER_DEFAULT], + &nm_sett_info_propert_type_boolean, + .to_dbus_data.get_boolean = (gboolean(*)( + NMSetting *)) nm_setting_ip_config_get_never_default); + + _nm_properties_override_gobj(properties_override, + obj_properties[PROP_MAY_FAIL], + &nm_sett_info_propert_type_boolean, + .to_dbus_data.get_boolean = + (gboolean(*)(NMSetting *)) nm_setting_ip_config_get_may_fail); + return properties_override; } diff --git a/src/libnm-core-impl/nm-setting-ip-tunnel.c b/src/libnm-core-impl/nm-setting-ip-tunnel.c index 68135eea81..e6cb00fea5 100644 --- a/src/libnm-core-impl/nm-setting-ip-tunnel.c +++ b/src/libnm-core-impl/nm-setting-ip-tunnel.c @@ -654,8 +654,9 @@ finalize(GObject *object) static void nm_setting_ip_tunnel_class_init(NMSettingIPTunnelClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); - NMSettingClass *setting_class = NM_SETTING_CLASS(klass); + GObjectClass * object_class = G_OBJECT_CLASS(klass); + NMSettingClass *setting_class = NM_SETTING_CLASS(klass); + GArray * properties_override = _nm_sett_info_property_override_create_array(); g_type_class_add_private(klass, sizeof(NMSettingIPTunnelPrivate)); @@ -769,12 +770,13 @@ nm_setting_ip_tunnel_class_init(NMSettingIPTunnelClass *klass) * * Since: 1.2 **/ - obj_properties[PROP_PATH_MTU_DISCOVERY] = g_param_spec_boolean( - NM_SETTING_IP_TUNNEL_PATH_MTU_DISCOVERY, - "", - "", - TRUE, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_IP_TUNNEL_PATH_MTU_DISCOVERY, + PROP_PATH_MTU_DISCOVERY, + TRUE, + NM_SETTING_PARAM_INFERRABLE, + nm_setting_ip_tunnel_get_path_mtu_discovery); /** * NMSettingIPTunnel:input-key: @@ -879,5 +881,8 @@ nm_setting_ip_tunnel_class_init(NMSettingIPTunnelClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_IP_TUNNEL); + _nm_setting_class_commit_full(setting_class, + NM_META_SETTING_TYPE_IP_TUNNEL, + NULL, + properties_override); } diff --git a/src/libnm-core-impl/nm-setting-macsec.c b/src/libnm-core-impl/nm-setting-macsec.c index 9593419304..55024bb4c2 100644 --- a/src/libnm-core-impl/nm-setting-macsec.c +++ b/src/libnm-core-impl/nm-setting-macsec.c @@ -529,8 +529,9 @@ finalize(GObject *object) static void nm_setting_macsec_class_init(NMSettingMacsecClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); - NMSettingClass *setting_class = NM_SETTING_CLASS(klass); + GObjectClass * object_class = G_OBJECT_CLASS(klass); + NMSettingClass *setting_class = NM_SETTING_CLASS(klass); + GArray * properties_override = _nm_sett_info_property_override_create_array(); g_type_class_add_private(klass, sizeof(NMSettingMacsecPrivate)); @@ -582,11 +583,13 @@ nm_setting_macsec_class_init(NMSettingMacsecClass *klass) * * Since: 1.6 **/ - obj_properties[PROP_ENCRYPT] = g_param_spec_boolean(NM_SETTING_MACSEC_ENCRYPT, - "", - "", - TRUE, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_MACSEC_ENCRYPT, + PROP_ENCRYPT, + TRUE, + NM_SETTING_PARAM_NONE, + nm_setting_macsec_get_encrypt); /** * NMSettingMacsec:mka-cak: @@ -673,14 +676,18 @@ nm_setting_macsec_class_init(NMSettingMacsecClass *klass) * * Since: 1.12 **/ - obj_properties[PROP_SEND_SCI] = - g_param_spec_boolean(NM_SETTING_MACSEC_SEND_SCI, - "", - "", - TRUE, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_MACSEC_SEND_SCI, + PROP_SEND_SCI, + TRUE, + NM_SETTING_PARAM_NONE, + nm_setting_macsec_get_send_sci); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_MACSEC); + _nm_setting_class_commit_full(setting_class, + NM_META_SETTING_TYPE_MACSEC, + NULL, + properties_override); } diff --git a/src/libnm-core-impl/nm-setting-macvlan.c b/src/libnm-core-impl/nm-setting-macvlan.c index 98f943e9cd..9cb2b2621f 100644 --- a/src/libnm-core-impl/nm-setting-macvlan.c +++ b/src/libnm-core-impl/nm-setting-macvlan.c @@ -269,8 +269,9 @@ finalize(GObject *object) static void nm_setting_macvlan_class_init(NMSettingMacvlanClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); - NMSettingClass *setting_class = NM_SETTING_CLASS(klass); + GObjectClass * object_class = G_OBJECT_CLASS(klass); + NMSettingClass *setting_class = NM_SETTING_CLASS(klass); + GArray * properties_override = _nm_sett_info_property_override_create_array(); g_type_class_add_private(klass, sizeof(NMSettingMacvlanPrivate)); @@ -321,12 +322,13 @@ nm_setting_macvlan_class_init(NMSettingMacvlanClass *klass) * * Since: 1.2 **/ - obj_properties[PROP_PROMISCUOUS] = g_param_spec_boolean( - NM_SETTING_MACVLAN_PROMISCUOUS, - "", - "", - TRUE, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_MACVLAN_PROMISCUOUS, + PROP_PROMISCUOUS, + TRUE, + NM_SETTING_PARAM_INFERRABLE, + nm_setting_macvlan_get_promiscuous); /** * NMSettingMacvlan:tap: @@ -335,14 +337,18 @@ nm_setting_macvlan_class_init(NMSettingMacvlanClass *klass) * * Since: 1.2 **/ - obj_properties[PROP_TAP] = g_param_spec_boolean(NM_SETTING_MACVLAN_TAP, - "", - "", - FALSE, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE - | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_MACVLAN_TAP, + PROP_TAP, + FALSE, + NM_SETTING_PARAM_INFERRABLE, + nm_setting_macvlan_get_tap); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_MACVLAN); + _nm_setting_class_commit_full(setting_class, + NM_META_SETTING_TYPE_MACVLAN, + NULL, + properties_override); } diff --git a/src/libnm-core-impl/nm-setting-ovs-bridge.c b/src/libnm-core-impl/nm-setting-ovs-bridge.c index 9d67231b93..22738d204d 100644 --- a/src/libnm-core-impl/nm-setting-ovs-bridge.c +++ b/src/libnm-core-impl/nm-setting-ovs-bridge.c @@ -289,8 +289,9 @@ finalize(GObject *object) static void nm_setting_ovs_bridge_class_init(NMSettingOvsBridgeClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); - NMSettingClass *setting_class = NM_SETTING_CLASS(klass); + GObjectClass * object_class = G_OBJECT_CLASS(klass); + NMSettingClass *setting_class = NM_SETTING_CLASS(klass); + GArray * properties_override = _nm_sett_info_property_override_create_array(); object_class->get_property = get_property; object_class->set_property = set_property; @@ -319,12 +320,13 @@ nm_setting_ovs_bridge_class_init(NMSettingOvsBridgeClass *klass) * * Since: 1.10 **/ - obj_properties[PROP_MCAST_SNOOPING_ENABLE] = - g_param_spec_boolean(NM_SETTING_OVS_BRIDGE_MCAST_SNOOPING_ENABLE, - "", - "", - FALSE, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_OVS_BRIDGE_MCAST_SNOOPING_ENABLE, + PROP_MCAST_SNOOPING_ENABLE, + FALSE, + NM_SETTING_PARAM_NONE, + nm_setting_ovs_bridge_get_mcast_snooping_enable); /** * NMSettingOvsBridge:rstp-enable: @@ -333,12 +335,13 @@ nm_setting_ovs_bridge_class_init(NMSettingOvsBridgeClass *klass) * * Since: 1.10 **/ - obj_properties[PROP_RSTP_ENABLE] = - g_param_spec_boolean(NM_SETTING_OVS_BRIDGE_RSTP_ENABLE, - "", - "", - FALSE, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_OVS_BRIDGE_RSTP_ENABLE, + PROP_RSTP_ENABLE, + FALSE, + NM_SETTING_PARAM_NONE, + nm_setting_ovs_bridge_get_rstp_enable); /** * NMSettingOvsBridge:stp-enable: @@ -347,12 +350,13 @@ nm_setting_ovs_bridge_class_init(NMSettingOvsBridgeClass *klass) * * Since: 1.10 **/ - obj_properties[PROP_STP_ENABLE] = - g_param_spec_boolean(NM_SETTING_OVS_BRIDGE_STP_ENABLE, - "", - "", - FALSE, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_OVS_BRIDGE_STP_ENABLE, + PROP_STP_ENABLE, + FALSE, + NM_SETTING_PARAM_NONE, + nm_setting_ovs_bridge_get_stp_enable); /** * NMSettingOvsBridge:datapath-type: @@ -370,5 +374,8 @@ nm_setting_ovs_bridge_class_init(NMSettingOvsBridgeClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_OVS_BRIDGE); + _nm_setting_class_commit_full(setting_class, + NM_META_SETTING_TYPE_OVS_BRIDGE, + NULL, + properties_override); } diff --git a/src/libnm-core-impl/nm-setting-ppp.c b/src/libnm-core-impl/nm-setting-ppp.c index 73ffad647e..cc722c4456 100644 --- a/src/libnm-core-impl/nm-setting-ppp.c +++ b/src/libnm-core-impl/nm-setting-ppp.c @@ -534,8 +534,9 @@ nm_setting_ppp_new(void) static void nm_setting_ppp_class_init(NMSettingPppClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); - NMSettingClass *setting_class = NM_SETTING_CLASS(klass); + GObjectClass * object_class = G_OBJECT_CLASS(klass); + NMSettingClass *setting_class = NM_SETTING_CLASS(klass); + GArray * properties_override = _nm_sett_info_property_override_create_array(); g_type_class_add_private(klass, sizeof(NMSettingPppPrivate)); @@ -551,107 +552,117 @@ nm_setting_ppp_class_init(NMSettingPppClass *klass) * authenticate itself to the client. If %FALSE, require authentication * from the remote side. In almost all cases, this should be %TRUE. **/ - obj_properties[PROP_NOAUTH] = g_param_spec_boolean(NM_SETTING_PPP_NOAUTH, - "", - "", - TRUE, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_PPP_NOAUTH, + PROP_NOAUTH, + TRUE, + NM_SETTING_PARAM_NONE, + nm_setting_ppp_get_noauth); /** * NMSettingPpp:refuse-eap: * * If %TRUE, the EAP authentication method will not be used. **/ - obj_properties[PROP_REFUSE_EAP] = - g_param_spec_boolean(NM_SETTING_PPP_REFUSE_EAP, - "", - "", - FALSE, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_PPP_REFUSE_EAP, + PROP_REFUSE_EAP, + FALSE, + NM_SETTING_PARAM_NONE, + nm_setting_ppp_get_refuse_eap); /** * NMSettingPpp:refuse-pap: * * If %TRUE, the PAP authentication method will not be used. **/ - obj_properties[PROP_REFUSE_PAP] = - g_param_spec_boolean(NM_SETTING_PPP_REFUSE_PAP, - "", - "", - FALSE, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_PPP_REFUSE_PAP, + PROP_REFUSE_PAP, + FALSE, + NM_SETTING_PARAM_NONE, + nm_setting_ppp_get_refuse_pap); /** * NMSettingPpp:refuse-chap: * * If %TRUE, the CHAP authentication method will not be used. **/ - obj_properties[PROP_REFUSE_CHAP] = - g_param_spec_boolean(NM_SETTING_PPP_REFUSE_CHAP, - "", - "", - FALSE, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_PPP_REFUSE_CHAP, + PROP_REFUSE_CHAP, + FALSE, + NM_SETTING_PARAM_NONE, + nm_setting_ppp_get_refuse_chap); /** * NMSettingPpp:refuse-mschap: * * If %TRUE, the MSCHAP authentication method will not be used. **/ - obj_properties[PROP_REFUSE_MSCHAP] = - g_param_spec_boolean(NM_SETTING_PPP_REFUSE_MSCHAP, - "", - "", - FALSE, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_PPP_REFUSE_MSCHAP, + PROP_REFUSE_MSCHAP, + FALSE, + NM_SETTING_PARAM_NONE, + nm_setting_ppp_get_refuse_mschap); /** * NMSettingPpp:refuse-mschapv2: * * If %TRUE, the MSCHAPv2 authentication method will not be used. **/ - obj_properties[PROP_REFUSE_MSCHAPV2] = - g_param_spec_boolean(NM_SETTING_PPP_REFUSE_MSCHAPV2, - "", - "", - FALSE, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_PPP_REFUSE_MSCHAPV2, + PROP_REFUSE_MSCHAPV2, + FALSE, + NM_SETTING_PARAM_NONE, + nm_setting_ppp_get_refuse_mschapv2); /** * NMSettingPpp:nobsdcomp: * * If %TRUE, BSD compression will not be requested. **/ - obj_properties[PROP_NOBSDCOMP] = g_param_spec_boolean( - NM_SETTING_PPP_NOBSDCOMP, - "", - "", - FALSE, - G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_PPP_NOBSDCOMP, + PROP_NOBSDCOMP, + FALSE, + NM_SETTING_PARAM_FUZZY_IGNORE, + nm_setting_ppp_get_nobsdcomp); /** * NMSettingPpp:nodeflate: * * If %TRUE, "deflate" compression will not be requested. **/ - obj_properties[PROP_NODEFLATE] = g_param_spec_boolean( - NM_SETTING_PPP_NODEFLATE, - "", - "", - FALSE, - G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_PPP_NODEFLATE, + PROP_NODEFLATE, + FALSE, + NM_SETTING_PARAM_FUZZY_IGNORE, + nm_setting_ppp_get_nodeflate); /** * NMSettingPpp:no-vj-comp: * * If %TRUE, Van Jacobsen TCP header compression will not be requested. **/ - obj_properties[PROP_NO_VJ_COMP] = g_param_spec_boolean( - NM_SETTING_PPP_NO_VJ_COMP, - "", - "", - FALSE, - G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_PPP_NO_VJ_COMP, + PROP_NO_VJ_COMP, + FALSE, + NM_SETTING_PARAM_FUZZY_IGNORE, + nm_setting_ppp_get_no_vj_comp); /** * NMSettingPpp:require-mppe: @@ -661,12 +672,13 @@ nm_setting_ppp_class_init(NMSettingPppClass *klass) * session will fail. Note that MPPE is not used on mobile broadband * connections. **/ - obj_properties[PROP_REQUIRE_MPPE] = - g_param_spec_boolean(NM_SETTING_PPP_REQUIRE_MPPE, - "", - "", - FALSE, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_PPP_REQUIRE_MPPE, + PROP_REQUIRE_MPPE, + FALSE, + NM_SETTING_PARAM_NONE, + nm_setting_ppp_get_require_mppe); /** * NMSettingPpp:require-mppe-128: @@ -675,12 +687,13 @@ nm_setting_ppp_class_init(NMSettingPppClass *klass) * required for the PPP session, and the "require-mppe" property must also * be set to %TRUE. If 128-bit MPPE is not available the session will fail. **/ - obj_properties[PROP_REQUIRE_MPPE_128] = - g_param_spec_boolean(NM_SETTING_PPP_REQUIRE_MPPE_128, - "", - "", - FALSE, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_PPP_REQUIRE_MPPE_128, + PROP_REQUIRE_MPPE_128, + FALSE, + NM_SETTING_PARAM_NONE, + nm_setting_ppp_get_require_mppe_128); /** * NMSettingPpp:mppe-stateful: @@ -688,12 +701,13 @@ nm_setting_ppp_class_init(NMSettingPppClass *klass) * If %TRUE, stateful MPPE is used. See pppd documentation for more * information on stateful MPPE. **/ - obj_properties[PROP_MPPE_STATEFUL] = - g_param_spec_boolean(NM_SETTING_PPP_MPPE_STATEFUL, - "", - "", - FALSE, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_PPP_MPPE_STATEFUL, + PROP_MPPE_STATEFUL, + FALSE, + NM_SETTING_PARAM_NONE, + nm_setting_ppp_get_mppe_stateful); /** * NMSettingPpp:crtscts: @@ -702,11 +716,13 @@ nm_setting_ppp_class_init(NMSettingPppClass *klass) * flow control with RTS and CTS signals. This value should normally be set * to %FALSE. **/ - obj_properties[PROP_CRTSCTS] = g_param_spec_boolean(NM_SETTING_PPP_CRTSCTS, - "", - "", - FALSE, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_PPP_CRTSCTS, + PROP_CRTSCTS, + FALSE, + NM_SETTING_PARAM_NONE, + nm_setting_ppp_get_crtscts); /** * NMSettingPpp:baud: @@ -790,5 +806,8 @@ nm_setting_ppp_class_init(NMSettingPppClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_PPP); + _nm_setting_class_commit_full(setting_class, + NM_META_SETTING_TYPE_PPP, + NULL, + properties_override); } diff --git a/src/libnm-core-impl/nm-setting-proxy.c b/src/libnm-core-impl/nm-setting-proxy.c index 50c6cc08aa..fd09e1d402 100644 --- a/src/libnm-core-impl/nm-setting-proxy.c +++ b/src/libnm-core-impl/nm-setting-proxy.c @@ -295,8 +295,9 @@ finalize(GObject *object) static void nm_setting_proxy_class_init(NMSettingProxyClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); - NMSettingClass *setting_class = NM_SETTING_CLASS(klass); + GObjectClass * object_class = G_OBJECT_CLASS(klass); + NMSettingClass *setting_class = NM_SETTING_CLASS(klass); + GArray * properties_override = _nm_sett_info_property_override_create_array(); g_type_class_add_private(klass, sizeof(NMSettingProxyPrivate)); @@ -344,12 +345,13 @@ nm_setting_proxy_class_init(NMSettingProxyClass *klass) * description: Whether the proxy configuration is for browser only. * ---end--- */ - obj_properties[PROP_BROWSER_ONLY] = - g_param_spec_boolean(NM_SETTING_PROXY_BROWSER_ONLY, - "", - "", - FALSE, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_PROXY_BROWSER_ONLY, + PROP_BROWSER_ONLY, + FALSE, + NM_SETTING_PARAM_NONE, + nm_setting_proxy_get_browser_only); /** * NMSettingProxy:pac-url: @@ -394,5 +396,8 @@ nm_setting_proxy_class_init(NMSettingProxyClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_PROXY); + _nm_setting_class_commit_full(setting_class, + NM_META_SETTING_TYPE_PROXY, + NULL, + properties_override); } diff --git a/src/libnm-core-impl/nm-setting-tun.c b/src/libnm-core-impl/nm-setting-tun.c index be953e695e..d75dcf80ab 100644 --- a/src/libnm-core-impl/nm-setting-tun.c +++ b/src/libnm-core-impl/nm-setting-tun.c @@ -300,8 +300,9 @@ finalize(GObject *object) static void nm_setting_tun_class_init(NMSettingTunClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); - NMSettingClass *setting_class = NM_SETTING_CLASS(klass); + GObjectClass * object_class = G_OBJECT_CLASS(klass); + NMSettingClass *setting_class = NM_SETTING_CLASS(klass); + GArray * properties_override = _nm_sett_info_property_override_create_array(); g_type_class_add_private(klass, sizeof(NMSettingTunPrivate)); @@ -368,12 +369,13 @@ nm_setting_tun_class_init(NMSettingTunClass *klass) * * Since: 1.2 */ - obj_properties[PROP_PI] = g_param_spec_boolean(NM_SETTING_TUN_PI, - "", - "", - FALSE, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE - | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_TUN_PI, + PROP_PI, + FALSE, + NM_SETTING_PARAM_INFERRABLE, + nm_setting_tun_get_pi); /** * NMSettingTun:vnet-hdr: @@ -383,12 +385,13 @@ nm_setting_tun_class_init(NMSettingTunClass *klass) * * Since: 1.2 */ - obj_properties[PROP_VNET_HDR] = g_param_spec_boolean( - NM_SETTING_TUN_VNET_HDR, - "", - "", - FALSE, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_TUN_VNET_HDR, + PROP_VNET_HDR, + FALSE, + NM_SETTING_PARAM_INFERRABLE, + nm_setting_tun_get_vnet_hdr); /** * NMSettingTun:multi-queue: @@ -400,14 +403,18 @@ nm_setting_tun_class_init(NMSettingTunClass *klass) * * Since: 1.2 */ - obj_properties[PROP_MULTI_QUEUE] = g_param_spec_boolean( - NM_SETTING_TUN_MULTI_QUEUE, - "", - "", - FALSE, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_TUN_MULTI_QUEUE, + PROP_MULTI_QUEUE, + FALSE, + NM_SETTING_PARAM_INFERRABLE, + nm_setting_tun_get_multi_queue); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_TUN); + _nm_setting_class_commit_full(setting_class, + NM_META_SETTING_TYPE_TUN, + NULL, + properties_override); } diff --git a/src/libnm-core-impl/nm-setting-vpn.c b/src/libnm-core-impl/nm-setting-vpn.c index 7b8fdb7644..351f3fd721 100644 --- a/src/libnm-core-impl/nm-setting-vpn.c +++ b/src/libnm-core-impl/nm-setting-vpn.c @@ -1172,12 +1172,13 @@ nm_setting_vpn_class_init(NMSettingVpnClass *klass) * the VPN will attempt to stay connected across link changes and outages, * until explicitly disconnected. **/ - obj_properties[PROP_PERSISTENT] = - g_param_spec_boolean(NM_SETTING_VPN_PERSISTENT, - "", - "", - FALSE, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_VPN_PERSISTENT, + PROP_PERSISTENT, + FALSE, + NM_SETTING_PARAM_NONE, + nm_setting_vpn_get_persistent); /** * NMSettingVpn:data: (type GHashTable(utf8,utf8)): diff --git a/src/libnm-core-impl/nm-setting-vxlan.c b/src/libnm-core-impl/nm-setting-vxlan.c index 2a89b0c32e..f2aeb66a16 100644 --- a/src/libnm-core-impl/nm-setting-vxlan.c +++ b/src/libnm-core-impl/nm-setting-vxlan.c @@ -570,8 +570,9 @@ finalize(GObject *object) static void nm_setting_vxlan_class_init(NMSettingVxlanClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); - NMSettingClass *setting_class = NM_SETTING_CLASS(klass); + GObjectClass * object_class = G_OBJECT_CLASS(klass); + NMSettingClass *setting_class = NM_SETTING_CLASS(klass); + GArray * properties_override = _nm_sett_info_property_override_create_array(); g_type_class_add_private(klass, sizeof(NMSettingVxlanPrivate)); @@ -764,12 +765,13 @@ nm_setting_vxlan_class_init(NMSettingVxlanClass *klass) * * Since: 1.2 **/ - obj_properties[PROP_PROXY] = g_param_spec_boolean( - NM_SETTING_VXLAN_PROXY, - "", - "", - FALSE, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_VXLAN_PROXY, + PROP_PROXY, + FALSE, + NM_SETTING_PARAM_INFERRABLE, + nm_setting_vxlan_get_proxy); /** * NMSettingVxlan:learning: @@ -779,12 +781,14 @@ nm_setting_vxlan_class_init(NMSettingVxlanClass *klass) * * Since: 1.2 **/ - obj_properties[PROP_LEARNING] = g_param_spec_boolean( - NM_SETTING_VXLAN_LEARNING, - "", - "", - TRUE, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_VXLAN_LEARNING, + PROP_LEARNING, + TRUE, + NM_SETTING_PARAM_INFERRABLE, + nm_setting_vxlan_get_learning); + /** * NMSettingVxlan:rsc: * @@ -792,12 +796,14 @@ nm_setting_vxlan_class_init(NMSettingVxlanClass *klass) * * Since: 1.2 **/ - obj_properties[PROP_RSC] = g_param_spec_boolean(NM_SETTING_VXLAN_RSC, - "", - "", - FALSE, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE - | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_VXLAN_RSC, + PROP_RSC, + FALSE, + NM_SETTING_PARAM_INFERRABLE, + nm_setting_vxlan_get_rsc); + /** * NMSettingVxlan:l2-miss: * @@ -805,12 +811,13 @@ nm_setting_vxlan_class_init(NMSettingVxlanClass *klass) * * Since: 1.2 **/ - obj_properties[PROP_L2_MISS] = g_param_spec_boolean( - NM_SETTING_VXLAN_L2_MISS, - "", - "", - FALSE, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_VXLAN_L2_MISS, + PROP_L2_MISS, + FALSE, + NM_SETTING_PARAM_INFERRABLE, + nm_setting_vxlan_get_l2_miss); /** * NMSettingVxlan:l3-miss: @@ -819,14 +826,18 @@ nm_setting_vxlan_class_init(NMSettingVxlanClass *klass) * * Since: 1.2 **/ - obj_properties[PROP_L3_MISS] = g_param_spec_boolean( - NM_SETTING_VXLAN_L3_MISS, - "", - "", - FALSE, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_VXLAN_L3_MISS, + PROP_L3_MISS, + FALSE, + NM_SETTING_PARAM_INFERRABLE, + nm_setting_vxlan_get_l3_miss); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_VXLAN); + _nm_setting_class_commit_full(setting_class, + NM_META_SETTING_TYPE_VXLAN, + NULL, + properties_override); } diff --git a/src/libnm-core-impl/nm-setting-wireguard.c b/src/libnm-core-impl/nm-setting-wireguard.c index b5ec0bb88a..3290ff567f 100644 --- a/src/libnm-core-impl/nm-setting-wireguard.c +++ b/src/libnm-core-impl/nm-setting-wireguard.c @@ -2514,12 +2514,13 @@ nm_setting_wireguard_class_init(NMSettingWireGuardClass *klass) * * Since: 1.16 **/ - obj_properties[PROP_PEER_ROUTES] = g_param_spec_boolean( - NM_SETTING_WIREGUARD_PEER_ROUTES, - "", - "", - TRUE, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_WIREGUARD_PEER_ROUTES, + PROP_PEER_ROUTES, + TRUE, + NM_SETTING_PARAM_INFERRABLE, + nm_setting_wireguard_get_peer_routes); /** * NMSettingWireGuard:mtu: diff --git a/src/libnm-core-impl/nm-setting-wireless.c b/src/libnm-core-impl/nm-setting-wireless.c index e73d8eeb21..111116965a 100644 --- a/src/libnm-core-impl/nm-setting-wireless.c +++ b/src/libnm-core-impl/nm-setting-wireless.c @@ -1791,11 +1791,13 @@ nm_setting_wireless_class_init(NMSettingWirelessClass *klass) * description: Whether the network hides the SSID. * ---end--- */ - obj_properties[PROP_HIDDEN] = g_param_spec_boolean(NM_SETTING_WIRELESS_HIDDEN, - "", - "", - FALSE, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_boolean(properties_override, + obj_properties, + NM_SETTING_WIRELESS_HIDDEN, + PROP_HIDDEN, + FALSE, + NM_SETTING_PARAM_NONE, + nm_setting_wireless_get_hidden); /** * NMSettingWireless:powersave: From 17fab764fc6b92c6ffaabd41bb37a77c5db4d74b Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 17 Jun 2021 22:53:52 +0200 Subject: [PATCH 21/21] libnm: use _nm_setting_property_define_string() for string NMSetting properties (cherry picked from commit a3eb2c7026ae09911ee6c226239094b6b0849031) --- src/libnm-core-impl/nm-setting-6lowpan.c | 22 ++-- src/libnm-core-impl/nm-setting-adsl.c | 56 +++++----- src/libnm-core-impl/nm-setting-connection.c | 108 ++++++++++---------- src/libnm-core-impl/nm-setting-ip-config.c | 27 ++++- src/libnm-core-impl/nm-setting-ip-tunnel.c | 60 +++++------ src/libnm-core-impl/nm-setting-ip4-config.c | 36 +++---- src/libnm-core-impl/nm-setting-ip6-config.c | 24 ++--- src/libnm-core-impl/nm-setting-wired.c | 59 ++++++----- 8 files changed, 214 insertions(+), 178 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-6lowpan.c b/src/libnm-core-impl/nm-setting-6lowpan.c index 408b39b5dd..c07fb38e69 100644 --- a/src/libnm-core-impl/nm-setting-6lowpan.c +++ b/src/libnm-core-impl/nm-setting-6lowpan.c @@ -196,8 +196,9 @@ finalize(GObject *object) static void nm_setting_6lowpan_class_init(NMSetting6LowpanClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); - NMSettingClass *setting_class = NM_SETTING_CLASS(klass); + GObjectClass * object_class = G_OBJECT_CLASS(klass); + NMSettingClass *setting_class = NM_SETTING_CLASS(klass); + GArray * properties_override = _nm_sett_info_property_override_create_array(); g_type_class_add_private(klass, sizeof(NMSetting6LowpanPrivate)); @@ -215,14 +216,17 @@ nm_setting_6lowpan_class_init(NMSetting6LowpanClass *klass) * * Since: 1.14 **/ - obj_properties[PROP_PARENT] = g_param_spec_string( - NM_SETTING_6LOWPAN_PARENT, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_string(properties_override, + obj_properties, + NM_SETTING_6LOWPAN_PARENT, + PROP_PARENT, + NM_SETTING_PARAM_INFERRABLE, + nm_setting_6lowpan_get_parent); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_6LOWPAN); + _nm_setting_class_commit_full(setting_class, + NM_META_SETTING_TYPE_6LOWPAN, + NULL, + properties_override); } diff --git a/src/libnm-core-impl/nm-setting-adsl.c b/src/libnm-core-impl/nm-setting-adsl.c index 8a82fb724c..9f45163dff 100644 --- a/src/libnm-core-impl/nm-setting-adsl.c +++ b/src/libnm-core-impl/nm-setting-adsl.c @@ -351,8 +351,9 @@ finalize(GObject *object) static void nm_setting_adsl_class_init(NMSettingAdslClass *klass) { - GObjectClass * object_class = G_OBJECT_CLASS(klass); - NMSettingClass *setting_class = NM_SETTING_CLASS(klass); + GObjectClass * object_class = G_OBJECT_CLASS(klass); + NMSettingClass *setting_class = NM_SETTING_CLASS(klass); + GArray * properties_override = _nm_sett_info_property_override_create_array(); g_type_class_add_private(klass, sizeof(NMSettingAdslPrivate)); @@ -369,23 +370,24 @@ nm_setting_adsl_class_init(NMSettingAdslClass *klass) * * Username used to authenticate with the ADSL service. **/ - obj_properties[PROP_USERNAME] = g_param_spec_string(NM_SETTING_ADSL_USERNAME, - "", - "", - NULL, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_string(properties_override, + obj_properties, + NM_SETTING_ADSL_USERNAME, + PROP_USERNAME, + NM_SETTING_PARAM_NONE, + nm_setting_adsl_get_username); /** * NMSettingAdsl:password: * * Password used to authenticate with the ADSL service. **/ - obj_properties[PROP_PASSWORD] = - g_param_spec_string(NM_SETTING_ADSL_PASSWORD, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_SECRET | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_string(properties_override, + obj_properties, + NM_SETTING_ADSL_PASSWORD, + PROP_PASSWORD, + NM_SETTING_PARAM_SECRET, + nm_setting_adsl_get_password); /** * NMSettingAdsl:password-flags: @@ -405,23 +407,24 @@ nm_setting_adsl_class_init(NMSettingAdslClass *klass) * * ADSL connection protocol. Can be "pppoa", "pppoe" or "ipoatm". **/ - obj_properties[PROP_PROTOCOL] = g_param_spec_string(NM_SETTING_ADSL_PROTOCOL, - "", - "", - NULL, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_string(properties_override, + obj_properties, + NM_SETTING_ADSL_PROTOCOL, + PROP_PROTOCOL, + NM_SETTING_PARAM_NONE, + nm_setting_adsl_get_protocol); /** * NMSettingAdsl:encapsulation: * * Encapsulation of ADSL connection. Can be "vcmux" or "llc". **/ - obj_properties[PROP_ENCAPSULATION] = - g_param_spec_string(NM_SETTING_ADSL_ENCAPSULATION, - "", - "", - NULL, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_string(properties_override, + obj_properties, + NM_SETTING_ADSL_ENCAPSULATION, + PROP_ENCAPSULATION, + NM_SETTING_PARAM_NONE, + nm_setting_adsl_get_encapsulation); /** * NMSettingAdsl:vpi: @@ -451,5 +454,8 @@ nm_setting_adsl_class_init(NMSettingAdslClass *klass) g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_ADSL); + _nm_setting_class_commit_full(setting_class, + NM_META_SETTING_TYPE_ADSL, + NULL, + properties_override); } diff --git a/src/libnm-core-impl/nm-setting-connection.c b/src/libnm-core-impl/nm-setting-connection.c index fc89467b47..3d57bc3e2e 100644 --- a/src/libnm-core-impl/nm-setting-connection.c +++ b/src/libnm-core-impl/nm-setting-connection.c @@ -1872,12 +1872,12 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass) * description: User friendly name for the connection profile. * ---end--- */ - obj_properties[PROP_ID] = g_param_spec_string(NM_SETTING_CONNECTION_ID, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE - | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_string(properties_override, + obj_properties, + NM_SETTING_CONNECTION_ID, + PROP_ID, + NM_SETTING_PARAM_FUZZY_IGNORE, + nm_setting_connection_get_id); /** * NMSettingConnection:uuid: @@ -1902,12 +1902,12 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass) * creates the UUID itself (by hashing the filename). * ---end--- */ - obj_properties[PROP_UUID] = g_param_spec_string( - NM_SETTING_CONNECTION_UUID, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_string(properties_override, + obj_properties, + NM_SETTING_CONNECTION_UUID, + PROP_UUID, + NM_SETTING_PARAM_FUZZY_IGNORE, + nm_setting_connection_get_uuid); /** * NMSettingConnection:stable-id: @@ -1986,18 +1986,17 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass) * can be required for some connection types. * ---end--- */ - obj_properties[PROP_INTERFACE_NAME] = g_param_spec_string( - NM_SETTING_CONNECTION_INTERFACE_NAME, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - _nm_properties_override_gobj( + _nm_setting_property_define_string_full( properties_override, - obj_properties[PROP_INTERFACE_NAME], - NM_SETT_INFO_PROPERT_TYPE_GPROP(G_VARIANT_TYPE_STRING, - .missing_from_dbus_fcn = - nm_setting_connection_no_interface_name, )); + obj_properties, + NM_SETTING_CONNECTION_INTERFACE_NAME, + PROP_INTERFACE_NAME, + NM_SETTING_PARAM_INFERRABLE, + NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_STRING, + .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_get_string, + .missing_from_dbus_fcn = + nm_setting_connection_no_interface_name), + nm_setting_connection_get_interface_name); /** * NMSettingConnection:type: @@ -2017,12 +2016,12 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass) * example: TYPE=Ethernet; TYPE=Bond; TYPE=Bridge; DEVICETYPE=TeamPort * ---end--- */ - obj_properties[PROP_TYPE] = g_param_spec_string(NM_SETTING_CONNECTION_TYPE, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE - | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_string(properties_override, + obj_properties, + NM_SETTING_CONNECTION_TYPE, + PROP_TYPE, + NM_SETTING_PARAM_INFERRABLE, + nm_setting_connection_get_connection_type); /** * NMSettingConnection:permissions: @@ -2220,13 +2219,13 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass) * example: ZONE=Work * ---end--- */ - obj_properties[PROP_ZONE] = - g_param_spec_string(NM_SETTING_CONNECTION_ZONE, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE - | NM_SETTING_PARAM_REAPPLY_IMMEDIATELY | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_string(properties_override, + obj_properties, + NM_SETTING_CONNECTION_ZONE, + PROP_ZONE, + NM_SETTING_PARAM_FUZZY_IGNORE + | NM_SETTING_PARAM_REAPPLY_IMMEDIATELY, + nm_setting_connection_get_zone); /** * NMSettingConnection:master: @@ -2242,13 +2241,12 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass) * for compatibility with legacy tooling. * ---end--- */ - obj_properties[PROP_MASTER] = - g_param_spec_string(NM_SETTING_CONNECTION_MASTER, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE - | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_string(properties_override, + obj_properties, + NM_SETTING_CONNECTION_MASTER, + PROP_MASTER, + NM_SETTING_PARAM_FUZZY_IGNORE | NM_SETTING_PARAM_INFERRABLE, + nm_setting_connection_get_master); /** * NMSettingConnection:slave-type: @@ -2267,13 +2265,12 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass) * and BRIDGE_UUID for bridging. * ---end--- */ - obj_properties[PROP_SLAVE_TYPE] = - g_param_spec_string(NM_SETTING_CONNECTION_SLAVE_TYPE, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE - | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_string(properties_override, + obj_properties, + NM_SETTING_CONNECTION_SLAVE_TYPE, + PROP_SLAVE_TYPE, + NM_SETTING_PARAM_FUZZY_IGNORE | NM_SETTING_PARAM_INFERRABLE, + nm_setting_connection_get_slave_type); /** * NMSettingConnection:autoconnect-slaves: @@ -2555,11 +2552,12 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass) * example: https://yourdevice.example.com/model.json * ---end--- */ - obj_properties[PROP_MUD_URL] = g_param_spec_string(NM_SETTING_CONNECTION_MUD_URL, - "", - "", - NULL, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_string(properties_override, + obj_properties, + NM_SETTING_CONNECTION_MUD_URL, + PROP_MUD_URL, + NM_SETTING_PARAM_NONE, + nm_setting_connection_get_mud_url); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/src/libnm-core-impl/nm-setting-ip-config.c b/src/libnm-core-impl/nm-setting-ip-config.c index b95eb8eeb4..ecb880e95d 100644 --- a/src/libnm-core-impl/nm-setting-ip-config.c +++ b/src/libnm-core-impl/nm-setting-ip-config.c @@ -5760,10 +5760,35 @@ _nm_sett_info_property_override_create_array_ip_config(void) { GArray *properties_override = _nm_sett_info_property_override_create_array(); + _nm_properties_override_gobj( + properties_override, + obj_properties[PROP_METHOD], + &nm_sett_info_propert_type_string, + .to_dbus_data.get_string = + (const char *(*) (NMSetting *) ) nm_setting_ip_config_get_method); + _nm_properties_override_gobj( properties_override, obj_properties[PROP_GATEWAY], - NM_SETT_INFO_PROPERT_TYPE_GPROP(G_VARIANT_TYPE_STRING, .from_dbus_fcn = ip_gateway_set, )); + NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_STRING, + .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_get_string, + .from_dbus_fcn = ip_gateway_set), + .to_dbus_data.get_string = + (const char *(*) (NMSetting *) ) nm_setting_ip_config_get_gateway); + + _nm_properties_override_gobj( + properties_override, + obj_properties[PROP_DHCP_HOSTNAME], + &nm_sett_info_propert_type_string, + .to_dbus_data.get_string = + (const char *(*) (NMSetting *) ) nm_setting_ip_config_get_dhcp_hostname); + + _nm_properties_override_gobj( + properties_override, + obj_properties[PROP_DHCP_IAID], + &nm_sett_info_propert_type_string, + .to_dbus_data.get_string = + (const char *(*) (NMSetting *) ) nm_setting_ip_config_get_dhcp_iaid); /* ---dbus--- * property: routing-rules diff --git a/src/libnm-core-impl/nm-setting-ip-tunnel.c b/src/libnm-core-impl/nm-setting-ip-tunnel.c index e6cb00fea5..d87a59f4a8 100644 --- a/src/libnm-core-impl/nm-setting-ip-tunnel.c +++ b/src/libnm-core-impl/nm-setting-ip-tunnel.c @@ -675,12 +675,12 @@ nm_setting_ip_tunnel_class_init(NMSettingIPTunnelClass *klass) * * Since: 1.2 **/ - obj_properties[PROP_PARENT] = g_param_spec_string( - NM_SETTING_IP_TUNNEL_PARENT, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_string(properties_override, + obj_properties, + NM_SETTING_IP_TUNNEL_PARENT, + PROP_PARENT, + NM_SETTING_PARAM_INFERRABLE, + nm_setting_ip_tunnel_get_parent); /** * NMSettingIPTunnel:mode: @@ -707,12 +707,12 @@ nm_setting_ip_tunnel_class_init(NMSettingIPTunnelClass *klass) * * Since: 1.2 **/ - obj_properties[PROP_LOCAL] = g_param_spec_string(NM_SETTING_IP_TUNNEL_LOCAL, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE - | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_string(properties_override, + obj_properties, + NM_SETTING_IP_TUNNEL_LOCAL, + PROP_LOCAL, + NM_SETTING_PARAM_INFERRABLE, + nm_setting_ip_tunnel_get_local); /** * NMSettingIPTunnel:remote: @@ -722,12 +722,12 @@ nm_setting_ip_tunnel_class_init(NMSettingIPTunnelClass *klass) * * Since: 1.2 **/ - obj_properties[PROP_REMOTE] = g_param_spec_string( - NM_SETTING_IP_TUNNEL_REMOTE, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_string(properties_override, + obj_properties, + NM_SETTING_IP_TUNNEL_REMOTE, + PROP_REMOTE, + NM_SETTING_PARAM_INFERRABLE, + nm_setting_ip_tunnel_get_remote); /** * NMSettingIPTunnel:ttl @@ -786,12 +786,12 @@ nm_setting_ip_tunnel_class_init(NMSettingIPTunnelClass *klass) * * Since: 1.2 **/ - obj_properties[PROP_INPUT_KEY] = g_param_spec_string( - NM_SETTING_IP_TUNNEL_INPUT_KEY, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_string(properties_override, + obj_properties, + NM_SETTING_IP_TUNNEL_INPUT_KEY, + PROP_INPUT_KEY, + NM_SETTING_PARAM_INFERRABLE, + nm_setting_ip_tunnel_get_input_key); /** * NMSettingIPTunnel:output-key: @@ -801,12 +801,12 @@ nm_setting_ip_tunnel_class_init(NMSettingIPTunnelClass *klass) * * Since: 1.2 **/ - obj_properties[PROP_OUTPUT_KEY] = g_param_spec_string( - NM_SETTING_IP_TUNNEL_OUTPUT_KEY, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_string(properties_override, + obj_properties, + NM_SETTING_IP_TUNNEL_OUTPUT_KEY, + PROP_OUTPUT_KEY, + NM_SETTING_PARAM_INFERRABLE, + nm_setting_ip_tunnel_get_output_key); /** * NMSettingIPTunnel:encapsulation-limit: diff --git a/src/libnm-core-impl/nm-setting-ip4-config.c b/src/libnm-core-impl/nm-setting-ip4-config.c index 336e59640d..15bae0cd40 100644 --- a/src/libnm-core-impl/nm-setting-ip4-config.c +++ b/src/libnm-core-impl/nm-setting-ip4-config.c @@ -847,12 +847,12 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) * example: DHCP_CLIENT_ID=ax-srv-1; DHCP_CLIENT_ID=01:44:44:44:44:44:44 * ---end--- */ - obj_properties[PROP_DHCP_CLIENT_ID] = - g_param_spec_string(NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID, - "", - "", - NULL, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_string(properties_override, + obj_properties, + NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID, + PROP_DHCP_CLIENT_ID, + NM_SETTING_PARAM_NONE, + nm_setting_ip4_config_get_dhcp_client_id); /* ---ifcfg-rh--- * property: dad-timeout @@ -898,12 +898,12 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) * example: DHCP_FQDN=foo.bar.com * ---end--- */ - obj_properties[PROP_DHCP_FQDN] = - g_param_spec_string(NM_SETTING_IP4_CONFIG_DHCP_FQDN, - "", - "", - NULL, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_string(properties_override, + obj_properties, + NM_SETTING_IP4_CONFIG_DHCP_FQDN, + PROP_DHCP_FQDN, + NM_SETTING_PARAM_NONE, + nm_setting_ip4_config_get_dhcp_fqdn); /** * NMSettingIP4Config:dhcp-vendor-class-identifier: @@ -924,12 +924,12 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) * example: DHCP_VENDOR_CLASS_IDENTIFIER=foo * ---end--- */ - obj_properties[PROP_DHCP_VENDOR_CLASS_IDENTIFIER] = - g_param_spec_string(NM_SETTING_IP4_CONFIG_DHCP_VENDOR_CLASS_IDENTIFIER, - "", - "", - NULL, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_string(properties_override, + obj_properties, + NM_SETTING_IP4_CONFIG_DHCP_VENDOR_CLASS_IDENTIFIER, + PROP_DHCP_VENDOR_CLASS_IDENTIFIER, + NM_SETTING_PARAM_NONE, + nm_setting_ip4_config_get_dhcp_vendor_class_identifier); /* IP4-specific property overrides */ diff --git a/src/libnm-core-impl/nm-setting-ip6-config.c b/src/libnm-core-impl/nm-setting-ip6-config.c index 2bea668150..f6d59a46d1 100644 --- a/src/libnm-core-impl/nm-setting-ip6-config.c +++ b/src/libnm-core-impl/nm-setting-ip6-config.c @@ -914,12 +914,12 @@ nm_setting_ip6_config_class_init(NMSettingIP6ConfigClass *klass) * example: IPV6_TOKEN=::53 * ---end--- */ - obj_properties[PROP_TOKEN] = g_param_spec_string(NM_SETTING_IP6_CONFIG_TOKEN, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE - | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_string(properties_override, + obj_properties, + NM_SETTING_IP6_CONFIG_TOKEN, + PROP_TOKEN, + NM_SETTING_PARAM_INFERRABLE, + nm_setting_ip6_config_get_token); /** * NMSettingIP6Config:ra-timeout: @@ -994,12 +994,12 @@ nm_setting_ip6_config_class_init(NMSettingIP6ConfigClass *klass) * example: DHCPV6_DUID=LL; DHCPV6_DUID=0301deadbeef0001; DHCPV6_DUID=03:01:de:ad:be:ef:00:01 * ---end--- */ - obj_properties[PROP_DHCP_DUID] = - g_param_spec_string(NM_SETTING_IP6_CONFIG_DHCP_DUID, - "", - "", - NULL, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_string(properties_override, + obj_properties, + NM_SETTING_IP6_CONFIG_DHCP_DUID, + PROP_DHCP_DUID, + NM_SETTING_PARAM_NONE, + nm_setting_ip6_config_get_dhcp_duid); /* IP6-specific property overrides */ diff --git a/src/libnm-core-impl/nm-setting-wired.c b/src/libnm-core-impl/nm-setting-wired.c index c325413b22..4acc5641e3 100644 --- a/src/libnm-core-impl/nm-setting-wired.c +++ b/src/libnm-core-impl/nm-setting-wired.c @@ -1291,11 +1291,12 @@ nm_setting_wired_class_init(NMSettingWiredClass *klass) * description: The property is not saved by the plugin. * ---end--- */ - obj_properties[PROP_PORT] = g_param_spec_string(NM_SETTING_WIRED_PORT, - "", - "", - NULL, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_string(properties_override, + obj_properties, + NM_SETTING_WIRED_PORT, + PROP_PORT, + NM_SETTING_PARAM_NONE, + nm_setting_wired_get_port); /** * NMSettingWired:speed: @@ -1352,11 +1353,12 @@ nm_setting_wired_class_init(NMSettingWiredClass *klass) * "duplex" parameter in the ETHOOL_OPTS variable. * ---end--- */ - obj_properties[PROP_DUPLEX] = g_param_spec_string(NM_SETTING_WIRED_DUPLEX, - "", - "", - NULL, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_string(properties_override, + obj_properties, + NM_SETTING_WIRED_DUPLEX, + PROP_DUPLEX, + NM_SETTING_PARAM_NONE, + nm_setting_wired_get_duplex); /** * NMSettingWired:auto-negotiate: @@ -1529,12 +1531,12 @@ nm_setting_wired_class_init(NMSettingWiredClass *klass) * cloned-mac-address. * ---end--- */ - obj_properties[PROP_GENERATE_MAC_ADDRESS_MASK] = g_param_spec_string( - NM_SETTING_WIRED_GENERATE_MAC_ADDRESS_MASK, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_string(properties_override, + obj_properties, + NM_SETTING_WIRED_GENERATE_MAC_ADDRESS_MASK, + PROP_GENERATE_MAC_ADDRESS_MASK, + NM_SETTING_PARAM_FUZZY_IGNORE, + nm_setting_wired_get_generate_mac_address_mask); /** * NMSettingWired:mac-address-blacklist: @@ -1625,12 +1627,12 @@ nm_setting_wired_class_init(NMSettingWiredClass *klass) * example: NETTYPE=qeth * ---end--- */ - obj_properties[PROP_S390_NETTYPE] = g_param_spec_string( - NM_SETTING_WIRED_S390_NETTYPE, - "", - "", - NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_string(properties_override, + obj_properties, + NM_SETTING_WIRED_S390_NETTYPE, + PROP_S390_NETTYPE, + NM_SETTING_PARAM_INFERRABLE, + nm_setting_wired_get_s390_nettype); /** * NMSettingWired:s390-options: (type GHashTable(utf8,utf8)): @@ -1706,12 +1708,13 @@ nm_setting_wired_class_init(NMSettingWiredClass *klass) * example: ETHTOOL_OPTS="wol gs sopass 00:11:22:33:44:55" * ---end--- */ - obj_properties[PROP_WAKE_ON_LAN_PASSWORD] = - g_param_spec_string(NM_SETTING_WIRED_WAKE_ON_LAN_PASSWORD, - "", - "", - NULL, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + _nm_setting_property_define_string(properties_override, + obj_properties, + NM_SETTING_WIRED_WAKE_ON_LAN_PASSWORD, + PROP_WAKE_ON_LAN_PASSWORD, + NM_SETTING_PARAM_NONE, + nm_setting_wired_get_wake_on_lan_password); + /** * NMSettingWired:accept-all-mac-addresses: *