summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2021-01-10 11:44:25 +0100
committerThomas Haller <thaller@redhat.com>2021-01-15 11:32:46 +0100
commit0dc5ea241253eb13bd7402fa37e338552f02380b (patch)
treef8f962be11a463c19f596b9978f07e24c0a6aac9
parentd2464c260fbb7ce8c2b45485b2e080cbcec172e5 (diff)
downloadNetworkManager-0dc5ea241253eb13bd7402fa37e338552f02380b.tar.gz
shared: add NMOptionBool as alternative to NMTernary
NMTernary is part of libnm's public API. It thus cannot be used by code without libnm/libnm-core dependency. Add another enum with the same purpose. The name "NMTernary" is already taken, and we should not use some macro trickery to use (effectively) different types under the same name. Another possible name would be "NMTern", but for no strong reasons we choose NMOptionBool. The naming reminds of rust's std::option::Option.
-rw-r--r--libnm-core/nm-core-internal.h18
-rw-r--r--shared/nm-glib-aux/nm-shared-utils.h12
2 files changed, 30 insertions, 0 deletions
diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h
index 01b3a55db6..afdd2f2fc1 100644
--- a/libnm-core/nm-core-internal.h
+++ b/libnm-core/nm-core-internal.h
@@ -230,6 +230,24 @@ _NM_SETTING_WIRED_WAKE_ON_LAN_CAST(NMSettingWiredWakeOnLan v)
/*****************************************************************************/
+static inline NMTernary
+NM_TERNARY_FROM_OPTION_BOOL(NMOptionBool v)
+{
+ nm_assert(NM_IN_SET(v, NM_OPTION_BOOL_DEFAULT, NM_OPTION_BOOL_TRUE, NM_OPTION_BOOL_FALSE));
+
+ return (NMTernary) v;
+}
+
+static inline NMOptionBool
+NM_TERNARY_TO_OPTION_BOOL(NMTernary v)
+{
+ nm_assert(NM_IN_SET(v, NM_TERNARY_DEFAULT, NM_TERNARY_TRUE, NM_TERNARY_FALSE));
+
+ return (NMOptionBool) v;
+}
+
+/*****************************************************************************/
+
typedef enum { /*< skip >*/
NM_SETTING_PARSE_FLAGS_NONE = 0,
NM_SETTING_PARSE_FLAGS_STRICT = 1LL << 0,
diff --git a/shared/nm-glib-aux/nm-shared-utils.h b/shared/nm-glib-aux/nm-shared-utils.h
index 669c9fbcb4..8f0d50c9f5 100644
--- a/shared/nm-glib-aux/nm-shared-utils.h
+++ b/shared/nm-glib-aux/nm-shared-utils.h
@@ -8,6 +8,18 @@
#include <netinet/in.h>
+/*****************************************************************************/
+
+/* An optional boolean (like NMTernary, with identical numerical
+ * enum values). Note that this enum type is _nm_packed! */
+typedef enum _nm_packed {
+ NM_OPTION_BOOL_DEFAULT = -1,
+ NM_OPTION_BOOL_FALSE = 0,
+ NM_OPTION_BOOL_TRUE = 1,
+} NMOptionBool;
+
+/*****************************************************************************/
+
static inline gboolean
nm_is_ascii(char ch)
{