9ae3a8
From 89a70ccf822a86d05efb34e50958de831a071d05 Mon Sep 17 00:00:00 2001
9ae3a8
From: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Date: Mon, 9 Sep 2013 14:28:05 +0200
9ae3a8
Subject: [PATCH 14/38] qapi.py: Allow top-level type reference for command definitions
9ae3a8
9ae3a8
RH-Author: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Message-id: <1378736903-18489-15-git-send-email-kwolf@redhat.com>
9ae3a8
Patchwork-id: 54201
9ae3a8
O-Subject: [RHEL-7.0 qemu-kvm PATCH 14/32] qapi.py: Allow top-level type reference for command definitions
9ae3a8
Bugzilla: 1005818
9ae3a8
RH-Acked-by: Fam Zheng <famz@redhat.com>
9ae3a8
RH-Acked-by: Max Reitz <mreitz@redhat.com>
9ae3a8
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
9ae3a8
Bugzilla: 1005818
9ae3a8
9ae3a8
If 'data' for a command definition isn't a dict, but a string, it is
9ae3a8
taken as a (struct) type name and the fields of this struct are directly
9ae3a8
used as parameters.
9ae3a8
9ae3a8
This is useful for transactionable commands that can use the same type
9ae3a8
definition for both the transaction action and the arguments of the
9ae3a8
standalone command.
9ae3a8
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>
9ae3a8
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
9ae3a8
(cherry picked from commit b35284ea207a0ae1c0b162344cdef2a83304befc)
9ae3a8
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
---
9ae3a8
 scripts/qapi.py | 19 +++++++++++++++++++
9ae3a8
 1 file changed, 19 insertions(+)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 scripts/qapi.py |   19 +++++++++++++++++++
9ae3a8
 1 files changed, 19 insertions(+), 0 deletions(-)
9ae3a8
9ae3a8
diff --git a/scripts/qapi.py b/scripts/qapi.py
9ae3a8
index daedaea..0c3bd84 100644
9ae3a8
--- a/scripts/qapi.py
9ae3a8
+++ b/scripts/qapi.py
9ae3a8
@@ -100,11 +100,18 @@ def parse_schema(fp):
9ae3a8
             add_enum(expr_eval['enum'])
9ae3a8
         elif expr_eval.has_key('union'):
9ae3a8
             add_enum('%sKind' % expr_eval['union'])
9ae3a8
+        elif expr_eval.has_key('type'):
9ae3a8
+            add_struct(expr_eval)
9ae3a8
         exprs.append(expr_eval)
9ae3a8
 
9ae3a8
     return exprs
9ae3a8
 
9ae3a8
 def parse_args(typeinfo):
9ae3a8
+    if isinstance(typeinfo, basestring):
9ae3a8
+        struct = find_struct(typeinfo)
9ae3a8
+        assert struct != None
9ae3a8
+        typeinfo = struct['data']
9ae3a8
+
9ae3a8
     for member in typeinfo:
9ae3a8
         argname = member
9ae3a8
         argentry = typeinfo[member]
9ae3a8
@@ -174,6 +181,18 @@ def type_name(name):
9ae3a8
     return name
9ae3a8
 
9ae3a8
 enum_types = []
9ae3a8
+struct_types = []
9ae3a8
+
9ae3a8
+def add_struct(definition):
9ae3a8
+    global struct_types
9ae3a8
+    struct_types.append(definition)
9ae3a8
+
9ae3a8
+def find_struct(name):
9ae3a8
+    global struct_types
9ae3a8
+    for struct in struct_types:
9ae3a8
+        if struct['type'] == name:
9ae3a8
+            return struct
9ae3a8
+    return None
9ae3a8
 
9ae3a8
 def add_enum(name):
9ae3a8
     global enum_types
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8