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