[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] libxl: autogenerate to_string and from_string functions for Enumerations.



# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1308677199 -3600
# Node ID d67133289286751e9ab0844aedcf2bd0e643cfb3
# Parent  c2995f0555af9ab63495cd8c652c776460343fbb
libxl: autogenerate to_string and from_string functions for Enumerations.

The generated strings are the lower case enum value names, with underscores.
Accepted string for parsing are the same but are case insensitive.

We provide a table of strings->value for each Enumeration as well as a
convenience function to perform a lookup.

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
Acked-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
Committed-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---


diff -r c2995f0555af -r d67133289286 .hgignore
--- a/.hgignore Tue Jun 21 18:24:34 2011 +0100
+++ b/.hgignore Tue Jun 21 18:26:39 2011 +0100
@@ -187,6 +187,7 @@
 ^tools/libxl/_.*\.c$
 ^tools/libxl/libxlu_cfg_y\.output$
 ^tools/libxl/xl$
+^tools/libxl/testenum$
 ^tools/libaio/src/.*\.ol$
 ^tools/libaio/src/.*\.os$
 ^tools/misc/cpuperf/cpuperf-perfcntr$
diff -r c2995f0555af -r d67133289286 tools/libxl/Makefile
--- a/tools/libxl/Makefile      Tue Jun 21 18:24:34 2011 +0100
+++ b/tools/libxl/Makefile      Tue Jun 21 18:26:39 2011 +0100
@@ -44,12 +44,17 @@
 LIBXLU_OBJS = libxlu_cfg_y.o libxlu_cfg_l.o libxlu_cfg.o
 $(LIBXLU_OBJS): CFLAGS += $(CFLAGS_libxenctrl) # For xentoollog.h
 
-CLIENTS = xl
+CLIENTS = xl testenum
 
 XL_OBJS = xl.o xl_cmdimpl.o xl_cmdtable.o
 $(XL_OBJS): CFLAGS += $(CFLAGS_libxenctrl) # For xentoollog.h
 $(XL_OBJS): CFLAGS += $(CFLAGS_libxenlight)
 
+testenum.o: CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenlight)
+testenum.c: libxl.idl gentest.py
+       $(PYTHON) gentest.py libxl.idl testenum.c.new
+       mv testenum.c.new testenum.c
+
 .PHONY: all
 all: $(CLIENTS) libxenlight.so libxenlight.a libxlutil.so libxlutil.a \
        $(AUTOSRCS) $(AUTOINCS)
@@ -106,9 +111,12 @@
 libxlutil.a: $(LIBXLU_OBJS)
        $(AR) rcs libxlutil.a $^
 
-$(CLIENTS): $(XL_OBJS) libxlutil.so libxenlight.so
+xl: $(XL_OBJS) libxlutil.so libxenlight.so
        $(CC) $(LDFLAGS) -o $@ $(XL_OBJS) libxlutil.so $(LDLIBS_libxenlight) 
$(LDLIBS_libxenctrl)
 
+testenum: testenum.o libxlutil.so libxenlight.so
+       $(CC) $(LDFLAGS) -o $@ testenum.o libxlutil.so $(LDLIBS_libxenlight) 
$(LDLIBS_libxenctrl)
+
 .PHONY: install
 install: all
        $(INSTALL_DIR) $(DESTDIR)$(SBINDIR)
