qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [RFC PATCH v2 5/7] qapi: Add @arg property dictionary synta


From: Fam Zheng
Subject: [Qemu-devel] [RFC PATCH v2 5/7] qapi: Add @arg property dictionary syntax
Date: Tue, 20 May 2014 17:07:59 +0800

parse_args now yields one more item in an iteration - default. It is the
default value for the argument, that is parsed from

    'data': { '@ARG_NAME': { PROP_NAME : PROP_VALUE } }

syntax added into qapi schema.

ARG_NAME is the name of argument. PROP_NAME is the property name of
argument, currently can be 'type', 'optional' or 'default'.

'type' defines the type of the argument, as what we have in:

    'data': { 'ARG_NAME': 'TYPE_NAME' }

'optional' can be true or false.

'default' gives the default value of argument. if 'default' is set,
'optional' is ignored and the qmp handler will always get a value, hence
parse_args yields an False, so that has_xxx parameter is not generated
in the handler prototype. Later, in qapi-commands.py, the value will be
used if user doesn't specify one.

See the coming change on block-commit for example of how qmp commands
can make use of this.

Signed-off-by: Fam Zheng <address@hidden>
---
 scripts/qapi-commands.py |  8 ++++----
 scripts/qapi-types.py    |  2 +-
 scripts/qapi-visit.py    |  4 ++--
 scripts/qapi.py          | 20 ++++++++++++++++++--
 4 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py
index 386f17e..05904f9 100644
--- a/scripts/qapi-commands.py
+++ b/scripts/qapi-commands.py
@@ -28,7 +28,7 @@ def type_visitor(name):
 
 def generate_command_decl(name, args, ret_type):
     arglist=""
-    for argname, argtype, optional, structured in parse_args(args):
+    for argname, argtype, optional, structured, default in parse_args(args):
         argtype = c_type(argtype)
         if argtype == "char *":
             argtype = "const char *"
@@ -55,7 +55,7 @@ def gen_sync_call(name, args, ret_type, indent=0):
     retval=""
     if ret_type:
         retval = "retval = "
-    for argname, argtype, optional, structured in parse_args(args):
+    for argname, argtype, optional, structured, default in parse_args(args):
         if optional:
             arglist += "has_%s, " % c_var(argname)
         arglist += "%s, " % (c_var(argname))
@@ -98,7 +98,7 @@ Visitor *v;
 def gen_visitor_input_vars_decl(args):
     ret = ""
     push_indent()
-    for argname, argtype, optional, structured in parse_args(args):
+    for argname, argtype, optional, structured, default in parse_args(args):
         if optional:
             ret += mcgen('''
 bool has_%(argname)s = false;
@@ -141,7 +141,7 @@ v = qapi_dealloc_get_visitor(md);
 v = qmp_input_get_visitor(mi);
 ''')
 
-    for argname, argtype, optional, structured in parse_args(args):
+    for argname, argtype, optional, structured, default in parse_args(args):
         if optional:
             ret += mcgen('''
 visit_optional(v, &has_%(c_name)s, "%(name)s", %(errp)s);
diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index b463232..ba3aa2b 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -63,7 +63,7 @@ typedef struct %(name)sList
 def generate_struct_fields(members):
     ret = ''
 
-    for argname, argentry, optional, structured in parse_args(members):
+    for argname, argentry, optional, structured, default in 
parse_args(members):
         if optional:
             ret += mcgen('''
     bool has_%(c_name)s;
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index 06a79f1..4d9ee66 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -51,7 +51,7 @@ def generate_visit_struct_fields(name, field_prefix, 
fn_prefix, members, base =
     else:
         full_name = "%s_%s" % (name, fn_prefix)
 
-    for argname, argentry, optional, structured in parse_args(members):
+    for argname, argentry, optional, structured, default in 
parse_args(members):
         if structured:
             if not fn_prefix:
                 nested_fn_prefix = argname
@@ -94,7 +94,7 @@ if (err) {
                      c_prefix=c_var(field_prefix),
                      type=type_name(base), c_name=c_var('base'))
 
-    for argname, argentry, optional, structured in parse_args(members):
+    for argname, argentry, optional, structured, default in 
parse_args(members):
         if optional:
             ret += mcgen('''
 visit_optional(m, &(*obj)->%(c_prefix)shas_%(c_name)s, "%(name)s", &err);
diff --git a/scripts/qapi.py b/scripts/qapi.py
index ca2f1cc..fbe3ce3 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -384,13 +384,29 @@ def parse_args(typeinfo):
         argname = member
         argentry = typeinfo[member]
         optional = False
+        argtype = argentry
+        default = None
         structured = False
         if member.startswith('*'):
             argname = member[1:]
             optional = True
+        if member.startswith('@'):
+            if not isinstance(argentry, OrderedDict):
+                raise Exception("Expecting property dictionary for argument 
'%s'" % member)
+            # Parse argument property dict
+            argname = member[1:]
+            argtype = argentry.get("type", None)
+            optional = argentry.get("optional", False)
+            default = argentry.get("default", None)
+            if default is not None:
+                optional = False
         if isinstance(argentry, OrderedDict):
-            structured = True
-        yield (argname, argentry, optional, structured)
+                structured = True
+
+        else:
+            argtype = argentry
+
+        yield (argname, argtype, optional, structured, default)
 
 def de_camel_case(name):
     new_name = ''
-- 
1.9.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]