提交 f81a7021 编写于 作者: M Michal Privoznik

virConfType: switch to VIR_ENUM_{DECL,IMPL}

There's no need to implement ToString() function like we do if we
can use our shiny macros.
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
上级 4523b776
...@@ -123,8 +123,8 @@ checkType(virConfValuePtr p, const char *filename, ...@@ -123,8 +123,8 @@ checkType(virConfValuePtr p, const char *filename,
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("remoteReadConfigFile: %s: %s: invalid type:" _("remoteReadConfigFile: %s: %s: invalid type:"
" got %s; expected %s"), filename, key, " got %s; expected %s"), filename, key,
virConfTypeName(p->type), virConfTypeToString(p->type),
virConfTypeName(required_type)); virConfTypeToString(required_type));
return -1; return -1;
} }
return 0; return 0;
......
...@@ -1211,6 +1211,8 @@ virConfNew; ...@@ -1211,6 +1211,8 @@ virConfNew;
virConfReadFile; virConfReadFile;
virConfReadMem; virConfReadMem;
virConfSetValue; virConfSetValue;
virConfTypeFromString;
virConfTypeToString;
virConfWalk; virConfWalk;
virConfWriteFile; virConfWriteFile;
virConfWriteMem; virConfWriteMem;
......
...@@ -47,8 +47,8 @@ checkType(virConfValuePtr p, const char *filename, ...@@ -47,8 +47,8 @@ checkType(virConfValuePtr p, const char *filename,
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("remoteReadConfigFile: %s: %s: invalid type:" _("remoteReadConfigFile: %s: %s: invalid type:"
" got %s; expected %s"), filename, key, " got %s; expected %s"), filename, key,
virConfTypeName(p->type), virConfTypeToString(p->type),
virConfTypeName(required_type)); virConfTypeToString(required_type));
return -1; return -1;
} }
return 0; return 0;
......
...@@ -80,6 +80,12 @@ struct _virConfParserCtxt { ...@@ -80,6 +80,12 @@ struct _virConfParserCtxt {
* * * *
************************************************************************/ ************************************************************************/
VIR_ENUM_IMPL(virConf, VIR_CONF_LAST,
"*unexpected*",
"long",
"string",
"list");
typedef struct _virConfEntry virConfEntry; typedef struct _virConfEntry virConfEntry;
typedef virConfEntry *virConfEntryPtr; typedef virConfEntry *virConfEntryPtr;
......
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
#ifndef __VIR_CONF_H__ #ifndef __VIR_CONF_H__
# define __VIR_CONF_H__ # define __VIR_CONF_H__
# include "virutil.h"
/** /**
* virConfType: * virConfType:
* one of the possible type for a value from the configuration file * one of the possible type for a value from the configuration file
...@@ -30,12 +32,15 @@ ...@@ -30,12 +32,15 @@
* TODO: we probably need a float too. * TODO: we probably need a float too.
*/ */
typedef enum { typedef enum {
VIR_CONF_NONE = 0, /* undefined */ VIR_CONF_NONE = 0, /* undefined */
VIR_CONF_LONG = 1, /* a long int */ VIR_CONF_LONG, /* a long int */
VIR_CONF_STRING = 2, /* a string */ VIR_CONF_STRING, /* a string */
VIR_CONF_LIST = 3 /* a list */ VIR_CONF_LIST, /* a list */
VIR_CONF_LAST, /* sentinel */
} virConfType; } virConfType;
VIR_ENUM_DECL(virConf)
typedef enum { typedef enum {
VIR_CONF_FLAG_VMX_FORMAT = 1, /* allow ':', '.' and '-' in names for compatibility VIR_CONF_FLAG_VMX_FORMAT = 1, /* allow ':', '.' and '-' in names for compatibility
with VMware VMX configuration file, but restrict with VMware VMX configuration file, but restrict
...@@ -45,21 +50,6 @@ typedef enum { ...@@ -45,21 +50,6 @@ typedef enum {
to string only and don't expect quotes for values */ to string only and don't expect quotes for values */
} virConfFlags; } virConfFlags;
static inline const char *
virConfTypeName (virConfType t)
{
switch (t) {
case VIR_CONF_LONG:
return "long";
case VIR_CONF_STRING:
return "string";
case VIR_CONF_LIST:
return "list";
default:
return "*unexpected*";
}
}
/** /**
* virConfValue: * virConfValue:
* a value from the configuration file * a value from the configuration file
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册