blob: 93e43f0e48e4e9f125cb46e4bb26f1cdab94556e [file] [log] [blame]
Michael Rothc17d9902011-07-19 14:50:42 -05001#
2# QAPI command marshaller generator
3#
4# Copyright IBM, Corp. 2011
Eric Blaked708cdb2015-05-04 09:05:19 -06005# Copyright (C) 2014-2015 Red Hat, Inc.
Michael Rothc17d9902011-07-19 14:50:42 -05006#
7# Authors:
8# Anthony Liguori <aliguori@us.ibm.com>
9# Michael Roth <mdroth@linux.vnet.ibm.com>
Markus Armbruster297a3642014-05-07 09:53:54 +020010# Markus Armbruster <armbru@redhat.com>
Michael Rothc17d9902011-07-19 14:50:42 -050011#
Markus Armbruster678e48a2014-03-01 08:40:34 +010012# This work is licensed under the terms of the GNU GPL, version 2.
13# See the COPYING file in the top-level directory.
Michael Rothc17d9902011-07-19 14:50:42 -050014
15from ordereddict import OrderedDict
16from qapi import *
Markus Armbruster297a3642014-05-07 09:53:54 +020017import re
Michael Rothc17d9902011-07-19 14:50:42 -050018import sys
19import os
20import getopt
21import errno
22
Anthony Liguori15e43e62011-09-14 14:30:00 -050023def type_visitor(name):
24 if type(name) == list:
25 return 'visit_type_%sList' % name[0]
26 else:
27 return 'visit_type_%s' % name
28
Michael Rothc17d9902011-07-19 14:50:42 -050029def generate_command_decl(name, args, ret_type):
30 arglist=""
Eric Blake6b5abc72015-05-04 09:05:33 -060031 for argname, argtype, optional in parse_args(args):
Amos Kong0d14eeb2014-06-10 19:25:52 +080032 argtype = c_type(argtype, is_param=True)
Michael Rothc17d9902011-07-19 14:50:42 -050033 if optional:
34 arglist += "bool has_%s, " % c_var(argname)
35 arglist += "%s %s, " % (argtype, c_var(argname))
36 return mcgen('''
37%(ret_type)s qmp_%(name)s(%(args)sError **errp);
38''',
Federico Simoncellic9da2282012-03-20 13:54:35 +000039 ret_type=c_type(ret_type), name=c_fun(name), args=arglist).strip()
Michael Rothc17d9902011-07-19 14:50:42 -050040
Markus Armbruster297a3642014-05-07 09:53:54 +020041def gen_err_check(errvar):
42 if errvar:
43 return mcgen('''
44if (local_err) {
45 goto out;
46}
47''')
48 return ''
49
Michael Rothc17d9902011-07-19 14:50:42 -050050def gen_sync_call(name, args, ret_type, indent=0):
51 ret = ""
52 arglist=""
53 retval=""
54 if ret_type:
55 retval = "retval = "
Eric Blake6b5abc72015-05-04 09:05:33 -060056 for argname, argtype, optional in parse_args(args):
Michael Rothc17d9902011-07-19 14:50:42 -050057 if optional:
58 arglist += "has_%s, " % c_var(argname)
59 arglist += "%s, " % (c_var(argname))
60 push_indent(indent)
61 ret = mcgen('''
Markus Armbruster297a3642014-05-07 09:53:54 +020062%(retval)sqmp_%(name)s(%(args)s&local_err);
Michael Rothc17d9902011-07-19 14:50:42 -050063
64''',
Federico Simoncellic9da2282012-03-20 13:54:35 +000065 name=c_fun(name), args=arglist, retval=retval).rstrip()
Michael Rothc17d9902011-07-19 14:50:42 -050066 if ret_type:
Markus Armbruster297a3642014-05-07 09:53:54 +020067 ret += "\n" + gen_err_check('local_err')
Michael Rothc17d9902011-07-19 14:50:42 -050068 ret += "\n" + mcgen(''''
Markus Armbruster297a3642014-05-07 09:53:54 +020069%(marshal_output_call)s
Michael Rothc17d9902011-07-19 14:50:42 -050070''',
71 marshal_output_call=gen_marshal_output_call(name, ret_type)).rstrip()
72 pop_indent(indent)
73 return ret.rstrip()
74
75
76def gen_marshal_output_call(name, ret_type):
77 if not ret_type:
78 return ""
Markus Armbruster297a3642014-05-07 09:53:54 +020079 return "qmp_marshal_output_%s(retval, ret, &local_err);" % c_fun(name)
Michael Rothc17d9902011-07-19 14:50:42 -050080
Markus Armbrusterf9bee752014-05-07 09:53:44 +020081def gen_visitor_input_containers_decl(args, obj):
Michael Rothc17d9902011-07-19 14:50:42 -050082 ret = ""
83
84 push_indent()
85 if len(args) > 0:
86 ret += mcgen('''
Markus Armbrusterf9bee752014-05-07 09:53:44 +020087QmpInputVisitor *mi = qmp_input_visitor_new_strict(%(obj)s);
Michael Rothc17d9902011-07-19 14:50:42 -050088QapiDeallocVisitor *md;
89Visitor *v;
Markus Armbrusterf9bee752014-05-07 09:53:44 +020090''',
91 obj=obj)
Michael Rothc17d9902011-07-19 14:50:42 -050092 pop_indent()
93
94 return ret.rstrip()
95
96def gen_visitor_input_vars_decl(args):
97 ret = ""
98 push_indent()
Eric Blake6b5abc72015-05-04 09:05:33 -060099 for argname, argtype, optional in parse_args(args):
Michael Rothc17d9902011-07-19 14:50:42 -0500100 if optional:
101 ret += mcgen('''
102bool has_%(argname)s = false;
103''',
104 argname=c_var(argname))
Amos Kong05dfb262014-06-10 19:25:53 +0800105 if is_c_ptr(argtype):
Michael Rothc17d9902011-07-19 14:50:42 -0500106 ret += mcgen('''
107%(argtype)s %(argname)s = NULL;
108''',
109 argname=c_var(argname), argtype=c_type(argtype))
110 else:
111 ret += mcgen('''
Michael Rothfc13d932014-05-20 12:20:39 -0500112%(argtype)s %(argname)s = {0};
Michael Rothc17d9902011-07-19 14:50:42 -0500113''',
114 argname=c_var(argname), argtype=c_type(argtype))
115
116 pop_indent()
117 return ret.rstrip()
118
Markus Armbrusterf9bee752014-05-07 09:53:44 +0200119def gen_visitor_input_block(args, dealloc=False):
Michael Rothc17d9902011-07-19 14:50:42 -0500120 ret = ""
Markus Armbruster297a3642014-05-07 09:53:54 +0200121 errparg = '&local_err'
122 errarg = 'local_err'
Luiz Capitulino8f91ad82013-07-11 14:26:56 -0400123
Michael Rothc17d9902011-07-19 14:50:42 -0500124 if len(args) == 0:
125 return ret
126
127 push_indent()
128
129 if dealloc:
Luiz Capitulino8f91ad82013-07-11 14:26:56 -0400130 errparg = 'NULL'
Markus Armbruster297a3642014-05-07 09:53:54 +0200131 errarg = None;
Michael Rothc17d9902011-07-19 14:50:42 -0500132 ret += mcgen('''
Markus Armbrusterf9bee752014-05-07 09:53:44 +0200133qmp_input_visitor_cleanup(mi);
Michael Rothc17d9902011-07-19 14:50:42 -0500134md = qapi_dealloc_visitor_new();
135v = qapi_dealloc_get_visitor(md);
136''')
137 else:
138 ret += mcgen('''
Michael Rothc17d9902011-07-19 14:50:42 -0500139v = qmp_input_get_visitor(mi);
Markus Armbrusterf9bee752014-05-07 09:53:44 +0200140''')
Michael Rothc17d9902011-07-19 14:50:42 -0500141
Eric Blake6b5abc72015-05-04 09:05:33 -0600142 for argname, argtype, optional in parse_args(args):
Michael Rothc17d9902011-07-19 14:50:42 -0500143 if optional:
144 ret += mcgen('''
Markus Armbrustere2cd0f42014-05-07 09:53:46 +0200145visit_optional(v, &has_%(c_name)s, "%(name)s", %(errp)s);
Michael Rothc17d9902011-07-19 14:50:42 -0500146''',
Luiz Capitulino8f91ad82013-07-11 14:26:56 -0400147 c_name=c_var(argname), name=argname, errp=errparg)
Markus Armbruster297a3642014-05-07 09:53:54 +0200148 ret += gen_err_check(errarg)
149 ret += mcgen('''
150if (has_%(c_name)s) {
151''',
152 c_name=c_var(argname))
Michael Rothc17d9902011-07-19 14:50:42 -0500153 push_indent()
154 ret += mcgen('''
Luiz Capitulino8f91ad82013-07-11 14:26:56 -0400155%(visitor)s(v, &%(c_name)s, "%(name)s", %(errp)s);
Michael Rothc17d9902011-07-19 14:50:42 -0500156''',
Anthony Liguori15e43e62011-09-14 14:30:00 -0500157 c_name=c_var(argname), name=argname, argtype=argtype,
Luiz Capitulino8f91ad82013-07-11 14:26:56 -0400158 visitor=type_visitor(argtype), errp=errparg)
Markus Armbruster297a3642014-05-07 09:53:54 +0200159 ret += gen_err_check(errarg)
Michael Rothc17d9902011-07-19 14:50:42 -0500160 if optional:
161 pop_indent()
162 ret += mcgen('''
163}
Markus Armbrustere2cd0f42014-05-07 09:53:46 +0200164''')
Michael Rothc17d9902011-07-19 14:50:42 -0500165
166 if dealloc:
167 ret += mcgen('''
168qapi_dealloc_visitor_cleanup(md);
169''')
Michael Rothc17d9902011-07-19 14:50:42 -0500170 pop_indent()
171 return ret.rstrip()
172
Anthony Liguori776574d2011-09-02 12:34:46 -0500173def gen_marshal_output(name, args, ret_type, middle_mode):
Michael Rothc17d9902011-07-19 14:50:42 -0500174 if not ret_type:
175 return ""
Anthony Liguori776574d2011-09-02 12:34:46 -0500176
Michael Rothc17d9902011-07-19 14:50:42 -0500177 ret = mcgen('''
178static void qmp_marshal_output_%(c_name)s(%(c_ret_type)s ret_in, QObject **ret_out, Error **errp)
179{
Markus Armbruster297a3642014-05-07 09:53:54 +0200180 Error *local_err = NULL;
Michael Rothc17d9902011-07-19 14:50:42 -0500181 QmpOutputVisitor *mo = qmp_output_visitor_new();
Markus Armbrusterf9bee752014-05-07 09:53:44 +0200182 QapiDeallocVisitor *md;
Michael Rothc17d9902011-07-19 14:50:42 -0500183 Visitor *v;
184
185 v = qmp_output_get_visitor(mo);
Markus Armbruster297a3642014-05-07 09:53:54 +0200186 %(visitor)s(v, &ret_in, "unused", &local_err);
187 if (local_err) {
188 goto out;
Michael Rothc17d9902011-07-19 14:50:42 -0500189 }
Markus Armbruster297a3642014-05-07 09:53:54 +0200190 *ret_out = qmp_output_get_qobject(mo);
191
192out:
193 error_propagate(errp, local_err);
Michael Rothc17d9902011-07-19 14:50:42 -0500194 qmp_output_visitor_cleanup(mo);
Markus Armbrusterf9bee752014-05-07 09:53:44 +0200195 md = qapi_dealloc_visitor_new();
Michael Rothc17d9902011-07-19 14:50:42 -0500196 v = qapi_dealloc_get_visitor(md);
Luiz Capitulino8f91ad82013-07-11 14:26:56 -0400197 %(visitor)s(v, &ret_in, "unused", NULL);
Michael Rothc17d9902011-07-19 14:50:42 -0500198 qapi_dealloc_visitor_cleanup(md);
199}
200''',
Federico Simoncellic9da2282012-03-20 13:54:35 +0000201 c_ret_type=c_type(ret_type), c_name=c_fun(name),
Anthony Liguori15e43e62011-09-14 14:30:00 -0500202 visitor=type_visitor(ret_type))
Michael Rothc17d9902011-07-19 14:50:42 -0500203
204 return ret
205
Anthony Liguori776574d2011-09-02 12:34:46 -0500206def gen_marshal_input_decl(name, args, ret_type, middle_mode):
207 if middle_mode:
Federico Simoncellic9da2282012-03-20 13:54:35 +0000208 return 'int qmp_marshal_input_%s(Monitor *mon, const QDict *qdict, QObject **ret)' % c_fun(name)
Anthony Liguori776574d2011-09-02 12:34:46 -0500209 else:
Federico Simoncellic9da2282012-03-20 13:54:35 +0000210 return 'static void qmp_marshal_input_%s(QDict *args, QObject **ret, Error **errp)' % c_fun(name)
Anthony Liguori776574d2011-09-02 12:34:46 -0500211
212
213
214def gen_marshal_input(name, args, ret_type, middle_mode):
215 hdr = gen_marshal_input_decl(name, args, ret_type, middle_mode)
216
Michael Rothc17d9902011-07-19 14:50:42 -0500217 ret = mcgen('''
Anthony Liguori776574d2011-09-02 12:34:46 -0500218%(header)s
Michael Rothc17d9902011-07-19 14:50:42 -0500219{
Markus Armbruster297a3642014-05-07 09:53:54 +0200220 Error *local_err = NULL;
Michael Rothc17d9902011-07-19 14:50:42 -0500221''',
Anthony Liguori776574d2011-09-02 12:34:46 -0500222 header=hdr)
223
224 if middle_mode:
225 ret += mcgen('''
Anthony Liguori776574d2011-09-02 12:34:46 -0500226 QDict *args = (QDict *)qdict;
227''')
Michael Rothc17d9902011-07-19 14:50:42 -0500228
229 if ret_type:
Amos Kong05dfb262014-06-10 19:25:53 +0800230 if is_c_ptr(ret_type):
Michael Rothc17d9902011-07-19 14:50:42 -0500231 retval = " %s retval = NULL;" % c_type(ret_type)
232 else:
233 retval = " %s retval;" % c_type(ret_type)
234 ret += mcgen('''
235%(retval)s
236''',
237 retval=retval)
238
239 if len(args) > 0:
240 ret += mcgen('''
241%(visitor_input_containers_decl)s
242%(visitor_input_vars_decl)s
243
244%(visitor_input_block)s
245
246''',
Markus Armbrusterf9bee752014-05-07 09:53:44 +0200247 visitor_input_containers_decl=gen_visitor_input_containers_decl(args, "QOBJECT(args)"),
Michael Rothc17d9902011-07-19 14:50:42 -0500248 visitor_input_vars_decl=gen_visitor_input_vars_decl(args),
Markus Armbrusterf9bee752014-05-07 09:53:44 +0200249 visitor_input_block=gen_visitor_input_block(args))
Anthony Liguori776574d2011-09-02 12:34:46 -0500250 else:
251 ret += mcgen('''
Markus Armbruster297a3642014-05-07 09:53:54 +0200252
Anthony Liguori776574d2011-09-02 12:34:46 -0500253 (void)args;
254''')
Michael Rothc17d9902011-07-19 14:50:42 -0500255
256 ret += mcgen('''
Michael Rothc17d9902011-07-19 14:50:42 -0500257%(sync_call)s
258''',
259 sync_call=gen_sync_call(name, args, ret_type, indent=4))
Markus Armbruster297a3642014-05-07 09:53:54 +0200260 if re.search('^ *goto out\\;', ret, re.MULTILINE):
261 ret += mcgen('''
Michael Rothc17d9902011-07-19 14:50:42 -0500262
263out:
264''')
Markus Armbruster297a3642014-05-07 09:53:54 +0200265 if not middle_mode:
266 ret += mcgen('''
267 error_propagate(errp, local_err);
268''')
Michael Rothc17d9902011-07-19 14:50:42 -0500269 ret += mcgen('''
270%(visitor_input_block_cleanup)s
Michael Rothc17d9902011-07-19 14:50:42 -0500271''',
Markus Armbrusterf9bee752014-05-07 09:53:44 +0200272 visitor_input_block_cleanup=gen_visitor_input_block(args,
Anthony Liguori776574d2011-09-02 12:34:46 -0500273 dealloc=True))
274
275 if middle_mode:
276 ret += mcgen('''
277
278 if (local_err) {
279 qerror_report_err(local_err);
280 error_free(local_err);
281 return -1;
282 }
283 return 0;
284''')
285 else:
286 ret += mcgen('''
287 return;
288''')
289
290 ret += mcgen('''
291}
292''')
293
Michael Rothc17d9902011-07-19 14:50:42 -0500294 return ret
295
296def gen_registry(commands):
297 registry=""
298 push_indent()
299 for cmd in commands:
Luiz Capitulinod34b8672012-05-08 14:24:44 -0300300 options = 'QCO_NO_OPTIONS'
Eric Blaked708cdb2015-05-04 09:05:19 -0600301 if not cmd.get('success-response', True):
Luiz Capitulinod34b8672012-05-08 14:24:44 -0300302 options = 'QCO_NO_SUCCESS_RESP'
303
Michael Rothc17d9902011-07-19 14:50:42 -0500304 registry += mcgen('''
Luiz Capitulinod34b8672012-05-08 14:24:44 -0300305qmp_register_command("%(name)s", qmp_marshal_input_%(c_name)s, %(opts)s);
Michael Rothc17d9902011-07-19 14:50:42 -0500306''',
Luiz Capitulinod34b8672012-05-08 14:24:44 -0300307 name=cmd['command'], c_name=c_fun(cmd['command']),
308 opts=options)
Michael Rothc17d9902011-07-19 14:50:42 -0500309 pop_indent()
310 ret = mcgen('''
311static void qmp_init_marshal(void)
312{
313%(registry)s
314}
315
316qapi_init(qmp_init_marshal);
317''',
318 registry=registry.rstrip())
319 return ret
320
321def gen_command_decl_prologue(header, guard, prefix=""):
322 ret = mcgen('''
323/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */
324
325/*
326 * schema-defined QAPI function prototypes
327 *
328 * Copyright IBM, Corp. 2011
329 *
330 * Authors:
331 * Anthony Liguori <aliguori@us.ibm.com>
332 *
333 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
334 * See the COPYING.LIB file in the top-level directory.
335 *
336 */
337
338#ifndef %(guard)s
339#define %(guard)s
340
341#include "%(prefix)sqapi-types.h"
Paolo Bonzini7b1b5d12012-12-17 18:19:43 +0100342#include "qapi/qmp/qdict.h"
343#include "qapi/error.h"
Michael Rothc17d9902011-07-19 14:50:42 -0500344
345''',
Anthony Liguori776574d2011-09-02 12:34:46 -0500346 header=basename(header), guard=guardname(header), prefix=prefix)
Michael Rothc17d9902011-07-19 14:50:42 -0500347 return ret
348
349def gen_command_def_prologue(prefix="", proxy=False):
350 ret = mcgen('''
351/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */
352
353/*
354 * schema-defined QMP->QAPI command dispatch
355 *
356 * Copyright IBM, Corp. 2011
357 *
358 * Authors:
359 * Anthony Liguori <aliguori@us.ibm.com>
360 *
361 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
362 * See the COPYING.LIB file in the top-level directory.
363 *
364 */
365
Paolo Bonzini79ee7df2012-12-06 11:22:34 +0100366#include "qemu-common.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +0100367#include "qemu/module.h"
Paolo Bonzini7b1b5d12012-12-17 18:19:43 +0100368#include "qapi/qmp/qerror.h"
369#include "qapi/qmp/types.h"
370#include "qapi/qmp/dispatch.h"
371#include "qapi/visitor.h"
Michael Rothc17d9902011-07-19 14:50:42 -0500372#include "qapi/qmp-output-visitor.h"
373#include "qapi/qmp-input-visitor.h"
Paolo Bonzini7b1b5d12012-12-17 18:19:43 +0100374#include "qapi/dealloc-visitor.h"
Michael Rothc17d9902011-07-19 14:50:42 -0500375#include "%(prefix)sqapi-types.h"
376#include "%(prefix)sqapi-visit.h"
377
378''',
379 prefix=prefix)
380 if not proxy:
381 ret += '#include "%sqmp-commands.h"' % prefix
Anthony Liguori776574d2011-09-02 12:34:46 -0500382 return ret + "\n\n"
Michael Rothc17d9902011-07-19 14:50:42 -0500383
384
385try:
Lluís Vilanova33aaad52014-05-02 15:52:35 +0200386 opts, args = getopt.gnu_getopt(sys.argv[1:], "chp:i:o:m",
Avi Kivity8d3bc512011-12-27 16:02:16 +0200387 ["source", "header", "prefix=",
Lluís Vilanova33aaad52014-05-02 15:52:35 +0200388 "input-file=", "output-dir=",
389 "type=", "middle"])
Michael Rothc17d9902011-07-19 14:50:42 -0500390except getopt.GetoptError, err:
391 print str(err)
392 sys.exit(1)
393
394output_dir = ""
395prefix = ""
396dispatch_type = "sync"
397c_file = 'qmp-marshal.c'
398h_file = 'qmp-commands.h'
Anthony Liguori776574d2011-09-02 12:34:46 -0500399middle_mode = False
Michael Rothc17d9902011-07-19 14:50:42 -0500400
Avi Kivity8d3bc512011-12-27 16:02:16 +0200401do_c = False
402do_h = False
403
Michael Rothc17d9902011-07-19 14:50:42 -0500404for o, a in opts:
405 if o in ("-p", "--prefix"):
406 prefix = a
Lluís Vilanova33aaad52014-05-02 15:52:35 +0200407 elif o in ("-i", "--input-file"):
408 input_file = a
Michael Rothc17d9902011-07-19 14:50:42 -0500409 elif o in ("-o", "--output-dir"):
410 output_dir = a + "/"
411 elif o in ("-t", "--type"):
412 dispatch_type = a
Anthony Liguori776574d2011-09-02 12:34:46 -0500413 elif o in ("-m", "--middle"):
414 middle_mode = True
Avi Kivity8d3bc512011-12-27 16:02:16 +0200415 elif o in ("-c", "--source"):
Avi Kivity8d3bc512011-12-27 16:02:16 +0200416 do_c = True
Avi Kivity19bf7c82011-12-28 12:26:58 +0200417 elif o in ("-h", "--header"):
418 do_h = True
Avi Kivity8d3bc512011-12-27 16:02:16 +0200419
420if not do_c and not do_h:
421 do_c = True
422 do_h = True
Michael Rothc17d9902011-07-19 14:50:42 -0500423
424c_file = output_dir + prefix + c_file
425h_file = output_dir + prefix + h_file
426
Avi Kivity8d3bc512011-12-27 16:02:16 +0200427def maybe_open(really, name, opt):
Avi Kivity8d3bc512011-12-27 16:02:16 +0200428 if really:
429 return open(name, opt)
430 else:
Avi Kivity19bf7c82011-12-28 12:26:58 +0200431 import StringIO
432 return StringIO.StringIO()
Avi Kivity8d3bc512011-12-27 16:02:16 +0200433
Michael Rothc17d9902011-07-19 14:50:42 -0500434try:
435 os.makedirs(output_dir)
436except os.error, e:
437 if e.errno != errno.EEXIST:
438 raise
439
Lluís Vilanova33aaad52014-05-02 15:52:35 +0200440exprs = parse_schema(input_file)
Michael Rothc17d9902011-07-19 14:50:42 -0500441commands = filter(lambda expr: expr.has_key('command'), exprs)
Anthony Liguori5dbee472011-12-12 14:29:33 -0600442commands = filter(lambda expr: not expr.has_key('gen'), commands)
Michael Rothc17d9902011-07-19 14:50:42 -0500443
444if dispatch_type == "sync":
Avi Kivity8d3bc512011-12-27 16:02:16 +0200445 fdecl = maybe_open(do_h, h_file, 'w')
446 fdef = maybe_open(do_c, c_file, 'w')
Michael Rothc17d9902011-07-19 14:50:42 -0500447 ret = gen_command_decl_prologue(header=basename(h_file), guard=guardname(h_file), prefix=prefix)
448 fdecl.write(ret)
449 ret = gen_command_def_prologue(prefix=prefix)
450 fdef.write(ret)
451
452 for cmd in commands:
453 arglist = []
454 ret_type = None
455 if cmd.has_key('data'):
456 arglist = cmd['data']
457 if cmd.has_key('returns'):
458 ret_type = cmd['returns']
459 ret = generate_command_decl(cmd['command'], arglist, ret_type) + "\n"
460 fdecl.write(ret)
461 if ret_type:
Anthony Liguori776574d2011-09-02 12:34:46 -0500462 ret = gen_marshal_output(cmd['command'], arglist, ret_type, middle_mode) + "\n"
Michael Rothc17d9902011-07-19 14:50:42 -0500463 fdef.write(ret)
Anthony Liguori776574d2011-09-02 12:34:46 -0500464
465 if middle_mode:
466 fdecl.write('%s;\n' % gen_marshal_input_decl(cmd['command'], arglist, ret_type, middle_mode))
467
468 ret = gen_marshal_input(cmd['command'], arglist, ret_type, middle_mode) + "\n"
Michael Rothc17d9902011-07-19 14:50:42 -0500469 fdef.write(ret)
470
Michael Roth7534ba02011-08-10 13:10:51 -0500471 fdecl.write("\n#endif\n");
Anthony Liguori776574d2011-09-02 12:34:46 -0500472
473 if not middle_mode:
474 ret = gen_registry(commands)
475 fdef.write(ret)
Michael Rothc17d9902011-07-19 14:50:42 -0500476
477 fdef.flush()
478 fdef.close()
479 fdecl.flush()
480 fdecl.close()