]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: Move enum convertors into virenum.(c|h)
authorPeter Krempa <pkrempa@redhat.com>
Mon, 1 Apr 2019 10:14:26 +0000 (12:14 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 10 Apr 2019 07:12:04 +0000 (09:12 +0200)
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@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
70 files changed:
src/Makefile.am
src/access/viraccessperm.h
src/conf/capabilities.c
src/conf/cpu_conf.h
src/conf/device_conf.h
src/conf/domain_capabilities.h
src/conf/domain_conf.h
src/conf/interface_conf.h
src/conf/network_conf.h
src/conf/node_device_conf.h
src/conf/numa_conf.h
src/conf/nwfilter_conf.h
src/conf/snapshot_conf.h
src/conf/storage_adapter_conf.h
src/conf/storage_conf.h
src/libvirt_private.syms
src/libxl/libxl_conf.c
src/libxl/libxl_domain.h
src/locking/lock_daemon.c
src/logging/log_daemon.c
src/lxc/lxc_domain.h
src/lxc/lxc_native.h
src/network/leaseshelper.c
src/qemu/qemu_agent.c
src/qemu/qemu_capabilities.h
src/qemu/qemu_command.h
src/qemu/qemu_domain.h
src/qemu/qemu_driver.c
src/qemu/qemu_firmware.c
src/qemu/qemu_migration.h
src/qemu/qemu_migration_cookie.h
src/qemu/qemu_migration_params.h
src/qemu/qemu_monitor.h
src/qemu/qemu_monitor_json.c
src/util/Makefile.inc.am
src/util/vircgroup.h
src/util/virconf.h
src/util/virenum.c [new file with mode: 0644]
src/util/virenum.h [new file with mode: 0644]
src/util/virfirewalld.c
src/util/virgic.h
src/util/virjson.c
src/util/virkeycode.h
src/util/virmdev.h
src/util/virnetdev.h
src/util/virnetdevmacvlan.h
src/util/virnetdevvlan.h
src/util/virnetdevvportprofile.h
src/util/virpci.h
src/util/virperf.h
src/util/virprocess.h
src/util/virresctrl.h
src/util/virsecret.h
src/util/virstorageencryption.h
src/util/virstoragefile.h
src/util/virsysinfo.h
src/util/virtypedparam.h
src/util/virutil.c
src/util/virutil.h
src/vmware/vmware_conf.h
tools/virsh-domain-monitor.c
tools/virsh-domain.c
tools/virsh-host.c
tools/virsh-network.c
tools/virsh-nodedev.c
tools/virsh-pool.c
tools/virsh-secret.c
tools/virsh-volume.c
tools/virt-admin.c
tools/virt-host-validate-common.h

index b3b1e172ff5c5bb683dbf8ca7b5992f9519c44ee..ce199d1e93a233cf83ed339d94cff6509daef51f 100644 (file)
@@ -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 \
index ce3865b35926f44bbfe4698a4f5c619ddf1ad9ae..ed1f7168ca4fb4b01f30938dd691420e13c2d926 100644 (file)
@@ -23,6 +23,7 @@
 
 # include "internal.h"
 # include "virutil.h"
+# include "virenum.h"
 
 typedef enum {
     /**
index 47308700bb8604fad691b419a27ed7d53d7c8f2f..64c04d9774305965b6b57971859e4a543a03f824 100644 (file)
@@ -41,6 +41,7 @@
 #include "virstring.h"
 #include "virtypedparam.h"
 #include "viruuid.h"
+#include "virenum.h"
 
 #define VIR_FROM_THIS VIR_FROM_CAPABILITIES
 
index 6e810e5486d8448e248f3ba5b4ca794feaed0299..c98db65693142693125b4d21244de6d6854ed357 100644 (file)
@@ -27,6 +27,7 @@
 # include "virbitmap.h"
 # include "virarch.h"
 # include "numa_conf.h"
+# include "virenum.h"
 
 # define VIR_CPU_VENDOR_ID_LENGTH 12
 
index 7a3455f99f602ffb0dfe9b668ad2bb56ca9edbd5..b3299ac69dcb80fdae911825e4af4519c57feaf4 100644 (file)
@@ -31,6 +31,7 @@
 # include "virbuffer.h"
 # include "virpci.h"
 # include "virnetdev.h"
+# include "virenum.h"
 
 typedef enum {
     VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE,
index a9723fddd74c82acb17b82ac8e262745f932e327..d31d346a7b36b34c2dbb788941d2aa524f55372b 100644 (file)
@@ -24,6 +24,7 @@
 # include "internal.h"
 # include "domain_conf.h"
 # include "virautoclean.h"
+# include "virenum.h"
 
 typedef const char * (*virDomainCapsValToStr)(int value);
 
index ce6e5b47484a201142ec6ae77009581bafaaa567..12eb71c1977e0404ca175fb363af8c7fa88ef4e2 100644 (file)
@@ -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 {
index fd3fc7cba0e906a019bdb188a5f89fb21a09a0b8..e56b158b6dd8e87ecc0517f25c0a494907786864 100644 (file)
@@ -29,6 +29,7 @@
 # include "virutil.h"
 # include "virthread.h"
 # include "device_conf.h"
+# include "virenum.h"
 
 /* There is currently 3 types of interfaces */
 
index 4fba8f025d8a876a777701b8027ce82532ba5d9f..5410a57c67b92ec8962396db4c7129d31f88d83a 100644 (file)
@@ -40,6 +40,7 @@
 # include "networkcommon_conf.h"
 # include "virobject.h"
 # include "virmacmap.h"
+# include "virenum.h"
 
 typedef enum {
     VIR_NETWORK_FORWARD_NONE   = 0,
index e8cb315e305263cc5dd2642ac397313e06619d9d..510624968f1c1c5177ef332a75bd8db1eff4016b 100644 (file)
@@ -31,6 +31,7 @@
 # include "virvhba.h"
 # include "device_conf.h"
 # include "storage_adapter_conf.h"
+# include "virenum.h"
 
 # include <libxml/tree.h>
 
index 1e389397a753f2161ca4daccc99acd040b417c3f..ae1793a9508f3fb96ad0f1ddd8af8daa97026ae8 100644 (file)
@@ -27,6 +27,7 @@
 # include "virutil.h"
 # include "virbitmap.h"
 # include "virbuffer.h"
+# include "virenum.h"
 
 
 typedef struct _virDomainNuma virDomainNuma;
index de4c3b1d40ee84af23576ac53546f3d12e160932..4366ccc4d1be22411bbb4933003f5e8906338a44 100644 (file)
@@ -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
index cc8f384bf7252bb7f77ccb91e432934343ea8a3b..5a762ccd96a452c5ee8c8a0a4c07b2ec3c1e2de7 100644 (file)
@@ -25,6 +25,7 @@
 # include "internal.h"
 # include "domain_conf.h"
 # include "moment_conf.h"
+# include "virenum.h"
 
 /* Items related to snapshot state */
 
index 763e4ba0e9530b1f492395d7003bc49792ac19ec..81d73ea88933b2f165ac934e4530327ab26bf0de 100644 (file)
@@ -22,6 +22,7 @@
 
 # include "virpci.h"
 # include "virxml.h"
+# include "virenum.h"
 
 
 typedef enum {
index d848fa0fb7ecd47395605e911f09365db74360a9..6e4f7c689a54cc286ddc20f151bd232c14d71032 100644 (file)
@@ -31,6 +31,7 @@
 # include "object_event.h"
 # include "storage_adapter_conf.h"
 # include "virautoclean.h"
+# include "virenum.h"
 
 # include <libxml/tree.h>
 
index 212adf53c169ed3e2e6b1be3d2528c1f5eb47a8c..6e64e7783914b893ee62d3b413c2e2aa6a88d75c 100644 (file)
@@ -1784,6 +1784,17 @@ ebtablesContextNew;
 ebtablesRemoveForwardAllowIn;
 
 
+# util/virenum.h
+virEnumFromString;
+virEnumToString;
+virTristateBoolFromBool;
+virTristateBoolTypeFromString;
+virTristateBoolTypeToString;
+virTristateSwitchFromBool;
+virTristateSwitchTypeFromString;
+virTristateSwitchTypeToString;
+
+
 # util/virerror.h
 virDispatchError;
 virErrorCopyNew;
@@ -3187,8 +3198,6 @@ virUSBDeviceSetUsedBy;
 virDoesGroupExist;
 virDoesUserExist;
 virDoubleToStr;
-virEnumFromString;
-virEnumToString;
 virFormatIntDecimal;
 virFormatIntPretty;
 virGetDeviceID;
@@ -3234,12 +3243,6 @@ virSetNonBlock;
 virSetSockReuseAddr;
 virSetUIDGID;
 virSetUIDGIDWithCaps;
-virTristateBoolFromBool;
-virTristateBoolTypeFromString;
-virTristateBoolTypeToString;
-virTristateSwitchFromBool;
-virTristateSwitchTypeFromString;
-virTristateSwitchTypeToString;
 virUpdateSelfLastChanged;
 virValidateWWN;
 virWaitForDevices;
index 0c7a5f3dd57eb478cccee823796f2d88f00319fe..4faef43945cfc48ac10ca0e278b8b197184ac55a 100644 (file)
@@ -48,6 +48,7 @@
 #include "xen_common.h"
 #include "xen_xl.h"
 #include "virnetdevvportprofile.h"
+#include "virenum.h"
 
 
 #define VIR_FROM_THIS VIR_FROM_LIBXL
index 8ce5e9b2a9a7c4dcd0c47b8664671a361ea348ce..769ee8ec4db499d6db01f47196deaf9713abe267 100644 (file)
@@ -26,6 +26,7 @@
 # include "domain_conf.h"
 # include "libxl_conf.h"
 # include "virchrdev.h"
+# include "virenum.h"
 
 # define JOB_MASK(job)                  (job == 0 ? 0 : 1 << (job - 1))
 # define DEFAULT_JOB_MASK \
index d204e60ca0ba8b85ee1f5d9a8b0738a8e7214c23..7da60fa3a95a087f07e4625fdb9815a383b85688 100644 (file)
@@ -45,6 +45,7 @@
 #include "viruuid.h"
 #include "virstring.h"
 #include "virgettext.h"
+#include "virenum.h"
 
 #include "locking/lock_daemon_dispatch.h"
 #include "locking/lock_protocol.h"
index 36da4860ff8052f9a1de65760a26404a800a381b..2f7634a6a95c43413d6844043ccb25818572e845 100644 (file)
@@ -44,6 +44,7 @@
 #include "viruuid.h"
 #include "virstring.h"
 #include "virgettext.h"
+#include "virenum.h"
 
 #include "log_daemon_dispatch.h"
 #include "log_protocol.h"
index f4e9c378a901e90a614feaca7b3c86d5d36db315..20484818299fad44e246de2f71ba954d679edb83 100644 (file)
@@ -25,6 +25,7 @@
 # include "vircgroup.h"
 # include "lxc_conf.h"
 # include "lxc_monitor.h"
+# include "virenum.h"
 
 
 typedef enum {
index 0939be346dad35b7c1ad46cb1cc71c3b8b8ecfc2..57725d3d2b961c04745b1a2755b70d4cc7d4a6bc 100644 (file)
@@ -22,6 +22,7 @@
 # define LIBVIRT_LXC_NATIVE_H
 
 # include "domain_conf.h"
+# include "virenum.h"
 
 # define LXC_CONFIG_FORMAT "lxc-tools"
 
index 21119b3fbb29f458241950c99adfe25327b77c09..4c23a55326909435a45a4db0d0e5de902f3e5802 100644 (file)
@@ -32,6 +32,7 @@
 #include "viralloc.h"
 #include "virjson.h"
 #include "virlease.h"
+#include "virenum.h"
 #include "configmake.h"
 #include "virgettext.h"
 
index ea62b4b4a5f1b9d11f0fb8d67f37f78d8e45d0fb..361db299a5614ca560e6de60930829675d1d6d2c 100644 (file)
@@ -40,6 +40,7 @@
 #include "virobject.h"
 #include "virstring.h"
 #include "base64.h"
+#include "virenum.h"
 
 #define VIR_FROM_THIS VIR_FROM_QEMU
 
index c6f6980684231f9a5e802ec8bcaff073c780d15d..1f341fc0cd9df1fe8e55f2fdf8e79e08e722932a 100644 (file)
@@ -29,6 +29,7 @@
 # include "domain_capabilities.h"
 # include "virfirmware.h"
 # include "virfilecache.h"
+# include "virenum.h"
 
 /*
  * Internal flags to keep track of qemu command line capabilities
index 77578155e6d0339c68dab61afc2cac234dc1cbb9..9565a7a377740ad928cbc8ef547cf91ac72bc62a 100644 (file)
@@ -25,6 +25,7 @@
 # include "domain_addr.h"
 # include "domain_conf.h"
 # include "vircommand.h"
+# include "virenum.h"
 # include "capabilities.h"
 # include "qemu_block.h"
 # include "qemu_conf.h"
index 8857044d41a87acf9afa10cf9d721a8db7251156..06640a9510d23cd288cf427dbfe5d812b54dce26 100644 (file)
@@ -39,6 +39,7 @@
 # include "virobject.h"
 # include "logging/log_manager.h"
 # include "virdomainmomentobjlist.h"
+# include "virenum.h"
 
 # define QEMU_DOMAIN_FORMAT_LIVE_FLAGS \
     (VIR_DOMAIN_XML_SECURE)
index 7e5bbc3cc9c1e72643f4cb8d8f1195a716933653..1b40567dee4614092cc73061dc7212cbbdca6a5d 100644 (file)
 #include "netdev_bandwidth_conf.h"
 #include "virqemu.h"
 #include "virdomainsnapshotobjlist.h"
+#include "virenum.h"
 
 #define VIR_FROM_THIS VIR_FROM_QEMU
 
index affa0d633420a11996c8f47b8cc7014d1e5aced8..4f5214f3dbaf065da851eaa62c3973cdd9e515b2 100644 (file)
@@ -34,6 +34,7 @@
 #include "virlog.h"
 #include "virstring.h"
 #include "viralloc.h"
+#include "virenum.h"
 
 #define VIR_FROM_THIS VIR_FROM_QEMU
 
index ff7c765c60a84133ac3b8986847f05b86223d5a7..828caf268da15adb188f8de20836295aa4fb1011 100644 (file)
@@ -25,6 +25,7 @@
 # include "qemu_conf.h"
 # include "qemu_domain.h"
 # include "qemu_migration_params.h"
+# include "virenum.h"
 
 /*
  * General function naming conventions:
index 56678b008ab15546eb2d13c4471edf77a0c827a5..0c80b17e5e1390957b15f6fc01db831440718337 100644 (file)
@@ -20,6 +20,7 @@
 # define LIBVIRT_QEMU_MIGRATION_COOKIE_H
 
 # include "qemu_migration_params.h"
+# include "virenum.h"
 
 typedef enum {
     QEMU_MIGRATION_COOKIE_FLAG_GRAPHICS,
index 303c266969abf0dd8631daa2b90574b865f96113..b7bc71edaf91b5fdae2df3950aa3a8586be2c20e 100644 (file)
@@ -29,6 +29,7 @@
 # include "qemu_monitor.h"
 # include "qemu_conf.h"
 # include "virautoclean.h"
+# include "virenum.h"
 
 typedef enum {
     QEMU_MIGRATION_CAP_XBZRLE,
index 086195ff980f0b258dfe92a37678dc17f76950ea..caf62af5e282d2606e8c40a66dc8988af92e88e4 100644 (file)
@@ -32,6 +32,7 @@
 # include "device_conf.h"
 # include "cpu/cpu.h"
 # include "util/virgic.h"
+# include "virenum.h"
 
 typedef struct _qemuMonitor qemuMonitor;
 typedef qemuMonitor *qemuMonitorPtr;
index 8e6c3ccd63c2039ee670c79653dad63b2db382c5..c0564fdc2b8114316c0baad7f21ef36f9dea8c1f 100644 (file)
@@ -43,6 +43,7 @@
 #include "virstring.h"
 #include "cpu/cpu_x86.h"
 #include "c-strcasestr.h"
+#include "virenum.h"
 
 #ifdef WITH_DTRACE_PROBES
 # include "libvirt_qemu_probes.h"
index 6b24245aa112d5b570705307e9a82bbbc70f2b4d..58874cca3c98c60f23a1570847b131aad5b035b7 100644 (file)
@@ -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 \
index 372009de4a1afc0795e55f0bf0f04c929de973fa..377e0fd870165f994a65f7506b94bb18b3852901 100644 (file)
@@ -24,6 +24,7 @@
 
 # include "virutil.h"
 # include "virbitmap.h"
+# include "virenum.h"
 
 struct _virCgroup;
 typedef struct _virCgroup virCgroup;
index ff4c2b661525231ab73655570bd5e72699ac9e8c..d692e4a80599be529206b7349121b29191c21877 100644 (file)
@@ -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 (file)
index 0000000..abbc74d
--- /dev/null
@@ -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 (file)
index 0000000..3ae1a70
--- /dev/null
@@ -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 */
index 7a730f2bea550844c86dc8237a7ecc0bdd6ab3a5..1e30dadff315d9f2253ae642b39259b4062bf98f 100644 (file)
@@ -31,6 +31,7 @@
 #include "virutil.h"
 #include "virlog.h"
 #include "virdbus.h"
+#include "virenum.h"
 
 #define VIR_FROM_THIS VIR_FROM_FIREWALLD
 
index 371d04f708a9db4fd81ceea71b3c4ec7e4c52ea7..e54d7ec9d28440c859b27d2623103f7f7b1e79cb 100644 (file)
@@ -22,6 +22,7 @@
 # define LIBVIRT_VIRGIC_H
 
 # include "virutil.h"
+# include "virenum.h"
 
 typedef enum {
     VIR_GIC_VERSION_NONE = 0,
index 03547a9a2896f699be91d67461a0c2f3e8701b73..bd5084741899691da7454f8abe6dcc267f243000 100644 (file)
@@ -30,6 +30,7 @@
 #include "virstring.h"
 #include "virutil.h"
 #include "virbuffer.h"
+#include "virenum.h"
 
 #if WITH_YAJL
 # include <yajl/yajl_gen.h>
index 7120fb96e60513477df015010a73fc97ecb5a73b..9e94d6f61e4888e38de0c6b7fc8c5bf599e52bea 100644 (file)
@@ -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);
index a0e64f67aef8b595f6987533720e6ab94f604631..784cee5bcec06e278f61878aa9aa29261ea7e1e1 100644 (file)
@@ -23,6 +23,7 @@
 # include "virobject.h"
 # include "virutil.h"
 # include "virautoclean.h"
+# include "virenum.h"
 
 typedef enum {
     VIR_MDEV_MODEL_TYPE_VFIO_PCI = 0,
index e58c385dbec988cb58eaa19ea9ff1198154e44d6..7ca22de9a50c03e545942b2953bbe8a9dc8a3a2b 100644 (file)
@@ -27,6 +27,7 @@
 # include "virpci.h"
 # include "virnetdevvlan.h"
 # include "virautoclean.h"
+# include "virenum.h"
 
 # ifdef HAVE_STRUCT_IFREQ
 typedef struct ifreq virIfreq;
index 504a8c89ae1dfa29ef541d4ba94d094378d392cb..a33ea8f29e3486f080bad302d4f07c02fd5d4bab 100644 (file)
@@ -26,6 +26,7 @@
 # include "virnetdevbandwidth.h"
 # include "virnetdevvportprofile.h"
 # include "virnetdevvlan.h"
+# include "virenum.h"
 
 /* the mode type for macvtap devices */
 typedef enum {
index c250181f69b0260612caa0063e3e9d6c7a91d9d2..d986300d2a034647d2a7e6a4ab19d99935eac54e 100644 (file)
@@ -22,6 +22,7 @@
 # include <virutil.h>
 
 # include "virautoclean.h"
+# include "virenum.h"
 
 typedef enum {
     VIR_NATIVE_VLAN_MODE_DEFAULT = 0,
index 65b47798615cf7453a308b33febd6d6013e3c7e2..5506194001bb2e961defc676978d20d3fb520d6d 100644 (file)
@@ -23,6 +23,7 @@
 # include "viruuid.h"
 # include "virutil.h"
 # include "virmacaddr.h"
+# include "virenum.h"
 
 # define LIBVIRT_IFLA_VF_PORT_PROFILE_MAX 40
 
index 0a03927df85271708b61113f64057004156d0280..664e141039d6d5502ae00a7117d93ccaea6eae7b 100644 (file)
@@ -26,6 +26,7 @@
 # include "virobject.h"
 # include "virutil.h"
 # include "virautoclean.h"
+# include "virenum.h"
 
 typedef struct _virPCIDevice virPCIDevice;
 typedef virPCIDevice *virPCIDevicePtr;
index f43b8567238ab35a54325cb40879ad90a12d2fa2..e68baa527d7a83c9e52f85e7c692ade6be610c0f 100644 (file)
@@ -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
index e3944d3f1b87e0dc75f114ad3eb37f33aa942e27..8e5b0c2127adebe9f76f4f6b69d5d24b4ea926e8 100644 (file)
@@ -27,6 +27,7 @@
 # include "internal.h"
 # include "virbitmap.h"
 # include "virutil.h"
+# include "virenum.h"
 
 typedef enum {
     VIR_PROC_POLICY_NONE = 0,
index 0aa8bf7ea3bfbe695cf0a10c42dc17d37ab5661c..abdeb594eeb2358be65151a066b6bfd913cd47eb 100644 (file)
@@ -23,7 +23,7 @@
 
 # include "virbitmap.h"
 # include "virutil.h"
-
+# include "virenum.h"
 
 typedef enum {
     VIR_CACHE_TYPE_BOTH,
index a44d1bcdb6a83a0296ba63aa910d60de0c69564a..aaeb204f7c0cfa9777aa70a3eda99e955424ce41 100644 (file)
@@ -26,6 +26,7 @@
 
 # include "virutil.h"
 # include "virxml.h"
+# include "virenum.h"
 
 VIR_ENUM_DECL(virSecretUsage);
 
index 3fc4d970a18ac53d898b290c24ad889be5e56495..68d879a63e7be170c5f96c2c71dcc901ea3c0868 100644 (file)
@@ -25,6 +25,7 @@
 # include "virbuffer.h"
 # include "virsecret.h"
 # include "virutil.h"
+# include "virenum.h"
 
 # include <libxml/tree.h>
 
index 79cfb9cb40579fc2ce1777daff919a6fe4391dd9..763030eefa0ce075737fda91df46ab90e6be7861 100644 (file)
@@ -31,6 +31,7 @@
 # include "virutil.h"
 # include "virsecret.h"
 # include "virautoclean.h"
+# include "virenum.h"
 
 /* Minimum header size required to probe all known formats with
  * virStorageFileProbeFormat, or obtain metadata from a known format.
index 835ee4c62e5b5c56937dddc749cd90ed145f0632..c0015834bcc0f51b399feb6833a37580ce98af93 100644 (file)
@@ -25,6 +25,7 @@
 # include "internal.h"
 # include "virutil.h"
 # include "virbuffer.h"
+# include "virenum.h"
 
 typedef enum {
     VIR_SYSINFO_SMBIOS,
index 911ae52f6c8700bee2ea691d1e812a00fc308370..112f2a2af9d38b9e7937f4d2bf5ffd3cd245ddb6 100644 (file)
@@ -24,6 +24,7 @@
 
 # include "internal.h"
 # include "virutil.h"
+# include "virenum.h"
 
 /**
  * VIR_TYPED_PARAM_MULTIPLE:
index 3f214629ac45c6bac40cb6c0f8f527302d1b4b5b..f0c30063f295041b940985841d1c2668f43ed3e1 100644 (file)
@@ -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
 
@@ -324,22 +292,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
@@ -419,16 +371,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))
index e537cc36cb5cf1002246c3f7943d6e71d56f9db1..ded9b039e50366476d8a5366f4aab5018af3c754 100644 (file)
@@ -68,32 +68,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)
@@ -176,34 +150,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);
 
index 3c11d59fc0ec268dc8797af11432235840bf8ed3..93b424ef2f8637821d1698ca55ca276cc14d3c67 100644 (file)
@@ -26,6 +26,7 @@
 # include "internal.h"
 # include "virdomainobjlist.h"
 # include "virthread.h"
+# include "virenum.h"
 
 # define VIR_FROM_THIS VIR_FROM_VMWARE
 # define PROGRAM_SENTINEL ((char *)0x1)
index ad739a9df5544f245060b8301e963dcd5e08371c..d87475f6f6d9ff67ffd56b8742a31fddee0db3c5 100644 (file)
@@ -35,6 +35,7 @@
 #include "virxml.h"
 #include "virstring.h"
 #include "vsh-table.h"
+#include "virenum.h"
 
 VIR_ENUM_DECL(virshDomainIOError);
 VIR_ENUM_IMPL(virshDomainIOError,
index e8d5404acfc01330267bdec88b0c03635b1e3a8e..da087b74ae92c4ab77c8fdff7d180a8bddb2fa57 100644 (file)
@@ -55,6 +55,7 @@
 #include "virsh-nodedev.h"
 #include "viruri.h"
 #include "vsh-table.h"
+#include "virenum.h"
 
 /* Gnulib doesn't guarantee SA_SIGINFO support.  */
 #ifndef SA_SIGINFO
index be3c2cf1cb905638f6a8c4e371943bd64c2bdfed..dfd22bc0fef52b4cfd2bdf37018a3d22e15df3fc 100644 (file)
@@ -34,6 +34,7 @@
 #include "virtypedparam.h"
 #include "virstring.h"
 #include "virfile.h"
+#include "virenum.h"
 
 /*
  * "capabilities" command
index 9adc63a8fa442432a4a029924e82fae057412c46..bd5239ae66ed3ea629ebfafc63e03ea7cc2ea802 100644 (file)
@@ -29,6 +29,7 @@
 #include "virtime.h"
 #include "conf/network_conf.h"
 #include "vsh-table.h"
+#include "virenum.h"
 
 #define VIRSH_COMMON_OPT_NETWORK(_helpstr, cflags) \
     {.name = "network", \
index 1f787dadf36dd92b6483e6f6424aa6496560382e..0dfefe3a2fe3a188997c7713fa78c7778bb4bf8b 100644 (file)
@@ -28,6 +28,7 @@
 #include "virstring.h"
 #include "virtime.h"
 #include "conf/node_device_conf.h"
+#include "virenum.h"
 
 /*
  * "nodedev-create" command
index f8688fa1f2723fb796d8a2ba638b4083ef7cd49e..c56ab2d90a32f43a0335f1a992117243a60be905 100644 (file)
@@ -29,6 +29,7 @@
 #include "virstring.h"
 #include "virtime.h"
 #include "vsh-table.h"
+#include "virenum.h"
 
 #define VIRSH_COMMON_OPT_POOL_FULL(cflags) \
     VIRSH_COMMON_OPT_POOL(N_("pool name or uuid"), cflags)
index b9fc5ededf9882f9929d3e79ba4e67344a00e7dd..b34ae12bbedbec9949a9bc3367102e2269c26a7e 100644 (file)
@@ -31,6 +31,7 @@
 #include "virstring.h"
 #include "virtime.h"
 #include "vsh-table.h"
+#include "virenum.h"
 
 static virSecretPtr
 virshCommandOptSecret(vshControl *ctl, const vshCmd *cmd, const char **name)
index 59a75f3d8c87594ee73c4dc52d1d519ab516a518..d800836fef70d98e3919d2d7c4c9bfef8dd9c127 100644 (file)
@@ -38,6 +38,7 @@
 #include "virxml.h"
 #include "virstring.h"
 #include "vsh-table.h"
+#include "virenum.h"
 
 #define VIRSH_COMMON_OPT_POOL_FULL \
     VIRSH_COMMON_OPT_POOL(N_("pool name or uuid"), \
index 048c805f0ab0fc63eaaec527c505c7198ca7e1ea..4ff006ffcb5ea3a58a70aa10a0785dc849183bc8 100644 (file)
@@ -38,6 +38,7 @@
 #include "virtime.h"
 #include "virt-admin-completer.h"
 #include "vsh-table.h"
+#include "virenum.h"
 
 /* Gnulib doesn't guarantee SA_SIGINFO support.  */
 #ifndef SA_SIGINFO
index c2e11dae01cf171a298fe24608e925158adf3576..94a5005d5de360a99f599fc1e42bf3e269dbb002 100644 (file)
@@ -25,6 +25,7 @@
 # include "internal.h"
 # include "virutil.h"
 # include "virbitmap.h"
+# include "virenum.h"
 
 typedef enum {
     VIR_HOST_VALIDATE_FAIL,