From 3d3dd128f9493e39a47412ff0cbcd79672c489f3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 8 Jun 2023 14:35:46 +0200 Subject: [PATCH] core: add nm_match_spec_match_type_to_bool() helper to convert enum to boolean All callers eventually want a boolean instead of a NMMatchSpecMatchType. I think the NMMatchSpecMatchType enum still has value at the lower layers, where the enum values are clearer (when reading the code). So don't drop NMMatchSpecMatchType entirely. However, let's add nm_match_spec_match_type_to_bool() to convert the match-type to a boolean to avoid duplicating the code. (cherry picked from commit cba8eb978492f3cc83cb8a854d526414851dc5e3) --- src/core/NetworkManagerUtils.c | 12 +----------- src/core/NetworkManagerUtils.h | 2 ++ src/core/devices/nm-device.c | 11 +---------- src/core/nm-core-utils.c | 14 ++++++++++++++ src/core/nm-core-utils.h | 2 ++ 5 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/core/NetworkManagerUtils.c b/src/core/NetworkManagerUtils.c index 6f4c60f876..5744a87e2c 100644 --- a/src/core/NetworkManagerUtils.c +++ b/src/core/NetworkManagerUtils.c @@ -918,17 +918,7 @@ nm_match_spec_device_by_pllink(const NMPlatformLink *pllink, NULL, NULL, match_dhcp_plugin); - - switch (m) { - case NM_MATCH_SPEC_MATCH: - return TRUE; - case NM_MATCH_SPEC_NEG_MATCH: - return FALSE; - case NM_MATCH_SPEC_NO_MATCH: - return no_match_value; - } - nm_assert_not_reached(); - return no_match_value; + return nm_match_spec_match_type_to_bool(m, no_match_value); } /*****************************************************************************/ diff --git a/src/core/NetworkManagerUtils.h b/src/core/NetworkManagerUtils.h index 67c9cba471..676215f38c 100644 --- a/src/core/NetworkManagerUtils.h +++ b/src/core/NetworkManagerUtils.h @@ -89,6 +89,8 @@ NMConnection *nm_utils_match_connection(NMConnection *const *connections, NMUtilsMatchFilterFunc match_filter_func, gpointer match_filter_data); +/*****************************************************************************/ + int nm_match_spec_device_by_pllink(const NMPlatformLink *pllink, const char *match_device_type, const char *match_dhcp_plugin, diff --git a/src/core/devices/nm-device.c b/src/core/devices/nm-device.c index dab79457ff..5d18289b52 100644 --- a/src/core/devices/nm-device.c +++ b/src/core/devices/nm-device.c @@ -17059,16 +17059,7 @@ nm_device_spec_match_list_full(NMDevice *self, const GSList *specs, int no_match klass->get_s390_subchannels ? klass->get_s390_subchannels(self) : NULL, nm_dhcp_manager_get_config(nm_dhcp_manager_get())); - switch (m) { - case NM_MATCH_SPEC_MATCH: - return TRUE; - case NM_MATCH_SPEC_NEG_MATCH: - return FALSE; - case NM_MATCH_SPEC_NO_MATCH: - return no_match_value; - } - nm_assert_not_reached(); - return no_match_value; + return nm_match_spec_match_type_to_bool(m, no_match_value); } guint diff --git a/src/core/nm-core-utils.c b/src/core/nm-core-utils.c index 28d9a788d6..7bba770f84 100644 --- a/src/core/nm-core-utils.c +++ b/src/core/nm-core-utils.c @@ -1484,6 +1484,20 @@ nm_match_spec_device(const GSList *specs, return _match_result(has_except, has_not_except, has_match, has_match_except); } +int +nm_match_spec_match_type_to_bool(NMMatchSpecMatchType m, int no_match_value) +{ + switch (m) { + case NM_MATCH_SPEC_MATCH: + return TRUE; + case NM_MATCH_SPEC_NEG_MATCH: + return FALSE; + case NM_MATCH_SPEC_NO_MATCH: + return no_match_value; + } + return nm_assert_unreachable_val(no_match_value); +} + typedef struct { const char *uuid; const char *id; diff --git a/src/core/nm-core-utils.h b/src/core/nm-core-utils.h index bc93649630..a57786479f 100644 --- a/src/core/nm-core-utils.h +++ b/src/core/nm-core-utils.h @@ -193,6 +193,8 @@ typedef enum { NM_MATCH_SPEC_NEG_MATCH = 2, } NMMatchSpecMatchType; +int nm_match_spec_match_type_to_bool(NMMatchSpecMatchType m, int no_match_value); + NMMatchSpecMatchType nm_match_spec_device(const GSList *specs, const char *interface_name, const char *device_type,