WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] tools: libxl: add an Enumeration type to

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] tools: libxl: add an Enumeration type to the IDL
From: Xen patchbot-unstable <patchbot@xxxxxxx>
Date: Fri, 29 Apr 2011 01:55:15 +0100
Delivery-date: Thu, 28 Apr 2011 17:56:59 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1303315987 -3600
# Node ID 9d48dd43cd3b83802b94903aef5501126c3eff3f
# Parent  6d617996f5c13e7f3e429a8f565e608307a9fd38
tools: libxl: add an Enumeration type to the IDL

The IDL requires a specific value for each enumerate, this make it
much easier to avoid (or at least track) ABI changes since they must
now be explicit.

I believe I have used the same values as would have been chosen
previoulsy but have not confirmed.

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


diff -r 6d617996f5c1 -r 9d48dd43cd3b tools/libxl/gentypes.py
--- a/tools/libxl/gentypes.py   Wed Apr 20 17:13:07 2011 +0100
+++ b/tools/libxl/gentypes.py   Wed Apr 20 17:13:07 2011 +0100
@@ -34,7 +34,28 @@
 
 def libxl_C_type_define(ty, indent = ""):
     s = ""
-    if isinstance(ty, libxltypes.Aggregate):
+
+    if isinstance(ty, libxltypes.Enumeration):
+        if ty.comment is not None:
+            s += format_comment(0, ty.comment)
+        
+        if ty.typename is None:
+            s += "enum {\n"
+        else:
+            s += "typedef enum %s {\n" % ty.typename
+
+        for v in ty.values:
+            if v.comment is not None:
+                s += format_comment(4, v.comment)
+            x = "%s = %d" % (v.name, v.value)
+            x = x.replace("\n", "\n    ")
+            s += "    " + x + ",\n"
+        if ty.typename is None:
+            s += "}"
+        else:
+            s += "} %s" % ty.typename
+
+    elif isinstance(ty, libxltypes.Aggregate):
         if ty.comment is not None:
             s += format_comment(0, ty.comment)
 
diff -r 6d617996f5c1 -r 9d48dd43cd3b tools/libxl/idl.txt
--- a/tools/libxl/idl.txt       Wed Apr 20 17:13:07 2011 +0100
+++ b/tools/libxl/idl.txt       Wed Apr 20 17:13:07 2011 +0100
@@ -82,6 +82,30 @@
 Complex type-Classes
 --------------------
 
+libxltype.Enumeration
+
+  A class representing an enumeration (named integer values).
+
+  The values are available in the list Enumeration.values. Each
+  element in the list is of type libxltype.EnumerationValue.
+
+  Each EnumerationValue has the following properties:
+
+    EnumerationValue.enum      Reference to containing Enumeration
+    EnumerationValue.name       The C name of this value, including
+                                    the namespace and typename of the
+                                    containing Enumeration (e.g.
+                                    "LIBXL_FOOENUM_VALUE")
+    EnumerationValue.rawname    The C name of this value, excluding
+                                    the namespace but including the
+                                    typename of the containing
+                                    Enumeration (e.g. "FOOENUM_VALUE")
+    EnumerationValue.valuename The name of this value, excluding the
+                                   name of the containing Enumeration
+                                   and any namespace (e.g. "VALUE")
+    EnumerationValue.value     The integer value associated with this name.
+    EnumerationValue.comment   A free text comment which describes the member.
+
 libxltype.Aggregate
 
  Base class for type-Classes which contain a number of other types
diff -r 6d617996f5c1 -r 9d48dd43cd3b tools/libxl/libxl.h
--- a/tools/libxl/libxl.h       Wed Apr 20 17:13:07 2011 +0100
+++ b/tools/libxl/libxl.h       Wed Apr 20 17:13:07 2011 +0100
@@ -161,49 +161,6 @@
 #define LIBXL_CPUARRAY_INVALID_ENTRY  ~0
 void libxl_cpuarray_destroy(libxl_cpuarray *array);
 