diff -r c2995f0555af -r d67133289286 tools/libxl/gentest.py
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/libxl/gentest.py    Tue Jun 21 18:26:39 2011 +0100
@@ -0,0 +1,63 @@
+#!/usr/bin/python
+
+import sys
+import re
+import random
+
+import libxltypes
+def randomize_char(c):
+    if random.random() < 0.5:
+        return str.lower(c)
+    else:
+        return str.upper(c)
+
+def randomize_case(s):
+    r = [randomize_char(c) for c in s]
+    return "".join(r)
+
+if __name__ == '__main__':
+    if len(sys.argv) < 3:
+        print >>sys.stderr, "Usage: gentest.py <idl> <implementation>"
+        sys.exit(1)
+
+    random.seed()
+    
+    idl = sys.argv[1]
+    (_,types) = libxltypes.parse(idl)
+                    
+    impl = sys.argv[2]
+    f = open(impl, "w")
+    f.write("""
+#include <stdio.h>
+#include \"libxl.h\"
+
+int main(int argc, char **argv)
+{
+""")
+
+    for ty in [t for t in types if isinstance(t,libxltypes.Enumeration)]:
+        f.write("    %s %s_val;\n" % (ty.typename, ty.typename))
+    f.write("    int rc;\n")
+    f.write("\n")
+                
+    for ty in [t for t in types if isinstance(t,libxltypes.Enumeration)]:
+        f.write("    printf(\"%s -- to string:\\n\");\n" % (ty.typename))
+        for v in ty.values:
+            f.write("    printf(\"\\t%s = %%d = \\\"%%s\\\"\\n\", %s, 
%s_to_string(%s));\n" %\
+                    (v.valuename, v.name, ty.typename, v.name))
+        f.write("\n")
+
+        f.write("    printf(\"%s -- from string:\\n\");\n" % (ty.typename))
+        for v in [v.valuename for v in ty.values] + ["AN INVALID VALUE"]:
+            n = randomize_case(v)
+            f.write("    %s_val = -1;\n" % (ty.typename))
+            f.write("    rc = %s_from_string(\"%s\", &%s_val);\n" %\
+                    (ty.typename, n, ty.typename))
+                    
+            f.write("    printf(\"\\t%s = \\\"%%s\\\" = %%d (rc %%d)\\n\", 
\"%s\", %s_val, rc);\n" %\
+                    (v, n, ty.typename))
+        f.write("\n")
+
+    f.write("""return 0;
+}
+""")
diff -r c2995f0555af -r d67133289286 tools/libxl/gentypes.py
--- a/tools/libxl/gentypes.py   Tue Jun 21 18:24:34 2011 +0100
+++ b/tools/libxl/gentypes.py   Tue Jun 21 18:26:39 2011 +0100
@@ -113,6 +113,43 @@
         s = indent + s
     return s.replace("\n", "\n%s" % indent).rstrip(indent)
 
+def libxl_C_enum_to_string(ty, e, indent = "    "):
+    s = ""
+    s += "switch(%s) {\n" % e
+    for v in ty.values:
+        s += "    case %s:\n" % (v.name)
+        s += "        return \"%s\";\n" % (v.valuename.lower())
+    s += "    default:\n "
+    s += "        return NULL;\n"
+    s += "}\n"
+
+    if s != "":
+        s = indent + s
+    return s.replace("\n", "\n%s" % indent).rstrip(indent)
+
+def libxl_C_enum_strings(ty, indent=""):
+    s = ""
+    s += "libxl_enum_string_table %s_string_table[] = {\n" % (ty.typename)
+    for v in ty.values:
+        s += "    { .s = \"%s\", .v = %s },\n" % (v.valuename.lower(), v.name)
+    s += "    { NULL, -1 },\n"
+    s += "};\n"
+    s += "\n"
+    
+    if s != "":
+        s = indent + s
+    return s.replace("\n", "\n%s" % indent).rstrip(indent)
+
+def libxl_C_enum_from_string(ty, str, e, indent = "    "):
+    s = ""
+    s += "return libxl__enum_from_string(%s_string_table,\n" % ty.typename
+    s += "                               %s, (int *)%s);\n" % (str, e)
+    
+    if s != "":
+        s = indent + s
+    return s.replace("\n", "\n%s" % indent).rstrip(indent)
+    
+
 if __name__ == '__main__':
     if len(sys.argv) < 4:
         print >>sys.stderr, "Usage: gentypes.py <idl> <header> 
<implementation>"
@@ -142,6 +179,10 @@
         f.write(libxl_C_type_define(ty) + ";\n")
         if ty.destructor_fn is not None:
             f.write("void %s(%s *p);\n" % (ty.destructor_fn, ty.typename))
