diff options
author | Thomas Haller <thaller@redhat.com> | 2023-05-03 12:15:47 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2023-06-30 17:59:52 +0200 |
commit | 86b4953fad11a26700ddf24c416df932be867ad1 (patch) | |
tree | 60f52c9c4f0edc84f78cb39738add859a1f851b6 | |
parent | 60eb1c98354a225efae0b151c39ed7d82706f270 (diff) |
core: add nm_settings_connection_get_setting() helper
For efficiently and conveniently lookup an NMSetting from the
NMConnection inside the NMSettingsConnection.
Note that this uses the NMMetaSettingType as lookup key. That is a novel
approach, compared to lookup by name (nm_connection_get_setting_by_name())
or GType (nm_connection_get_setting()).
Using the NMMetaSettingType enum is however faster, because it does not
require resolving the name/GType first. This is perfecly fine internal API,
we should use it.
(cherry picked from commit 429cf416fd12f14d3a5639d7890f0d334c5e9328)
-rw-r--r-- | src/core/settings/nm-settings-connection.c | 14 | ||||
-rw-r--r-- | src/core/settings/nm-settings-connection.h | 4 |
2 files changed, 18 insertions, 0 deletions
diff --git a/src/core/settings/nm-settings-connection.c b/src/core/settings/nm-settings-connection.c index c7febca335..54bea8f713 100644 --- a/src/core/settings/nm-settings-connection.c +++ b/src/core/settings/nm-settings-connection.c @@ -377,6 +377,20 @@ nm_settings_connection_get_connection(NMSettingsConnection *self) return NM_SETTINGS_CONNECTION_GET_PRIVATE(self)->connection; } +gpointer +nm_settings_connection_get_setting(NMSettingsConnection *self, NMMetaSettingType meta_type) +{ + NMConnection *connection; + + nm_assert(NM_IS_SETTINGS_CONNECTION(self)); + + connection = NM_SETTINGS_CONNECTION_GET_PRIVATE(self)->connection; + + nm_assert(NM_IS_SIMPLE_CONNECTION(connection)); + + return _nm_connection_get_setting_by_metatype_unsafe(connection, meta_type); +} + void _nm_settings_connection_set_connection(NMSettingsConnection *self, NMConnection *new_connection, diff --git a/src/core/settings/nm-settings-connection.h b/src/core/settings/nm-settings-connection.h index d49da282ed..b125e22880 100644 --- a/src/core/settings/nm-settings-connection.h +++ b/src/core/settings/nm-settings-connection.h @@ -7,6 +7,8 @@ #ifndef __NETWORKMANAGER_SETTINGS_CONNECTION_H__ #define __NETWORKMANAGER_SETTINGS_CONNECTION_H__ +#include "libnm-core-intern/nm-meta-setting-base.h" + #include "nm-dbus-object.h" #include "nm-connection.h" @@ -222,6 +224,8 @@ NMSettings *nm_settings_connection_get_settings(NMSettingsConnection *self); NMManager *nm_settings_connection_get_manager(NMSettingsConnection *self); NMConnection *nm_settings_connection_get_connection(NMSettingsConnection *self); +gpointer nm_settings_connection_get_setting(NMSettingsConnection *self, + NMMetaSettingType meta_type); void _nm_settings_connection_set_connection(NMSettingsConnection *self, NMConnection *new_connection, |