diff options
author | Thomas Haller <thaller@redhat.com> | 2018-07-28 15:26:03 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2018-08-10 10:38:19 +0200 |
commit | 3793804314c32b7199311736a8b1638c8f28d9fc (patch) | |
tree | 9b7261dd787b611f3c181831eb106d287aafdd19 | |
parent | 2b43ce3a940664a063f49c167abb614c241940cf (diff) | |
download | NetworkManager-3793804314c32b7199311736a8b1638c8f28d9fc.tar.gz |
libnm: rework setting metadata for property handling
NMSetting internally already tracked a list of all proper GObject properties
and D-Bus-only properties.
Rework the tracking of the list, so that:
- instead of attaching the data to the GType of the setting via
g_type_set_qdata(), it is tracked in a static array indexed by
NMMetaSettingType. This allows to find the setting-data by simple
pointer arithmetic, instead of taking a look and iterating (like
g_type_set_qdata() does).
Note, that this is still thread safe, because the static table entry is
initialized in the class-init function with _nm_setting_class_commit().
And it only accessed by following a NMSettingClass instance, thus
the class constructor already ran (maybe not for all setting classes,
but for the particular one that we look up).
I think this makes initialization of the metadata simpler to
understand.
Previously, in a first phase each class would attach the metadata
to the GType as setting_property_overrides_quark(). Then during
nm_setting_class_ensure_properties() it would merge them and
set as setting_properties_quark(). Now, during the first phase,
we only incrementally build a properties_override GArray, which
we finally hand over during nm_setting_class_commit().
- sort the property infos by name and do binary search.
Also expose this meta data types as internal API in nm-setting-private.h.
While not accessed yet, it can prove beneficial, to have direct (internal)
access to these structures.
Also, rename NMSettingProperty to NMSettInfoProperty to use a distinct
naming scheme. We already have 40+ subclasses of NMSetting that are called
NMSetting*. Likewise, NMMetaSetting* is heavily used already. So, choose a
new, distinct name.
46 files changed, 810 insertions, 540 deletions
diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h index b53f5c02f8..21c45ab425 100644 --- a/libnm-core/nm-core-internal.h +++ b/libnm-core/nm-core-internal.h @@ -479,4 +479,57 @@ gboolean _nm_utils_dhcp_duid_valid (const char *duid, GBytes **out_duid_bin); gboolean _nm_setting_sriov_sort_vfs (NMSettingSriov *setting); +/*****************************************************************************/ + +typedef GVariant *(*NMSettingPropertyGetFunc) (NMSetting *setting, + const char *property); +typedef GVariant *(*NMSettingPropertySynthFunc) (NMSetting *setting, + NMConnection *connection, + const char *property); +typedef gboolean (*NMSettingPropertySetFunc) (NMSetting *setting, + GVariant *connection_dict, + const char *property, + GVariant *value, + NMSettingParseFlags parse_flags, + GError **error); +typedef gboolean (*NMSettingPropertyNotSetFunc) (NMSetting *setting, + GVariant *connection_dict, + const char *property, + NMSettingParseFlags parse_flags, + GError **error); +typedef GVariant *(*NMSettingPropertyTransformToFunc) (const GValue *from); +typedef void (*NMSettingPropertyTransformFromFunc) (GVariant *from, + GValue *to); + +typedef struct { + const char *name; + GParamSpec *param_spec; + const GVariantType *dbus_type; + + NMSettingPropertyGetFunc get_func; + NMSettingPropertySynthFunc synth_func; + NMSettingPropertySetFunc set_func; + NMSettingPropertyNotSetFunc not_set_func; + + NMSettingPropertyTransformToFunc to_dbus; + NMSettingPropertyTransformFromFunc from_dbus; +} NMSettInfoProperty; + +typedef struct { +} NMSettInfoSettDetail; + +typedef struct { + NMSettingClass *setting_class; + const NMSettInfoProperty *property_infos; + guint property_infos_len; + NMSettInfoSettDetail detail; +} NMSettInfoSetting; + +const NMSettInfoSetting *_nm_sett_info_setting_get (NMSettingClass *setting_class); + +const NMSettInfoProperty *_nm_sett_info_property_get (NMSettingClass *setting_class, + const char *property_name); + +/*****************************************************************************/ + #endif diff --git a/libnm-core/nm-setting-6lowpan.c b/libnm-core/nm-setting-6lowpan.c index 6d2b510799..c0ce232dab 100644 --- a/libnm-core/nm-setting-6lowpan.c +++ b/libnm-core/nm-setting-6lowpan.c @@ -206,8 +206,7 @@ nm_setting_6lowpan_class_init (NMSetting6LowpanClass *klass) object_class->get_property = get_property; object_class->finalize = finalize; - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_6LOWPAN]; - setting_class->verify = verify; + setting_class->verify = verify; /** * NMSetting6Lowpan:parent: @@ -226,4 +225,6 @@ nm_setting_6lowpan_class_init (NMSetting6LowpanClass *klass) G_PARAM_STATIC_STRINGS); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); + + _nm_setting_class_commit (setting_class, NM_META_SETTING_TYPE_6LOWPAN); } diff --git a/libnm-core/nm-setting-8021x.c b/libnm-core/nm-setting-8021x.c index 8c08bfa53b..0d61f91c5d 100644 --- a/libnm-core/nm-setting-8021x.c +++ b/libnm-core/nm-setting-8021x.c @@ -3771,7 +3771,6 @@ nm_setting_802_1x_class_init (NMSetting8021xClass *klass) object_class->get_property = get_property; object_class->finalize = finalize; - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_802_1X]; setting_class->verify = verify; setting_class->need_secrets = need_secrets; @@ -4803,4 +4802,6 @@ nm_setting_802_1x_class_init (NMSetting8021xClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_STATIC_STRINGS)); + + _nm_setting_class_commit (setting_class, NM_META_SETTING_TYPE_802_1X); } diff --git a/libnm-core/nm-setting-adsl.c b/libnm-core/nm-setting-adsl.c index eb9aad41ab..9ffff92783 100644 --- a/libnm-core/nm-setting-adsl.c +++ b/libnm-core/nm-setting-adsl.c @@ -355,7 +355,6 @@ nm_setting_adsl_class_init (NMSettingAdslClass *klass) object_class->get_property = get_property; object_class->finalize = finalize; - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_ADSL]; setting_class->verify = verify; setting_class->verify_secrets = verify_secrets; setting_class->need_secrets = need_secrets; @@ -445,4 +444,6 @@ nm_setting_adsl_class_init (NMSettingAdslClass *klass) 0, 65536, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + _nm_setting_class_commit (setting_class, NM_META_SETTING_TYPE_ADSL); } diff --git a/libnm-core/nm-setting-bluetooth.c b/libnm-core/nm-setting-bluetooth.c index 2cc3d7ad41..bbc6a83de3 100644 --- a/libnm-core/nm-setting-bluetooth.c +++ b/libnm-core/nm-setting-bluetooth.c @@ -285,6 +285,7 @@ nm_setting_bluetooth_class_init (NMSettingBluetoothClass *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 (NMSettingBluetoothPrivate)); @@ -292,7 +293,6 @@ nm_setting_bluetooth_class_init (NMSettingBluetoothClass *klass) object_class->get_property = get_property; object_class->finalize = finalize; - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_BLUETOOTH]; setting_class->verify = verify; /** @@ -307,10 +307,13 @@ nm_setting_bluetooth_class_init (NMSettingBluetoothClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS)); - _nm_setting_class_transform_property (setting_class, NM_SETTING_BLUETOOTH_BDADDR, - G_VARIANT_TYPE_BYTESTRING, - _nm_utils_hwaddr_to_dbus, - _nm_utils_hwaddr_from_dbus); + + _properties_override_add_transform (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_BLUETOOTH_BDADDR), + G_VARIANT_TYPE_BYTESTRING, + _nm_utils_hwaddr_to_dbus, + _nm_utils_hwaddr_from_dbus); /** * NMSettingBluetooth:type: @@ -325,4 +328,7 @@ nm_setting_bluetooth_class_init (NMSettingBluetoothClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS)); + + _nm_setting_class_commit_full (setting_class, NM_META_SETTING_TYPE_BLUETOOTH, + NULL, properties_override); } diff --git a/libnm-core/nm-setting-bond.c b/libnm-core/nm-setting-bond.c index 53db178218..0c84b3a01c 100644 --- a/libnm-core/nm-setting-bond.c +++ b/libnm-core/nm-setting-bond.c @@ -962,6 +962,7 @@ nm_setting_bond_class_init (NMSettingBondClass *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 (NMSettingBondPrivate)); @@ -969,7 +970,6 @@ nm_setting_bond_class_init (NMSettingBondClass *klass) object_class->get_property = get_property; object_class->finalize = finalize; - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_BOND]; setting_class->verify = verify; setting_class->compare_property = compare_property; @@ -994,10 +994,13 @@ nm_setting_bond_class_init (NMSettingBondClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS)); - _nm_setting_class_transform_property (setting_class, NM_SETTING_BOND_OPTIONS, - G_VARIANT_TYPE ("a{ss}"), - _nm_utils_strdict_to_dbus, - _nm_utils_strdict_from_dbus); + + _properties_override_add_transform (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_BOND_OPTIONS), + G_VARIANT_TYPE ("a{ss}"), + _nm_utils_strdict_to_dbus, + _nm_utils_strdict_from_dbus); /* ---dbus--- * property: interface-name @@ -1007,8 +1010,12 @@ nm_setting_bond_class_init (NMSettingBondClass *klass) * bond's interface name. * ---end--- */ - _nm_setting_class_add_dbus_only_property (setting_class, "interface-name", - G_VARIANT_TYPE_STRING, - _nm_setting_get_deprecated_virtual_interface_name, - NULL); + _properties_override_add_dbus_only (properties_override, + "interface-name", + G_VARIANT_TYPE_STRING, + _nm_setting_get_deprecated_virtual_interface_name, + NULL); + + _nm_setting_class_commit_full (setting_class, NM_META_SETTING_TYPE_BOND, + NULL, properties_override); } diff --git a/libnm-core/nm-setting-bridge-port.c b/libnm-core/nm-setting-bridge-port.c index 23a431f4fe..4104f8c5cc 100644 --- a/libnm-core/nm-setting-bridge-port.c +++ b/libnm-core/nm-setting-bridge-port.c @@ -220,8 +220,7 @@ nm_setting_bridge_port_class_init (NMSettingBridgePortClass *klass) object_class->set_property = set_property; object_class->get_property = get_property; - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_BRIDGE_PORT]; - setting_class->verify = verify; + setting_class->verify = verify; /** * NMSettingBridgePort:priority: @@ -288,4 +287,6 @@ nm_setting_bridge_port_class_init (NMSettingBridgePortClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS)); + + _nm_setting_class_commit (setting_class, NM_META_SETTING_TYPE_BRIDGE_PORT); } diff --git a/libnm-core/nm-setting-bridge.c b/libnm-core/nm-setting-bridge.c index 951f35888b..71fe2ed234 100644 --- a/libnm-core/nm-setting-bridge.c +++ b/libnm-core/nm-setting-bridge.c @@ -395,6 +395,7 @@ nm_setting_bridge_class_init (NMSettingBridgeClass *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 (NMSettingBridgePrivate)); @@ -402,8 +403,7 @@ nm_setting_bridge_class_init (NMSettingBridgeClass *klass) object_class->get_property = get_property; object_class->finalize = finalize; - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_BRIDGE]; - setting_class->verify = verify; + setting_class->verify = verify; /** * NMSettingBridge:mac-address: @@ -442,10 +442,13 @@ nm_setting_bridge_class_init (NMSettingBridgeClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS)); - _nm_setting_class_transform_property (setting_class, NM_SETTING_BRIDGE_MAC_ADDRESS, - G_VARIANT_TYPE_BYTESTRING, - _nm_utils_hwaddr_to_dbus, - _nm_utils_hwaddr_from_dbus); + + _properties_override_add_transform (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_BRIDGE_MAC_ADDRESS), + G_VARIANT_TYPE_BYTESTRING, + _nm_utils_hwaddr_to_dbus, + _nm_utils_hwaddr_from_dbus); /** * NMSettingBridge:stp: @@ -636,8 +639,12 @@ nm_setting_bridge_class_init (NMSettingBridgeClass *klass) * bridge's interface name. * ---end--- */ - _nm_setting_class_add_dbus_only_property (setting_class, "interface-name", - G_VARIANT_TYPE_STRING, - _nm_setting_get_deprecated_virtual_interface_name, - NULL); + _properties_override_add_dbus_only (properties_override, + "interface-name", + G_VARIANT_TYPE_STRING, + _nm_setting_get_deprecated_virtual_interface_name, + NULL); + + _nm_setting_class_commit_full (setting_class, NM_META_SETTING_TYPE_BRIDGE, + NULL, properties_override); } diff --git a/libnm-core/nm-setting-cdma.c b/libnm-core/nm-setting-cdma.c index bb49ec9d3f..a5d5428d4b 100644 --- a/libnm-core/nm-setting-cdma.c +++ b/libnm-core/nm-setting-cdma.c @@ -294,7 +294,6 @@ nm_setting_cdma_class_init (NMSettingCdmaClass *klass) object_class->get_property = get_property; object_class->finalize = finalize; - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_CDMA]; setting_class->verify = verify; setting_class->verify_secrets = verify_secrets; setting_class->need_secrets = need_secrets; @@ -372,4 +371,5 @@ nm_setting_cdma_class_init (NMSettingCdmaClass *klass) NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_STATIC_STRINGS)); + _nm_setting_class_commit (setting_class, NM_META_SETTING_TYPE_CDMA); } diff --git a/libnm-core/nm-setting-connection.c b/libnm-core/nm-setting-connection.c index 6a6c76036f..a7d1777f01 100644 --- a/libnm-core/nm-setting-connection.c +++ b/libnm-core/nm-setting-connection.c @@ -1505,6 +1505,7 @@ nm_setting_connection_class_init (NMSettingConnectionClass *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 (NMSettingConnectionPrivate)); @@ -1512,7 +1513,6 @@ nm_setting_connection_class_init (NMSettingConnectionClass *klass) object_class->get_property = get_property; object_class->finalize = finalize; - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_CONNECTION]; setting_class->verify = verify; setting_class->compare_property = compare_property; @@ -1651,11 +1651,14 @@ nm_setting_connection_class_init (NMSettingConnectionClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS)); - _nm_setting_class_override_property (setting_class, NM_SETTING_CONNECTION_INTERFACE_NAME, - G_VARIANT_TYPE_STRING, - NULL, - nm_setting_connection_set_interface_name, - nm_setting_connection_no_interface_name); + + _properties_override_add_override (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_CONNECTION_INTERFACE_NAME), + G_VARIANT_TYPE_STRING, + NULL, + nm_setting_connection_set_interface_name, + nm_setting_connection_no_interface_name); /** * NMSettingConnection:type: @@ -2125,4 +2128,7 @@ nm_setting_connection_class_init (NMSettingConnectionClass *klass) NM_SETTING_CONNECTION_MDNS_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + _nm_setting_class_commit_full (setting_class, NM_META_SETTING_TYPE_CONNECTION, + NULL, properties_override); } diff --git a/libnm-core/nm-setting-dcb.c b/libnm-core/nm-setting-dcb.c index f306b77b16..dabcbbaf19 100644 --- a/libnm-core/nm-setting-dcb.c +++ b/libnm-core/nm-setting-dcb.c @@ -909,6 +909,7 @@ nm_setting_dcb_class_init (NMSettingDcbClass *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 (NMSettingDcbPrivate)); @@ -916,8 +917,7 @@ nm_setting_dcb_class_init (NMSettingDcbClass *klass) object_class->get_property = get_property; object_class->finalize = finalize; - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_DCB]; - setting_class->verify = verify; + setting_class->verify = verify; /** * NMSettingDcb:app-fcoe-flags: @@ -1117,10 +1117,13 @@ nm_setting_dcb_class_init (NMSettingDcbClass *klass) G_TYPE_ARRAY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - _nm_setting_class_transform_property (setting_class, NM_SETTING_DCB_PRIORITY_FLOW_CONTROL, - G_VARIANT_TYPE ("au"), - _nm_setting_dcb_uint_array_to_dbus, - _nm_setting_dcb_uint_array_from_dbus); + + _properties_override_add_transform (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_DCB_PRIORITY_FLOW_CONTROL), + G_VARIANT_TYPE ("au"), + _nm_setting_dcb_uint_array_to_dbus, + _nm_setting_dcb_uint_array_from_dbus); /** * NMSettingDcb:priority-group-flags: @@ -1165,10 +1168,13 @@ nm_setting_dcb_class_init (NMSettingDcbClass *klass) G_TYPE_ARRAY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - _nm_setting_class_transform_property (setting_class, NM_SETTING_DCB_PRIORITY_GROUP_ID, - G_VARIANT_TYPE ("au"), - _nm_setting_dcb_uint_array_to_dbus, - _nm_setting_dcb_uint_array_from_dbus); + + _properties_override_add_transform (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_DCB_PRIORITY_GROUP_ID), + G_VARIANT_TYPE ("au"), + _nm_setting_dcb_uint_array_to_dbus, + _nm_setting_dcb_uint_array_from_dbus); /** * NMSettingDcb:priority-group-bandwidth: (type GArray(guint)) @@ -1191,10 +1197,13 @@ nm_setting_dcb_class_init (NMSettingDcbClass *klass) G_TYPE_ARRAY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - _nm_setting_class_transform_property (setting_class, NM_SETTING_DCB_PRIORITY_GROUP_BANDWIDTH, - G_VARIANT_TYPE ("au"), - _nm_setting_dcb_uint_array_to_dbus, - _nm_setting_dcb_uint_array_from_dbus); + + _properties_override_add_transform (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_DCB_PRIORITY_GROUP_BANDWIDTH), + G_VARIANT_TYPE ("au"), + _nm_setting_dcb_uint_array_to_dbus, + _nm_setting_dcb_uint_array_from_dbus); /** * NMSettingDcb:priority-bandwidth: (type GArray(guint)) @@ -1219,10 +1228,13 @@ nm_setting_dcb_class_init (NMSettingDcbClass *klass) G_TYPE_ARRAY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - _nm_setting_class_transform_property (setting_class, NM_SETTING_DCB_PRIORITY_BANDWIDTH, - G_VARIANT_TYPE ("au"), - _nm_setting_dcb_uint_array_to_dbus, - _nm_setting_dcb_uint_array_from_dbus); + + _properties_override_add_transform (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_DCB_PRIORITY_BANDWIDTH), + G_VARIANT_TYPE ("au"), + _nm_setting_dcb_uint_array_to_dbus, + _nm_setting_dcb_uint_array_from_dbus); /** * NMSettingDcb:priority-strict-bandwidth: (type GArray(gboolean)) @@ -1245,10 +1257,13 @@ nm_setting_dcb_class_init (NMSettingDcbClass *klass) G_TYPE_ARRAY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - _nm_setting_class_transform_property (setting_class, NM_SETTING_DCB_PRIORITY_STRICT_BANDWIDTH, - G_VARIANT_TYPE ("au"), - _nm_setting_dcb_uint_array_to_dbus, - _nm_setting_dcb_uint_array_from_dbus); + + _properties_override_add_transform (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_DCB_PRIORITY_STRICT_BANDWIDTH), + G_VARIANT_TYPE ("au"), + _nm_setting_dcb_uint_array_to_dbus, + _nm_setting_dcb_uint_array_from_dbus); /** * NMSettingDcb:priority-traffic-class: (type GArray(guint)) @@ -1270,8 +1285,14 @@ nm_setting_dcb_class_init (NMSettingDcbClass *klass) G_TYPE_ARRAY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - _nm_setting_class_transform_property (setting_class, NM_SETTING_DCB_PRIORITY_TRAFFIC_CLASS, - G_VARIANT_TYPE ("au"), - _nm_setting_dcb_uint_array_to_dbus, - _nm_setting_dcb_uint_array_from_dbus); + + _properties_override_add_transform (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_DCB_PRIORITY_TRAFFIC_CLASS), + G_VARIANT_TYPE ("au"), + _nm_setting_dcb_uint_array_to_dbus, + _nm_setting_dcb_uint_array_from_dbus); + + _nm_setting_class_commit_full (setting_class, NM_META_SETTING_TYPE_DCB, + NULL, properties_override); } diff --git a/libnm-core/nm-setting-dummy.c b/libnm-core/nm-setting-dummy.c index 78e67d1dd7..9ae05ec4e7 100644 --- a/libnm-core/nm-setting-dummy.c +++ b/libnm-core/nm-setting-dummy.c @@ -70,6 +70,7 @@ nm_setting_dummy_class_init (NMSettingDummyClass *klass) { NMSettingClass *setting_class = NM_SETTING_CLASS (klass); - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_DUMMY]; - setting_class->verify = verify; + setting_class->verify = verify; + + _nm_setting_class_commit (setting_class, NM_META_SETTING_TYPE_DUMMY); } diff --git a/libnm-core/nm-setting-generic.c b/libnm-core/nm-setting-generic.c index 762062417e..44402e397d 100644 --- a/libnm-core/nm-setting-generic.c +++ b/libnm-core/nm-setting-generic.c @@ -71,5 +71,5 @@ nm_setting_generic_class_init (NMSettingGenericClass *klass) g_type_class_add_private (klass, sizeof (NMSettingGenericPrivate)); - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_GENERIC]; + _nm_setting_class_commit (setting_class, NM_META_SETTING_TYPE_GENERIC); } diff --git a/libnm-core/nm-setting-gsm.c b/libnm-core/nm-setting-gsm.c index 3b4f604628..b31da68912 100644 --- a/libnm-core/nm-setting-gsm.c +++ b/libnm-core/nm-setting-gsm.c @@ -606,6 +606,7 @@ nm_setting_gsm_class_init (NMSettingGsmClass *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 (NMSettingGsmPrivate)); @@ -613,7 +614,6 @@ nm_setting_gsm_class_init (NMSettingGsmClass *klass) object_class->get_property = get_property; object_class->finalize = finalize; - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_GSM]; setting_class->verify = verify; setting_class->verify_secrets = verify_secrets; setting_class->need_secrets = need_secrets; @@ -819,10 +819,18 @@ nm_setting_gsm_class_init (NMSettingGsmClass *klass) G_PARAM_STATIC_STRINGS)); /* Ignore incoming deprecated properties */ - _nm_setting_class_add_dbus_only_property (setting_class, "allowed-bands", - G_VARIANT_TYPE_UINT32, - NULL, NULL); - _nm_setting_class_add_dbus_only_property (setting_class, "network-type", - G_VARIANT_TYPE_INT32, - NULL, NULL); + _properties_override_add_dbus_only (properties_override, + "allowed-bands", + G_VARIANT_TYPE_UINT32, + NULL, + NULL); + + _properties_override_add_dbus_only (properties_override, + "network-type", + G_VARIANT_TYPE_INT32, + NULL, + NULL); + + _nm_setting_class_commit_full (setting_class, NM_META_SETTING_TYPE_GSM, + NULL, properties_override); } diff --git a/libnm-core/nm-setting-infiniband.c b/libnm-core/nm-setting-infiniband.c index 96997e9ebd..d5ae708530 100644 --- a/libnm-core/nm-setting-infiniband.c +++ b/libnm-core/nm-setting-infiniband.c @@ -380,6 +380,7 @@ nm_setting_infiniband_class_init (NMSettingInfinibandClass *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 (NMSettingInfinibandPrivate)); @@ -387,8 +388,7 @@ nm_setting_infiniband_class_init (NMSettingInfinibandClass *klass) object_class->get_property = get_property; object_class->finalize = finalize; - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_INFINIBAND]; - setting_class->verify = verify; + setting_class->verify = verify; /** * NMSettingInfiniband:mac-address: @@ -422,10 +422,13 @@ nm_setting_infiniband_class_init (NMSettingInfinibandClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS)); - _nm_setting_class_transform_property (setting_class, NM_SETTING_INFINIBAND_MAC_ADDRESS, - G_VARIANT_TYPE_BYTESTRING, - _nm_utils_hwaddr_to_dbus, - _nm_utils_hwaddr_from_dbus); + + _properties_override_add_transform (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_INFINIBAND_MAC_ADDRESS), + G_VARIANT_TYPE_BYTESTRING, + _nm_utils_hwaddr_to_dbus, + _nm_utils_hwaddr_from_dbus); /** * NMSettingInfiniband:mtu: @@ -523,4 +526,6 @@ nm_setting_infiniband_class_init (NMSettingInfinibandClass *klass) NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS)); + _nm_setting_class_commit_full (setting_class, NM_META_SETTING_TYPE_INFINIBAND, + NULL, properties_override); } diff --git a/libnm-core/nm-setting-ip-config.c b/libnm-core/nm-setting-ip-config.c index c3ad316632..5af9b64041 100644 --- a/libnm-core/nm-setting-ip-config.c +++ b/libnm-core/nm-setting-ip-config.c @@ -2878,6 +2878,23 @@ ip_gateway_set (NMSetting *setting, return TRUE; } +GArray * +_nm_sett_info_property_override_create_array_ip_config (void) +{ + nm_auto_unref_gtypeclass NMSettingClass *setting_class = g_type_class_ref (NM_TYPE_SETTING_IP_CONFIG); + GArray *properties_override = _nm_sett_info_property_override_create_array (); + + _properties_override_add_override (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_IP_CONFIG_GATEWAY), + G_VARIANT_TYPE_STRING, + NULL, + ip_gateway_set, + NULL); + + return properties_override; +} + static void nm_setting_ip_config_class_init (NMSettingIPConfigClass *klass) { @@ -3041,13 +3058,6 @@ nm_setting_ip_config_class_init (NMSettingIPConfigClass *klass) NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS)); - _nm_setting_class_override_property (setting_class, - NM_SETTING_IP_CONFIG_GATEWAY, - G_VARIANT_TYPE_STRING, - NULL, - ip_gateway_set, - NULL); - /** * NMSettingIPConfig:routes: (type GPtrArray(NMIPRoute)) * diff --git a/libnm-core/nm-setting-ip-tunnel.c b/libnm-core/nm-setting-ip-tunnel.c index b255edf339..41314f5894 100644 --- a/libnm-core/nm-setting-ip-tunnel.c +++ b/libnm-core/nm-setting-ip-tunnel.c @@ -632,8 +632,7 @@ nm_setting_ip_tunnel_class_init (NMSettingIPTunnelClass *klass) object_class->get_property = get_property; object_class->finalize = finalize; - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_IP_TUNNEL]; - setting_class->verify = verify; + setting_class->verify = verify; /** * NMSettingIPTunnel:parent: @@ -851,4 +850,6 @@ nm_setting_ip_tunnel_class_init (NMSettingIPTunnelClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_STATIC_STRINGS)); + + _nm_setting_class_commit (setting_class, NM_META_SETTING_TYPE_IP_TUNNEL); } diff --git a/libnm-core/nm-setting-ip4-config.c b/libnm-core/nm-setting-ip4-config.c index 95ff57ca1b..44de154ec0 100644 --- a/libnm-core/nm-setting-ip4-config.c +++ b/libnm-core/nm-setting-ip4-config.c @@ -527,6 +527,7 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *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_ip_config (); g_type_class_add_private (setting_class, sizeof (NMSettingIP4ConfigPrivate)); @@ -534,8 +535,7 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *klass) object_class->get_property = get_property; object_class->finalize = finalize; - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_IP4_CONFIG]; - setting_class->verify = verify; + setting_class->verify = verify; /* ---ifcfg-rh--- * property: method @@ -795,11 +795,12 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *klass) * integers) * ---end--- */ - _nm_setting_class_transform_property (setting_class, - NM_SETTING_IP_CONFIG_DNS, - G_VARIANT_TYPE ("au"), - ip4_dns_to_dbus, - ip4_dns_from_dbus); + _properties_override_add_transform (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_IP_CONFIG_DNS), + G_VARIANT_TYPE ("au"), + ip4_dns_to_dbus, + ip4_dns_from_dbus); /* ---dbus--- * property: addresses @@ -816,18 +817,19 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *klass) * for that subnet. * ---end--- */ - _nm_setting_class_override_property (setting_class, - NM_SETTING_IP_CONFIG_ADDRESSES, - G_VARIANT_TYPE ("aau"), - ip4_addresses_get, - ip4_addresses_set, - NULL); - - _nm_setting_class_add_dbus_only_property (setting_class, - "address-labels", - G_VARIANT_TYPE_STRING_ARRAY, - ip4_address_labels_get, - NULL); + _properties_override_add_override (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_IP_CONFIG_ADDRESSES), + G_VARIANT_TYPE ("aau"), + ip4_addresses_get, + ip4_addresses_set, + NULL); + + _properties_override_add_dbus_only (properties_override, + "address-labels", + G_VARIANT_TYPE_STRING_ARRAY, + ip4_address_labels_get, + NULL); /* ---dbus--- * property: address-data @@ -838,11 +840,11 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *klass) * also exist on some addresses. * ---end--- */ - _nm_setting_class_add_dbus_only_property (setting_class, - "address-data", - G_VARIANT_TYPE ("aa{sv}"), - ip4_address_data_get, - ip4_address_data_set); + _properties_override_add_dbus_only (properties_override, + "address-data", + G_VARIANT_TYPE ("aa{sv}"), + ip4_address_data_get, + ip4_address_data_set); /* ---dbus--- * property: routes @@ -861,12 +863,13 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *klass) * property.) * ---end--- */ - _nm_setting_class_override_property (setting_class, - NM_SETTING_IP_CONFIG_ROUTES, - G_VARIANT_TYPE ("aau"), - ip4_routes_get, - ip4_routes_set, - NULL); + _properties_override_add_override (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_IP_CONFIG_ROUTES), + G_VARIANT_TYPE ("aau"), + ip4_routes_get, + ip4_routes_set, + NULL); /* ---dbus--- * property: route-data @@ -881,10 +884,12 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *klass) * also exist on some routes. * ---end--- */ - _nm_setting_class_add_dbus_only_property (setting_class, - "route-data", - G_VARIANT_TYPE ("aa{sv}"), - ip4_route_data_get, - ip4_route_data_set); - + _properties_override_add_dbus_only (properties_override, + "route-data", + G_VARIANT_TYPE ("aa{sv}"), + ip4_route_data_get, + ip4_route_data_set); + + _nm_setting_class_commit_full (setting_class, NM_META_SETTING_TYPE_IP4_CONFIG, + NULL, properties_override); } diff --git a/libnm-core/nm-setting-ip6-config.c b/libnm-core/nm-setting-ip6-config.c index 3f7dd00ce0..a55fd80195 100644 --- a/libnm-core/nm-setting-ip6-config.c +++ b/libnm-core/nm-setting-ip6-config.c @@ -551,6 +551,7 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *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_ip_config (); g_type_class_add_private (klass, sizeof (NMSettingIP6ConfigPrivate)); @@ -558,8 +559,7 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *klass) object_class->get_property = get_property; object_class->finalize = finalize; - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_IP6_CONFIG]; - setting_class->verify = verify; + setting_class->verify = verify; /* ---ifcfg-rh--- * property: method @@ -888,11 +888,12 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *klass) * description: Array of IP addresses of DNS servers (in network byte order) * ---end--- */ - _nm_setting_class_transform_property (setting_class, - NM_SETTING_IP_CONFIG_DNS, - G_VARIANT_TYPE ("aay"), - ip6_dns_to_dbus, - ip6_dns_from_dbus); + _properties_override_add_transform (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_IP_CONFIG_DNS), + G_VARIANT_TYPE ("aay"), + ip6_dns_to_dbus, + ip6_dns_from_dbus); /* ---dbus--- * property: addresses @@ -908,12 +909,13 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *klass) * that subnet. * ---end--- */ - _nm_setting_class_override_property (setting_class, - NM_SETTING_IP_CONFIG_ADDRESSES, - G_VARIANT_TYPE ("a(ayuay)"), - ip6_addresses_get, - ip6_addresses_set, - NULL); + _properties_override_add_override (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_IP_CONFIG_ADDRESSES), + G_VARIANT_TYPE ("a(ayuay)"), + ip6_addresses_get, + ip6_addresses_set, + NULL); /* ---dbus--- * property: address-data @@ -924,11 +926,11 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *klass) * also exist on some addresses. * ---end--- */ - _nm_setting_class_add_dbus_only_property (setting_class, - "address-data", - G_VARIANT_TYPE ("aa{sv}"), - ip6_address_data_get, - ip6_address_data_set); + _properties_override_add_dbus_only (properties_override, + "address-data", + G_VARIANT_TYPE ("aa{sv}"), + ip6_address_data_get, + ip6_address_data_set); /* ---dbus--- * property: routes @@ -944,12 +946,13 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *klass) * default metric for the device. * ---end--- */ - _nm_setting_class_override_property (setting_class, - NM_SETTING_IP_CONFIG_ROUTES, - G_VARIANT_TYPE ("a(ayuayu)"), - ip6_routes_get, - ip6_routes_set, - NULL); + _properties_override_add_override (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_IP_CONFIG_ROUTES), + G_VARIANT_TYPE ("a(ayuayu)"), + ip6_routes_get, + ip6_routes_set, + NULL); /* ---dbus--- * property: route-data @@ -964,9 +967,12 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *klass) * also exist on some routes. * ---end--- */ - _nm_setting_class_add_dbus_only_property (setting_class, - "route-data", - G_VARIANT_TYPE ("aa{sv}"), - ip6_route_data_get, - ip6_route_data_set); + _properties_override_add_dbus_only (properties_override, + "route-data", + G_VARIANT_TYPE ("aa{sv}"), + ip6_route_data_get, + ip6_route_data_set); + + _nm_setting_class_commit_full (setting_class, NM_META_SETTING_TYPE_IP6_CONFIG, + NULL, properties_override); } diff --git a/libnm-core/nm-setting-macsec.c b/libnm-core/nm-setting-macsec.c index 9705a31040..2c7cff23b1 100644 --- a/libnm-core/nm-setting-macsec.c +++ b/libnm-core/nm-setting-macsec.c @@ -483,7 +483,6 @@ nm_setting_macsec_class_init (NMSettingMacsecClass *klass) object_class->get_property = get_property; object_class->finalize = finalize; - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_MACSEC]; setting_class->verify = verify; setting_class->need_secrets = need_secrets; @@ -627,4 +626,6 @@ nm_setting_macsec_class_init (NMSettingMacsecClass *klass) G_PARAM_STATIC_STRINGS); g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); + + _nm_setting_class_commit (setting_class, NM_META_SETTING_TYPE_MACSEC); } diff --git a/libnm-core/nm-setting-macvlan.c b/libnm-core/nm-setting-macvlan.c index 133131fa5d..1fc16116e0 100644 --- a/libnm-core/nm-setting-macvlan.c +++ b/libnm-core/nm-setting-macvlan.c @@ -269,8 +269,7 @@ nm_setting_macvlan_class_init (NMSettingMacvlanClass *klass) object_class->get_property = get_property; object_class->finalize = finalize; - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_MACVLAN]; - setting_class->verify = verify; + setting_class->verify = verify; /** * NMSettingMacvlan:parent: @@ -339,4 +338,6 @@ nm_setting_macvlan_class_init (NMSettingMacvlanClass *klass) G_PARAM_CONSTRUCT | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS)); + + _nm_setting_class_commit (setting_class, NM_META_SETTING_TYPE_MACVLAN); } diff --git a/libnm-core/nm-setting-olpc-mesh.c b/libnm-core/nm-setting-olpc-mesh.c index 9e215dc60d..7f4a1bbf11 100644 --- a/libnm-core/nm-setting-olpc-mesh.c +++ b/libnm-core/nm-setting-olpc-mesh.c @@ -216,6 +216,7 @@ nm_setting_olpc_mesh_class_init (NMSettingOlpcMeshClass *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 (NMSettingOlpcMeshPrivate)); @@ -223,8 +224,7 @@ nm_setting_olpc_mesh_class_init (NMSettingOlpcMeshClass *klass) object_class->get_property = get_property; object_class->finalize = finalize; - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_OLPC_MESH]; - setting_class->verify = verify; + setting_class->verify = verify; /** * NMSettingOlpcMesh:ssid: @@ -266,8 +266,14 @@ nm_setting_olpc_mesh_class_init (NMSettingOlpcMeshClass *klass) NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - _nm_setting_class_transform_property (setting_class, NM_SETTING_OLPC_MESH_DHCP_ANYCAST_ADDRESS, - G_VARIANT_TYPE_BYTESTRING, - _nm_utils_hwaddr_to_dbus, - _nm_utils_hwaddr_from_dbus); + + _properties_override_add_transform (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_OLPC_MESH_DHCP_ANYCAST_ADDRESS), + G_VARIANT_TYPE_BYTESTRING, + _nm_utils_hwaddr_to_dbus, + _nm_utils_hwaddr_from_dbus); + + _nm_setting_class_commit_full (setting_class, NM_META_SETTING_TYPE_OLPC_MESH, + NULL, properties_override); } diff --git a/libnm-core/nm-setting-ovs-bridge.c b/libnm-core/nm-setting-ovs-bridge.c index 669bae9631..9ca5566fb9 100644 --- a/libnm-core/nm-setting-ovs-bridge.c +++ b/libnm-core/nm-setting-ovs-bridge.c @@ -271,8 +271,7 @@ nm_setting_ovs_bridge_class_init (NMSettingOvsBridgeClass *klass) object_class->get_property = get_property; object_class->finalize = finalize; - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_OVS_BRIDGE]; - setting_class->verify = verify; + setting_class->verify = verify; /** * NMSettingOvsBridge:fail-mode: @@ -334,4 +333,6 @@ nm_setting_ovs_bridge_class_init (NMSettingOvsBridgeClass *klass) G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS)); + + _nm_setting_class_commit (setting_class, NM_META_SETTING_TYPE_OVS_BRIDGE); } diff --git a/libnm-core/nm-setting-ovs-interface.c b/libnm-core/nm-setting-ovs-interface.c index 23325eb957..a177098dbf 100644 --- a/libnm-core/nm-setting-ovs-interface.c +++ b/libnm-core/nm-setting-ovs-interface.c @@ -370,8 +370,7 @@ nm_setting_ovs_interface_class_init (NMSettingOvsInterfaceClass *klass) object_class->get_property = get_property; object_class->finalize = finalize; - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_OVS_INTERFACE]; - setting_class->verify = verify; + setting_class->verify = verify; /** * NMSettingOvsInterface:type: @@ -388,4 +387,6 @@ nm_setting_ovs_interface_class_init (NMSettingOvsInterfaceClass *klass) G_PARAM_CONSTRUCT | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS)); + + _nm_setting_class_commit (setting_class, NM_META_SETTING_TYPE_OVS_INTERFACE); } diff --git a/libnm-core/nm-setting-ovs-patch.c b/libnm-core/nm-setting-ovs-patch.c index 0acdcb9d03..15005eeaef 100644 --- a/libnm-core/nm-setting-ovs-patch.c +++ b/libnm-core/nm-setting-ovs-patch.c @@ -189,8 +189,7 @@ nm_setting_ovs_patch_class_init (NMSettingOvsPatchClass *klass) object_class->get_property = get_property; object_class->finalize = finalize; - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_OVS_PATCH]; - setting_class->verify = verify; + setting_class->verify = verify; /** * NMSettingOvsPatch:peer: @@ -208,4 +207,6 @@ nm_setting_ovs_patch_class_init (NMSettingOvsPatchClass *klass) G_PARAM_CONSTRUCT | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS)); + + _nm_setting_class_commit (setting_class, NM_META_SETTING_TYPE_OVS_PATCH); } diff --git a/libnm-core/nm-setting-ovs-port.c b/libnm-core/nm-setting-ovs-port.c index 8fc19fc3c1..10e542e7d2 100644 --- a/libnm-core/nm-setting-ovs-port.c +++ b/libnm-core/nm-setting-ovs-port.c @@ -368,8 +368,7 @@ nm_setting_ovs_port_class_init (NMSettingOvsPortClass *klass) object_class->get_property = get_property; object_class->finalize = finalize; - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_OVS_PORT]; - setting_class->verify = verify; + setting_class->verify = verify; /** * NMSettingOvsPort:vlan-mode: @@ -467,4 +466,6 @@ nm_setting_ovs_port_class_init (NMSettingOvsPortClass *klass) G_PARAM_CONSTRUCT | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS)); + + _nm_setting_class_commit (setting_class, NM_META_SETTING_TYPE_OVS_PORT); } diff --git a/libnm-core/nm-setting-ppp.c b/libnm-core/nm-setting-ppp.c index 905ec146a7..7425da193b 100644 --- a/libnm-core/nm-setting-ppp.c +++ b/libnm-core/nm-setting-ppp.c @@ -533,8 +533,7 @@ nm_setting_ppp_class_init (NMSettingPppClass *klass) object_class->set_property = set_property; object_class->get_property = get_property; - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_PPP]; - setting_class->verify = verify; + setting_class->verify = verify; /** * NMSettingPpp:noauth: @@ -796,4 +795,6 @@ nm_setting_ppp_class_init (NMSettingPppClass *klass) G_PARAM_CONSTRUCT | NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_STATIC_STRINGS)); + + _nm_setting_class_commit (setting_class, NM_META_SETTING_TYPE_PPP); } diff --git a/libnm-core/nm-setting-pppoe.c b/libnm-core/nm-setting-pppoe.c index 679a30cebb..793d93cea2 100644 --- a/libnm-core/nm-setting-pppoe.c +++ b/libnm-core/nm-setting-pppoe.c @@ -297,7 +297,6 @@ nm_setting_pppoe_class_init (NMSettingPppoeClass *klass) object_class->get_property = get_property; object_class->finalize = finalize; - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_PPPOE]; setting_class->verify = verify; setting_class->need_secrets = need_secrets; @@ -372,4 +371,6 @@ nm_setting_pppoe_class_init (NMSettingPppoeClass *klass) NM_SETTING_SECRET_FLAG_NONE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + _nm_setting_class_commit (setting_class, NM_META_SETTING_TYPE_PPPOE); } diff --git a/libnm-core/nm-setting-private.h b/libnm-core/nm-setting-private.h index 4a92264b7c..99c7b69ccd 100644 --- a/libnm-core/nm-setting-private.h +++ b/libnm-core/nm-setting-private.h @@ -105,44 +105,69 @@ NMSetting *_nm_setting_new_from_dbus (GType setting_type, NMSettingParseFlags parse_flags, GError **error); -typedef GVariant * (*NMSettingPropertyGetFunc) (NMSetting *setting, - const char *property); -typedef GVariant * (*NMSettingPropertySynthFunc) (NMSetting *setting, - NMConnection *connection, - const char *property); -typedef gboolean (*NMSettingPropertySetFunc) (NMSetting *setting, - GVariant *connection_dict, - const char *property, - GVariant *value, - NMSettingParseFlags parse_flags, - GError **error); -typedef gboolean (*NMSettingPropertyNotSetFunc) (NMSetting *setting, - GVariant *connection_dict, - const char *property, - NMSettingParseFlags parse_flags, - GError **error); - -void _nm_setting_class_add_dbus_only_property (NMSettingClass *setting_class, - const char *property_name, - const GVariantType *dbus_type, - NMSettingPropertySynthFunc synth_func, - NMSettingPropertySetFunc set_func); - -void _nm_setting_class_override_property (NMSettingClass *setting_class, - const char *property_name, - const GVariantType *dbus_type, - NMSettingPropertyGetFunc get_func, - NMSettingPropertySetFunc set_func, - NMSettingPropertyNotSetFunc not_set_func); - -typedef GVariant * (*NMSettingPropertyTransformToFunc) (const GValue *from); -typedef void (*NMSettingPropertyTransformFromFunc) (GVariant *from, GValue *to); - -void _nm_setting_class_transform_property (NMSettingClass *setting_class, - const char *property_name, - const GVariantType *dbus_type, - NMSettingPropertyTransformToFunc to_dbus, - NMSettingPropertyTransformFromFunc from_dbus); +/*****************************************************************************/ + +static inline GArray * +_nm_sett_info_property_override_create_array (void) +{ + return g_array_new (FALSE, FALSE, sizeof (NMSettInfoProperty)); +} + +GArray *_nm_sett_info_property_override_create_array_ip_config (void); + +void _nm_setting_class_commit_full (NMSettingClass *setting_class, + NMMetaSettingType meta_type, + const NMSettInfoSettDetail *detail, + GArray *properties_override); + +static inline void +_nm_setting_class_commit (NMSettingClass *setting_class, + NMMetaSettingType meta_type) +{ + _nm_setting_class_commit_full (setting_class, meta_type, NULL, NULL); +} + +#define NM_SETT_INFO_SETT_DETAIL(...) \ + (&((const NMSettInfoSettDetail) { \ + __VA_ARGS__ \ + })) + +#define NM_SETT_INFO_PROPERTY(...) \ + (&((const NMSettInfoProperty) { \ + __VA_ARGS__ \ + })) + +void _properties_override_add_struct (GArray *properties_override, + const NMSettInfoProperty *prop_info); + +void _properties_override_add__helper (GArray *properties_override, + NMSettInfoProperty *prop_info); + +#define _properties_override_add(properties_override, \ + ...) \ + (_properties_override_add_struct (properties_override, \ + NM_SETT_INFO_PROPERTY (__VA_ARGS__))) + +void _properties_override_add_dbus_only (GArray *properties_override, + const char *property_name, + const GVariantType *dbus_type, + NMSettingPropertySynthFunc synth_func, + NMSettingPropertySetFunc set_func); + +void _properties_override_add_override (GArray *properties_override, + GParamSpec *param_spec, + const GVariantType *dbus_type, + NMSettingPropertyGetFunc get_func, + NMSettingPropertySetFunc set_func, + NMSettingPropertyNotSetFunc not_set_func); + +void _properties_override_add_transform (GArray *properties_override, + GParamSpec *param_spec, + const GVariantType *dbus_type, + NMSettingPropertyTransformToFunc to_dbus, + NMSettingPropertyTransformFromFunc from_dbus); + +/*****************************************************************************/ gboolean _nm_setting_use_legacy_property (NMSetting *setting, GVariant *connection_dict, @@ -151,4 +176,6 @@ gboolean _nm_setting_use_legacy_property (NMSetting *setting, GPtrArray *_nm_setting_need_secrets (NMSetting *setting); +/*****************************************************************************/ + #endif /* NM_SETTING_PRIVATE_H */ diff --git a/libnm-core/nm-setting-proxy.c b/libnm-core/nm-setting-proxy.c index 8faf9ba4e7..d544c7fa14 100644 --- a/libnm-core/nm-setting-proxy.c +++ b/libnm-core/nm-setting-proxy.c @@ -294,8 +294,7 @@ nm_setting_proxy_class_init (NMSettingProxyClass *klass) object_class->get_property = get_property; object_class->finalize = finalize; - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_PROXY]; - setting_class->verify = verify; + setting_class->verify = verify; /** * NMSettingProxy:method: @@ -383,4 +382,6 @@ nm_setting_proxy_class_init (NMSettingProxyClass *klass) NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + _nm_setting_class_commit (setting_class, NM_META_SETTING_TYPE_PROXY); } diff --git a/libnm-core/nm-setting-serial.c b/libnm-core/nm-setting-serial.c index 26baf95011..b173197db8 100644 --- a/libnm-core/nm-setting-serial.c +++ b/libnm-core/nm-setting-serial.c @@ -240,14 +240,13 @@ nm_setting_serial_class_init (NMSettingSerialClass *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 (NMSettingSerialPrivate)); object_class->set_property = set_property; object_class->get_property = get_property; - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_SERIAL]; - /** * NMSettingSerial:baud: * @@ -304,11 +303,13 @@ nm_setting_serial_class_init (NMSettingSerialClass *klass) G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS)); - _nm_setting_class_transform_property (setting_class, - NM_SETTING_SERIAL_PARITY, - G_VARIANT_TYPE_BYTE, - parity_to_dbus, - parity_from_dbus); + + _properties_override_add_transform (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_SERIAL_PARITY), + G_VARIANT_TYPE_BYTE, + parity_to_dbus, + parity_from_dbus); /** * NMSettingSerial:stopbits: @@ -336,4 +337,7 @@ nm_setting_serial_class_init (NMSettingSerialClass *klass) G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS)); + + _nm_setting_class_commit_full (setting_class, NM_META_SETTING_TYPE_SERIAL, + NULL, properties_override); } diff --git a/libnm-core/nm-setting-sriov.c b/libnm-core/nm-setting-sriov.c index 90108ca721..45b3a1d2f5 100644 --- a/libnm-core/nm-setting-sriov.c +++ b/libnm-core/nm-setting-sriov.c @@ -1234,12 +1234,12 @@ nm_setting_sriov_class_init (NMSettingSriovClass *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; object_class->finalize = finalize; - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_SRIOV]; setting_class->compare_property = compare_property; setting_class->verify = verify; @@ -1308,12 +1308,13 @@ nm_setting_sriov_class_init (NMSettingSriovClass *klass) NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS)); - _nm_setting_class_override_property (setting_class, - NM_SETTING_SRIOV_VFS, - G_VARIANT_TYPE ("aa{sv}"), - vfs_to_dbus, - vfs_from_dbus, - NULL); + _properties_override_add_override (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_SRIOV_VFS), + G_VARIANT_TYPE ("aa{sv}"), + vfs_to_dbus, + vfs_from_dbus, + NULL); /** * NMSettingSriov:autoprobe-drivers @@ -1350,4 +1351,7 @@ nm_setting_sriov_class_init (NMSettingSriovClass *klass) G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS)); + + _nm_setting_class_commit_full (setting_class, NM_META_SETTING_TYPE_SRIOV, + NULL, properties_override); } diff --git a/libnm-core/nm-setting-tc-config.c b/libnm-core/nm-setting-tc-config.c index 01e2e34fb9..43015d3708 100644 --- a/libnm-core/nm-setting-tc-config.c +++ b/libnm-core/nm-setting-tc-config.c @@ -1591,12 +1591,12 @@ nm_setting_tc_config_class_init (NMSettingTCConfigClass *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->set_property = set_property; object_class->get_property = get_property; object_class->finalize = finalize; - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_TC_CONFIG]; setting_class->compare_property = compare_property; setting_class->verify = verify; @@ -1620,12 +1620,13 @@ nm_setting_tc_config_class_init (NMSettingTCConfigClass *klass) NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS)); - _nm_setting_class_override_property (setting_class, - NM_SETTING_TC_CONFIG_QDISCS, - G_VARIANT_TYPE ("aa{sv}"), - tc_qdiscs_get, - tc_qdiscs_set, - NULL); + _properties_override_add_override (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_TC_CONFIG_QDISCS), + G_VARIANT_TYPE ("aa{sv}"), + tc_qdiscs_get, + tc_qdiscs_set, + NULL); /** * NMSettingTCConfig:tfilters: (type GPtrArray(NMTCTfilter)) @@ -1647,10 +1648,14 @@ nm_setting_tc_config_class_init (NMSettingTCConfigClass *klass) NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS)); - _nm_setting_class_override_property (setting_class, - NM_SETTING_TC_CONFIG_TFILTERS, - G_VARIANT_TYPE ("aa{sv}"), - tc_tfilters_get, - tc_tfilters_set, - NULL); + _properties_override_add_override (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_TC_CONFIG_TFILTERS), + G_VARIANT_TYPE ("aa{sv}"), + tc_tfilters_get, + tc_tfilters_set, + NULL); + + _nm_setting_class_commit_full (setting_class, NM_META_SETTING_TYPE_TC_CONFIG, + NULL, properties_override); } diff --git a/libnm-core/nm-setting-team-port.c b/libnm-core/nm-setting-team-port.c index 4eb33050ee..ee84aaf72e 100644 --- a/libnm-core/nm-setting-team-port.c +++ b/libnm-core/nm-setting-team-port.c @@ -589,6 +589,7 @@ nm_setting_team_port_class_init (NMSettingTeamPortClass *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 (NMSettingTeamPortPrivate)); @@ -596,7 +597,6 @@ nm_setting_team_port_class_init (NMSettingTeamPortClass *klass) object_class->get_property = get_property; object_class->finalize = finalize; - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_TEAM_PORT]; setting_class->compare_property = compare_property; setting_class->verify = verify; @@ -713,10 +713,14 @@ nm_setting_team_port_class_init (NMSettingTeamPortClass *klass) G_TYPE_PTR_ARRAY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - _nm_setting_class_transform_property (setting_class, - NM_SETTING_TEAM_PORT_LINK_WATCHERS, - G_VARIANT_TYPE ("aa{sv}"), - team_link_watchers_to_dbus, - team_link_watchers_from_dbus); + _properties_override_add_transform (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_TEAM_PORT_LINK_WATCHERS), + G_VARIANT_TYPE ("aa{sv}"), + team_link_watchers_to_dbus, + team_link_watchers_from_dbus); + + _nm_setting_class_commit_full (setting_class, NM_META_SETTING_TYPE_TEAM_PORT, + NULL, properties_override); } diff --git a/libnm-core/nm-setting-team.c b/libnm-core/nm-setting-team.c index f0120ff114..e6737e48ce 100644 --- a/libnm-core/nm-setting-team.c +++ b/libnm-core/nm-setting-team.c @@ -1560,6 +1560,7 @@ nm_setting_team_class_init (NMSettingTeamClass *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 (NMSettingTeamPrivate)); @@ -1567,7 +1568,6 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) object_class->get_property = get_property; object_class->finalize = finalize; - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_TEAM]; setting_class->compare_property = compare_property; setting_class->verify = verify; @@ -1816,11 +1816,13 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) G_TYPE_PTR_ARRAY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - _nm_setting_class_transform_property (setting_class, - NM_SETTING_TEAM_LINK_WATCHERS, - G_VARIANT_TYPE ("aa{sv}"), - team_link_watchers_to_dbus, - team_link_watchers_from_dbus); + + _properties_override_add_transform (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_TEAM_LINK_WATCHERS), + G_VARIANT_TYPE ("aa{sv}"), + team_link_watchers_to_dbus, + team_link_watchers_from_dbus); /* ---dbus--- * property: interface-name @@ -1830,8 +1832,12 @@ nm_setting_team_class_init (NMSettingTeamClass *klass) * team's interface name. * ---end--- */ - _nm_setting_class_add_dbus_only_property (setting_class, "interface-name", - G_VARIANT_TYPE_STRING, - _nm_setting_get_deprecated_virtual_interface_name, - NULL); + _properties_override_add_dbus_only (properties_override, + "interface-name", + G_VARIANT_TYPE_STRING, + _nm_setting_get_deprecated_virtual_interface_name, + NULL); + + _nm_setting_class_commit_full (setting_class, NM_META_SETTING_TYPE_TEAM, + NULL, properties_override); } diff --git a/libnm-core/nm-setting-tun.c b/libnm-core/nm-setting-tun.c index 0fbb6375e0..3e033e2586 100644 --- a/libnm-core/nm-setting-tun.c +++ b/libnm-core/nm-setting-tun.c @@ -301,8 +301,7 @@ nm_setting_tun_class_init (NMSettingTunClass *klass) object_class->get_property = get_property; object_class->finalize = finalize; - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_TUN]; - setting_class->verify = verify; + setting_class->verify = verify; /** * NMSettingTun:mode: @@ -404,4 +403,6 @@ nm_setting_tun_class_init (NMSettingTunClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS)); + + _nm_setting_class_commit (setting_class, NM_META_SETTING_TYPE_TUN); } diff --git a/libnm-core/nm-setting-user.c b/libnm-core/nm-setting-user.c index c5d763e77e..d72c909462 100644 --- a/libnm-core/nm-setting-user.c +++ b/libnm-core/nm-setting-user.c @@ -547,12 +547,12 @@ nm_setting_user_class_init (NMSettingUserClass *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->set_property = set_property; object_class->get_property = get_property; object_class->finalize = finalize; - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_USER]; setting_class->compare_property = compare_property; setting_class->verify = verify; @@ -585,8 +585,13 @@ nm_setting_user_class_init (NMSettingUserClass *klass) g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); - _nm_setting_class_transform_property (setting_class, NM_SETTING_USER_DATA, - G_VARIANT_TYPE ("a{ss}"), - _nm_utils_strdict_to_dbus, - _nm_utils_strdict_from_dbus); + _properties_override_add_transform (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_USER_DATA), + G_VARIANT_TYPE ("a{ss}"), + _nm_utils_strdict_to_dbus, + _nm_utils_strdict_from_dbus); + + _nm_setting_class_commit_full (setting_class, NM_META_SETTING_TYPE_USER, + NULL, properties_override); } diff --git a/libnm-core/nm-setting-vlan.c b/libnm-core/nm-setting-vlan.c index 54a3145ee9..1b61da5578 100644 --- a/libnm-core/nm-setting-vlan.c +++ b/libnm-core/nm-setting-vlan.c @@ -833,6 +833,7 @@ nm_setting_vlan_class_init (NMSettingVlanClass *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 (NMSettingVlanPrivate)); @@ -840,8 +841,7 @@ nm_setting_vlan_class_init (NMSettingVlanClass *klass) object_class->get_property = get_property; object_class->finalize = finalize; - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_VLAN]; - setting_class->verify = verify; + setting_class->verify = verify; /** * NMSettingVlan:parent: @@ -918,11 +918,14 @@ nm_setting_vlan_class_init (NMSettingVlanClass *klass) G_PARAM_CONSTRUCT | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS)); - _nm_setting_class_override_property (setting_class, NM_SETTING_VLAN_FLAGS, - NULL, - _override_flags_get, - NULL, - _override_flags_not_set); + + _properties_override_add_override (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_VLAN_FLAGS), + NULL, + _override_flags_get, + NULL, + _override_flags_not_set); /** * NMSettingVlan:ingress-priority-map: @@ -984,8 +987,12 @@ nm_setting_vlan_class_init (NMSettingVlanClass *klass) * vlan's interface name. * ---end--- */ - _nm_setting_class_add_dbus_only_property (setting_class, "interface-name", - G_VARIANT_TYPE_STRING, - _nm_setting_get_deprecated_virtual_interface_name, - NULL); + _properties_override_add_dbus_only (properties_override, + "interface-name", + G_VARIANT_TYPE_STRING, + _nm_setting_get_deprecated_virtual_interface_name, + NULL); + + _nm_setting_class_commit_full (setting_class, NM_META_SETTING_TYPE_VLAN, + NULL, properties_override); } diff --git a/libnm-core/nm-setting-vpn.c b/libnm-core/nm-setting-vpn.c index 39126421ee..3b61736128 100644 --- a/libnm-core/nm-setting-vpn.c +++ b/libnm-core/nm-setting-vpn.c @@ -891,6 +891,7 @@ nm_setting_vpn_class_init (NMSettingVpnClass *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 (NMSettingVpnPrivate)); @@ -898,7 +899,6 @@ nm_setting_vpn_class_init (NMSettingVpnClass *klass) object_class->get_property = get_property; object_class->finalize = finalize; - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_VPN]; setting_class->verify = verify; setting_class->update_one_secret = update_one_secret; setting_class->get_secret_flags = get_secret_flags; @@ -972,10 +972,13 @@ nm_setting_vpn_class_init (NMSettingVpnClass *klass) G_TYPE_HASH_TABLE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - _nm_setting_class_transform_property (setting_class, NM_SETTING_VPN_DATA, - G_VARIANT_TYPE ("a{ss}"), - _nm_utils_strdict_to_dbus, - _nm_utils_strdict_from_dbus); + + _properties_override_add_transform (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_VPN_DATA), + G_VARIANT_TYPE ("a{ss}"), + _nm_utils_strdict_to_dbus, + _nm_utils_strdict_from_dbus); /** * NMSettingVpn:secrets: (type GHashTable(utf8,utf8)): @@ -998,10 +1001,13 @@ nm_setting_vpn_class_init (NMSettingVpnClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_SECRET | G_PARAM_STATIC_STRINGS)); - _nm_setting_class_transform_property (setting_class, NM_SETTING_VPN_SECRETS, - G_VARIANT_TYPE ("a{ss}"), - _nm_utils_strdict_to_dbus, - _nm_utils_strdict_from_dbus); + + _properties_override_add_transform (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_VPN_SECRETS), + G_VARIANT_TYPE ("a{ss}"), + _nm_utils_strdict_to_dbus, + _nm_utils_strdict_from_dbus); /** * NMSettingVpn:timeout: @@ -1020,4 +1026,7 @@ nm_setting_vpn_class_init (NMSettingVpnClass *klass) 0, G_MAXUINT32, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + _nm_setting_class_commit_full (setting_class, NM_META_SETTING_TYPE_VPN, + NULL, properties_override); } diff --git a/libnm-core/nm-setting-vxlan.c b/libnm-core/nm-setting-vxlan.c index 2f906f8ac5..d00c5a7abd 100644 --- a/libnm-core/nm-setting-vxlan.c +++ b/libnm-core/nm-setting-vxlan.c @@ -574,8 +574,7 @@ nm_setting_vxlan_class_init (NMSettingVxlanClass *klass) object_class->get_property = get_property; object_class->finalize = finalize; - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_VXLAN]; - setting_class->verify = verify; + setting_class->verify = verify; /** * NMSettingVxlan:parent: @@ -837,4 +836,6 @@ nm_setting_vxlan_class_init (NMSettingVxlanClass *klass) G_PARAM_CONSTRUCT | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS)); + + _nm_setting_class_commit (setting_class, NM_META_SETTING_TYPE_VXLAN); } diff --git a/libnm-core/nm-setting-wimax.c b/libnm-core/nm-setting-wimax.c index 12ab0da374..4c1a572ee0 100644 --- a/libnm-core/nm-setting-wimax.c +++ b/libnm-core/nm-setting-wimax.c @@ -209,6 +209,7 @@ nm_setting_wimax_class_init (NMSettingWimaxClass *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 (NMSettingWimaxPrivate)); @@ -216,8 +217,7 @@ nm_setting_wimax_class_init (NMSettingWimaxClass *klass) object_class->get_property = get_property; object_class->finalize = finalize; - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_WIMAX]; - setting_class->verify = verify; + setting_class->verify = verify; /** * NMSettingWimax:network-name: @@ -249,8 +249,14 @@ nm_setting_wimax_class_init (NMSettingWimaxClass *klass) NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - _nm_setting_class_transform_property (setting_class, NM_SETTING_WIMAX_MAC_ADDRESS, - G_VARIANT_TYPE_BYTESTRING, - _nm_utils_hwaddr_to_dbus, - _nm_utils_hwaddr_from_dbus); + + _properties_override_add_transform (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_WIMAX_MAC_ADDRESS), + G_VARIANT_TYPE_BYTESTRING, + _nm_utils_hwaddr_to_dbus, + _nm_utils_hwaddr_from_dbus); + + _nm_setting_class_commit_full (setting_class, NM_META_SETTING_TYPE_WIMAX, + NULL, properties_override); } diff --git a/libnm-core/nm-setting-wired.c b/libnm-core/nm-setting-wired.c index 212ddb6218..baa40cc4f4 100644 --- a/libnm-core/nm-setting-wired.c +++ b/libnm-core/nm-setting-wired.c @@ -980,6 +980,7 @@ nm_setting_wired_class_init (NMSettingWiredClass *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 (NMSettingWiredPrivate)); @@ -987,7 +988,6 @@ nm_setting_wired_class_init (NMSettingWiredClass *klass) object_class->get_property = get_property; object_class->finalize = finalize; - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_WIRED]; setting_class->verify = verify; setting_class->compare_property = compare_property; @@ -1101,12 +1101,14 @@ nm_setting_wired_class_init (NMSettingWiredClass *klass) G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS)); - _nm_setting_class_override_property (setting_class, - NM_SETTING_WIRED_AUTO_NEGOTIATE, - G_VARIANT_TYPE_BOOLEAN, - _override_autoneg_get, - NULL, - NULL); + + _properties_override_add_override (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_WIRED_AUTO_NEGOTIATE), + G_VARIANT_TYPE_BOOLEAN, + _override_autoneg_get, + NULL, + NULL); /** * NMSettingWired:mac-address: @@ -1139,10 +1141,13 @@ nm_setting_wired_class_init (NMSettingWiredClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS)); - _nm_setting_class_transform_property (setting_class, NM_SETTING_WIRED_MAC_ADDRESS, - G_VARIANT_TYPE_BYTESTRING, - _nm_utils_hwaddr_to_dbus, - _nm_utils_hwaddr_from_dbus); + + _properties_override_add_transform (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_WIRED_MAC_ADDRESS), + G_VARIANT_TYPE_BYTESTRING, + _nm_utils_hwaddr_to_dbus, + _nm_utils_hwaddr_from_dbus); /** * NMSettingWired:cloned-mac-address: @@ -1194,8 +1199,10 @@ nm_setting_wired_class_init (NMSettingWiredClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS)); - _nm_setting_class_override_property (setting_class, - NM_SETTING_WIRED_CLONED_MAC_ADDRESS, + + _properties_override_add_override (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_WIRED_CLONED_MAC_ADDRESS), G_VARIANT_TYPE_BYTESTRING, _nm_utils_hwaddr_cloned_get, _nm_utils_hwaddr_cloned_set, @@ -1213,11 +1220,11 @@ nm_setting_wired_class_init (NMSettingWiredClass *klass) * "cloned-mac-address". * ---end--- */ - _nm_setting_class_add_dbus_only_property (setting_class, - "assigned-mac-address", - G_VARIANT_TYPE_STRING, - _nm_utils_hwaddr_cloned_data_synth, - _nm_utils_hwaddr_cloned_data_set); + _properties_override_add_dbus_only (properties_override, + "assigned-mac-address", + G_VARIANT_TYPE_STRING, + _nm_utils_hwaddr_cloned_data_synth, + _nm_utils_hwaddr_cloned_data_set); /** * NMSettingWired:generate-mac-address-mask: @@ -1387,10 +1394,13 @@ nm_setting_wired_class_init (NMSettingWiredClass *klass) G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS)); - _nm_setting_class_transform_property (setting_class, NM_SETTING_WIRED_S390_OPTIONS, - G_VARIANT_TYPE ("a{ss}"), - _nm_utils_strdict_to_dbus, - _nm_utils_strdict_from_dbus); + + _properties_override_add_transform (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_WIRED_S390_OPTIONS), + G_VARIANT_TYPE ("a{ss}"), + _nm_utils_strdict_to_dbus, + _nm_utils_strdict_from_dbus); /** * NMSettingWired:wake-on-lan: @@ -1429,4 +1439,7 @@ nm_setting_wired_class_init (NMSettingWiredClass *klass) NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + _nm_setting_class_commit_full (setting_class, NM_META_SETTING_TYPE_WIRED, + NULL, properties_override); } diff --git a/libnm-core/nm-setting-wireless-security.c b/libnm-core/nm-setting-wireless-security.c index e4d3454107..d152782168 100644 --- a/libnm-core/nm-setting-wireless-security.c +++ b/libnm-core/nm-setting-wireless-security.c @@ -1433,6 +1433,7 @@ nm_setting_wireless_security_class_init (NMSettingWirelessSecurityClass *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 (NMSettingWirelessSecurityPrivate)); @@ -1440,7 +1441,6 @@ nm_setting_wireless_security_class_init (NMSettingWirelessSecurityClass *klass) object_class->get_property = get_property; object_class->finalize = finalize; - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_WIRELESS_SECURITY]; setting_class->verify = verify; setting_class->verify_secrets = verify_secrets; setting_class->need_secrets = need_secrets; @@ -1853,11 +1853,13 @@ nm_setting_wireless_security_class_init (NMSettingWirelessSecurityClass *klass) G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS)); - _nm_setting_class_transform_property (setting_class, - NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, - G_VARIANT_TYPE_UINT32, - wep_key_type_to_dbus, - NULL); + + _properties_override_add_transform (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE), + G_VARIANT_TYPE_UINT32, + wep_key_type_to_dbus, + NULL); /** * NMSettingWirelessSecurity:wps-method: * @@ -1919,4 +1921,7 @@ nm_setting_wireless_security_class_init (NMSettingWirelessSecurityClass *klass) G_PARAM_CONSTRUCT | NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_STATIC_STRINGS)); + + _nm_setting_class_commit_full (setting_class, NM_META_SETTING_TYPE_WIRELESS_SECURITY, + NULL, properties_override); } diff --git a/libnm-core/nm-setting-wireless.c b/libnm-core/nm-setting-wireless.c index 47e78d18e7..a9cae6c0db 100644 --- a/libnm-core/nm-setting-wireless.c +++ b/libnm-core/nm-setting-wireless.c @@ -1178,6 +1178,7 @@ nm_setting_wireless_class_init (NMSettingWirelessClass *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 (NMSettingWirelessPrivate)); @@ -1185,7 +1186,6 @@ nm_setting_wireless_class_init (NMSettingWirelessClass *klass) object_class->get_property = get_property; object_class->finalize = finalize; - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_WIRELESS]; setting_class->verify = verify; setting_class->compare_property = compare_property; @@ -1306,10 +1306,13 @@ nm_setting_wireless_class_init (NMSettingWirelessClass *klass) NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - _nm_setting_class_transform_property (setting_class, NM_SETTING_WIRELESS_BSSID, - G_VARIANT_TYPE_BYTESTRING, - _nm_utils_hwaddr_to_dbus, - _nm_utils_hwaddr_from_dbus); + + _properties_override_add_transform (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_WIRELESS_BSSID), + G_VARIANT_TYPE_BYTESTRING, + _nm_utils_hwaddr_to_dbus, + _nm_utils_hwaddr_from_dbus); /** * NMSettingWireless:rate: @@ -1386,10 +1389,13 @@ nm_setting_wireless_class_init (NMSettingWirelessClass *klass) NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - _nm_setting_class_transform_property (setting_class, NM_SETTING_WIRELESS_MAC_ADDRESS, - G_VARIANT_TYPE_BYTESTRING, - _nm_utils_hwaddr_to_dbus, - _nm_utils_hwaddr_from_dbus); + + _properties_override_add_transform (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_WIRELESS_MAC_ADDRESS), + G_VARIANT_TYPE_BYTESTRING, + _nm_utils_hwaddr_to_dbus, + _nm_utils_hwaddr_from_dbus); /** * NMSettingWireless:cloned-mac-address: @@ -1439,12 +1445,14 @@ nm_setting_wireless_class_init (NMSettingWirelessClass *klass) NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - _nm_setting_class_override_property (setting_class, - NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS, - G_VARIANT_TYPE_BYTESTRING, - _nm_utils_hwaddr_cloned_get, - _nm_utils_hwaddr_cloned_set, - _nm_utils_hwaddr_cloned_not_set); + + _properties_override_add_override (properties_override, + g_object_class_find_property (G_OBJECT_CLASS (setting_class), + NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS), + G_VARIANT_TYPE_BYTESTRING, + _nm_utils_hwaddr_cloned_get, + _nm_utils_hwaddr_cloned_set, + _nm_utils_hwaddr_cloned_not_set); /* ---dbus--- * property: assigned-mac-address @@ -1458,11 +1466,11 @@ nm_setting_wireless_class_init (NMSettingWirelessClass *klass) * "cloned-mac-address". * ---end--- */ - _nm_setting_class_add_dbus_only_property (setting_class, - "assigned-mac-address", - G_VARIANT_TYPE_STRING, - _nm_utils_hwaddr_cloned_data_synth, - _nm_utils_hwaddr_cloned_data_set); + _properties_override_add_dbus_only (properties_override, + "assigned-mac-address", + G_VARIANT_TYPE_STRING, + _nm_utils_hwaddr_cloned_data_synth, + _nm_utils_hwaddr_cloned_data_set); /** * NMSettingWireless:generate-mac-address-mask: @@ -1677,9 +1685,11 @@ nm_setting_wireless_class_init (NMSettingWirelessClass *klass) * NetworkManager daemons. * ---end--- */ - _nm_setting_class_add_dbus_only_property (setting_class, "security", - G_VARIANT_TYPE_STRING, - nm_setting_wireless_get_security, NULL); + _properties_override_add_dbus_only (properties_override, + "security", + G_VARIANT_TYPE_STRING, + nm_setting_wireless_get_security, + NULL); /** * NMSettingWireless:wake-on-wlan: @@ -1706,4 +1716,7 @@ nm_setting_wireless_class_init (NMSettingWirelessClass *klass) G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + _nm_setting_class_commit_full (setting_class, NM_META_SETTING_TYPE_WIRELESS, + NULL, properties_override); } diff --git a/libnm-core/nm-setting-wpan.c b/libnm-core/nm-setting-wpan.c index 462f054344..6e1aaadc45 100644 --- a/libnm-core/nm-setting-wpan.c +++ b/libnm-core/nm-setting-wpan.c @@ -224,8 +224,7 @@ nm_setting_wpan_class_init (NMSettingWpanClass *klass) object_class->get_property = get_property; object_class->finalize = finalize; - setting_class->setting_info = &nm_meta_setting_infos[NM_META_SETTING_TYPE_WPAN]; - setting_class->verify = verify; + setting_class->verify = verify; /** * NMSettingWpan:mac-address: @@ -270,4 +269,6 @@ nm_setting_wpan_class_init (NMSettingWpanClass *klass) 0, G_MAXUINT16, G_MAXUINT16, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + _nm_setting_class_commit (setting_class, NM_META_SETTING_TYPE_WPAN); } diff --git a/libnm-core/nm-setting.c b/libnm-core/nm-setting.c index 86acc04e6b..2e884de7a0 100644 --- a/libnm-core/nm-setting.c +++ b/libnm-core/nm-setting.c @@ -191,90 +191,53 @@ _nm_setting_slave_type_is_valid (const char *slave_type, const char **out_port_t /*****************************************************************************/ -typedef struct { - const char *name; - GParamSpec *param_spec; - const GVariantType *dbus_type; - - NMSettingPropertyGetFunc get_func; - NMSettingPropertySynthFunc synth_func; - NMSettingPropertySetFunc set_func; - NMSettingPropertyNotSetFunc not_set_func; - - NMSettingPropertyTransformToFunc to_dbus; - NMSettingPropertyTransformFromFunc from_dbus; -} NMSettingProperty; - -static NM_CACHED_QUARK_FCN ("nm-setting-property-overrides", setting_property_overrides_quark) -static NM_CACHED_QUARK_FCN ("nm-setting-properties", setting_properties_quark) - -static NMSettingProperty * -find_property (GArray *properties, const char *name) +static const NMSettInfoProperty * +_nm_sett_info_property_find_in_array (const NMSettInfoProperty *properties, guint len, const char *name) { - NMSettingProperty *property; - int i; - - if (!properties) - return NULL; + guint i; - for (i = 0; i < properties->len; i++) { - property = &g_array_index (properties, NMSettingProperty, i); - if (strcmp (name, property->name) == 0) - return property; + for (i = 0; i < len; i++) { + if (nm_streq (name, properties[i].name)) + return &properties[i]; } - return NULL; } -static void -add_property_override (NMSettingClass *setting_class, - const char *property_name, - GParamSpec *param_spec, - const GVariantType *dbus_type, - NMSettingPropertyGetFunc get_func, - NMSettingPropertySynthFunc synth_func, - NMSettingPropertySetFunc set_func, - NMSettingPropertyNotSetFunc not_set_func, - NMSettingPropertyTransformToFunc to_dbus, - NMSettingPropertyTransformFromFunc from_dbus) +void +_properties_override_add_struct (GArray *properties_override, + const NMSettInfoProperty *prop_info) { - GType setting_type = G_TYPE_FROM_CLASS (setting_class); - GArray *overrides; - NMSettingProperty override; - - g_return_if_fail (g_type_get_qdata (setting_type, setting_properties_quark ()) == NULL); - - memset (&override, 0, sizeof (override)); - override.name = property_name; - override.param_spec = param_spec; - override.dbus_type = dbus_type; - override.get_func = get_func; - override.synth_func = synth_func; - override.set_func = set_func; - override.not_set_func = not_set_func; - override.to_dbus = to_dbus; - override.from_dbus = from_dbus; - - overrides = g_type_get_qdata (setting_type, setting_property_overrides_quark ()); - if (!overrides) { - overrides = g_array_new (FALSE, FALSE, sizeof (NMSettingProperty)); - g_type_set_qdata (setting_type, setting_property_overrides_quark (), overrides); + nm_assert (properties_override); + nm_assert (prop_info); + nm_assert (prop_info->name || prop_info->param_spec); + nm_assert (!prop_info->param_spec || !prop_info->name || nm_streq0 (prop_info->name, prop_info->param_spec->name)); + nm_assert (!_nm_sett_info_property_find_in_array ((NMSettInfoProperty *) properties_override->data, + properties_override->len, + prop_info->name ?: prop_info->param_spec->name)); + + nm_assert (!prop_info->from_dbus || prop_info->dbus_type); + nm_assert (!prop_info->set_func || prop_info->dbus_type); + + g_array_append_vals (properties_override, prop_info, 1); + + if (!prop_info->name) { + /* for convenience, allow omitting "name" if "param_spec" is given. */ + g_array_index (properties_override, + NMSettInfoProperty, + properties_override->len - 1).name = prop_info->param_spec->name; } - g_return_if_fail (find_property (overrides, property_name) == NULL); - - g_array_append_val (overrides, override); } /** - * _nm_setting_class_add_dbus_only_property: - * @setting_class: the setting class + * _properties_override_add_dbus_only: + * @properties_override: an array collecting the overrides * @property_name: the name of the property to override * @dbus_type: the type of the property (in its D-Bus representation) * @synth_func: (allow-none): function to call to synthesize a value for the property * @set_func: (allow-none): function to call to set the value of the property * * Registers a property named @property_name, which will be used in the D-Bus - * serialization of objects of @setting_class, but which does not correspond to + * serialization of objects of this setting type, but which does not correspond to * a #GObject property. * * When serializing a setting to D-Bus, @synth_func will be called to synthesize @@ -287,35 +250,30 @@ add_property_override (NMSettingClass *setting_class, * then the property will be ignored when deserializing.) */ void -_nm_setting_class_add_dbus_only_property (NMSettingClass *setting_class, - const char *property_name, - const GVariantType *dbus_type, - NMSettingPropertySynthFunc synth_func, - NMSettingPropertySetFunc set_func) +_properties_override_add_dbus_only (GArray *properties_override, + const char *property_name, + const GVariantType *dbus_type, + NMSettingPropertySynthFunc synth_func, + NMSettingPropertySetFunc set_func) { - g_return_if_fail (NM_IS_SETTING_CLASS (setting_class)); - g_return_if_fail (property_name != NULL); - - /* Must not match any GObject property. */ - g_return_if_fail (!g_object_class_find_property (G_OBJECT_CLASS (setting_class), property_name)); - - add_property_override (setting_class, - property_name, NULL, dbus_type, - NULL, synth_func, set_func, NULL, - NULL, NULL); + _properties_override_add (properties_override, + .name = property_name, + .dbus_type = dbus_type, + .synth_func = synth_func, + .set_func = set_func); } /** - * _nm_setting_class_override_property: - * @setting_class: the setting class - * @property_name: the name of the property to override + * _properties_override_add_override: + * @properties_override: an array collecting the overrides + * @param_spec: the name of the property to override * @dbus_type: the type of the property (in its D-Bus representation) * @get_func: (allow-none): function to call to get the value of the property * @set_func: (allow-none): function to call to set the value of the property * @not_set_func: (allow-none): function to call to indicate the property was not set * - * Overrides the D-Bus representation of the #GObject property named - * @property_name on @setting_class. + * Overrides the D-Bus representation of the #GObject property that shares the + * same name as @param_spec. * * When serializing a setting to D-Bus, if @get_func is non-%NULL, then it will * be called to get the property's value. If it returns a #GVariant, the @@ -324,38 +282,38 @@ _nm_setting_class_add_dbus_only_property (NMSettingClass *setting_class, * with g_object_get_property(), and added to the hash if it is not the default * value.) * - * When deserializing a D-Bus representation into a setting, if @property_name - * is present, then @set_func will be called to set it. (If @set_func is %NULL - * then the property will be set normally with g_object_set_property().) + * When deserializing a D-Bus representation into a setting, if a value with + * the name of @param_spec is present, then @set_func will be called to set it. + * (If @set_func is %NULL then the property will be set normally with + * g_object_set_property().) * * If @not_set_func is non-%NULL, then it will be called when deserializing a - * representation that does NOT contain @property_name. This can be used, eg, if - * a new property needs to be initialized from some older deprecated property + * representation that does NOT contain a value for the property. This can be used, + * eg, if a new property needs to be initialized from some older deprecated property * when it is not present. */ void -_nm_setting_class_override_property (NMSettingClass *setting_class, - const char *property_name, - const GVariantType *dbus_type, - NMSettingPropertyGetFunc get_func, - NMSettingPropertySetFunc set_func, - NMSettingPropertyNotSetFunc not_set_func) +_properties_override_add_override (GArray *properties_override, + GParamSpec *param_spec, + const GVariantType *dbus_type, + NMSettingPropertyGetFunc get_func, + NMSettingPropertySetFunc set_func, + NMSettingPropertyNotSetFunc not_set_func) { - GParamSpec *param_spec; - - param_spec = g_object_class_find_property (G_OBJECT_CLASS (setting_class), property_name); - g_return_if_fail (param_spec != NULL); - - add_property_override (setting_class, - property_name, param_spec, dbus_type, - get_func, NULL, set_func, not_set_func, - NULL, NULL); + nm_assert (param_spec); + + _properties_override_add (properties_override, + .param_spec = param_spec, + .dbus_type = dbus_type, + .get_func = get_func, + .set_func = set_func, + .not_set_func = not_set_func); } /** - * _nm_setting_class_transform_property: - * @setting_class: the setting class - * @property: the name of the property to transform + * _properties_override_add_transform: + * @properties_override: an array collecting the overrides + * @param_spec: the param spec of the property to transform. * @dbus_type: the type of the property (in its D-Bus representation) * @to_dbus: function to convert from object to D-Bus format * @from_dbus: function to convert from D-Bus to object format @@ -369,92 +327,139 @@ _nm_setting_class_override_property (NMSettingClass *setting_class, * nm_property_compare() recognizes, as long as it recognizes @dbus_type. */ void -_nm_setting_class_transform_property (NMSettingClass *setting_class, - const char *property, - const GVariantType *dbus_type, - NMSettingPropertyTransformToFunc to_dbus, - NMSettingPropertyTransformFromFunc from_dbus) +_properties_override_add_transform (GArray *properties_override, + GParamSpec *param_spec, + const GVariantType *dbus_type, + NMSettingPropertyTransformToFunc to_dbus, + NMSettingPropertyTransformFromFunc from_dbus) { - GParamSpec *param_spec; + nm_assert (param_spec); - param_spec = g_object_class_find_property (G_OBJECT_CLASS (setting_class), property); - g_return_if_fail (param_spec != NULL); - - add_property_override (setting_class, - property, param_spec, dbus_type, - NULL, NULL, NULL, NULL, - to_dbus, from_dbus); + _properties_override_add (properties_override, + .param_spec = param_spec, + .dbus_type = dbus_type, + .to_dbus = to_dbus, + .from_dbus = from_dbus); } -static GArray * -nm_setting_class_ensure_properties (NMSettingClass *setting_class) +static NMSettInfoSetting _sett_info_settings[_NM_META_SETTING_TYPE_NUM]; + +void +_nm_setting_class_commit_full (NMSettingClass *setting_class, + NMMetaSettingType meta_type, + const NMSettInfoSettDetail *detail, + GArray *properties_override) { - GType type = G_TYPE_FROM_CLASS (setting_class), otype; - NMSettingProperty property, *override; - GArray *overrides, *type_overrides, *properties; - GParamSpec **property_specs; - guint n_property_specs, i; - - properties = g_type_get_qdata (type, setting_properties_quark ()); - if (properties) - return properties; - - /* Build overrides array from @setting_class and its superclasses */ - overrides = g_array_new (FALSE, FALSE, sizeof (NMSettingProperty)); - for (otype = type; otype != G_TYPE_OBJECT; otype = g_type_parent (otype)) { - type_overrides = g_type_get_qdata (otype, setting_property_overrides_quark ()); - if (type_overrides) - g_array_append_vals (overrides, (NMSettingProperty *)type_overrides->data, type_overrides->len); - } + NMSettInfoSetting *sett_info; + gs_free GParamSpec **property_specs = NULL; + guint i, n_property_specs, override_len; + + nm_assert (NM_IS_SETTING_CLASS (setting_class)); + nm_assert (!setting_class->setting_info); + + nm_assert (meta_type < G_N_ELEMENTS (_sett_info_settings)); - /* Build the properties array from the GParamSpecs, obeying overrides */ - properties = g_array_new (FALSE, FALSE, sizeof (NMSettingProperty)); + sett_info = &_sett_info_settings[meta_type]; + + nm_assert (!sett_info->setting_class); + nm_assert (!sett_info->property_infos_len); + nm_assert (!sett_info->property_infos); + + if (!properties_override) { + override_len = 0; + properties_override = _nm_sett_info_property_override_create_array (); + } else + override_len = properties_override->len; property_specs = g_object_class_list_properties (G_OBJECT_CLASS (setting_class), &n_property_specs); - for (i = 0; i < n_property_specs; i++) { - override = find_property (overrides, property_specs[i]->name); - if (override) - property = *override; - else { - memset (&property, 0, sizeof (property)); - property.name = property_specs[i]->name; - property.param_spec = property_specs[i]; + +#if NM_MORE_ASSERTS > 10 + /* assert that properties_override is constructed consistently. */ + for (i = 0; i < override_len; i++) { + guint j; + const NMSettInfoProperty *p = &g_array_index (properties_override, NMSettInfoProperty, i); + + nm_assert (!_nm_sett_info_property_find_in_array ((NMSettInfoProperty *) properties_override->data, + i, + p->name)); + for (j = 0; j < n_property_specs; j++) { + if (nm_streq (property_specs[j]->name, p->name)) { + nm_assert (p->param_spec == property_specs[j]); + break; + } } - g_array_append_val (properties, property); + nm_assert ((j == n_property_specs) == (p->param_spec == NULL)); } - g_free (property_specs); +#endif + + for (i = 0; i < n_property_specs; i++) { + const char *name = property_specs[i]->name; + NMSettInfoProperty *p; - /* Add any remaining overrides not corresponding to GObject properties */ - for (i = 0; i < overrides->len; i++) { - override = &g_array_index (overrides, NMSettingProperty, i); - if (!g_object_class_find_property (G_OBJECT_CLASS (setting_class), override->name)) - g_array_append_val (properties, *override); + if (_nm_sett_info_property_find_in_array ((NMSettInfoProperty *) properties_override->data, + override_len, + name)) + continue; + + g_array_set_size (properties_override, properties_override->len + 1); + p = &g_array_index (properties_override, NMSettInfoProperty, properties_override->len - 1); + memset (p, 0, sizeof (*p)); + p->name = name; + p->param_spec = property_specs[i]; } - g_array_unref (overrides); - g_type_set_qdata (type, setting_properties_quark (), properties); - return properties; + G_STATIC_ASSERT_EXPR (G_STRUCT_OFFSET (NMSettInfoProperty, name) == 0); + g_array_sort (properties_override, nm_strcmp_p); + + setting_class->setting_info = &nm_meta_setting_infos[meta_type]; + sett_info->setting_class = setting_class; + if (detail) + sett_info->detail = *detail; + sett_info->property_infos_len = properties_override->len; + sett_info->property_infos = (const NMSettInfoProperty *) g_array_free (properties_override, + properties_override->len == 0); } -static const NMSettingProperty * -nm_setting_class_get_properties (NMSettingClass *setting_class, guint *n_properties) +const NMSettInfoSetting * +_nm_sett_info_setting_get (NMSettingClass *setting_class) { - GArray *properties; - - properties = nm_setting_class_ensure_properties (setting_class); - - *n_properties = properties->len; - return (NMSettingProperty *) properties->data; + if ( NM_IS_SETTING_CLASS (setting_class) + && setting_class->setting_info) { + nm_assert (setting_class->setting_info->meta_type < G_N_ELEMENTS (_sett_info_settings)); + return &_sett_info_settings[setting_class->setting_info->meta_type]; + } + return NULL; } -static const NMSettingProperty * -nm_setting_class_find_property (NMSettingClass *setting_class, const char *property_name) +const NMSettInfoProperty * +_nm_sett_info_property_get (NMSettingClass *setting_class, + const char *property_name) { - GArray *properties; + const NMSettInfoSetting *sett_info = _nm_sett_info_setting_get (setting_class); + const NMSettInfoProperty *property; + gssize idx; - properties = nm_setting_class_ensure_properties (setting_class); - return find_property (properties, property_name); + if (!sett_info) + return NULL; + + G_STATIC_ASSERT_EXPR (G_STRUCT_OFFSET (NMSettInfoProperty, name) == 0); + idx = nm_utils_array_find_binary_search (sett_info->property_infos, + sizeof (NMSettInfoProperty), + sett_info->property_infos_len, + &property_name, + nm_strcmp_p_with_data, + NULL); + + if (idx < 0) + return NULL; + + property = &sett_info->property_infos[idx]; + + nm_assert (idx == 0 || strcmp (property[-1].name, property[0].name) < 0); + nm_assert (idx == sett_info->property_infos_len - 1 || strcmp (property[0].name, property[1].name) < 0); + + return property; } /*****************************************************************************/ @@ -530,7 +535,7 @@ variant_type_for_gtype (GType type) static GVariant * get_property_for_dbus (NMSetting *setting, - const NMSettingProperty *property, + const NMSettInfoProperty *property, gboolean ignore_default) { GValue prop_value = { 0, }; @@ -567,7 +572,7 @@ get_property_for_dbus (NMSetting *setting, } static gboolean -set_property_from_dbus (const NMSettingProperty *property, +set_property_from_dbus (const NMSettInfoProperty *property, GVariant *src_value, GValue *dst_value) { @@ -620,17 +625,16 @@ _nm_setting_to_dbus (NMSetting *setting, NMConnection *connection, NMConnectionS { GVariantBuilder builder; GVariant *dbus_value; - const NMSettingProperty *properties; - guint n_properties, i; + const NMSettInfoSetting *sett_info; + guint i; g_return_val_if_fail (NM_IS_SETTING (setting), NULL); - properties = nm_setting_class_get_properties (NM_SETTING_GET_CLASS (setting), &n_properties); - g_variant_builder_init (&builder, NM_VARIANT_TYPE_SETTING); - for (i = 0; i < n_properties; i++) { - const NMSettingProperty *property = &properties[i]; + sett_info = _nm_sett_info_setting_get (NM_SETTING_GET_CLASS (setting)); + for (i = 0; i < sett_info->property_infos_len; i++) { + const NMSettInfoProperty *property = &sett_info->property_infos[i]; GParamSpec *prop_spec = property->param_spec; if (!prop_spec) { @@ -701,8 +705,8 @@ _nm_setting_new_from_dbus (GType setting_type, { gs_unref_object NMSetting *setting = NULL; gs_unref_hashtable GHashTable *keys = NULL; - const NMSettingProperty *properties; - guint i, n_properties; + const NMSettInfoSetting *sett_info; + guint i; g_return_val_if_fail (G_TYPE_IS_INSTANTIATABLE (setting_type), NULL); g_return_val_if_fail (g_variant_is_of_type (setting_dict, NM_VARIANT_TYPE_SETTING), NULL); @@ -746,9 +750,9 @@ _nm_setting_new_from_dbus (GType setting_type, } } - properties = nm_setting_class_get_properties (NM_SETTING_GET_CLASS (setting), &n_properties); - for (i = 0; i < n_properties; i++) { - const NMSettingProperty *property = &properties[i]; + sett_info = _nm_sett_info_setting_get (NM_SETTING_GET_CLASS (setting)); + for (i = 0; i < sett_info->property_infos_len; i++) { + const NMSettInfoProperty *property = &sett_info->property_infos[i]; gs_unref_variant GVariant *value = NULL; gs_free_error GError *local = NULL; @@ -867,12 +871,12 @@ const GVariantType * nm_setting_get_dbus_property_type (NMSetting *setting, const char *property_name) { - const NMSettingProperty *property; + const NMSettInfoProperty *property; g_return_val_if_fail (NM_IS_SETTING (setting), NULL); g_return_val_if_fail (property_name != NULL, NULL); - property = nm_setting_class_find_property (NM_SETTING_GET_CLASS (setting), property_name); + property = _nm_sett_info_property_get (NM_SETTING_GET_CLASS (setting), property_name); g_return_val_if_fail (property != NULL, NULL); if (property->dbus_type) @@ -1049,7 +1053,7 @@ compare_property (NMSetting *setting, const GParamSpec *prop_spec, NMSettingCompareFlags flags) { - const NMSettingProperty *property; + const NMSettInfoProperty *property; GVariant *value1, *value2; int cmp; @@ -1081,7 +1085,7 @@ compare_property (NMSetting *setting, return TRUE; } - property = nm_setting_class_find_property (NM_SETTING_GET_CLASS (setting), prop_spec->name); + property = _nm_sett_info_property_get (NM_SETTING_GET_CLASS (setting), prop_spec->name); g_return_val_if_fail (property != NULL, FALSE); value1 = get_property_for_dbus (setting, property, TRUE); @@ -1595,11 +1599,11 @@ _nm_setting_need_secrets (NMSetting *setting) static int update_one_secret (NMSetting *setting, const char *key, GVariant *value, GError **error) { - const NMSettingProperty *property; + const NMSettInfoProperty *property; GParamSpec *prop_spec; GValue prop_value = { 0, }; - property = nm_setting_class_find_property (NM_SETTING_GET_CLASS (setting), key); + property = _nm_sett_info_property_get (NM_SETTING_GET_CLASS (setting), key); if (!property) { g_set_error_literal (error, NM_CONNECTION_ERROR, @@ -1688,10 +1692,10 @@ _nm_setting_update_secrets (NMSetting *setting, GVariant *secrets, GError **erro static gboolean is_secret_prop (NMSetting *setting, const char *secret_name, GError **error) { - const NMSettingProperty *property; + const NMSettInfoProperty *property; GParamSpec *pspec; - property = nm_setting_class_find_property (NM_SETTING_GET_CLASS (setting), secret_name); + property = _nm_sett_info_property_get (NM_SETTING_GET_CLASS (setting), secret_name); if (!property) { g_set_error_literal (error, NM_CONNECTION_ERROR, |