+        if isinstance(ty, libxltypes.Enumeration):
+            f.write("const char *%s_to_string(%s e);\n" % (ty.typename, 
ty.typename))
+            f.write("int %s_from_string(const char *s, %s *e);\n" % 
(ty.typename, ty.typename))
+            f.write("extern libxl_enum_string_table %s_string_table[];\n" % 
(ty.typename))
         f.write("\n")
 
     f.write("""#endif /* __LIBXL_TYPES_H */\n""")
@@ -165,6 +206,7 @@
 #include <string.h>
 
 #include "libxl.h"
+#include "libxl_internal.h"
 
 #define LIBXL_DTOR_POISON 0xa5
 
@@ -177,4 +219,21 @@
         f.write("    memset(p, LIBXL_DTOR_POISON, sizeof(*p));\n")
         f.write("}\n")
         f.write("\n")
+
+    for ty in [t for t in types if isinstance(t,libxltypes.Enumeration)]:
+        f.write("const char *%s_to_string(%s e)\n" % (ty.typename, 
ty.typename))
+        f.write("{\n")
+        f.write(libxl_C_enum_to_string(ty, "e"))
+        f.write("}\n")
+        f.write("\n")
+
+        f.write(libxl_C_enum_strings(ty))               
+
+        f.write("int %s_from_string(const char *s, %s *e)\n" % (ty.typename, 
ty.typename))
+        f.write("{\n")
+        f.write(libxl_C_enum_from_string(ty, "s", "e"))               
+        f.write("}\n")
+        f.write("\n")
+
+
     f.close()
diff -r c2995f0555af -r d67133289286 tools/libxl/libxl.h
--- a/tools/libxl/libxl.h       Tue Jun 21 18:24:34 2011 +0100
+++ b/tools/libxl/libxl.h       Tue Jun 21 18:26:39 2011 +0100
@@ -185,6 +185,17 @@
 
 typedef uint32_t libxl_domid;
 
+/*
+ * Formatting Enumerations.
+ *
+ * Each enumeration type libxl_E declares an associated lookup table
+ * libxl_E_string_table and a lookup function libxl_E_from_string.
+ */
+typedef struct {
+    const char *s;
+    int v;
+} libxl_enum_string_table;
+
 #include "_libxl_types.h"
 
 typedef struct libxl__ctx libxl_ctx;
diff -r c2995f0555af -r d67133289286 tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h      Tue Jun 21 18:24:34 2011 +0100
+++ b/tools/libxl/libxl_internal.h      Tue Jun 21 18:26:39 2011 +0100
@@ -325,6 +325,8 @@
 _hidden char *libxl__domid_to_name(libxl__gc *gc, uint32_t domid);
 _hidden char *libxl__cpupoolid_to_name(libxl__gc *gc, uint32_t poolid);
 
