aboutsummaryrefslogtreecommitdiff
path: root/scripts/qapi-commands.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/qapi-commands.py')
-rw-r--r--scripts/qapi-commands.py81
1 files changed, 48 insertions, 33 deletions
diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py
index a06a2c4f9b..2f603b0c0e 100644
--- a/scripts/qapi-commands.py
+++ b/scripts/qapi-commands.py
@@ -84,10 +84,7 @@ static void qmp_marshal_output_%(c_name)s(%(c_type)s ret_in, QObject **ret_out,
def gen_marshal_proto(name):
- ret = 'void qmp_marshal_%s(QDict *args, QObject **ret, Error **errp)' % c_name(name)
- if not middle_mode:
- ret = 'static ' + ret
- return ret
+ return 'void qmp_marshal_%s(QDict *args, QObject **ret, Error **errp)' % c_name(name)
def gen_marshal_decl(name):
@@ -98,6 +95,8 @@ def gen_marshal_decl(name):
def gen_marshal(name, arg_type, boxed, ret_type):
+ have_args = arg_type and not arg_type.is_empty()
+
ret = mcgen('''
%(proto)s
@@ -112,17 +111,31 @@ def gen_marshal(name, arg_type, boxed, ret_type):
''',
c_type=ret_type.c_type())
- if arg_type and not arg_type.is_empty():
+ if have_args:
+ visit_members = ('visit_type_%s_members(v, &arg, &err);'
+ % arg_type.c_name())
ret += mcgen('''
Visitor *v;
%(c_name)s arg = {0};
+''',
+ c_name=arg_type.c_name())
+ else:
+ visit_members = ''
+ ret += mcgen('''
+ Visitor *v = NULL;
+
+ if (args) {
+''')
+ push_indent()
+
+ ret += mcgen('''
v = qmp_input_visitor_new(QOBJECT(args), true);
visit_start_struct(v, NULL, NULL, 0, &err);
if (err) {
goto out;
}
- visit_type_%(c_name)s_members(v, &arg, &err);
+ %(visit_members)s
if (!err) {
visit_check_struct(v, &err);
}
@@ -131,35 +144,47 @@ def gen_marshal(name, arg_type, boxed, ret_type):
goto out;
}
''',
- c_name=arg_type.c_name())
+ visit_members=visit_members)
- else:
+ if not have_args:
+ pop_indent()
ret += mcgen('''
-
- (void)args;
+ }
''')
ret += gen_call(name, arg_type, boxed, ret_type)
- # 'goto out' produced above for arg_type, and by gen_call() for ret_type
- if (arg_type and not arg_type.is_empty()) or ret_type:
- ret += mcgen('''
+ ret += mcgen('''
out:
-''')
- ret += mcgen('''
error_propagate(errp, err);
+ visit_free(v);
''')
- if arg_type and not arg_type.is_empty():
+
+ if have_args:
+ visit_members = ('visit_type_%s_members(v, &arg, NULL);'
+ % arg_type.c_name())
+ else:
+ visit_members = ''
ret += mcgen('''
- visit_free(v);
+ if (args) {
+''')
+ push_indent()
+
+ ret += mcgen('''
v = qapi_dealloc_visitor_new();
visit_start_struct(v, NULL, NULL, 0, NULL);
- visit_type_%(c_name)s_members(v, &arg, NULL);
+ %(visit_members)s
visit_end_struct(v, NULL);
visit_free(v);
''',
- c_name=arg_type.c_name())
+ visit_members=visit_members)
+
+ if not have_args:
+ pop_indent()
+ ret += mcgen('''
+ }
+''')
ret += mcgen('''
}
@@ -209,8 +234,7 @@ class QAPISchemaGenCommandVisitor(QAPISchemaVisitor):
self._visited_ret_types = set()
def visit_end(self):
- if not middle_mode:
- self.defn += gen_registry(self._regy)
+ self.defn += gen_registry(self._regy)
self._regy = None
self._visited_ret_types = None
@@ -222,21 +246,12 @@ class QAPISchemaGenCommandVisitor(QAPISchemaVisitor):
if ret_type and ret_type not in self._visited_ret_types:
self._visited_ret_types.add(ret_type)
self.defn += gen_marshal_output(ret_type)
- if middle_mode:
- self.decl += gen_marshal_decl(name)
+ self.decl += gen_marshal_decl(name)
self.defn += gen_marshal(name, arg_type, boxed, ret_type)
- if not middle_mode:
- self._regy += gen_register_command(name, success_response)
-
-
-middle_mode = False
+ self._regy += gen_register_command(name, success_response)
-(input_file, output_dir, do_c, do_h, prefix, opts) = \
- parse_command_line("m", ["middle"])
-for o, a in opts:
- if o in ("-m", "--middle"):
- middle_mode = True
+(input_file, output_dir, do_c, do_h, prefix, opts) = parse_command_line()
c_comment = '''
/*