virutil.(c|h) is a very gross collection of random code. Remove the enum
handlers from there so we can limit the scope where virtutil.h is used.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/Makefile.am | 3 ++
src/access/viraccessperm.h | 1 +
src/conf/capabilities.c | 1 +
src/conf/cpu_conf.h | 1 +
src/conf/device_conf.h | 1 +
src/conf/domain_capabilities.h | 1 +
src/conf/domain_conf.h | 1 +
src/conf/interface_conf.h | 1 +
src/conf/network_conf.h | 1 +
src/conf/node_device_conf.h | 1 +
src/conf/numa_conf.h | 1 +
src/conf/nwfilter_conf.h | 1 +
src/conf/storage_adapter_conf.h | 1 +
src/conf/storage_conf.h | 1 +
src/libvirt_private.syms | 19 ++++---
src/util/Makefile.inc.am | 2 +
src/util/vircgroup.h | 1 +
src/util/virconf.h | 1 +
src/util/virenum.c | 84 +++++++++++++++++++++++++++++++
src/util/virenum.h | 80 +++++++++++++++++++++++++++++
src/util/virfirewalld.c | 1 +
src/util/virgic.h | 1 +
src/util/virjson.c | 1 +
src/util/virkeycode.h | 1 +
src/util/virmdev.h | 1 +
src/util/virnetdev.h | 1 +
src/util/virnetdevmacvlan.h | 1 +
src/util/virnetdevvlan.h | 1 +
src/util/virnetdevvportprofile.h | 1 +
src/util/virpci.h | 1 +
src/util/virperf.h | 1 +
src/util/virprocess.h | 1 +
src/util/virresctrl.h | 2 +-
src/util/virsecret.h | 1 +
src/util/virstorageencryption.h | 1 +
src/util/virstoragefile.h | 1 +
src/util/virsysinfo.h | 1 +
src/util/virtypedparam.h | 1 +
src/util/virutil.c | 58 ---------------------
src/util/virutil.h | 54 --------------------
tools/virt-host-validate-common.h | 1 +
41 files changed, 214 insertions(+), 121 deletions(-)
create mode 100644 src/util/virenum.c
create mode 100644 src/util/virenum.h
diff --git a/src/Makefile.am b/src/Makefile.am
index b3b1e172ff..ce199d1e93 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -672,6 +672,7 @@ libvirt_setuid_rpc_client_la_SOURCES = \
util/vircommand.c \
util/virconf.c \
util/virdbus.c \
+ util/virenum.c \
util/virerror.c \
util/virevent.c \
util/vireventpoll.c \
@@ -882,6 +883,8 @@ libvirt_nss_la_SOURCES = \
util/virbuffer.h \
util/vircommand.c \
util/vircommand.h \
+ util/virenum.c \
+ util/virenum.h \
util/virerror.c \
util/virerror.h \
util/virfile.c \
diff --git a/src/access/viraccessperm.h b/src/access/viraccessperm.h
index ce3865b359..ed1f7168ca 100644
--- a/src/access/viraccessperm.h
+++ b/src/access/viraccessperm.h
@@ -23,6 +23,7 @@
# include "internal.h"
# include "virutil.h"
+# include "virenum.h"
typedef enum {
/**
diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
index 47308700bb..64c04d9774 100644
--- a/src/conf/capabilities.c
+++ b/src/conf/capabilities.c
@@ -41,6 +41,7 @@
#include "virstring.h"
#include "virtypedparam.h"
#include "viruuid.h"
+#include "virenum.h"
#define VIR_FROM_THIS VIR_FROM_CAPABILITIES
diff --git a/src/conf/cpu_conf.h b/src/conf/cpu_conf.h
index 6e810e5486..c98db65693 100644
--- a/src/conf/cpu_conf.h
+++ b/src/conf/cpu_conf.h
@@ -27,6 +27,7 @@
# include "virbitmap.h"
# include "virarch.h"
# include "numa_conf.h"
+# include "virenum.h"
# define VIR_CPU_VENDOR_ID_LENGTH 12
diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h
index 7a3455f99f..b3299ac69d 100644
--- a/src/conf/device_conf.h
+++ b/src/conf/device_conf.h
@@ -31,6 +31,7 @@
# include "virbuffer.h"
# include "virpci.h"
# include "virnetdev.h"
+# include "virenum.h"
typedef enum {
VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE,
diff --git a/src/conf/domain_capabilities.h b/src/conf/domain_capabilities.h
index 28e7d495c5..b82c78f1f5 100644
--- a/src/conf/domain_capabilities.h
+++ b/src/conf/domain_capabilities.h
@@ -23,6 +23,7 @@
# include "internal.h"
# include "domain_conf.h"
+# include "virenum.h"
typedef const char * (*virDomainCapsValToStr)(int value);
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index ce6e5b4748..12eb71c197 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -56,6 +56,7 @@
# include "virtypedparam.h"
# include "virsavecookie.h"
# include "virresctrl.h"
+# include "virenum.h"
/* Flags for the 'type' field in virDomainDeviceDef */
typedef enum {
diff --git a/src/conf/interface_conf.h b/src/conf/interface_conf.h
index fd3fc7cba0..e56b158b6d 100644
--- a/src/conf/interface_conf.h
+++ b/src/conf/interface_conf.h
@@ -29,6 +29,7 @@
# include "virutil.h"
# include "virthread.h"
# include "device_conf.h"
+# include "virenum.h"
/* There is currently 3 types of interfaces */
diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h
index 4fba8f025d..5410a57c67 100644
--- a/src/conf/network_conf.h
+++ b/src/conf/network_conf.h
@@ -40,6 +40,7 @@
# include "networkcommon_conf.h"
# include "virobject.h"
# include "virmacmap.h"
+# include "virenum.h"
typedef enum {
VIR_NETWORK_FORWARD_NONE = 0,
diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h
index e8cb315e30..510624968f 100644
--- a/src/conf/node_device_conf.h
+++ b/src/conf/node_device_conf.h
@@ -31,6 +31,7 @@
# include "virvhba.h"
# include "device_conf.h"
# include "storage_adapter_conf.h"
+# include "virenum.h"
# include <libxml/tree.h>
diff --git a/src/conf/numa_conf.h b/src/conf/numa_conf.h
index 1e389397a7..ae1793a950 100644
--- a/src/conf/numa_conf.h
+++ b/src/conf/numa_conf.h
@@ -27,6 +27,7 @@
# include "virutil.h"
# include "virbitmap.h"
# include "virbuffer.h"
+# include "virenum.h"
typedef struct _virDomainNuma virDomainNuma;
diff --git a/src/conf/nwfilter_conf.h b/src/conf/nwfilter_conf.h
index de4c3b1d40..4366ccc4d1 100644
--- a/src/conf/nwfilter_conf.h
+++ b/src/conf/nwfilter_conf.h
@@ -33,6 +33,7 @@
# include "virsocketaddr.h"
# include "virmacaddr.h"
# include "virdomainobjlist.h"
+# include "virenum.h"
/* XXX
* The config parser/structs should not be using platform specific
diff --git a/src/conf/storage_adapter_conf.h b/src/conf/storage_adapter_conf.h
index 763e4ba0e9..81d73ea889 100644
--- a/src/conf/storage_adapter_conf.h
+++ b/src/conf/storage_adapter_conf.h
@@ -22,6 +22,7 @@
# include "virpci.h"
# include "virxml.h"
+# include "virenum.h"
typedef enum {
diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h
index 87db8edadb..a8b6f72688 100644
--- a/src/conf/storage_conf.h
+++ b/src/conf/storage_conf.h
@@ -30,6 +30,7 @@
# include "device_conf.h"
# include "object_event.h"
# include "storage_adapter_conf.h"
+# include "virenum.h"
# include <libxml/tree.h>
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 23cbd27ce1..40ae82cd03 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1784,6 +1784,17 @@ ebtablesContextNew;
ebtablesRemoveForwardAllowIn;
+# util/virenum.h
+virEnumFromString;
+virEnumToString;
+virTristateBoolFromBool;
+virTristateBoolTypeFromString;
+virTristateBoolTypeToString;
+virTristateSwitchFromBool;
+virTristateSwitchTypeFromString;
+virTristateSwitchTypeToString;
+
+
# util/virerror.h
virDispatchError;
virErrorCopyNew;
@@ -3186,8 +3197,6 @@ virUSBDeviceSetUsedBy;
virDoesGroupExist;
virDoesUserExist;
virDoubleToStr;
-virEnumFromString;
-virEnumToString;
virFormatIntDecimal;
virFormatIntPretty;
virGetDeviceID;
@@ -3235,12 +3244,6 @@ virSetNonBlock;
virSetSockReuseAddr;
virSetUIDGID;
virSetUIDGIDWithCaps;
-virTristateBoolFromBool;
-virTristateBoolTypeFromString;
-virTristateBoolTypeToString;
-virTristateSwitchFromBool;
-virTristateSwitchTypeFromString;
-virTristateSwitchTypeToString;
virUpdateSelfLastChanged;
virValidateWWN;
virWaitForDevices;
diff --git a/src/util/Makefile.inc.am b/src/util/Makefile.inc.am
index 6b24245aa1..58874cca3c 100644
--- a/src/util/Makefile.inc.am
+++ b/src/util/Makefile.inc.am
@@ -49,6 +49,8 @@ UTIL_SOURCES = \
util/virebtables.c \
util/virebtables.h \
util/virendian.h \
+ util/virenum.h \
+ util/virenum.c \
util/virerror.c \
util/virerror.h \
util/virerrorpriv.h \
diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h
index 372009de4a..377e0fd870 100644
--- a/src/util/vircgroup.h
+++ b/src/util/vircgroup.h
@@ -24,6 +24,7 @@
# include "virutil.h"
# include "virbitmap.h"
+# include "virenum.h"
struct _virCgroup;
typedef struct _virCgroup virCgroup;
diff --git a/src/util/virconf.h b/src/util/virconf.h
index ff4c2b6615..d692e4a805 100644
--- a/src/util/virconf.h
+++ b/src/util/virconf.h
@@ -22,6 +22,7 @@
# define LIBVIRT_VIRCONF_H
# include "virutil.h"
+# include "virenum.h"
/**
* virConfType:
diff --git a/src/util/virenum.c b/src/util/virenum.c
new file mode 100644
index 0000000000..abbc74d28e
--- /dev/null
+++ b/src/util/virenum.c
@@ -0,0 +1,84 @@
+/*
+ * virenum.c: enum value conversion helpers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <
http://www.gnu.org/licenses/>.
+ */
+#include <config.h>
+
+#include "virenum.h"
+#include "virstring.h"
+
+#define VIR_FROM_THIS VIR_FROM_NONE
+
+VIR_ENUM_IMPL(virTristateBool, VIR_TRISTATE_BOOL_LAST,
+ "default",
+ "yes",
+ "no",
+);
+
+VIR_ENUM_IMPL(virTristateSwitch, VIR_TRISTATE_SWITCH_LAST,
+ "default",
+ "on",
+ "off",
+);
+
+
+virTristateBool
+virTristateBoolFromBool(bool val)
+{
+ if (val)
+ return VIR_TRISTATE_BOOL_YES;
+ else
+ return VIR_TRISTATE_BOOL_NO;
+}
+
+
+virTristateSwitch
+virTristateSwitchFromBool(bool val)
+{
+ if (val)
+ return VIR_TRISTATE_SWITCH_ON;
+ else
+ return VIR_TRISTATE_SWITCH_OFF;
+}
+
+
+int
+virEnumFromString(const char * const *types,
+ unsigned int ntypes,
+ const char *type)
+{
+ size_t i;
+ if (!type)
+ return -1;
+
+ for (i = 0; i < ntypes; i++)
+ if (STREQ(types[i], type))
+ return i;
+
+ return -1;
+}
+
+
+const char *
+virEnumToString(const char * const *types,
+ unsigned int ntypes,
+ int type)
+{
+ if (type < 0 || type >= ntypes)
+ return NULL;
+
+ return types[type];
+}
diff --git a/src/util/virenum.h b/src/util/virenum.h
new file mode 100644
index 0000000000..3ae1a70b72
--- /dev/null
+++ b/src/util/virenum.h
@@ -0,0 +1,80 @@
+/*
+ * virenum.h: enum value conversion helpers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <
http://www.gnu.org/licenses/>.
+ */
+
+#ifndef LIBVIRT_VIRENUM_H
+# define LIBVIRT_VIRENUM_H
+
+# include "internal.h"
+
+int
+virEnumFromString(const char * const *types,
+ unsigned int ntypes,
+ const char *type);
+
+const char *
+virEnumToString(const char * const *types,
+ unsigned int ntypes,
+ int type);
+
+# define VIR_ENUM_IMPL(name, lastVal, ...) \
+ static const char *const name ## TypeList[] = { __VA_ARGS__ }; \
+ const char *name ## TypeToString(int type) { \
+ return virEnumToString(name ## TypeList, \
+ ARRAY_CARDINALITY(name ## TypeList), \
+ type); \
+ } \
+ int name ## TypeFromString(const char *type) { \
+ return virEnumFromString(name ## TypeList, \
+ ARRAY_CARDINALITY(name ## TypeList), \
+ type); \
+ } \
+ verify(ARRAY_CARDINALITY(name ## TypeList) == lastVal)
+
+# define VIR_ENUM_DECL(name) \
+ const char *name ## TypeToString(int type); \
+ int name ## TypeFromString(const char*type)
+
+typedef enum {
+ VIR_TRISTATE_BOOL_ABSENT = 0,
+ VIR_TRISTATE_BOOL_YES,
+ VIR_TRISTATE_BOOL_NO,
+
+ VIR_TRISTATE_BOOL_LAST
+} virTristateBool;
+
+typedef enum {
+ VIR_TRISTATE_SWITCH_ABSENT = 0,
+ VIR_TRISTATE_SWITCH_ON,
+ VIR_TRISTATE_SWITCH_OFF,
+
+ VIR_TRISTATE_SWITCH_LAST
+} virTristateSwitch;
+
+VIR_ENUM_DECL(virTristateBool);
+VIR_ENUM_DECL(virTristateSwitch);
+
+virTristateBool virTristateBoolFromBool(bool val);
+virTristateSwitch virTristateSwitchFromBool(bool val);
+
+/* the two enums must be in sync to be able to use helpers interchangeably in
+ * some special cases */
+verify((int)VIR_TRISTATE_BOOL_YES == (int)VIR_TRISTATE_SWITCH_ON);
+verify((int)VIR_TRISTATE_BOOL_NO == (int)VIR_TRISTATE_SWITCH_OFF);
+verify((int)VIR_TRISTATE_BOOL_ABSENT == (int)VIR_TRISTATE_SWITCH_ABSENT);
+
+#endif /* LIBVIRT_VIRENUM_H */
diff --git a/src/util/virfirewalld.c b/src/util/virfirewalld.c
index 7a730f2bea..1e30dadff3 100644
--- a/src/util/virfirewalld.c
+++ b/src/util/virfirewalld.c
@@ -31,6 +31,7 @@
#include "virutil.h"
#include "virlog.h"
#include "virdbus.h"
+#include "virenum.h"
#define VIR_FROM_THIS VIR_FROM_FIREWALLD
diff --git a/src/util/virgic.h b/src/util/virgic.h
index 371d04f708..e54d7ec9d2 100644
--- a/src/util/virgic.h
+++ b/src/util/virgic.h
@@ -22,6 +22,7 @@
# define LIBVIRT_VIRGIC_H
# include "virutil.h"
+# include "virenum.h"
typedef enum {
VIR_GIC_VERSION_NONE = 0,
diff --git a/src/util/virjson.c b/src/util/virjson.c
index 467561c744..d62ae1475a 100644
--- a/src/util/virjson.c
+++ b/src/util/virjson.c
@@ -30,6 +30,7 @@
#include "virstring.h"
#include "virutil.h"
#include "virbuffer.h"
+#include "virenum.h"
#if WITH_YAJL
# include <yajl/yajl_gen.h>
diff --git a/src/util/virkeycode.h b/src/util/virkeycode.h
index 7120fb96e6..9e94d6f61e 100644
--- a/src/util/virkeycode.h
+++ b/src/util/virkeycode.h
@@ -23,6 +23,7 @@
# define LIBVIRT_VIRKEYCODE_H
# include "virutil.h"
+# include "virenum.h"
VIR_ENUM_DECL(virKeycodeSet);
int virKeycodeValueFromString(virKeycodeSet codeset, const char *keyname);
diff --git a/src/util/virmdev.h b/src/util/virmdev.h
index 0d3bc506e2..a6e9c3c605 100644
--- a/src/util/virmdev.h
+++ b/src/util/virmdev.h
@@ -22,6 +22,7 @@
# include "internal.h"
# include "virobject.h"
# include "virutil.h"
+# include "virenum.h"
typedef enum {
VIR_MDEV_MODEL_TYPE_VFIO_PCI = 0,
diff --git a/src/util/virnetdev.h b/src/util/virnetdev.h
index 98357128e4..c3f64edae9 100644
--- a/src/util/virnetdev.h
+++ b/src/util/virnetdev.h
@@ -26,6 +26,7 @@
# include "virmacaddr.h"
# include "virpci.h"
# include "virnetdevvlan.h"
+# include "virenum.h"
# ifdef HAVE_STRUCT_IFREQ
typedef struct ifreq virIfreq;
diff --git a/src/util/virnetdevmacvlan.h b/src/util/virnetdevmacvlan.h
index 504a8c89ae..a33ea8f29e 100644
--- a/src/util/virnetdevmacvlan.h
+++ b/src/util/virnetdevmacvlan.h
@@ -26,6 +26,7 @@
# include "virnetdevbandwidth.h"
# include "virnetdevvportprofile.h"
# include "virnetdevvlan.h"
+# include "virenum.h"
/* the mode type for macvtap devices */
typedef enum {
diff --git a/src/util/virnetdevvlan.h b/src/util/virnetdevvlan.h
index c250181f69..d986300d2a 100644
--- a/src/util/virnetdevvlan.h
+++ b/src/util/virnetdevvlan.h
@@ -22,6 +22,7 @@
# include <virutil.h>
# include "virautoclean.h"
+# include "virenum.h"
typedef enum {
VIR_NATIVE_VLAN_MODE_DEFAULT = 0,
diff --git a/src/util/virnetdevvportprofile.h b/src/util/virnetdevvportprofile.h
index 65b4779861..5506194001 100644
--- a/src/util/virnetdevvportprofile.h
+++ b/src/util/virnetdevvportprofile.h
@@ -23,6 +23,7 @@
# include "viruuid.h"
# include "virutil.h"
# include "virmacaddr.h"
+# include "virenum.h"
# define LIBVIRT_IFLA_VF_PORT_PROFILE_MAX 40
diff --git a/src/util/virpci.h b/src/util/virpci.h
index e89ea8390c..af98376d74 100644
--- a/src/util/virpci.h
+++ b/src/util/virpci.h
@@ -25,6 +25,7 @@
# include "virmdev.h"
# include "virobject.h"
# include "virutil.h"
+# include "virenum.h"
typedef struct _virPCIDevice virPCIDevice;
typedef virPCIDevice *virPCIDevicePtr;
diff --git a/src/util/virperf.h b/src/util/virperf.h
index f43b856723..e68baa527d 100644
--- a/src/util/virperf.h
+++ b/src/util/virperf.h
@@ -21,6 +21,7 @@
# include "virutil.h"
# include "virautoclean.h"
+# include "virenum.h"
/* Some Intel processor families introduced some RDT (Resource Director
* Technology) features to monitor or control shared resource based on
diff --git a/src/util/virprocess.h b/src/util/virprocess.h
index e3944d3f1b..8e5b0c2127 100644
--- a/src/util/virprocess.h
+++ b/src/util/virprocess.h
@@ -27,6 +27,7 @@
# include "internal.h"
# include "virbitmap.h"
# include "virutil.h"
+# include "virenum.h"
typedef enum {
VIR_PROC_POLICY_NONE = 0,
diff --git a/src/util/virresctrl.h b/src/util/virresctrl.h
index 0aa8bf7ea3..abdeb594ee 100644
--- a/src/util/virresctrl.h
+++ b/src/util/virresctrl.h
@@ -23,7 +23,7 @@
# include "virbitmap.h"
# include "virutil.h"
-
+# include "virenum.h"
typedef enum {
VIR_CACHE_TYPE_BOTH,
diff --git a/src/util/virsecret.h b/src/util/virsecret.h
index a44d1bcdb6..aaeb204f7c 100644
--- a/src/util/virsecret.h
+++ b/src/util/virsecret.h
@@ -26,6 +26,7 @@
# include "virutil.h"
# include "virxml.h"
+# include "virenum.h"
VIR_ENUM_DECL(virSecretUsage);
diff --git a/src/util/virstorageencryption.h b/src/util/virstorageencryption.h
index 3fc4d970a1..68d879a63e 100644
--- a/src/util/virstorageencryption.h
+++ b/src/util/virstorageencryption.h
@@ -25,6 +25,7 @@
# include "virbuffer.h"
# include "virsecret.h"
# include "virutil.h"
+# include "virenum.h"
# include <libxml/tree.h>
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index 420c8a57f3..b71004f4ef 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -30,6 +30,7 @@
# include "virstorageencryption.h"
# include "virutil.h"
# include "virsecret.h"
+# include "virenum.h"
/* Minimum header size required to probe all known formats with
* virStorageFileProbeFormat, or obtain metadata from a known format.
diff --git a/src/util/virsysinfo.h b/src/util/virsysinfo.h
index 835ee4c62e..c0015834bc 100644
--- a/src/util/virsysinfo.h
+++ b/src/util/virsysinfo.h
@@ -25,6 +25,7 @@
# include "internal.h"
# include "virutil.h"
# include "virbuffer.h"
+# include "virenum.h"
typedef enum {
VIR_SYSINFO_SMBIOS,
diff --git a/src/util/virtypedparam.h b/src/util/virtypedparam.h
index 911ae52f6c..112f2a2af9 100644
--- a/src/util/virtypedparam.h
+++ b/src/util/virtypedparam.h
@@ -24,6 +24,7 @@
# include "internal.h"
# include "virutil.h"
+# include "virenum.h"
/**
* VIR_TYPED_PARAM_MULTIPLE:
diff --git a/src/util/virutil.c b/src/util/virutil.c
index 0d58f1ee57..760557ea29 100644
--- a/src/util/virutil.c
+++ b/src/util/virutil.c
@@ -84,38 +84,6 @@ verify(sizeof(gid_t) <= sizeof(unsigned int) &&
VIR_LOG_INIT("util.util");
-VIR_ENUM_IMPL(virTristateBool, VIR_TRISTATE_BOOL_LAST,
- "default",
- "yes",
- "no",
-);
-
-VIR_ENUM_IMPL(virTristateSwitch, VIR_TRISTATE_SWITCH_LAST,
- "default",
- "on",
- "off",
-);
-
-
-virTristateBool
-virTristateBoolFromBool(bool val)
-{
- if (val)
- return VIR_TRISTATE_BOOL_YES;
- else
- return VIR_TRISTATE_BOOL_NO;
-}
-
-
-virTristateSwitch
-virTristateSwitchFromBool(bool val)
-{
- if (val)
- return VIR_TRISTATE_SWITCH_ON;
- else
- return VIR_TRISTATE_SWITCH_OFF;
-}
-
#ifndef WIN32
@@ -437,22 +405,6 @@ virParseVersionString(const char *str, unsigned long *version,
return 0;
}
-int virEnumFromString(const char *const*types,
- unsigned int ntypes,
- const char *type)
-{
- size_t i;
- if (!type)
- return -1;
-
- for (i = 0; i < ntypes; i++)
- if (STREQ(types[i], type))
- return i;
-
- return -1;
-}
-
-
/**
* Format @val as a base-10 decimal number, in the
* buffer @buf of size @buflen. To allocate a suitable
@@ -532,16 +484,6 @@ virFormatIntPretty(unsigned long long val,
}
-const char *virEnumToString(const char *const*types,
- unsigned int ntypes,
- int type)
-{
- if (type < 0 || type >= ntypes)
- return NULL;
-
- return types[type];
-}
-
/* Translates a device name of the form (regex) /^[fhv]d[a-z]+[0-9]*$/
* into the corresponding index and partition number
* (e.g. sda0 => (0,0), hdz2 => (25,2), vdaa12 => (26,12))
diff --git a/src/util/virutil.h b/src/util/virutil.h
index f8d8d85d27..67edf34d55 100644
--- a/src/util/virutil.h
+++ b/src/util/virutil.h
@@ -72,32 +72,6 @@ int virDiskNameParse(const char *name, int *disk, int *partition);
int virDiskNameToIndex(const char* str);
char *virIndexToDiskName(int idx, const char *prefix);
-int virEnumFromString(const char *const*types,
- unsigned int ntypes,
- const char *type);
-
-const char *virEnumToString(const char *const*types,
- unsigned int ntypes,
- int type);
-
-# define VIR_ENUM_IMPL(name, lastVal, ...) \
- static const char *const name ## TypeList[] = { __VA_ARGS__ }; \
- const char *name ## TypeToString(int type) { \
- return virEnumToString(name ## TypeList, \
- ARRAY_CARDINALITY(name ## TypeList), \
- type); \
- } \
- int name ## TypeFromString(const char *type) { \
- return virEnumFromString(name ## TypeList, \
- ARRAY_CARDINALITY(name ## TypeList), \
- type); \
- } \
- verify(ARRAY_CARDINALITY(name ## TypeList) == lastVal)
-
-# define VIR_ENUM_DECL(name) \
- const char *name ## TypeToString(int type); \
- int name ## TypeFromString(const char*type)
-
/* No-op workarounds for functionality missing in mingw. */
# ifndef HAVE_GETUID
static inline int getuid(void)
@@ -180,34 +154,6 @@ bool virIsSUID(void);
time_t virGetSelfLastChanged(void);
void virUpdateSelfLastChanged(const char *path);
-typedef enum {
- VIR_TRISTATE_BOOL_ABSENT = 0,
- VIR_TRISTATE_BOOL_YES,
- VIR_TRISTATE_BOOL_NO,
-
- VIR_TRISTATE_BOOL_LAST
-} virTristateBool;
-
-typedef enum {
- VIR_TRISTATE_SWITCH_ABSENT = 0,
- VIR_TRISTATE_SWITCH_ON,
- VIR_TRISTATE_SWITCH_OFF,
-
- VIR_TRISTATE_SWITCH_LAST
-} virTristateSwitch;
-
-VIR_ENUM_DECL(virTristateBool);
-VIR_ENUM_DECL(virTristateSwitch);
-
-virTristateBool virTristateBoolFromBool(bool val);
-virTristateSwitch virTristateSwitchFromBool(bool val);
-
-/* the two enums must be in sync to be able to use helpers interchangeably in
- * some special cases */
-verify((int)VIR_TRISTATE_BOOL_YES == (int)VIR_TRISTATE_SWITCH_ON);
-verify((int)VIR_TRISTATE_BOOL_NO == (int)VIR_TRISTATE_SWITCH_OFF);
-verify((int)VIR_TRISTATE_BOOL_ABSENT == (int)VIR_TRISTATE_SWITCH_ABSENT);
-
unsigned int virGetListenFDs(void);
char *virGetUNIXSocketPath(int fd);
diff --git a/tools/virt-host-validate-common.h b/tools/virt-host-validate-common.h
index c2e11dae01..94a5005d5d 100644
--- a/tools/virt-host-validate-common.h
+++ b/tools/virt-host-validate-common.h
@@ -25,6 +25,7 @@
# include "internal.h"
# include "virutil.h"
# include "virbitmap.h"
+# include "virenum.h"
typedef enum {
VIR_HOST_VALIDATE_FAIL,
--
2.20.1