mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-03-02 13:10:47 +01:00
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 cba8eb9784)
This commit is contained in:
parent
1ebf60d8ff
commit
3d3dd128f9
5 changed files with 20 additions and 21 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue