From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47787) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bWlKZ-0006p8-95 for qemu-devel@nongnu.org; Mon, 08 Aug 2016 10:15:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bWlKW-0005JX-Lu for qemu-devel@nongnu.org; Mon, 08 Aug 2016 10:15:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48346) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bWlKW-0005JO-Au for qemu-devel@nongnu.org; Mon, 08 Aug 2016 10:15:00 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 07B6A3F720 for ; Mon, 8 Aug 2016 14:15:00 +0000 (UTC) From: marcandre.lureau@redhat.com Date: Mon, 8 Aug 2016 18:14:29 +0400 Message-Id: <20160808141439.16908-6-marcandre.lureau@redhat.com> In-Reply-To: <20160808141439.16908-1-marcandre.lureau@redhat.com> References: <20160808141439.16908-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v3 05/15] qapi: add 'export-marshal' command key List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: eblake@redhat.com, armbru@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= From: Marc-Andr=C3=A9 Lureau When a command sets the 'export-marshal' key to true, the generated marshaller will be exported, so it can be called from outside. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi-commands.py | 27 ++++++++++++++------------- scripts/qapi-introspect.py | 3 ++- scripts/qapi.py | 15 ++++++++++----- tests/qapi-schema/test-qapi.py | 2 +- 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py index a06a2c4..4f64c58 100644 --- a/scripts/qapi-commands.py +++ b/scripts/qapi-commands.py @@ -83,28 +83,28 @@ static void qmp_marshal_output_%(c_name)s(%(c_type)s = ret_in, QObject **ret_out, c_type=3Dret_type.c_type(), c_name=3Dret_type.c_name()) =20 =20 -def gen_marshal_proto(name): - ret =3D 'void qmp_marshal_%s(QDict *args, QObject **ret, Error **err= p)' % c_name(name) - if not middle_mode: - ret =3D 'static ' + ret - return ret +def gen_marshal_proto(name, export): + return mcgen('%(export)svoid qmp_marshal_%(c_name)s(QDict *args, ' + 'QObject **ret, Error **errp)', + c_name=3Dc_name(name), + export=3D"" if export else "static ") =20 =20 -def gen_marshal_decl(name): +def gen_marshal_decl(name, export): return mcgen(''' %(proto)s; ''', - proto=3Dgen_marshal_proto(name)) + proto=3Dgen_marshal_proto(name, export)) =20 =20 -def gen_marshal(name, arg_type, boxed, ret_type): +def gen_marshal(name, arg_type, boxed, ret_type, export): ret =3D mcgen(''' =20 %(proto)s { Error *err =3D NULL; ''', - proto=3Dgen_marshal_proto(name)) + proto=3Dgen_marshal_proto(name, export)) =20 if ret_type: ret +=3D mcgen(''' @@ -215,16 +215,17 @@ class QAPISchemaGenCommandVisitor(QAPISchemaVisitor= ): self._visited_ret_types =3D None =20 def visit_command(self, name, info, arg_type, ret_type, - gen, success_response, boxed): + gen, success_response, boxed, export_marshal): if not gen: return self.decl +=3D gen_command_decl(name, arg_type, boxed, ret_type) if ret_type and ret_type not in self._visited_ret_types: self._visited_ret_types.add(ret_type) self.defn +=3D gen_marshal_output(ret_type) - if middle_mode: - self.decl +=3D gen_marshal_decl(name) - self.defn +=3D gen_marshal(name, arg_type, boxed, ret_type) + export =3D middle_mode or export_marshal + if export: + self.decl +=3D gen_marshal_decl(name, True) + self.defn +=3D gen_marshal(name, arg_type, boxed, ret_type, expo= rt) if not middle_mode: self._regy +=3D gen_register_command(name, success_response) =20 diff --git a/scripts/qapi-introspect.py b/scripts/qapi-introspect.py index 541644e..3c85be0 100644 --- a/scripts/qapi-introspect.py +++ b/scripts/qapi-introspect.py @@ -154,7 +154,8 @@ const char %(c_name)s[] =3D %(c_string)s; for m in variants.variants]}) =20 def visit_command(self, name, info, arg_type, ret_type, - gen, success_response, boxed): + gen, success_response, boxed, + export_marshal): arg_type =3D arg_type or self._schema.the_empty_object_type ret_type =3D ret_type or self._schema.the_empty_object_type self._gen_json(name, 'command', diff --git a/scripts/qapi.py b/scripts/qapi.py index 21bc32f..1d82e71 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -737,7 +737,8 @@ def check_exprs(exprs): add_struct(expr, info) elif 'command' in expr: check_keys(expr_elem, 'command', [], - ['data', 'returns', 'gen', 'success-response', 'b= oxed']) + ['data', 'returns', 'gen', 'success-response', 'b= oxed', + 'export-marshal']) add_name(expr['command'], info, 'command') elif 'event' in expr: check_keys(expr_elem, 'event', [], ['data', 'boxed']) @@ -838,7 +839,7 @@ class QAPISchemaVisitor(object): pass =20 def visit_command(self, name, info, arg_type, ret_type, - gen, success_response, boxed): + gen, success_response, boxed, export_marshal): pass =20 def visit_event(self, name, info, arg_type, boxed): @@ -1181,7 +1182,7 @@ class QAPISchemaAlternateType(QAPISchemaType): =20 class QAPISchemaCommand(QAPISchemaEntity): def __init__(self, name, info, arg_type, ret_type, gen, success_resp= onse, - boxed): + boxed, export_marshal): QAPISchemaEntity.__init__(self, name, info) assert not arg_type or isinstance(arg_type, str) assert not ret_type or isinstance(ret_type, str) @@ -1192,6 +1193,7 @@ class QAPISchemaCommand(QAPISchemaEntity): self.gen =3D gen self.success_response =3D success_response self.boxed =3D boxed + self.export_marshal =3D export_marshal =20 def check(self, schema): if self._arg_type_name: @@ -1216,7 +1218,8 @@ class QAPISchemaCommand(QAPISchemaEntity): def visit(self, visitor): visitor.visit_command(self.name, self.info, self.arg_type, self.ret_type, - self.gen, self.success_response, self.boxe= d) + self.gen, self.success_response, self.boxe= d, + self.export_marshal) =20 =20 class QAPISchemaEvent(QAPISchemaEntity): @@ -1422,6 +1425,7 @@ class QAPISchema(object): gen =3D expr.get('gen', True) success_response =3D expr.get('success-response', True) boxed =3D expr.get('boxed', False) + export_marshal =3D expr.get('export-marshal', False) if isinstance(data, OrderedDict): data =3D self._make_implicit_object_type( name, info, 'arg', self._make_members(data, info)) @@ -1429,7 +1433,8 @@ class QAPISchema(object): assert len(rets) =3D=3D 1 rets =3D self._make_array_type(rets[0], info) self._def_entity(QAPISchemaCommand(name, info, data, rets, gen, - success_response, boxed)) + success_response, boxed, + export_marshal)) =20 def _def_event(self, expr, info): name =3D expr['event'] diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi= .py index ef74e2c..02c6686 100644 --- a/tests/qapi-schema/test-qapi.py +++ b/tests/qapi-schema/test-qapi.py @@ -36,7 +36,7 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): self._print_variants(variants) =20 def visit_command(self, name, info, arg_type, ret_type, - gen, success_response, boxed): + gen, success_response, boxed, export_marshal): print 'command %s %s -> %s' % \ (name, arg_type and arg_type.name, ret_type and ret_type.nam= e) print ' gen=3D%s success_response=3D%s boxed=3D%s' % \ --=20 2.9.0