All of lore.kernel.org
 help / color / mirror / Atom feed
From: marcandre.lureau@redhat.com
To: qemu-devel@nongnu.org
Cc: eblake@redhat.com, armbru@redhat.com,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [Qemu-devel] [PATCH v3 05/15] qapi: add 'export-marshal' command key
Date: Mon,  8 Aug 2016 18:14:29 +0400	[thread overview]
Message-ID: <20160808141439.16908-6-marcandre.lureau@redhat.com> (raw)
In-Reply-To: <20160808141439.16908-1-marcandre.lureau@redhat.com>

From: Marc-André Lureau <marcandre.lureau@redhat.com>

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é Lureau <marcandre.lureau@redhat.com>
---
 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=ret_type.c_type(), c_name=ret_type.c_name())
 
 
-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
+def gen_marshal_proto(name, export):
+    return mcgen('%(export)svoid qmp_marshal_%(c_name)s(QDict *args, '
+                 'QObject **ret, Error **errp)',
+                 c_name=c_name(name),
+                 export="" if export else "static ")
 
 
-def gen_marshal_decl(name):
+def gen_marshal_decl(name, export):
     return mcgen('''
 %(proto)s;
 ''',
-                 proto=gen_marshal_proto(name))
+                 proto=gen_marshal_proto(name, export))
 
 
-def gen_marshal(name, arg_type, boxed, ret_type):
+def gen_marshal(name, arg_type, boxed, ret_type, export):
     ret = mcgen('''
 
 %(proto)s
 {
     Error *err = NULL;
 ''',
-                proto=gen_marshal_proto(name))
+                proto=gen_marshal_proto(name, export))
 
     if ret_type:
         ret += mcgen('''
@@ -215,16 +215,17 @@ class QAPISchemaGenCommandVisitor(QAPISchemaVisitor):
         self._visited_ret_types = None
 
     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 += 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 += gen_marshal_output(ret_type)
-        if middle_mode:
-            self.decl += gen_marshal_decl(name)
-        self.defn += gen_marshal(name, arg_type, boxed, ret_type)
+        export = middle_mode or export_marshal
+        if export:
+            self.decl += gen_marshal_decl(name, True)
+        self.defn += gen_marshal(name, arg_type, boxed, ret_type, export)
         if not middle_mode:
             self._regy += gen_register_command(name, success_response)
 
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[] = %(c_string)s;
                                     for m in variants.variants]})
 
     def visit_command(self, name, info, arg_type, ret_type,
-                      gen, success_response, boxed):
+                      gen, success_response, boxed,
+                      export_marshal):
         arg_type = arg_type or self._schema.the_empty_object_type
         ret_type = 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', 'boxed'])
+                       ['data', 'returns', 'gen', 'success-response', 'boxed',
+                        '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
 
     def visit_command(self, name, info, arg_type, ret_type,
-                      gen, success_response, boxed):
+                      gen, success_response, boxed, export_marshal):
         pass
 
     def visit_event(self, name, info, arg_type, boxed):
@@ -1181,7 +1182,7 @@ class QAPISchemaAlternateType(QAPISchemaType):
 
 class QAPISchemaCommand(QAPISchemaEntity):
     def __init__(self, name, info, arg_type, ret_type, gen, success_response,
-                 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 = gen
         self.success_response = success_response
         self.boxed = boxed
+        self.export_marshal = export_marshal
 
     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.boxed)
+                              self.gen, self.success_response, self.boxed,
+                              self.export_marshal)
 
 
 class QAPISchemaEvent(QAPISchemaEntity):
@@ -1422,6 +1425,7 @@ class QAPISchema(object):
         gen = expr.get('gen', True)
         success_response = expr.get('success-response', True)
         boxed = expr.get('boxed', False)
+        export_marshal = expr.get('export-marshal', False)
         if isinstance(data, OrderedDict):
             data = self._make_implicit_object_type(
                 name, info, 'arg', self._make_members(data, info))
@@ -1429,7 +1433,8 @@ class QAPISchema(object):
             assert len(rets) == 1
             rets = self._make_array_type(rets[0], info)
         self._def_entity(QAPISchemaCommand(name, info, data, rets, gen,
-                                           success_response, boxed))
+                                           success_response, boxed,
+                                           export_marshal))
 
     def _def_event(self, expr, info):
         name = 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)
 
     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.name)
         print '   gen=%s success_response=%s boxed=%s' % \
-- 
2.9.0

  parent reply	other threads:[~2016-08-08 14:15 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-08 14:14 [Qemu-devel] [PATCH v3 00/15] qapi: remove the 'middle' mode marcandre.lureau
2016-08-08 14:14 ` [Qemu-devel] [PATCH v3 01/15] qapi-schema: use generated marshaller for 'qmp_capabilities' marcandre.lureau
2016-08-09 11:22   ` Markus Armbruster
2016-08-08 14:14 ` [Qemu-devel] [PATCH v3 02/15] qapi-schema: add 'device_add' marcandre.lureau
2016-08-08 14:14 ` [Qemu-devel] [PATCH v3 03/15] monitor: register gen:false commands manually marcandre.lureau
2016-08-09  7:52   ` Markus Armbruster
2016-08-09 17:16     ` Marc-André Lureau
2016-08-08 14:14 ` [Qemu-devel] [PATCH v3 04/15] monitor: remove usage of generated marshal functions marcandre.lureau
2016-08-09  8:36   ` Markus Armbruster
2016-08-09  8:43     ` Marc-André Lureau
2016-08-08 14:14 ` marcandre.lureau [this message]
2016-08-09  8:05   ` [Qemu-devel] [PATCH v3 05/15] qapi: add 'export-marshal' command key Markus Armbruster
2016-08-09  8:38     ` Marc-André Lureau
2016-08-09 14:35       ` Markus Armbruster
2016-08-08 14:14 ` [Qemu-devel] [PATCH v3 06/15] monitor: register the qapi generated commands marcandre.lureau
2016-08-08 14:14 ` [Qemu-devel] [PATCH v3 07/15] monitor: remove mhandler.cmd_new marcandre.lureau
2016-08-08 14:14 ` [Qemu-devel] [PATCH v3 08/15] monitor: implement 'qmp_query_commands' without qmp_cmds marcandre.lureau
2016-08-08 14:14 ` [Qemu-devel] [PATCH v3 09/15] qapi: remove the "middle" mode marcandre.lureau
2016-08-08 14:14 ` [Qemu-devel] [PATCH v3 10/15] qapi: check invalid arguments on no-args commands marcandre.lureau
2016-08-09 12:11   ` Markus Armbruster
2016-08-09 12:20     ` Marc-André Lureau
2016-08-08 14:14 ` [Qemu-devel] [PATCH v3 11/15] qmp: update qmp_query_spice fallback marcandre.lureau
2016-08-09 12:38   ` Markus Armbruster
2016-08-08 14:14 ` [Qemu-devel] [PATCH v3 12/15] monitor: use qmp_dispatch() marcandre.lureau
2016-08-09 12:43   ` Markus Armbruster
2016-08-09 12:48     ` Daniel P. Berrange
2016-08-09 12:50     ` Marc-André Lureau
2016-08-09 14:29       ` Markus Armbruster
2016-08-09 14:41         ` Marc-André Lureau
2016-08-09 16:27           ` Markus Armbruster
2016-08-09 19:35             ` Marc-André Lureau
2016-08-10 10:17               ` Markus Armbruster
2016-08-10 15:28                 ` Marc-André Lureau
2016-08-08 14:14 ` [Qemu-devel] [PATCH v3 13/15] build-sys: remove qmp-commands-old.h marcandre.lureau
2016-08-08 14:14 ` [Qemu-devel] [PATCH v3 14/15] Drop qmp-commands.hx marcandre.lureau
2016-08-09 13:08   ` Markus Armbruster
2016-08-09 13:35     ` Marc-André Lureau
2016-08-17 15:01       ` Markus Armbruster
2016-08-08 14:14 ` [Qemu-devel] [PATCH v3 15/15] qmp-commands.txt: fix some styling marcandre.lureau
2016-08-08 14:55 ` [Qemu-devel] [PATCH v3 00/15] qapi: remove the 'middle' mode no-reply
2016-08-08 17:59   ` Marc-André Lureau
2016-08-09 14:50 ` Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160808141439.16908-6-marcandre.lureau@redhat.com \
    --to=marcandre.lureau@redhat.com \
    --cc=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.