blob: 0a1d636b18f4f60dac9dbd823632a87eca322610 [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
Michael Rothc17d9902011-07-19 14:50:42 -050023def generate_command_decl(name, args, ret_type):
24 arglist=""
Eric Blake6b5abc72015-05-04 09:05:33 -060025 for argname, argtype, optional in parse_args(args):
Amos Kong0d14eeb2014-06-10 19:25:52 +080026 argtype = c_type(argtype, is_param=True)
Michael Rothc17d9902011-07-19 14:50:42 -050027 if optional:
Eric Blake18df5152015-05-14 06:50:48 -060028 arglist += "bool has_%s, " % c_name(argname)
29 arglist += "%s %s, " % (argtype, c_name(argname))
Michael Rothc17d9902011-07-19 14:50:42 -050030 return mcgen('''
31%(ret_type)s qmp_%(name)s(%(args)sError **errp);
32''',
Eric Blake18df5152015-05-14 06:50:48 -060033 ret_type=c_type(ret_type), name=c_name(name),
34 args=arglist).strip()
Michael Rothc17d9902011-07-19 14:50:42 -050035
Markus Armbruster297a3642014-05-07 09:53:54 +020036def gen_err_check(errvar):
37 if errvar:
38 return mcgen('''
39if (local_err) {
40 goto out;
41}
42''')
43 return ''
44
Michael Rothc17d9902011-07-19 14:50:42 -050045def gen_sync_call(name, args, ret_type, indent=0):
46 ret = ""
47 arglist=""
48 retval=""
49 if ret_type:
50 retval = "retval = "
Eric Blake6b5abc72015-05-04 09:05:33 -060051 for argname, argtype, optional in parse_args(args):
Michael Rothc17d9902011-07-19 14:50:42 -050052 if optional:
Eric Blake18df5152015-05-14 06:50:48 -060053 arglist += "has_%s, " % c_name(argname)
54 arglist += "%s, " % (c_name(argname))
Michael Rothc17d9902011-07-19 14:50:42 -050055 push_indent(indent)
56 ret = mcgen('''
Markus Armbruster297a3642014-05-07 09:53:54 +020057%(retval)sqmp_%(name)s(%(args)s&local_err);
Michael Rothc17d9902011-07-19 14:50:42 -050058
59''',
Eric Blake18df5152015-05-14 06:50:48 -060060 name=c_name(name), args=arglist, retval=retval).rstrip()
Michael Rothc17d9902011-07-19 14:50:42 -050061 if ret_type:
Markus Armbruster297a3642014-05-07 09:53:54 +020062 ret += "\n" + gen_err_check('local_err')
Michael Rothc17d9902011-07-19 14:50:42 -050063 ret += "\n" + mcgen(''''
Markus Armbruster297a3642014-05-07 09:53:54 +020064%(marshal_output_call)s
Michael Rothc17d9902011-07-19 14:50:42 -050065''',
66 marshal_output_call=gen_marshal_output_call(name, ret_type)).rstrip()
67 pop_indent(indent)
68 return ret.rstrip()
69
70
71def gen_marshal_output_call(name, ret_type):
72 if not ret_type:
73 return ""
Eric Blake18df5152015-05-14 06:50:48 -060074 return "qmp_marshal_output_%s(retval, ret, &local_err);" % c_name(name)
Michael Rothc17d9902011-07-19 14:50:42 -050075
Markus Armbrusterf9bee752014-05-07 09:53:44 +020076def gen_visitor_input_containers_decl(args, obj):
Michael Rothc17d9902011-07-19 14:50:42 -050077 ret = ""
78
79 push_indent()
80 if len(args) > 0:
81 ret += mcgen('''
Markus Armbrusterf9bee752014-05-07 09:53:44 +020082QmpInputVisitor *mi = qmp_input_visitor_new_strict(%(obj)s);
Michael Rothc17d9902011-07-19 14:50:42 -050083QapiDeallocVisitor *md;
84Visitor *v;
Markus Armbrusterf9bee752014-05-07 09:53:44 +020085''',
86 obj=obj)
Michael Rothc17d9902011-07-19 14:50:42 -050087 pop_indent()
88
89 return ret.rstrip()
90
91def gen_visitor_input_vars_decl(args):
92 ret = ""
93 push_indent()
Eric Blake6b5abc72015-05-04 09:05:33 -060094 for argname, argtype, optional in parse_args(args):
Michael Rothc17d9902011-07-19 14:50:42 -050095 if optional:
96 ret += mcgen('''
97bool has_%(argname)s = false;
98''',
Eric Blake18df5152015-05-14 06:50:48 -060099 argname=c_name(argname))
Amos Kong05dfb262014-06-10 19:25:53 +0800100 if is_c_ptr(argtype):
Michael Rothc17d9902011-07-19 14:50:42 -0500101 ret += mcgen('''
102%(argtype)s %(argname)s = NULL;
103''',
Eric Blake18df5152015-05-14 06:50:48 -0600104 argname=c_name(argname), argtype=c_type(argtype))
Michael Rothc17d9902011-07-19 14:50:42 -0500105 else:
106 ret += mcgen('''
Michael Rothfc13d932014-05-20 12:20:39 -0500107%(argtype)s %(argname)s = {0};
Michael Rothc17d9902011-07-19 14:50:42 -0500108''',
Eric Blake18df5152015-05-14 06:50:48 -0600109 argname=c_name(argname), argtype=c_type(argtype))
Michael Rothc17d9902011-07-19 14:50:42 -0500110
111 pop_indent()
112 return ret.rstrip()
113
Markus Armbrusterf9bee752014-05-07 09:53:44 +0200114def gen_visitor_input_block(args, dealloc=False):
Michael Rothc17d9902011-07-19 14:50:42 -0500115 ret = ""
Markus Armbruster297a3642014-05-07 09:53:54 +0200116 errparg = '&local_err'
117 errarg = 'local_err'
Luiz Capitulino8f91ad82013-07-11 14:26:56 -0400118
Michael Rothc17d9902011-07-19 14:50:42 -0500119 if len(args) == 0:
120 return ret
121
122 push_indent()
123
124 if dealloc:
Luiz Capitulino8f91ad82013-07-11 14:26:56 -0400125 errparg = 'NULL'
Markus Armbruster297a3642014-05-07 09:53:54 +0200126 errarg = None;
Michael Rothc17d9902011-07-19 14:50:42 -0500127 ret += mcgen('''
Markus Armbrusterf9bee752014-05-07 09:53:44 +0200128qmp_input_visitor_cleanup(mi);
Michael Rothc17d9902011-07-19 14:50:42 -0500129md = qapi_dealloc_visitor_new();
130v = qapi_dealloc_get_visitor(md);
131''')
132 else:
133 ret += mcgen('''
Michael Rothc17d9902011-07-19 14:50:42 -0500134v = qmp_input_get_visitor(mi);
Markus Armbrusterf9bee752014-05-07 09:53:44 +0200135''')
Michael Rothc17d9902011-07-19 14:50:42 -0500136
Eric Blake6b5abc72015-05-04 09:05:33 -0600137 for argname, argtype, optional in parse_args(args):
Michael Rothc17d9902011-07-19 14:50:42 -0500138 if optional:
139 ret += mcgen('''
Markus Armbrustere2cd0f42014-05-07 09:53:46 +0200140visit_optional(v, &has_%(c_name)s, "%(name)s", %(errp)s);
Michael Rothc17d9902011-07-19 14:50:42 -0500141''',
Eric Blake18df5152015-05-14 06:50:48 -0600142 c_name=c_name(argname), name=argname, errp=errparg)
Markus Armbruster297a3642014-05-07 09:53:54 +0200143 ret += gen_err_check(errarg)
144 ret += mcgen('''
145if (has_%(c_name)s) {
146''',
Eric Blake18df5152015-05-14 06:50:48 -0600147 c_name=c_name(argname))
Michael Rothc17d9902011-07-19 14:50:42 -0500148 push_indent()
149 ret += mcgen('''
Eric Blakee3c4c3d2015-05-14 06:51:01 -0600150visit_type_%(visitor)s(v, &%(c_name)s, "%(name)s", %(errp)s);
Michael Rothc17d9902011-07-19 14:50:42 -0500151''',
Eric Blake18df5152015-05-14 06:50:48 -0600152 c_name=c_name(argname), name=argname, argtype=argtype,
Eric Blakee3c4c3d2015-05-14 06:51:01 -0600153 visitor=type_name(argtype), errp=errparg)
Markus Armbruster297a3642014-05-07 09:53:54 +0200154 ret += gen_err_check(errarg)
Michael Rothc17d9902011-07-19 14:50:42 -0500155 if optional:
156 pop_indent()
157 ret += mcgen('''
158}
Markus Armbrustere2cd0f42014-05-07 09:53:46 +0200159''')
Michael Rothc17d9902011-07-19 14:50:42 -0500160
161 if dealloc:
162 ret += mcgen('''
163qapi_dealloc_visitor_cleanup(md);
164''')
Michael Rothc17d9902011-07-19 14:50:42 -0500165 pop_indent()
166 return ret.rstrip()
167
Anthony Liguori776574d2011-09-02 12:34:46 -0500168def gen_marshal_output(name, args, ret_type, middle_mode):
Michael Rothc17d9902011-07-19 14:50:42 -0500169 if not ret_type:
170 return ""
Anthony Liguori776574d2011-09-02 12:34:46 -0500171
Michael Rothc17d9902011-07-19 14:50:42 -0500172 ret = mcgen('''
173static void qmp_marshal_output_%(c_name)s(%(c_ret_type)s ret_in, QObject **ret_out, Error **errp)
174{
Markus Armbruster297a3642014-05-07 09:53:54 +0200175 Error *local_err = NULL;
Michael Rothc17d9902011-07-19 14:50:42 -0500176 QmpOutputVisitor *mo = qmp_output_visitor_new();
Markus Armbrusterf9bee752014-05-07 09:53:44 +0200177 QapiDeallocVisitor *md;
Michael Rothc17d9902011-07-19 14:50:42 -0500178 Visitor *v;
179
180 v = qmp_output_get_visitor(mo);
Eric Blakee3c4c3d2015-05-14 06:51:01 -0600181 visit_type_%(visitor)s(v, &ret_in, "unused", &local_err);
Markus Armbruster297a3642014-05-07 09:53:54 +0200182 if (local_err) {
183 goto out;
Michael Rothc17d9902011-07-19 14:50:42 -0500184 }
Markus Armbruster297a3642014-05-07 09:53:54 +0200185 *ret_out = qmp_output_get_qobject(mo);
186
187out:
188 error_propagate(errp, local_err);
Michael Rothc17d9902011-07-19 14:50:42 -0500189 qmp_output_visitor_cleanup(mo);
Markus Armbrusterf9bee752014-05-07 09:53:44 +0200190 md = qapi_dealloc_visitor_new();
Michael Rothc17d9902011-07-19 14:50:42 -0500191 v = qapi_dealloc_get_visitor(md);
Eric Blakee3c4c3d2015-05-14 06:51:01 -0600192 visit_type_%(visitor)s(v, &ret_in, "unused", NULL);
Michael Rothc17d9902011-07-19 14:50:42 -0500193 qapi_dealloc_visitor_cleanup(md);
194}
195''',
Eric Blake18df5152015-05-14 06:50:48 -0600196 c_ret_type=c_type(ret_type), c_name=c_name(name),
Eric Blakee3c4c3d2015-05-14 06:51:01 -0600197 visitor=type_name(ret_type))
Michael Rothc17d9902011-07-19 14:50:42 -0500198
199 return ret
200
Anthony Liguori776574d2011-09-02 12:34:46 -0500201def gen_marshal_input_decl(name, args, ret_type, middle_mode):
202 if middle_mode:
Eric Blake18df5152015-05-14 06:50:48 -0600203 return 'int qmp_marshal_input_%s(Monitor *mon, const QDict *qdict, QObject **ret)' % c_name(name)
Anthony Liguori776574d2011-09-02 12:34:46 -0500204 else:
Eric Blake18df5152015-05-14 06:50:48 -0600205 return 'static void qmp_marshal_input_%s(QDict *args, QObject **ret, Error **errp)' % c_name(name)
Anthony Liguori776574d2011-09-02 12:34:46 -0500206
207
208
209def gen_marshal_input(name, args, ret_type, middle_mode):
210 hdr = gen_marshal_input_decl(name, args, ret_type, middle_mode)
211
Michael Rothc17d9902011-07-19 14:50:42 -0500212 ret = mcgen('''
Anthony Liguori776574d2011-09-02 12:34:46 -0500213%(header)s
Michael Rothc17d9902011-07-19 14:50:42 -0500214{
Markus Armbruster297a3642014-05-07 09:53:54 +0200215 Error *local_err = NULL;
Michael Rothc17d9902011-07-19 14:50:42 -0500216''',
Anthony Liguori776574d2011-09-02 12:34:46 -0500217 header=hdr)
218
219 if middle_mode:
220 ret += mcgen('''
Anthony Liguori776574d2011-09-02 12:34:46 -0500221 QDict *args = (QDict *)qdict;
222''')
Michael Rothc17d9902011-07-19 14:50:42 -0500223
224 if ret_type:
Amos Kong05dfb262014-06-10 19:25:53 +0800225 if is_c_ptr(ret_type):
Michael Rothc17d9902011-07-19 14:50:42 -0500226 retval = " %s retval = NULL;" % c_type(ret_type)
227 else:
228 retval = " %s retval;" % c_type(ret_type)
229 ret += mcgen('''
230%(retval)s
231''',
232 retval=retval)
233
234 if len(args) > 0:
235 ret += mcgen('''
236%(visitor_input_containers_decl)s
237%(visitor_input_vars_decl)s
238
239%(visitor_input_block)s
240
241''',
Markus Armbrusterf9bee752014-05-07 09:53:44 +0200242 visitor_input_containers_decl=gen_visitor_input_containers_decl(args, "QOBJECT(args)"),
Michael Rothc17d9902011-07-19 14:50:42 -0500243 visitor_input_vars_decl=gen_visitor_input_vars_decl(args),
Markus Armbrusterf9bee752014-05-07 09:53:44 +0200244 visitor_input_block=gen_visitor_input_block(args))
Anthony Liguori776574d2011-09-02 12:34:46 -0500245 else:
246 ret += mcgen('''
Markus Armbruster297a3642014-05-07 09:53:54 +0200247
Anthony Liguori776574d2011-09-02 12:34:46 -0500248 (void)args;
249''')
Michael Rothc17d9902011-07-19 14:50:42 -0500250
251 ret += mcgen('''
Michael Rothc17d9902011-07-19 14:50:42 -0500252%(sync_call)s
253''',
254 sync_call=gen_sync_call(name, args, ret_type, indent=4))
Markus Armbruster297a3642014-05-07 09:53:54 +0200255 if re.search('^ *goto out\\;', ret, re.MULTILINE):
256 ret += mcgen('''
Michael Rothc17d9902011-07-19 14:50:42 -0500257
258out:
259''')
Markus Armbruster297a3642014-05-07 09:53:54 +0200260 if not middle_mode:
261 ret += mcgen('''
262 error_propagate(errp, local_err);
263''')
Michael Rothc17d9902011-07-19 14:50:42 -0500264 ret += mcgen('''
265%(visitor_input_block_cleanup)s
Michael Rothc17d9902011-07-19 14:50:42 -0500266''',
Markus Armbrusterf9bee752014-05-07 09:53:44 +0200267 visitor_input_block_cleanup=gen_visitor_input_block(args,
Anthony Liguori776574d2011-09-02 12:34:46 -0500268 dealloc=True))
269
270 if middle_mode:
271 ret += mcgen('''
272
273 if (local_err) {
274 qerror_report_err(local_err);
275 error_free(local_err);
276 return -1;
277 }
278 return 0;
279''')
280 else:
281 ret += mcgen('''
282 return;
283''')
284
285 ret += mcgen('''
286}
287''')
288
Michael Rothc17d9902011-07-19 14:50:42 -0500289 return ret
290
291def gen_registry(commands):
292 registry=""
293 push_indent()
294 for cmd in commands:
Luiz Capitulinod34b8672012-05-08 14:24:44 -0300295 options = 'QCO_NO_OPTIONS'
Eric Blaked708cdb2015-05-04 09:05:19 -0600296 if not cmd.get('success-response', True):
Luiz Capitulinod34b8672012-05-08 14:24:44 -0300297 options = 'QCO_NO_SUCCESS_RESP'
298
Michael Rothc17d9902011-07-19 14:50:42 -0500299 registry += mcgen('''
Luiz Capitulinod34b8672012-05-08 14:24:44 -0300300qmp_register_command("%(name)s", qmp_marshal_input_%(c_name)s, %(opts)s);
Michael Rothc17d9902011-07-19 14:50:42 -0500301''',
Eric Blake18df5152015-05-14 06:50:48 -0600302 name=cmd['command'], c_name=c_name(cmd['command']),
Luiz Capitulinod34b8672012-05-08 14:24:44 -0300303 opts=options)
Michael Rothc17d9902011-07-19 14:50:42 -0500304 pop_indent()
305 ret = mcgen('''
306static void qmp_init_marshal(void)
307{
308%(registry)s
309}
310
311qapi_init(qmp_init_marshal);
312''',
313 registry=registry.rstrip())
314 return ret
315
316def gen_command_decl_prologue(header, guard, prefix=""):
317 ret = mcgen('''
318/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */
319
320/*
321 * schema-defined QAPI function prototypes
322 *
323 * Copyright IBM, Corp. 2011
324 *
325 * Authors:
326 * Anthony Liguori <aliguori@us.ibm.com>
327 *
328 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
329 * See the COPYING.LIB file in the top-level directory.
330 *
331 */
332
333#ifndef %(guard)s
334#define %(guard)s
335
336#include "%(prefix)sqapi-types.h"
Paolo Bonzini7b1b5d12012-12-17 18:19:43 +0100337#include "qapi/qmp/qdict.h"
338#include "qapi/error.h"
Michael Rothc17d9902011-07-19 14:50:42 -0500339
340''',
Anthony Liguori776574d2011-09-02 12:34:46 -0500341 header=basename(header), guard=guardname(header), prefix=prefix)
Michael Rothc17d9902011-07-19 14:50:42 -0500342 return ret
343
344def gen_command_def_prologue(prefix="", proxy=False):
345 ret = mcgen('''
346/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */
347
348/*
349 * schema-defined QMP->QAPI command dispatch
350 *
351 * Copyright IBM, Corp. 2011
352 *
353 * Authors:
354 * Anthony Liguori <aliguori@us.ibm.com>
355 *
356 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
357 * See the COPYING.LIB file in the top-level directory.
358 *
359 */
360
Paolo Bonzini79ee7df2012-12-06 11:22:34 +0100361#include "qemu-common.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +0100362#include "qemu/module.h"
Paolo Bonzini7b1b5d12012-12-17 18:19:43 +0100363#include "qapi/qmp/qerror.h"
364#include "qapi/qmp/types.h"
365#include "qapi/qmp/dispatch.h"
366#include "qapi/visitor.h"
Michael Rothc17d9902011-07-19 14:50:42 -0500367#include "qapi/qmp-output-visitor.h"
368#include "qapi/qmp-input-visitor.h"
Paolo Bonzini7b1b5d12012-12-17 18:19:43 +0100369#include "qapi/dealloc-visitor.h"
Michael Rothc17d9902011-07-19 14:50:42 -0500370#include "%(prefix)sqapi-types.h"
371#include "%(prefix)sqapi-visit.h"
372
373''',
374 prefix=prefix)
375 if not proxy:
376 ret += '#include "%sqmp-commands.h"' % prefix
Anthony Liguori776574d2011-09-02 12:34:46 -0500377 return ret + "\n\n"
Michael Rothc17d9902011-07-19 14:50:42 -0500378
379
380try:
Lluís Vilanova33aaad52014-05-02 15:52:35 +0200381 opts, args = getopt.gnu_getopt(sys.argv[1:], "chp:i:o:m",
Avi Kivity8d3bc512011-12-27 16:02:16 +0200382 ["source", "header", "prefix=",
Lluís Vilanova33aaad52014-05-02 15:52:35 +0200383 "input-file=", "output-dir=",
384 "type=", "middle"])
Michael Rothc17d9902011-07-19 14:50:42 -0500385except getopt.GetoptError, err:
386 print str(err)
387 sys.exit(1)
388
389output_dir = ""
390prefix = ""
391dispatch_type = "sync"
392c_file = 'qmp-marshal.c'
393h_file = 'qmp-commands.h'
Anthony Liguori776574d2011-09-02 12:34:46 -0500394middle_mode = False
Michael Rothc17d9902011-07-19 14:50:42 -0500395
Avi Kivity8d3bc512011-12-27 16:02:16 +0200396do_c = False
397do_h = False
398
Michael Rothc17d9902011-07-19 14:50:42 -0500399for o, a in opts:
400 if o in ("-p", "--prefix"):
401 prefix = a
Lluís Vilanova33aaad52014-05-02 15:52:35 +0200402 elif o in ("-i", "--input-file"):
403 input_file = a
Michael Rothc17d9902011-07-19 14:50:42 -0500404 elif o in ("-o", "--output-dir"):
405 output_dir = a + "/"
406 elif o in ("-t", "--type"):
407 dispatch_type = a
Anthony Liguori776574d2011-09-02 12:34:46 -0500408 elif o in ("-m", "--middle"):
409 middle_mode = True
Avi Kivity8d3bc512011-12-27 16:02:16 +0200410 elif o in ("-c", "--source"):
Avi Kivity8d3bc512011-12-27 16:02:16 +0200411 do_c = True
Avi Kivity19bf7c82011-12-28 12:26:58 +0200412 elif o in ("-h", "--header"):
413 do_h = True
Avi Kivity8d3bc512011-12-27 16:02:16 +0200414
415if not do_c and not do_h:
416 do_c = True
417 do_h = True
Michael Rothc17d9902011-07-19 14:50:42 -0500418
419c_file = output_dir + prefix + c_file
420h_file = output_dir + prefix + h_file
421
Avi Kivity8d3bc512011-12-27 16:02:16 +0200422def maybe_open(really, name, opt):
Avi Kivity8d3bc512011-12-27 16:02:16 +0200423 if really:
424 return open(name, opt)
425 else:
Avi Kivity19bf7c82011-12-28 12:26:58 +0200426 import StringIO
427 return StringIO.StringIO()
Avi Kivity8d3bc512011-12-27 16:02:16 +0200428
Michael Rothc17d9902011-07-19 14:50:42 -0500429try:
430 os.makedirs(output_dir)
431except os.error, e:
432 if e.errno != errno.EEXIST:
433 raise
434
Lluís Vilanova33aaad52014-05-02 15:52:35 +0200435exprs = parse_schema(input_file)
Michael Rothc17d9902011-07-19 14:50:42 -0500436commands = filter(lambda expr: expr.has_key('command'), exprs)
Anthony Liguori5dbee472011-12-12 14:29:33 -0600437commands = filter(lambda expr: not expr.has_key('gen'), commands)
Michael Rothc17d9902011-07-19 14:50:42 -0500438
439if dispatch_type == "sync":
Avi Kivity8d3bc512011-12-27 16:02:16 +0200440 fdecl = maybe_open(do_h, h_file, 'w')
441 fdef = maybe_open(do_c, c_file, 'w')
Michael Rothc17d9902011-07-19 14:50:42 -0500442 ret = gen_command_decl_prologue(header=basename(h_file), guard=guardname(h_file), prefix=prefix)
443 fdecl.write(ret)
444 ret = gen_command_def_prologue(prefix=prefix)
445 fdef.write(ret)
446
447 for cmd in commands:
448 arglist = []
449 ret_type = None
450 if cmd.has_key('data'):
451 arglist = cmd['data']
452 if cmd.has_key('returns'):
453 ret_type = cmd['returns']
454 ret = generate_command_decl(cmd['command'], arglist, ret_type) + "\n"
455 fdecl.write(ret)
456 if ret_type:
Anthony Liguori776574d2011-09-02 12:34:46 -0500457 ret = gen_marshal_output(cmd['command'], arglist, ret_type, middle_mode) + "\n"
Michael Rothc17d9902011-07-19 14:50:42 -0500458 fdef.write(ret)
Anthony Liguori776574d2011-09-02 12:34:46 -0500459
460 if middle_mode:
461 fdecl.write('%s;\n' % gen_marshal_input_decl(cmd['command'], arglist, ret_type, middle_mode))
462
463 ret = gen_marshal_input(cmd['command'], arglist, ret_type, middle_mode) + "\n"
Michael Rothc17d9902011-07-19 14:50:42 -0500464 fdef.write(ret)
465
Michael Roth7534ba02011-08-10 13:10:51 -0500466 fdecl.write("\n#endif\n");
Anthony Liguori776574d2011-09-02 12:34:46 -0500467
468 if not middle_mode:
469 ret = gen_registry(commands)
470 fdef.write(ret)
Michael Rothc17d9902011-07-19 14:50:42 -0500471
472 fdef.flush()
473 fdef.close()
474 fdecl.flush()
475 fdecl.close()