-typedef enum {
-    LIBXL_DOMAIN_TYPE_FV = 1,
-    LIBXL_DOMAIN_TYPE_PV,
-} libxl_domain_type;
-
-typedef enum libxl_device_model_version {
-    /* Historical qemu-xen device model (qemu-dm) */
-    LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL = 1,
-    /* Upstream based qemu-xen device model */
-    LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN = 2,
-} libxl_device_model_version;
-
-typedef enum {
-    LIBXL_CONSOLE_TYPE_SERIAL = 1,
-    LIBXL_CONSOLE_TYPE_PV,
-} libxl_console_type;
-
-typedef enum {
-    LIBXL_CONSOLE_BACKEND_XENCONSOLED,
-    LIBXL_CONSOLE_BACKEND_IOEMU,
-} libxl_console_backend;
-
-typedef enum {
-    LIBXL_DISK_FORMAT_UNKNOWN = 0,
-    LIBXL_DISK_FORMAT_QCOW,
-    LIBXL_DISK_FORMAT_QCOW2,
-    LIBXL_DISK_FORMAT_VHD,
-    LIBXL_DISK_FORMAT_RAW,
-    LIBXL_DISK_FORMAT_EMPTY,
-} libxl_disk_format;
-
-typedef enum {
-    LIBXL_DISK_BACKEND_UNKNOWN = 0,
-    LIBXL_DISK_BACKEND_PHY,
-    LIBXL_DISK_BACKEND_TAP,
-    LIBXL_DISK_BACKEND_QDISK,
-} libxl_disk_backend;
-
-typedef enum {
-    LIBXL_NIC_TYPE_IOEMU = 1,
-    LIBXL_NIC_TYPE_VIF,
-} libxl_nic_type;
-
 typedef struct {
     /*
      * Path is always set if the file reference is valid. However if
@@ -252,18 +209,6 @@
 
 #define LIBXL_VERSION 0
 
-typedef enum libxl_action_on_shutdown {
-    LIBXL_ACTION_ON_SHUTDOWN_DESTROY,
-
-    LIBXL_ACTION_ON_SHUTDOWN_RESTART,
-    LIBXL_ACTION_ON_SHUTDOWN_RESTART_RENAME,
-
-    LIBXL_ACTION_ON_SHUTDOWN_PRESERVE,
-
-    LIBXL_ACTION_ON_SHUTDOWN_COREDUMP_DESTROY,
-    LIBXL_ACTION_ON_SHUTDOWN_COREDUMP_RESTART,
-} libxl_action_on_shutdown;
-
 typedef struct {
     libxl_domain_create_info c_info;
     libxl_domain_build_info b_info;
@@ -327,11 +272,6 @@
 
 /* events handling */
 
-typedef enum {
-    LIBXL_EVENT_TYPE_DOMAIN_DEATH,
-    LIBXL_EVENT_TYPE_DISK_EJECT,
-} libxl_event_type;
-
 typedef struct {
     /* event type */
     libxl_event_type type;
@@ -494,11 +434,6 @@
    * On error return, *data_r and *datalen_r are undefined.
    */
 
-typedef enum {
-    LIBXL_BUTTON_POWER,
-    LIBXL_BUTTON_SLEEP
-} libxl_button;
-
 int libxl_button_press(libxl_ctx *ctx, uint32_t domid, libxl_button button);
 
 int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *physinfo);
diff -r 6d617996f5c1 -r 9d48dd43cd3b tools/libxl/libxl.idl
--- a/tools/libxl/libxl.idl     Wed Apr 20 17:13:07 2011 +0100
+++ b/tools/libxl/libxl.idl     Wed Apr 20 17:13:07 2011 +0100
@@ -8,13 +8,6 @@
 libxl_mac = Builtin("mac")
 libxl_cpumap = Builtin("cpumap", destructor_fn="libxl_cpumap_destroy", 
passby=PASS_BY_REFERENCE)
 libxl_cpuarray = Builtin("cpuarray", destructor_fn="libxl_cpuarray_destroy", 
passby=PASS_BY_REFERENCE)
-libxl_domain_type = Number("domain_type", namespace="libxl_")
-libxl_device_model_version = Number("device_model_version", namespace="libxl_")
-libxl_console_backend = Number("console_backend", namespace="libxl_")
-libxl_console_type = Number("console_type", namespace="libxl_")
-libxl_disk_format = Number("disk_format", namespace="libxl_")
-libxl_disk_backend = Number("disk_backend", namespace="libxl_")
-libxl_nic_type = Number("nic_type", namespace="libxl_")
 libxl_cpuid_policy_list = Builtin("cpuid_policy_list", 
destructor_fn="libxl_cpuid_destroy", passby=PASS_BY_REFERENCE)
 
 libxl_string_list = Builtin("string_list", 
destructor_fn="libxl_string_list_destroy", passby=PASS_BY_REFERENCE)
@@ -24,6 +17,73 @@
 libxl_hwcap = Builtin("hwcap")
 
 #
+# Constants / Enumerations
+#
+
+libxl_domain_type = Enumeration("domain_type", [
+    (1, "FV"),
+    (2, "PV"),
+    ])
+
+libxl_device_model_version = Enumeration("device_model_version", [
+    (1, "QEMU_XEN_TRADITIONAL", "Historical qemu-xen device model (qemu-dm)"),
+    (2, "QEMU_XEN", "Upstream based qemu-xen device model"),
+    ])
+
+libxl_console_type = Enumeration("console_type", [
+    (1, "SERIAL"),
+    (2, "PV"),
+    ])
+
+libxl_console_backend = Enumeration("console_backend", [
+    (1, "XENCONSOLED"),
+    (2, "IOEMU"),
+    ])
+
+libxl_disk_format = Enumeration("disk_format", [
+    (0, "UNKNOWN"),
+    (1, "QCOW"),
+    (2, "QCOW2"),
+    (3, "VHD"),
+    (4, "RAW"),
+    (5, "EMPTY"),
+    ])
+
+libxl_disk_backend = Enumeration("disk_backend", [
+    (0, "UNKNOWN"),
+    (1, "PHY"),
+    (2, "TAP"),
+    (3, "QDISK"),
+    ])
+
+libxl_nic_type = Enumeration("nic_type", [
+    (1, "IOEMU"),
+    (2, "VIF"),
+    ])
+
+libxl_action_on_shutdown = Enumeration("action_on_shutdown", [
+    (1, "DESTROY"),
+
+    (2, "RESTART"),
+    (3, "RESTART_RENAME"),
+
+    (4, "PRESERVE"),
+
+    (5, "COREDUMP_DESTROY"),
+    (6, "COREDUMP_RESTART"),
+    ])
+
+libxl_event_type = Enumeration("event_type", [
+    (1, "DOMAIN_DEATH"),
+    (2, "DISK_EJECT"),
+    ])
+
+libxl_button = Enumeration("button", [
+    (1, "POWER"),
+    (2, "SLEEP"),
+    ])
+
+#
 # Complex libxl types
 #
 libxl_dominfo = Struct("dominfo",[
diff -r 6d617996f5c1 -r 9d48dd43cd3b tools/libxl/libxltypes.py
--- a/tools/libxl/libxltypes.py Wed Apr 20 17:13:07 2011 +0100
+++ b/tools/libxl/libxltypes.py Wed Apr 20 17:13:07 2011 +0100
@@ -52,6 +52,35 @@
 
         self.width = w
 
+class EnumerationValue(object):
+    def __init__(self, enum, value, name, **kwargs):
+        self.enum = enum
+
+        self.valuename = str.upper(name)
+        self.rawname = str.upper(enum.rawname) + "_" + self.valuename
+        self.name = str.upper(enum.namespace) + self.rawname
+        self.value = value
+        self.comment = kwargs.setdefault("comment", None)
+        
+class Enumeration(Type):
+    def __init__(self, typename, values, **kwargs):
+        kwargs.setdefault('destructor_fn', None)
+        Type.__init__(self, typename, **kwargs)
+
+        self.values = []
+        for v in values:
+            # (value, name[, comment=None])
+            if len(v) == 2:
+                (num,name) = v
+                comment = None
+            elif len(v) == 3:
+                num,name,comment = v
+            else:
+                raise ""
+            self.values.append(EnumerationValue(self, num, name,
+                                                comment=comment,
+                                                typename=self.rawname))
+        
 class BitField(Type):
     def __init__(self, ty, w, **kwargs):
         kwargs.setdefault('namespace', None)
diff -r 6d617996f5c1 -r 9d48dd43cd3b tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c  Wed Apr 20 17:13:07 2011 +0100
+++ b/tools/libxl/xl_cmdimpl.c  Wed Apr 20 17:13:07 2011 +0100
@@ -451,6 +451,8 @@
     for (i = 0; i < sizeof(action_on_shutdown_names) / 
sizeof(action_on_shutdown_names[0]); i++) {
         n = action_on_shutdown_names[i];
 
+        if (!n) continue;
+
         if (strcmp(buf, n) == 0) {
             *a = i;
             return 1;
diff -r 6d617996f5c1 -r 9d48dd43cd3b tools/python/genwrap.py
--- a/tools/python/genwrap.py   Wed Apr 20 17:13:07 2011 +0100
+++ b/tools/python/genwrap.py   Wed Apr 20 17:13:07 2011 +0100
@@ -9,6 +9,8 @@
 def py_type(ty):
     if ty == libxltypes.bool or isinstance(ty, libxltypes.BitField) and 
ty.width == 1:
         return TYPE_BOOL
+    if isinstance(ty, libxltypes.Enumeration):
+        return TYPE_UINT
     if isinstance(ty, libxltypes.Number):
         if ty.signed:
             return TYPE_INT
@@ -34,15 +36,16 @@
 
 def py_decls(ty):
     l = []
-    l.append('_hidden Py_%s *Py%s_New(void);\n'%(ty.rawname, ty.rawname))
-    l.append('_hidden int Py%s_Check(PyObject *self);\n'%ty.rawname)
-    for f in ty.fields:
-        if py_type(f.type) is not None:
-            continue
-        l.append('_hidden PyObject *attrib__%s_get(%s *%s);'%(\
-                 fsanitize(f.type.typename), f.type.typename, f.name))
-        l.append('_hidden int attrib__%s_set(PyObject *v, %s *%s);'%(\
-                 fsanitize(f.type.typename), f.type.typename, f.name))
+    if isinstance(ty, libxltypes.Aggregate):
+        l.append('_hidden Py_%s *Py%s_New(void);\n'%(ty.rawname, ty.rawname))
+        l.append('_hidden int Py%s_Check(PyObject *self);\n'%ty.rawname)
+        for f in ty.fields:
+            if py_type(f.type) is not None:
+                continue
+            l.append('_hidden PyObject *attrib__%s_get(%s *%s);'%(\
+                fsanitize(f.type.typename), f.type.typename, f.name))
+            l.append('_hidden int attrib__%s_set(PyObject *v, %s *%s);'%(\
+                fsanitize(f.type.typename), f.type.typename, f.name))
     return '\n'.join(l) + "\n"
 
 def py_attrib_get(ty, f):
@@ -189,16 +192,23 @@
     l.append('void genwrap__init(PyObject *m)')
     l.append('{')
     for ty in types:
-        l.append('    if (PyType_Ready(&Py%s_Type) >= 0) {'%ty.rawname)
-        l.append('        Py_INCREF(&Py%s_Type);'%ty.rawname)
-        l.append('        PyModule_AddObject(m, "%s", (PyObject 
*)&Py%s_Type);'%(ty.rawname, ty.rawname))
-        l.append('    }')
+        if isinstance(ty, libxltypes.Enumeration):
+            for v in ty.values:
+                l.append('    PyModule_AddIntConstant(m, "%s", %s);' % 
(v.rawname, v.name))
+        elif isinstance(ty, libxltypes.Aggregate):
+            l.append('    if (PyType_Ready(&Py%s_Type) >= 0) {'%ty.rawname)
+            l.append('        Py_INCREF(&Py%s_Type);'%ty.rawname)
+            l.append('        PyModule_AddObject(m, "%s", (PyObject 
*)&Py%s_Type);'%(ty.rawname, ty.rawname))
+            l.append('    }')
+        else:
+            raise NotImplementedError("unknown type %s (%s)" % (ty.typename, 
type(ty)))        
+
     l.append('}')
     return '\n'.join(l) + "\n\n"
 
 def tree_frob(types):
     ret = types[:]
-    for ty in ret:
+    for ty in [ty for ty in ret if isinstance(ty, libxltypes.Aggregate)]:
         ty.fields = filter(lambda f:f.name is not None and f.type.typename is 
not None, ty.fields)
     return ret
 
@@ -249,8 +259,8 @@
 _hidden int genwrap__ll_set(PyObject *v, long long *val, long long mask);
 
 """ % " ".join(sys.argv))
-    for ty in types:
-        f.write('/* Internal APU for %s wrapper */\n'%ty.typename)
+    for ty in [ty for ty in types if isinstance(ty, libxltypes.Aggregate)]:
+        f.write('/* Internal API for %s wrapper */\n'%ty.typename)
         f.write(py_wrapstruct(ty))
         f.write(py_decls(ty))
         f.write('\n')
@@ -276,10 +286,11 @@
 
 """ % tuple((' '.join(sys.argv),) + (os.path.split(decls)[-1:]),))
     for ty in types:
-        f.write('/* Attribute get/set functions for %s */\n'%ty.typename)
-        for a in ty.fields:
-            f.write(py_attrib_get(ty,a))
-            f.write(py_attrib_set(ty,a))
-        f.write(py_object_def(ty))
+        if isinstance(ty, libxltypes.Aggregate):
+            f.write('/* Attribute get/set functions for %s */\n'%ty.typename)
+            for a in ty.fields:
+                f.write(py_attrib_get(ty,a))
+                f.write(py_attrib_set(ty,a))
+            f.write(py_object_def(ty))
     f.write(py_initfuncs(types))
     f.close()
diff -r 6d617996f5c1 -r 9d48dd43cd3b tools/python/xen/lowlevel/xl/xl.c
--- a/tools/python/xen/lowlevel/xl/xl.c Wed Apr 20 17:13:07 2011 +0100
+++ b/tools/python/xen/lowlevel/xl/xl.c Wed Apr 20 17:13:07 2011 +0100
@@ -769,35 +769,6 @@
     _INT_CONST(m, SHUTDOWN_crash);
     _INT_CONST(m, SHUTDOWN_watchdog);
 
-    _INT_CONST_LIBXL(m, DOMAIN_TYPE_FV);
-    _INT_CONST_LIBXL(m, DOMAIN_TYPE_PV);
-
-    _INT_CONST_LIBXL(m, CONSOLE_TYPE_SERIAL);
-    _INT_CONST_LIBXL(m, CONSOLE_TYPE_PV);
-
-    _INT_CONST_LIBXL(m, CONSOLE_BACKEND_XENCONSOLED);
-    _INT_CONST_LIBXL(m, CONSOLE_BACKEND_IOEMU);
-
-    _INT_CONST_LIBXL(m, DISK_FORMAT_UNKNOWN);
-    _INT_CONST_LIBXL(m, DISK_FORMAT_QCOW);
-    _INT_CONST_LIBXL(m, DISK_FORMAT_QCOW2);
-    _INT_CONST_LIBXL(m, DISK_FORMAT_VHD);
-    _INT_CONST_LIBXL(m, DISK_FORMAT_RAW);
-    _INT_CONST_LIBXL(m, DISK_FORMAT_EMPTY);
-
-    _INT_CONST_LIBXL(m, DISK_BACKEND_UNKNOWN);
-    _INT_CONST_LIBXL(m, DISK_BACKEND_PHY);
-    _INT_CONST_LIBXL(m, DISK_BACKEND_TAP);
-    _INT_CONST_LIBXL(m, DISK_BACKEND_QDISK);
-
-    _INT_CONST_LIBXL(m, NIC_TYPE_IOEMU);
-    _INT_CONST_LIBXL(m, NIC_TYPE_VIF);
-
-    _INT_CONST_LIBXL(m, EVENT_TYPE_DOMAIN_DEATH);
-    _INT_CONST_LIBXL(m, EVENT_TYPE_DISK_EJECT);
-
-    _INT_CONST_LIBXL(m, BUTTON_POWER);
-    _INT_CONST_LIBXL(m, BUTTON_SLEEP);
     genwrap__init(m);
 }
 

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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] tools: libxl: add an Enumeration type to the IDL, Xen patchbot-unstable <=