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-devel

[Xen-devel] [PATCH 6 of 8] libxl: add KeyedUnion type

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 6 of 8] libxl: add KeyedUnion type
From: Ian Campbell <ian.campbell@xxxxxxxxxx>
Date: Tue, 03 Aug 2010 12:00:21 +0100
Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>
Delivery-date: Tue, 03 Aug 2010 04:09:40 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1280833215@xxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1280829586 -3600
# Node ID 5d51a404379e3e91c08c07c8292abefa1440a655
# Parent  c87dd259a8ed069d8786aadf9e1f6e555aa6778e
libxl: add KeyedUnion type

Use this to express the construct where a union is differentiated on a
variable in the containing struct.

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>

diff -r c87dd259a8ed -r 5d51a404379e tools/libxl/libxltypes.py
--- a/tools/libxl/libxltypes.py Tue Aug 03 10:59:46 2010 +0100
+++ b/tools/libxl/libxltypes.py Tue Aug 03 10:59:46 2010 +0100
@@ -35,12 +35,13 @@ class BitField(Type):
 
 class Field(Type):
     """An element of an Aggregate type"""
-    def __init__(self, type, name, const = False, comment = None):
+    def __init__(self, type, name, const = False, comment = None, keyvar_expr 
= None):
         Type.__init__(self,type.typename)
         self.type = type
         self.name = name
         self.const = const
         self.comment = comment
+        self.keyvar_expr = keyvar_expr
 
 class Aggregate(Type):
     """A type containing a collection of other types"""
@@ -79,6 +80,19 @@ class KeyValueList(Type):
         
         Type.__init__(self, "char **", namespace = None)
 
+class KeyedUnion(Aggregate):
+    """A union which is keyed of another variable"""
+    def __init__(self, name, keyvar_name, fields, comment = None):
+        self.keyvar = keyvar_name
+        Aggregate.__init__(self, "union", name, [], comment)
+        for f in fields:
+            # (name, keyvar_expr, type)
+
+            # keyvar_expr must contain exactly one %s which will be replaced 
with the keyvar_name
+            
+            n, kve, ty = f
+            self.fields.append(Field(ty, n, False, None, kve))
+                 
 class Reference(Type):
     """A reference to another type"""
     def __init__(self, ty):
@@ -199,26 +213,26 @@ libxl_domain_build_info = Struct("domain
     ("disable_migrate", bool),
     ("kernel",          libxl_file_reference),
     ("hvm",             integer),
-    ("u", Union(None,
-                [("hvm", Struct(None,
-                                [("pae", bool),
-                                 ("apic", bool),
-                                 ("acpi", bool),
-                                 ("nx", bool),
-                                 ("viridian", bool),
-                                 ("timeoffset", string),
-                                 ("hpet", bool),
-                                 ("vpt_align", bool),
-                                 ("timer_mode", integer),
-                                 ])),
-                 ("pv", Struct(None,
-                               [("slack_memkb", uint32),
-                                ("bootloader", string, True),
-                                ("bootloader_args", string, True),
-                                ("cmdline", string),
-                                ("ramdisk", libxl_file_reference),
-                                ("features", string, True),
-                                ])),
+    ("u", KeyedUnion(None, "hvm",
+                [("hvm", "%s", Struct(None,
+                                       [("pae", bool),
+                                        ("apic", bool),
+                                        ("acpi", bool),
+                                        ("nx", bool),
+                                        ("viridian", bool),
+                                        ("timeoffset", string),
+                                        ("hpet", bool),
+                                        ("vpt_align", bool),
+                                        ("timer_mode", integer),
+                                        ])),
+                 ("pv", "!%s", Struct(None,
+                                       [("slack_memkb", uint32),
+                                        ("bootloader", string, True),
+                                        ("bootloader_args", string, True),
+                                        ("cmdline", string),
+                                        ("ramdisk", libxl_file_reference),
+                                        ("features", string, True),
+                                        ])),
                  ])),
     ],
     comment =

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

<Prev in Thread] Current Thread [Next in Thread>