mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-03 12:50:17 +01:00
libnm: expose _nm_connection_get_setting_by_metatype() in internal header
We have several variants to get the NMSetting from an NMConnection. Some of them are public API (nm_connection_get_setting(), nm_connection_get_setting_by_name()). The most efficient way is lookup by NMMetaSettingType. Expose that as internal API, so it can be used. The NMMetaSettingType is internal, but it exists because it's a very useful enum. Allow others to make use of it. Also, add a static assert which prevents various wrong uses at compile time, for example _nm_connection_get_setting_by_metatype(connection, NM_TYPE_SETTING_CONNECTION)
This commit is contained in:
parent
c60a4649b8
commit
db5946ac2f
2 changed files with 19 additions and 2 deletions
|
|
@ -285,8 +285,11 @@ _get_setting_by_metatype(NMConnectionPrivate *priv, NMMetaSettingType meta_type)
|
|||
return priv->settings[meta_type];
|
||||
}
|
||||
|
||||
static gpointer
|
||||
_nm_connection_get_setting_by_metatype(NMConnection *connection, NMMetaSettingType meta_type)
|
||||
/* The "unsafe" part here is that _nm_connection_get_setting_by_metatype() has a compile
|
||||
* time check that meta_type is valid. With the unsafe variant, the caller must ensure that,
|
||||
* and we only get an nm_assert() check -- which is basically nothing. */
|
||||
gpointer
|
||||
_nm_connection_get_setting_by_metatype_unsafe(NMConnection *connection, NMMetaSettingType meta_type)
|
||||
{
|
||||
g_return_val_if_fail(NM_IS_CONNECTION(connection), NULL);
|
||||
|
||||
|
|
|
|||
|
|
@ -455,6 +455,20 @@ _nm_connection_get_setting(NMConnection *connection, GType type)
|
|||
return (gpointer) nm_connection_get_setting(connection, type);
|
||||
}
|
||||
|
||||
gpointer _nm_connection_get_setting_by_metatype_unsafe(NMConnection *connection,
|
||||
NMMetaSettingType meta_type);
|
||||
|
||||
/* This variant is the most efficient one, because it does not require resolving a
|
||||
* name/GType first. The NMMetaSettingType enum allows for a direct lookup. */
|
||||
#define _nm_connection_get_setting_by_metatype(connection, meta_type) \
|
||||
({ \
|
||||
/* Static assert that meta_type is in the valid range. If you don't want that,
|
||||
* because the argument is no a compile time constant, use _nm_connection_get_setting_by_metatype_unsafe(). */ \
|
||||
G_STATIC_ASSERT((meta_type) < _NM_META_SETTING_TYPE_NUM && ((int) meta_type) >= 0); \
|
||||
\
|
||||
_nm_connection_get_setting_by_metatype_unsafe((connection), (meta_type)); \
|
||||
})
|
||||
|
||||
NMSettingIPConfig *nm_connection_get_setting_ip_config(NMConnection *connection, int addr_family);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue