]> xenbits.xensource.com Git - libvirt.git/commitdiff
virConfType: switch to VIR_ENUM_{DECL,IMPL}
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 9 Dec 2014 13:53:28 +0000 (14:53 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 15 Dec 2014 09:34:18 +0000 (10:34 +0100)
There's no need to implement ToString() function like we do if we
can use our shiny macros.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
daemon/libvirtd-config.c
src/libvirt_private.syms
src/locking/lock_daemon_config.c
src/util/virconf.c
src/util/virconf.h

index c31ef1641ea2d4d44e99269770efa8ed591b74f4..929dd1a222d4940f179c490943d6f9efba7ca934 100644 (file)
@@ -123,8 +123,8 @@ checkType(virConfValuePtr p, const char *filename,
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("remoteReadConfigFile: %s: %s: invalid type:"
                          " got %s; expected %s"), filename, key,
-                       virConfTypeName(p->type),
-                       virConfTypeName(required_type));
+                       virConfTypeToString(p->type),
+                       virConfTypeToString(required_type));
         return -1;
     }
     return 0;
index 6df27848ed922eaa516b611f025bd3624f51e306..57cf4d356ef69d619860d2327ed230facc2ce380 100644 (file)
@@ -1211,6 +1211,8 @@ virConfNew;
 virConfReadFile;
 virConfReadMem;
 virConfSetValue;
+virConfTypeFromString;
+virConfTypeToString;
 virConfWalk;
 virConfWriteFile;
 virConfWriteMem;
index 62b8b025e55359c2705f5f2259d4d42bc31d3f9a..abe6abae94569a4e4f8a5db2279fd96a7772dc64 100644 (file)
@@ -47,8 +47,8 @@ checkType(virConfValuePtr p, const char *filename,
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("remoteReadConfigFile: %s: %s: invalid type:"
                          " got %s; expected %s"), filename, key,
-                       virConfTypeName(p->type),
-                       virConfTypeName(required_type));
+                       virConfTypeToString(p->type),
+                       virConfTypeToString(required_type));
         return -1;
     }
     return 0;
index 74e695a894522d756c8b36adb3c3382c3e3c1828..5b4b4c3cbfa671e2874d7ae76d83bb670d030d5c 100644 (file)
@@ -80,6 +80,12 @@ struct _virConfParserCtxt {
  *                                                                     *
  ************************************************************************/
 
+VIR_ENUM_IMPL(virConf, VIR_CONF_LAST,
+              "*unexpected*",
+              "long",
+              "string",
+              "list");
+
 typedef struct _virConfEntry virConfEntry;
 typedef virConfEntry *virConfEntryPtr;
 
index 2a6b050d981212ff47286fb08fbee7255b6f2906..6176d431632baac013d4ef1dfd151df92ab310d0 100644 (file)
@@ -23,6 +23,8 @@
 #ifndef __VIR_CONF_H__
 # define __VIR_CONF_H__
 
+# include "virutil.h"
+
 /**
  * virConfType:
  * one of the possible type for a value from the configuration file
  * TODO: we probably need a float too.
  */
 typedef enum {
-    VIR_CONF_NONE = 0,         /* undefined */
-    VIR_CONF_LONG = 1,         /* a long int */
-    VIR_CONF_STRING = 2,       /* a string */
-    VIR_CONF_LIST = 3          /* a list */
+    VIR_CONF_NONE = 0,      /* undefined */
+    VIR_CONF_LONG,          /* a long int */
+    VIR_CONF_STRING,        /* a string */
+    VIR_CONF_LIST,          /* a list */
+    VIR_CONF_LAST,          /* sentinel */
 } virConfType;
 
+VIR_ENUM_DECL(virConf)
+
 typedef enum {
     VIR_CONF_FLAG_VMX_FORMAT = 1,  /* allow ':', '.' and '-' in names for compatibility
                                       with VMware VMX configuration file, but restrict
@@ -45,21 +50,6 @@ typedef enum {
                                       to string only and don't expect quotes for values */
 } 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:
  * a value from the configuration file