+_hidden int libxl__enum_from_string(const libxl_enum_string_table *t,
+                                    const char *s, int *e);
 
   /* holds the CPUID response for a single CPUID leaf
    * input contains the value of the EAX and ECX register,
diff -r c2995f0555af -r d67133289286 tools/libxl/libxl_utils.c
--- a/tools/libxl/libxl_utils.c Tue Jun 21 18:24:34 2011 +0100
+++ b/tools/libxl/libxl_utils.c Tue Jun 21 18:26:39 2011 +0100
@@ -639,3 +639,17 @@
 {
     return xc_get_max_cpus(ctx->xch);
 }
+
+int libxl__enum_from_string(const libxl_enum_string_table *t,
+                            const char *s, int *e)
+{
+    if (!t) return ERROR_INVAL;
+
+    for( ; t->s; t++) {
+        if (!strcasecmp(t->s, s)) {
+                *e = t->v;
+                return 0;
+        }
+    }
+    return ERROR_FAIL;
+}
diff -r c2995f0555af -r d67133289286 tools/libxl/testenum.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/libxl/testenum.c    Tue Jun 21 18:26:39 2011 +0100
@@ -0,0 +1,210 @@
+
+#include <stdio.h>
+#include "libxl.h"
+
+int main(int argc, char **argv)
+{
+    libxl_domain_type libxl_domain_type_val;
+    libxl_device_model_version libxl_device_model_version_val;
+    libxl_console_type libxl_console_type_val;
+    libxl_console_backend libxl_console_backend_val;
+    libxl_disk_format libxl_disk_format_val;
+    libxl_disk_backend libxl_disk_backend_val;
+    libxl_nic_type libxl_nic_type_val;
+    libxl_action_on_shutdown libxl_action_on_shutdown_val;
+    libxl_event_type libxl_event_type_val;
+    libxl_button libxl_button_val;
+    int rc;
+
+    printf("libxl_domain_type -- to string:\n");
+    printf("\tFV = %d = \"%s\"\n", LIBXL_DOMAIN_TYPE_FV, 
libxl_domain_type_to_string(LIBXL_DOMAIN_TYPE_FV));
+    printf("\tPV = %d = \"%s\"\n", LIBXL_DOMAIN_TYPE_PV, 
libxl_domain_type_to_string(LIBXL_DOMAIN_TYPE_PV));
+
+    printf("libxl_domain_type -- from string:\n");
+    libxl_domain_type_val = -1;
+    rc = libxl_domain_type_from_string("FV", &libxl_domain_type_val);
+    printf("\tFV = \"%s\" = %d (rc %d)\n", "FV", libxl_domain_type_val, rc);
+    libxl_domain_type_val = -1;
+    rc = libxl_domain_type_from_string("pV", &libxl_domain_type_val);
+    printf("\tPV = \"%s\" = %d (rc %d)\n", "pV", libxl_domain_type_val, rc);
+    libxl_domain_type_val = -1;
+    rc = libxl_domain_type_from_string("an InVALId VALUE", 
&libxl_domain_type_val);
+    printf("\tAN INVALID VALUE = \"%s\" = %d (rc %d)\n", "an InVALId VALUE", 
libxl_domain_type_val, rc);
+
+    printf("libxl_device_model_version -- to string:\n");
+    printf("\tQEMU_XEN_TRADITIONAL = %d = \"%s\"\n", 
LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL, 
libxl_device_model_version_to_string(LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL));
+    printf("\tQEMU_XEN = %d = \"%s\"\n", LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN, 
libxl_device_model_version_to_string(LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN));
+
+    printf("libxl_device_model_version -- from string:\n");
+    libxl_device_model_version_val = -1;
+    rc = libxl_device_model_version_from_string("QEmU_Xen_TrAdiTioNAl", 
&libxl_device_model_version_val);
+    printf("\tQEMU_XEN_TRADITIONAL = \"%s\" = %d (rc %d)\n", 
"QEmU_Xen_TrAdiTioNAl", libxl_device_model_version_val, rc);
+    libxl_device_model_version_val = -1;
+    rc = libxl_device_model_version_from_string("QemU_xen", 
&libxl_device_model_version_val);
+    printf("\tQEMU_XEN = \"%s\" = %d (rc %d)\n", "QemU_xen", 
libxl_device_model_version_val, rc);
+    libxl_device_model_version_val = -1;
+    rc = libxl_device_model_version_from_string("aN InVALiD vaLUE", 
&libxl_device_model_version_val);
+    printf("\tAN INVALID VALUE = \"%s\" = %d (rc %d)\n", "aN InVALiD vaLUE", 
libxl_device_model_version_val, rc);
+
+    printf("libxl_console_type -- to string:\n");
+    printf("\tSERIAL = %d = \"%s\"\n", LIBXL_CONSOLE_TYPE_SERIAL, 
libxl_console_type_to_string(LIBXL_CONSOLE_TYPE_SERIAL));
+    printf("\tPV = %d = \"%s\"\n", LIBXL_CONSOLE_TYPE_PV, 
libxl_console_type_to_string(LIBXL_CONSOLE_TYPE_PV));
+
+    printf("libxl_console_type -- from string:\n");
+    libxl_console_type_val = -1;
+    rc = libxl_console_type_from_string("SErIaL", &libxl_console_type_val);
+    printf("\tSERIAL = \"%s\" = %d (rc %d)\n", "SErIaL", 
libxl_console_type_val, rc);
+    libxl_console_type_val = -1;
+    rc = libxl_console_type_from_string("pv", &libxl_console_type_val);
+    printf("\tPV = \"%s\" = %d (rc %d)\n", "pv", libxl_console_type_val, rc);
+    libxl_console_type_val = -1;
+    rc = libxl_console_type_from_string("An InvAlID valuE", 
&libxl_console_type_val);
+    printf("\tAN INVALID VALUE = \"%s\" = %d (rc %d)\n", "An InvAlID valuE", 
libxl_console_type_val, rc);
+
+    printf("libxl_console_backend -- to string:\n");
+    printf("\tXENCONSOLED = %d = \"%s\"\n", LIBXL_CONSOLE_BACKEND_XENCONSOLED, 
libxl_console_backend_to_string(LIBXL_CONSOLE_BACKEND_XENCONSOLED));
+    printf("\tIOEMU = %d = \"%s\"\n", LIBXL_CONSOLE_BACKEND_IOEMU, 
libxl_console_backend_to_string(LIBXL_CONSOLE_BACKEND_IOEMU));
+
+    printf("libxl_console_backend -- from string:\n");
+    libxl_console_backend_val = -1;
+    rc = libxl_console_backend_from_string("XENCoNSoleD", 
&libxl_console_backend_val);
+    printf("\tXENCONSOLED = \"%s\" = %d (rc %d)\n", "XENCoNSoleD", 
libxl_console_backend_val, rc);
+    libxl_console_backend_val = -1;
+    rc = libxl_console_backend_from_string("iOEmU", 
&libxl_console_backend_val);
+    printf("\tIOEMU = \"%s\" = %d (rc %d)\n", "iOEmU", 
libxl_console_backend_val, rc);
+    libxl_console_backend_val = -1;
+    rc = libxl_console_backend_from_string("an INvAliD VALuE", 
&libxl_console_backend_val);
+    printf("\tAN INVALID VALUE = \"%s\" = %d (rc %d)\n", "an INvAliD VALuE", 
libxl_console_backend_val, rc);
+
+    printf("libxl_disk_format -- to string:\n");
+    printf("\tUNKNOWN = %d = \"%s\"\n", LIBXL_DISK_FORMAT_UNKNOWN, 
libxl_disk_format_to_string(LIBXL_DISK_FORMAT_UNKNOWN));
+    printf("\tQCOW = %d = \"%s\"\n", LIBXL_DISK_FORMAT_QCOW, 
libxl_disk_format_to_string(LIBXL_DISK_FORMAT_QCOW));
+    printf("\tQCOW2 = %d = \"%s\"\n", LIBXL_DISK_FORMAT_QCOW2, 
libxl_disk_format_to_string(LIBXL_DISK_FORMAT_QCOW2));
+    printf("\tVHD = %d = \"%s\"\n", LIBXL_DISK_FORMAT_VHD, 
libxl_disk_format_to_string(LIBXL_DISK_FORMAT_VHD));
+    printf("\tRAW = %d = \"%s\"\n", LIBXL_DISK_FORMAT_RAW, 
libxl_disk_format_to_string(LIBXL_DISK_FORMAT_RAW));
+    printf("\tEMPTY = %d = \"%s\"\n", LIBXL_DISK_FORMAT_EMPTY, 
libxl_disk_format_to_string(LIBXL_DISK_FORMAT_EMPTY));
+
+    printf("libxl_disk_format -- from string:\n");
+    libxl_disk_format_val = -1;
+    rc = libxl_disk_format_from_string("uNKnOWn", &libxl_disk_format_val);
+    printf("\tUNKNOWN = \"%s\" = %d (rc %d)\n", "uNKnOWn", 
libxl_disk_format_val, rc);
+    libxl_disk_format_val = -1;
+    rc = libxl_disk_format_from_string("QcoW", &libxl_disk_format_val);
+    printf("\tQCOW = \"%s\" = %d (rc %d)\n", "QcoW", libxl_disk_format_val, 
rc);
+    libxl_disk_format_val = -1;
+    rc = libxl_disk_format_from_string("qcOW2", &libxl_disk_format_val);
+    printf("\tQCOW2 = \"%s\" = %d (rc %d)\n", "qcOW2", libxl_disk_format_val, 
rc);
+    libxl_disk_format_val = -1;
+    rc = libxl_disk_format_from_string("vhd", &libxl_disk_format_val);
+    printf("\tVHD = \"%s\" = %d (rc %d)\n", "vhd", libxl_disk_format_val, rc);
+    libxl_disk_format_val = -1;
+    rc = libxl_disk_format_from_string("raw", &libxl_disk_format_val);
+    printf("\tRAW = \"%s\" = %d (rc %d)\n", "raw", libxl_disk_format_val, rc);
+    libxl_disk_format_val = -1;
+    rc = libxl_disk_format_from_string("EmpTy", &libxl_disk_format_val);
+    printf("\tEMPTY = \"%s\" = %d (rc %d)\n", "EmpTy", libxl_disk_format_val, 
rc);
+    libxl_disk_format_val = -1;
+    rc = libxl_disk_format_from_string("aN INvAlId vAluE", 
&libxl_disk_format_val);
+    printf("\tAN INVALID VALUE = \"%s\" = %d (rc %d)\n", "aN INvAlId vAluE", 
libxl_disk_format_val, rc);
+
+    printf("libxl_disk_backend -- to string:\n");
+    printf("\tUNKNOWN = %d = \"%s\"\n", LIBXL_DISK_BACKEND_UNKNOWN, 
libxl_disk_backend_to_string(LIBXL_DISK_BACKEND_UNKNOWN));
+    printf("\tPHY = %d = \"%s\"\n", LIBXL_DISK_BACKEND_PHY, 
libxl_disk_backend_to_string(LIBXL_DISK_BACKEND_PHY));
+    printf("\tTAP = %d = \"%s\"\n", LIBXL_DISK_BACKEND_TAP, 
libxl_disk_backend_to_string(LIBXL_DISK_BACKEND_TAP));
+    printf("\tQDISK = %d = \"%s\"\n", LIBXL_DISK_BACKEND_QDISK, 
libxl_disk_backend_to_string(LIBXL_DISK_BACKEND_QDISK));
+
+    printf("libxl_disk_backend -- from string:\n");
+    libxl_disk_backend_val = -1;
+    rc = libxl_disk_backend_from_string("unKNOWN", &libxl_disk_backend_val);
+    printf("\tUNKNOWN = \"%s\" = %d (rc %d)\n", "unKNOWN", 
libxl_disk_backend_val, rc);
+    libxl_disk_backend_val = -1;
+    rc = libxl_disk_backend_from_string("pHY", &libxl_disk_backend_val);
+    printf("\tPHY = \"%s\" = %d (rc %d)\n", "pHY", libxl_disk_backend_val, rc);
+    libxl_disk_backend_val = -1;
+    rc = libxl_disk_backend_from_string("taP", &libxl_disk_backend_val);
+    printf("\tTAP = \"%s\" = %d (rc %d)\n", "taP", libxl_disk_backend_val, rc);
+    libxl_disk_backend_val = -1;
+    rc = libxl_disk_backend_from_string("QdIsK", &libxl_disk_backend_val);
+    printf("\tQDISK = \"%s\" = %d (rc %d)\n", "QdIsK", libxl_disk_backend_val, 
rc);
+    libxl_disk_backend_val = -1;
+    rc = libxl_disk_backend_from_string("AN InValID VALue", 
&libxl_disk_backend_val);
+    printf("\tAN INVALID VALUE = \"%s\" = %d (rc %d)\n", "AN InValID VALue", 
libxl_disk_backend_val, rc);
+
+    printf("libxl_nic_type -- to string:\n");
+    printf("\tIOEMU = %d = \"%s\"\n", LIBXL_NIC_TYPE_IOEMU, 
libxl_nic_type_to_string(LIBXL_NIC_TYPE_IOEMU));
+    printf("\tVIF = %d = \"%s\"\n", LIBXL_NIC_TYPE_VIF, 
libxl_nic_type_to_string(LIBXL_NIC_TYPE_VIF));
+
+    printf("libxl_nic_type -- from string:\n");
+    libxl_nic_type_val = -1;
+    rc = libxl_nic_type_from_string("ioemU", &libxl_nic_type_val);
+    printf("\tIOEMU = \"%s\" = %d (rc %d)\n", "ioemU", libxl_nic_type_val, rc);
+    libxl_nic_type_val = -1;
+    rc = libxl_nic_type_from_string("vIf", &libxl_nic_type_val);
+    printf("\tVIF = \"%s\" = %d (rc %d)\n", "vIf", libxl_nic_type_val, rc);
+    libxl_nic_type_val = -1;
+    rc = libxl_nic_type_from_string("aN invAlid vaLuE", &libxl_nic_type_val);
+    printf("\tAN INVALID VALUE = \"%s\" = %d (rc %d)\n", "aN invAlid vaLuE", 
libxl_nic_type_val, rc);
+
+    printf("libxl_action_on_shutdown -- to string:\n");
+    printf("\tDESTROY = %d = \"%s\"\n", LIBXL_ACTION_ON_SHUTDOWN_DESTROY, 
libxl_action_on_shutdown_to_string(LIBXL_ACTION_ON_SHUTDOWN_DESTROY));
+    printf("\tRESTART = %d = \"%s\"\n", LIBXL_ACTION_ON_SHUTDOWN_RESTART, 
libxl_action_on_shutdown_to_string(LIBXL_ACTION_ON_SHUTDOWN_RESTART));
+    printf("\tRESTART_RENAME = %d = \"%s\"\n", 
LIBXL_ACTION_ON_SHUTDOWN_RESTART_RENAME, 
libxl_action_on_shutdown_to_string(LIBXL_ACTION_ON_SHUTDOWN_RESTART_RENAME));
+    printf("\tPRESERVE = %d = \"%s\"\n", LIBXL_ACTION_ON_SHUTDOWN_PRESERVE, 
libxl_action_on_shutdown_to_string(LIBXL_ACTION_ON_SHUTDOWN_PRESERVE));
+    printf("\tCOREDUMP_DESTROY = %d = \"%s\"\n", 
LIBXL_ACTION_ON_SHUTDOWN_COREDUMP_DESTROY, 
libxl_action_on_shutdown_to_string(LIBXL_ACTION_ON_SHUTDOWN_COREDUMP_DESTROY));
+    printf("\tCOREDUMP_RESTART = %d = \"%s\"\n", 
LIBXL_ACTION_ON_SHUTDOWN_COREDUMP_RESTART, 
libxl_action_on_shutdown_to_string(LIBXL_ACTION_ON_SHUTDOWN_COREDUMP_RESTART));
+
+    printf("libxl_action_on_shutdown -- from string:\n");
+    libxl_action_on_shutdown_val = -1;
+    rc = libxl_action_on_shutdown_from_string("DESTRoy", 
&libxl_action_on_shutdown_val);
+    printf("\tDESTROY = \"%s\" = %d (rc %d)\n", "DESTRoy", 
libxl_action_on_shutdown_val, rc);
+    libxl_action_on_shutdown_val = -1;
+    rc = libxl_action_on_shutdown_from_string("rEsTarT", 
&libxl_action_on_shutdown_val);
+    printf("\tRESTART = \"%s\" = %d (rc %d)\n", "rEsTarT", 
libxl_action_on_shutdown_val, rc);
+    libxl_action_on_shutdown_val = -1;
+    rc = libxl_action_on_shutdown_from_string("rEsTart_RenAmE", 
&libxl_action_on_shutdown_val);
+    printf("\tRESTART_RENAME = \"%s\" = %d (rc %d)\n", "rEsTart_RenAmE", 
libxl_action_on_shutdown_val, rc);
+    libxl_action_on_shutdown_val = -1;
+    rc = libxl_action_on_shutdown_from_string("pRESeRve", 
&libxl_action_on_shutdown_val);
+    printf("\tPRESERVE = \"%s\" = %d (rc %d)\n", "pRESeRve", 
libxl_action_on_shutdown_val, rc);
+    libxl_action_on_shutdown_val = -1;
+    rc = libxl_action_on_shutdown_from_string("CoRedUMp_DEsTROy", 
&libxl_action_on_shutdown_val);
+    printf("\tCOREDUMP_DESTROY = \"%s\" = %d (rc %d)\n", "CoRedUMp_DEsTROy", 
libxl_action_on_shutdown_val, rc);
+    libxl_action_on_shutdown_val = -1;
+    rc = libxl_action_on_shutdown_from_string("coREDUMp_RestArt", 
&libxl_action_on_shutdown_val);
+    printf("\tCOREDUMP_RESTART = \"%s\" = %d (rc %d)\n", "coREDUMp_RestArt", 
libxl_action_on_shutdown_val, rc);
+    libxl_action_on_shutdown_val = -1;
+    rc = libxl_action_on_shutdown_from_string("An InvAliD valUe", 
&libxl_action_on_shutdown_val);
+    printf("\tAN INVALID VALUE = \"%s\" = %d (rc %d)\n", "An InvAliD valUe", 
libxl_action_on_shutdown_val, rc);
+
+    printf("libxl_event_type -- to string:\n");
+    printf("\tDOMAIN_DEATH = %d = \"%s\"\n", LIBXL_EVENT_TYPE_DOMAIN_DEATH, 
libxl_event_type_to_string(LIBXL_EVENT_TYPE_DOMAIN_DEATH));
+    printf("\tDISK_EJECT = %d = \"%s\"\n", LIBXL_EVENT_TYPE_DISK_EJECT, 
libxl_event_type_to_string(LIBXL_EVENT_TYPE_DISK_EJECT));
+
+    printf("libxl_event_type -- from string:\n");
+    libxl_event_type_val = -1;
+    rc = libxl_event_type_from_string("doMAIN_DeAth", &libxl_event_type_val);
+    printf("\tDOMAIN_DEATH = \"%s\" = %d (rc %d)\n", "doMAIN_DeAth", 
libxl_event_type_val, rc);
+    libxl_event_type_val = -1;
+    rc = libxl_event_type_from_string("DIsk_EJECT", &libxl_event_type_val);
+    printf("\tDISK_EJECT = \"%s\" = %d (rc %d)\n", "DIsk_EJECT", 
libxl_event_type_val, rc);
+    libxl_event_type_val = -1;
+    rc = libxl_event_type_from_string("aN INVAlID Value", 
&libxl_event_type_val);
+    printf("\tAN INVALID VALUE = \"%s\" = %d (rc %d)\n", "aN INVAlID Value", 
libxl_event_type_val, rc);
+
+    printf("libxl_button -- to string:\n");
+    printf("\tPOWER = %d = \"%s\"\n", LIBXL_BUTTON_POWER, 
libxl_button_to_string(LIBXL_BUTTON_POWER));
+    printf("\tSLEEP = %d = \"%s\"\n", LIBXL_BUTTON_SLEEP, 
libxl_button_to_string(LIBXL_BUTTON_SLEEP));
+
+    printf("libxl_button -- from string:\n");
+    libxl_button_val = -1;
+    rc = libxl_button_from_string("poWer", &libxl_button_val);
+    printf("\tPOWER = \"%s\" = %d (rc %d)\n", "poWer", libxl_button_val, rc);
+    libxl_button_val = -1;
+    rc = libxl_button_from_string("SLEEP", &libxl_button_val);
+    printf("\tSLEEP = \"%s\" = %d (rc %d)\n", "SLEEP", libxl_button_val, rc);
+    libxl_button_val = -1;
+    rc = libxl_button_from_string("An InvAlid VALUe", &libxl_button_val);
+    printf("\tAN INVALID VALUE = \"%s\" = %d (rc %d)\n", "An InvAlid VALUe", 
libxl_button_val, rc);
+
+return 0;
+}

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.