mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-07-22 10:46:59 +00: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.
This commit is contained in:
parent
5b8e6c01a9
commit
cba8eb9784
|
@ -922,17 +922,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,
|
||||
|
|
|
@ -17303,16 +17303,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
|
||||
|
|
|
@ -1478,6 +1478,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…
Reference in a new issue