util: Move enum convertors into virenum.(c|h)

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>
This commit is contained in:
Peter Krempa 2019-04-01 12:14:26 +02:00
parent c0abcca417
commit 285c5f28c4
70 changed files with 243 additions and 121 deletions

View File

@ -672,6 +672,7 @@ libvirt_setuid_rpc_client_la_SOURCES = \
util/vircommand.c \ util/vircommand.c \
util/virconf.c \ util/virconf.c \
util/virdbus.c \ util/virdbus.c \
util/virenum.c \
util/virerror.c \ util/virerror.c \
util/virevent.c \ util/virevent.c \
util/vireventpoll.c \ util/vireventpoll.c \
@ -882,6 +883,8 @@ libvirt_nss_la_SOURCES = \
util/virbuffer.h \ util/virbuffer.h \
util/vircommand.c \ util/vircommand.c \
util/vircommand.h \ util/vircommand.h \
util/virenum.c \
util/virenum.h \
util/virerror.c \ util/virerror.c \
util/virerror.h \ util/virerror.h \
util/virfile.c \ util/virfile.c \

View File

@ -23,6 +23,7 @@
# include "internal.h" # include "internal.h"
# include "virutil.h" # include "virutil.h"
# include "virenum.h"
typedef enum { typedef enum {
/** /**

View File

@ -41,6 +41,7 @@
#include "virstring.h" #include "virstring.h"
#include "virtypedparam.h" #include "virtypedparam.h"
#include "viruuid.h" #include "viruuid.h"
#include "virenum.h"
#define VIR_FROM_THIS VIR_FROM_CAPABILITIES #define VIR_FROM_THIS VIR_FROM_CAPABILITIES

View File

@ -27,6 +27,7 @@
# include "virbitmap.h" # include "virbitmap.h"
# include "virarch.h" # include "virarch.h"
# include "numa_conf.h" # include "numa_conf.h"
# include "virenum.h"
# define VIR_CPU_VENDOR_ID_LENGTH 12 # define VIR_CPU_VENDOR_ID_LENGTH 12

View File

@ -31,6 +31,7 @@
# include "virbuffer.h" # include "virbuffer.h"
# include "virpci.h" # include "virpci.h"
# include "virnetdev.h" # include "virnetdev.h"
# include "virenum.h"
typedef enum { typedef enum {
VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE, VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE,

View File

@ -24,6 +24,7 @@
# include "internal.h" # include "internal.h"
# include "domain_conf.h" # include "domain_conf.h"
# include "virautoclean.h" # include "virautoclean.h"
# include "virenum.h"
typedef const char * (*virDomainCapsValToStr)(int value); typedef const char * (*virDomainCapsValToStr)(int value);

View File

@ -56,6 +56,7 @@
# include "virtypedparam.h" # include "virtypedparam.h"
# include "virsavecookie.h" # include "virsavecookie.h"
# include "virresctrl.h" # include "virresctrl.h"
# include "virenum.h"
/* Flags for the 'type' field in virDomainDeviceDef */ /* Flags for the 'type' field in virDomainDeviceDef */
typedef enum { typedef enum {

View File

@ -29,6 +29,7 @@
# include "virutil.h" # include "virutil.h"
# include "virthread.h" # include "virthread.h"
# include "device_conf.h" # include "device_conf.h"
# include "virenum.h"
/* There is currently 3 types of interfaces */ /* There is currently 3 types of interfaces */

View File

@ -40,6 +40,7 @@
# include "networkcommon_conf.h" # include "networkcommon_conf.h"
# include "virobject.h" # include "virobject.h"
# include "virmacmap.h" # include "virmacmap.h"
# include "virenum.h"
typedef enum { typedef enum {
VIR_NETWORK_FORWARD_NONE = 0, VIR_NETWORK_FORWARD_NONE = 0,

View File

@ -31,6 +31,7 @@
# include "virvhba.h" # include "virvhba.h"
# include "device_conf.h" # include "device_conf.h"
# include "storage_adapter_conf.h" # include "storage_adapter_conf.h"
# include "virenum.h"
# include <libxml/tree.h> # include <libxml/tree.h>

View File

@ -27,6 +27,7 @@
# include "virutil.h" # include "virutil.h"
# include "virbitmap.h" # include "virbitmap.h"
# include "virbuffer.h" # include "virbuffer.h"
# include "virenum.h"
typedef struct _virDomainNuma virDomainNuma; typedef struct _virDomainNuma virDomainNuma;

View File

@ -33,6 +33,7 @@
# include "virsocketaddr.h" # include "virsocketaddr.h"
# include "virmacaddr.h" # include "virmacaddr.h"
# include "virdomainobjlist.h" # include "virdomainobjlist.h"
# include "virenum.h"
/* XXX /* XXX
* The config parser/structs should not be using platform specific * The config parser/structs should not be using platform specific

View File

@ -25,6 +25,7 @@
# include "internal.h" # include "internal.h"
# include "domain_conf.h" # include "domain_conf.h"
# include "moment_conf.h" # include "moment_conf.h"
# include "virenum.h"
/* Items related to snapshot state */ /* Items related to snapshot state */

View File

@ -22,6 +22,7 @@
# include "virpci.h" # include "virpci.h"
# include "virxml.h" # include "virxml.h"
# include "virenum.h"
typedef enum { typedef enum {

View File

@ -31,6 +31,7 @@
# include "object_event.h" # include "object_event.h"
# include "storage_adapter_conf.h" # include "storage_adapter_conf.h"
# include "virautoclean.h" # include "virautoclean.h"
# include "virenum.h"
# include <libxml/tree.h> # include <libxml/tree.h>

View File

@ -1784,6 +1784,17 @@ ebtablesContextNew;
ebtablesRemoveForwardAllowIn; ebtablesRemoveForwardAllowIn;
# util/virenum.h
virEnumFromString;
virEnumToString;
virTristateBoolFromBool;
virTristateBoolTypeFromString;
virTristateBoolTypeToString;
virTristateSwitchFromBool;
virTristateSwitchTypeFromString;
virTristateSwitchTypeToString;
# util/virerror.h # util/virerror.h
virDispatchError; virDispatchError;
virErrorCopyNew; virErrorCopyNew;
@ -3187,8 +3198,6 @@ virUSBDeviceSetUsedBy;
virDoesGroupExist; virDoesGroupExist;
virDoesUserExist; virDoesUserExist;
virDoubleToStr; virDoubleToStr;
virEnumFromString;
virEnumToString;
virFormatIntDecimal; virFormatIntDecimal;
virFormatIntPretty; virFormatIntPretty;
virGetDeviceID; virGetDeviceID;
@ -3234,12 +3243,6 @@ virSetNonBlock;
virSetSockReuseAddr; virSetSockReuseAddr;
virSetUIDGID; virSetUIDGID;
virSetUIDGIDWithCaps; virSetUIDGIDWithCaps;
virTristateBoolFromBool;
virTristateBoolTypeFromString;
virTristateBoolTypeToString;
virTristateSwitchFromBool;
virTristateSwitchTypeFromString;
virTristateSwitchTypeToString;
virUpdateSelfLastChanged; virUpdateSelfLastChanged;
virValidateWWN; virValidateWWN;
virWaitForDevices; virWaitForDevices;

View File

@ -48,6 +48,7 @@
#include "xen_common.h" #include "xen_common.h"
#include "xen_xl.h" #include "xen_xl.h"
#include "virnetdevvportprofile.h" #include "virnetdevvportprofile.h"
#include "virenum.h"
#define VIR_FROM_THIS VIR_FROM_LIBXL #define VIR_FROM_THIS VIR_FROM_LIBXL

View File

@ -26,6 +26,7 @@
# include "domain_conf.h" # include "domain_conf.h"
# include "libxl_conf.h" # include "libxl_conf.h"
# include "virchrdev.h" # include "virchrdev.h"
# include "virenum.h"
# define JOB_MASK(job) (job == 0 ? 0 : 1 << (job - 1)) # define JOB_MASK(job) (job == 0 ? 0 : 1 << (job - 1))
# define DEFAULT_JOB_MASK \ # define DEFAULT_JOB_MASK \

View File

@ -45,6 +45,7 @@
#include "viruuid.h" #include "viruuid.h"
#include "virstring.h" #include "virstring.h"
#include "virgettext.h" #include "virgettext.h"
#include "virenum.h"
#include "locking/lock_daemon_dispatch.h" #include "locking/lock_daemon_dispatch.h"
#include "locking/lock_protocol.h" #include "locking/lock_protocol.h"

View File

@ -44,6 +44,7 @@
#include "viruuid.h" #include "viruuid.h"
#include "virstring.h" #include "virstring.h"
#include "virgettext.h" #include "virgettext.h"
#include "virenum.h"
#include "log_daemon_dispatch.h" #include "log_daemon_dispatch.h"
#include "log_protocol.h" #include "log_protocol.h"

View File

@ -25,6 +25,7 @@
# include "vircgroup.h" # include "vircgroup.h"
# include "lxc_conf.h" # include "lxc_conf.h"
# include "lxc_monitor.h" # include "lxc_monitor.h"
# include "virenum.h"
typedef enum { typedef enum {

View File

@ -22,6 +22,7 @@
# define LIBVIRT_LXC_NATIVE_H # define LIBVIRT_LXC_NATIVE_H
# include "domain_conf.h" # include "domain_conf.h"
# include "virenum.h"
# define LXC_CONFIG_FORMAT "lxc-tools" # define LXC_CONFIG_FORMAT "lxc-tools"

View File

@ -32,6 +32,7 @@
#include "viralloc.h" #include "viralloc.h"
#include "virjson.h" #include "virjson.h"
#include "virlease.h" #include "virlease.h"
#include "virenum.h"
#include "configmake.h" #include "configmake.h"
#include "virgettext.h" #include "virgettext.h"

View File

@ -40,6 +40,7 @@
#include "virobject.h" #include "virobject.h"
#include "virstring.h" #include "virstring.h"
#include "base64.h" #include "base64.h"
#include "virenum.h"
#define VIR_FROM_THIS VIR_FROM_QEMU #define VIR_FROM_THIS VIR_FROM_QEMU

View File

@ -29,6 +29,7 @@
# include "domain_capabilities.h" # include "domain_capabilities.h"
# include "virfirmware.h" # include "virfirmware.h"
# include "virfilecache.h" # include "virfilecache.h"
# include "virenum.h"
/* /*
* Internal flags to keep track of qemu command line capabilities * Internal flags to keep track of qemu command line capabilities

View File

@ -25,6 +25,7 @@
# include "domain_addr.h" # include "domain_addr.h"
# include "domain_conf.h" # include "domain_conf.h"
# include "vircommand.h" # include "vircommand.h"
# include "virenum.h"
# include "capabilities.h" # include "capabilities.h"
# include "qemu_block.h" # include "qemu_block.h"
# include "qemu_conf.h" # include "qemu_conf.h"

View File

@ -39,6 +39,7 @@
# include "virobject.h" # include "virobject.h"
# include "logging/log_manager.h" # include "logging/log_manager.h"
# include "virdomainmomentobjlist.h" # include "virdomainmomentobjlist.h"
# include "virenum.h"
# define QEMU_DOMAIN_FORMAT_LIVE_FLAGS \ # define QEMU_DOMAIN_FORMAT_LIVE_FLAGS \
(VIR_DOMAIN_XML_SECURE) (VIR_DOMAIN_XML_SECURE)

View File

@ -102,6 +102,7 @@
#include "netdev_bandwidth_conf.h" #include "netdev_bandwidth_conf.h"
#include "virqemu.h" #include "virqemu.h"
#include "virdomainsnapshotobjlist.h" #include "virdomainsnapshotobjlist.h"
#include "virenum.h"
#define VIR_FROM_THIS VIR_FROM_QEMU #define VIR_FROM_THIS VIR_FROM_QEMU

View File

@ -34,6 +34,7 @@
#include "virlog.h" #include "virlog.h"
#include "virstring.h" #include "virstring.h"
#include "viralloc.h" #include "viralloc.h"
#include "virenum.h"
#define VIR_FROM_THIS VIR_FROM_QEMU #define VIR_FROM_THIS VIR_FROM_QEMU

View File

@ -25,6 +25,7 @@
# include "qemu_conf.h" # include "qemu_conf.h"
# include "qemu_domain.h" # include "qemu_domain.h"
# include "qemu_migration_params.h" # include "qemu_migration_params.h"
# include "virenum.h"
/* /*
* General function naming conventions: * General function naming conventions:

View File

@ -20,6 +20,7 @@
# define LIBVIRT_QEMU_MIGRATION_COOKIE_H # define LIBVIRT_QEMU_MIGRATION_COOKIE_H
# include "qemu_migration_params.h" # include "qemu_migration_params.h"
# include "virenum.h"
typedef enum { typedef enum {
QEMU_MIGRATION_COOKIE_FLAG_GRAPHICS, QEMU_MIGRATION_COOKIE_FLAG_GRAPHICS,

View File

@ -29,6 +29,7 @@
# include "qemu_monitor.h" # include "qemu_monitor.h"
# include "qemu_conf.h" # include "qemu_conf.h"
# include "virautoclean.h" # include "virautoclean.h"
# include "virenum.h"
typedef enum { typedef enum {
QEMU_MIGRATION_CAP_XBZRLE, QEMU_MIGRATION_CAP_XBZRLE,

View File

@ -32,6 +32,7 @@
# include "device_conf.h" # include "device_conf.h"
# include "cpu/cpu.h" # include "cpu/cpu.h"
# include "util/virgic.h" # include "util/virgic.h"
# include "virenum.h"
typedef struct _qemuMonitor qemuMonitor; typedef struct _qemuMonitor qemuMonitor;
typedef qemuMonitor *qemuMonitorPtr; typedef qemuMonitor *qemuMonitorPtr;

View File

@ -43,6 +43,7 @@
#include "virstring.h" #include "virstring.h"
#include "cpu/cpu_x86.h" #include "cpu/cpu_x86.h"
#include "c-strcasestr.h" #include "c-strcasestr.h"
#include "virenum.h"
#ifdef WITH_DTRACE_PROBES #ifdef WITH_DTRACE_PROBES
# include "libvirt_qemu_probes.h" # include "libvirt_qemu_probes.h"

View File

@ -49,6 +49,8 @@ UTIL_SOURCES = \
util/virebtables.c \ util/virebtables.c \
util/virebtables.h \ util/virebtables.h \
util/virendian.h \ util/virendian.h \
util/virenum.h \
util/virenum.c \
util/virerror.c \ util/virerror.c \
util/virerror.h \ util/virerror.h \
util/virerrorpriv.h \ util/virerrorpriv.h \

View File

@ -24,6 +24,7 @@
# include "virutil.h" # include "virutil.h"
# include "virbitmap.h" # include "virbitmap.h"
# include "virenum.h"
struct _virCgroup; struct _virCgroup;
typedef struct _virCgroup virCgroup; typedef struct _virCgroup virCgroup;

View File

@ -22,6 +22,7 @@
# define LIBVIRT_VIRCONF_H # define LIBVIRT_VIRCONF_H
# include "virutil.h" # include "virutil.h"
# include "virenum.h"
/** /**
* virConfType: * virConfType:

84
src/util/virenum.c Normal file
View File

@ -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];
}

80
src/util/virenum.h Normal file
View File

@ -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 */

View File

@ -31,6 +31,7 @@
#include "virutil.h" #include "virutil.h"
#include "virlog.h" #include "virlog.h"
#include "virdbus.h" #include "virdbus.h"
#include "virenum.h"
#define VIR_FROM_THIS VIR_FROM_FIREWALLD #define VIR_FROM_THIS VIR_FROM_FIREWALLD

View File

@ -22,6 +22,7 @@
# define LIBVIRT_VIRGIC_H # define LIBVIRT_VIRGIC_H
# include "virutil.h" # include "virutil.h"
# include "virenum.h"
typedef enum { typedef enum {
VIR_GIC_VERSION_NONE = 0, VIR_GIC_VERSION_NONE = 0,

View File

@ -30,6 +30,7 @@
#include "virstring.h" #include "virstring.h"
#include "virutil.h" #include "virutil.h"
#include "virbuffer.h" #include "virbuffer.h"
#include "virenum.h"
#if WITH_YAJL #if WITH_YAJL
# include <yajl/yajl_gen.h> # include <yajl/yajl_gen.h>

View File

@ -23,6 +23,7 @@
# define LIBVIRT_VIRKEYCODE_H # define LIBVIRT_VIRKEYCODE_H
# include "virutil.h" # include "virutil.h"
# include "virenum.h"
VIR_ENUM_DECL(virKeycodeSet); VIR_ENUM_DECL(virKeycodeSet);
int virKeycodeValueFromString(virKeycodeSet codeset, const char *keyname); int virKeycodeValueFromString(virKeycodeSet codeset, const char *keyname);

View File

@ -23,6 +23,7 @@
# include "virobject.h" # include "virobject.h"
# include "virutil.h" # include "virutil.h"
# include "virautoclean.h" # include "virautoclean.h"
# include "virenum.h"
typedef enum { typedef enum {
VIR_MDEV_MODEL_TYPE_VFIO_PCI = 0, VIR_MDEV_MODEL_TYPE_VFIO_PCI = 0,

View File

@ -27,6 +27,7 @@
# include "virpci.h" # include "virpci.h"
# include "virnetdevvlan.h" # include "virnetdevvlan.h"
# include "virautoclean.h" # include "virautoclean.h"
# include "virenum.h"
# ifdef HAVE_STRUCT_IFREQ # ifdef HAVE_STRUCT_IFREQ
typedef struct ifreq virIfreq; typedef struct ifreq virIfreq;

View File

@ -26,6 +26,7 @@
# include "virnetdevbandwidth.h" # include "virnetdevbandwidth.h"
# include "virnetdevvportprofile.h" # include "virnetdevvportprofile.h"
# include "virnetdevvlan.h" # include "virnetdevvlan.h"
# include "virenum.h"
/* the mode type for macvtap devices */ /* the mode type for macvtap devices */
typedef enum { typedef enum {

View File

@ -22,6 +22,7 @@
# include <virutil.h> # include <virutil.h>
# include "virautoclean.h" # include "virautoclean.h"
# include "virenum.h"
typedef enum { typedef enum {
VIR_NATIVE_VLAN_MODE_DEFAULT = 0, VIR_NATIVE_VLAN_MODE_DEFAULT = 0,

View File

@ -23,6 +23,7 @@
# include "viruuid.h" # include "viruuid.h"
# include "virutil.h" # include "virutil.h"
# include "virmacaddr.h" # include "virmacaddr.h"
# include "virenum.h"
# define LIBVIRT_IFLA_VF_PORT_PROFILE_MAX 40 # define LIBVIRT_IFLA_VF_PORT_PROFILE_MAX 40

View File

@ -26,6 +26,7 @@
# include "virobject.h" # include "virobject.h"
# include "virutil.h" # include "virutil.h"
# include "virautoclean.h" # include "virautoclean.h"
# include "virenum.h"
typedef struct _virPCIDevice virPCIDevice; typedef struct _virPCIDevice virPCIDevice;
typedef virPCIDevice *virPCIDevicePtr; typedef virPCIDevice *virPCIDevicePtr;

View File

@ -21,6 +21,7 @@
# include "virutil.h" # include "virutil.h"
# include "virautoclean.h" # include "virautoclean.h"
# include "virenum.h"
/* Some Intel processor families introduced some RDT (Resource Director /* Some Intel processor families introduced some RDT (Resource Director
* Technology) features to monitor or control shared resource based on * Technology) features to monitor or control shared resource based on

View File

@ -27,6 +27,7 @@
# include "internal.h" # include "internal.h"
# include "virbitmap.h" # include "virbitmap.h"
# include "virutil.h" # include "virutil.h"
# include "virenum.h"
typedef enum { typedef enum {
VIR_PROC_POLICY_NONE = 0, VIR_PROC_POLICY_NONE = 0,

View File

@ -23,7 +23,7 @@
# include "virbitmap.h" # include "virbitmap.h"
# include "virutil.h" # include "virutil.h"
# include "virenum.h"
typedef enum { typedef enum {
VIR_CACHE_TYPE_BOTH, VIR_CACHE_TYPE_BOTH,

View File

@ -26,6 +26,7 @@
# include "virutil.h" # include "virutil.h"
# include "virxml.h" # include "virxml.h"
# include "virenum.h"
VIR_ENUM_DECL(virSecretUsage); VIR_ENUM_DECL(virSecretUsage);

View File

@ -25,6 +25,7 @@
# include "virbuffer.h" # include "virbuffer.h"
# include "virsecret.h" # include "virsecret.h"
# include "virutil.h" # include "virutil.h"
# include "virenum.h"
# include <libxml/tree.h> # include <libxml/tree.h>

View File

@ -31,6 +31,7 @@
# include "virutil.h" # include "virutil.h"
# include "virsecret.h" # include "virsecret.h"
# include "virautoclean.h" # include "virautoclean.h"
# include "virenum.h"
/* Minimum header size required to probe all known formats with /* Minimum header size required to probe all known formats with
* virStorageFileProbeFormat, or obtain metadata from a known format. * virStorageFileProbeFormat, or obtain metadata from a known format.

View File

@ -25,6 +25,7 @@
# include "internal.h" # include "internal.h"
# include "virutil.h" # include "virutil.h"
# include "virbuffer.h" # include "virbuffer.h"
# include "virenum.h"
typedef enum { typedef enum {
VIR_SYSINFO_SMBIOS, VIR_SYSINFO_SMBIOS,

View File

@ -24,6 +24,7 @@
# include "internal.h" # include "internal.h"
# include "virutil.h" # include "virutil.h"
# include "virenum.h"
/** /**
* VIR_TYPED_PARAM_MULTIPLE: * VIR_TYPED_PARAM_MULTIPLE:

View File

@ -84,38 +84,6 @@ verify(sizeof(gid_t) <= sizeof(unsigned int) &&
VIR_LOG_INIT("util.util"); 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 #ifndef WIN32
@ -324,22 +292,6 @@ virParseVersionString(const char *str, unsigned long *version,
return 0; 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 * Format @val as a base-10 decimal number, in the
* buffer @buf of size @buflen. To allocate a suitable * 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]*$/ /* Translates a device name of the form (regex) /^[fhv]d[a-z]+[0-9]*$/
* into the corresponding index and partition number * into the corresponding index and partition number
* (e.g. sda0 => (0,0), hdz2 => (25,2), vdaa12 => (26,12)) * (e.g. sda0 => (0,0), hdz2 => (25,2), vdaa12 => (26,12))

View File

@ -68,32 +68,6 @@ int virDiskNameParse(const char *name, int *disk, int *partition);
int virDiskNameToIndex(const char* str); int virDiskNameToIndex(const char* str);
char *virIndexToDiskName(int idx, const char *prefix); 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. */ /* No-op workarounds for functionality missing in mingw. */
# ifndef HAVE_GETUID # ifndef HAVE_GETUID
static inline int getuid(void) static inline int getuid(void)
@ -176,34 +150,6 @@ bool virIsSUID(void);
time_t virGetSelfLastChanged(void); time_t virGetSelfLastChanged(void);
void virUpdateSelfLastChanged(const char *path); 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); unsigned int virGetListenFDs(void);
char *virGetUNIXSocketPath(int fd); char *virGetUNIXSocketPath(int fd);

View File

@ -26,6 +26,7 @@
# include "internal.h" # include "internal.h"
# include "virdomainobjlist.h" # include "virdomainobjlist.h"
# include "virthread.h" # include "virthread.h"
# include "virenum.h"
# define VIR_FROM_THIS VIR_FROM_VMWARE # define VIR_FROM_THIS VIR_FROM_VMWARE
# define PROGRAM_SENTINEL ((char *)0x1) # define PROGRAM_SENTINEL ((char *)0x1)

View File

@ -35,6 +35,7 @@
#include "virxml.h" #include "virxml.h"
#include "virstring.h" #include "virstring.h"
#include "vsh-table.h" #include "vsh-table.h"
#include "virenum.h"
VIR_ENUM_DECL(virshDomainIOError); VIR_ENUM_DECL(virshDomainIOError);
VIR_ENUM_IMPL(virshDomainIOError, VIR_ENUM_IMPL(virshDomainIOError,

View File

@ -55,6 +55,7 @@
#include "virsh-nodedev.h" #include "virsh-nodedev.h"
#include "viruri.h" #include "viruri.h"
#include "vsh-table.h" #include "vsh-table.h"
#include "virenum.h"
/* Gnulib doesn't guarantee SA_SIGINFO support. */ /* Gnulib doesn't guarantee SA_SIGINFO support. */
#ifndef SA_SIGINFO #ifndef SA_SIGINFO

View File

@ -34,6 +34,7 @@
#include "virtypedparam.h" #include "virtypedparam.h"
#include "virstring.h" #include "virstring.h"
#include "virfile.h" #include "virfile.h"
#include "virenum.h"
/* /*
* "capabilities" command * "capabilities" command

View File

@ -29,6 +29,7 @@
#include "virtime.h" #include "virtime.h"
#include "conf/network_conf.h" #include "conf/network_conf.h"
#include "vsh-table.h" #include "vsh-table.h"
#include "virenum.h"
#define VIRSH_COMMON_OPT_NETWORK(_helpstr, cflags) \ #define VIRSH_COMMON_OPT_NETWORK(_helpstr, cflags) \
{.name = "network", \ {.name = "network", \

View File

@ -28,6 +28,7 @@
#include "virstring.h" #include "virstring.h"
#include "virtime.h" #include "virtime.h"
#include "conf/node_device_conf.h" #include "conf/node_device_conf.h"
#include "virenum.h"
/* /*
* "nodedev-create" command * "nodedev-create" command

View File

@ -29,6 +29,7 @@
#include "virstring.h" #include "virstring.h"
#include "virtime.h" #include "virtime.h"
#include "vsh-table.h" #include "vsh-table.h"
#include "virenum.h"
#define VIRSH_COMMON_OPT_POOL_FULL(cflags) \ #define VIRSH_COMMON_OPT_POOL_FULL(cflags) \
VIRSH_COMMON_OPT_POOL(N_("pool name or uuid"), cflags) VIRSH_COMMON_OPT_POOL(N_("pool name or uuid"), cflags)

View File

@ -31,6 +31,7 @@
#include "virstring.h" #include "virstring.h"
#include "virtime.h" #include "virtime.h"
#include "vsh-table.h" #include "vsh-table.h"
#include "virenum.h"
static virSecretPtr static virSecretPtr
virshCommandOptSecret(vshControl *ctl, const vshCmd *cmd, const char **name) virshCommandOptSecret(vshControl *ctl, const vshCmd *cmd, const char **name)

View File

@ -38,6 +38,7 @@
#include "virxml.h" #include "virxml.h"
#include "virstring.h" #include "virstring.h"
#include "vsh-table.h" #include "vsh-table.h"
#include "virenum.h"
#define VIRSH_COMMON_OPT_POOL_FULL \ #define VIRSH_COMMON_OPT_POOL_FULL \
VIRSH_COMMON_OPT_POOL(N_("pool name or uuid"), \ VIRSH_COMMON_OPT_POOL(N_("pool name or uuid"), \

View File

@ -38,6 +38,7 @@
#include "virtime.h" #include "virtime.h"
#include "virt-admin-completer.h" #include "virt-admin-completer.h"
#include "vsh-table.h" #include "vsh-table.h"
#include "virenum.h"
/* Gnulib doesn't guarantee SA_SIGINFO support. */ /* Gnulib doesn't guarantee SA_SIGINFO support. */
#ifndef SA_SIGINFO #ifndef SA_SIGINFO

View File

@ -25,6 +25,7 @@
# include "internal.h" # include "internal.h"
# include "virutil.h" # include "virutil.h"
# include "virbitmap.h" # include "virbitmap.h"
# include "virenum.h"
typedef enum { typedef enum {
VIR_HOST_VALIDATE_FAIL, VIR_HOST_VALIDATE_FAIL,