4 # Copyright (c) 2014 Wenchao Xia
5 # Copyright (c) 2015 Red Hat Inc.
11 # This work is licensed under the terms of the GNU GPL, version 2.
12 # See the COPYING file in the top-level directory.
17 def gen_event_send_proto(name, arg_type):
18 return 'void qapi_event_send_%(c_name)s(%(param)s)' % {
19 'c_name': c_name(name.lower()),
20 'param': gen_params(arg_type, 'Error **errp')}
23 def gen_event_send_decl(name, arg_type):
28 proto=gen_event_send_proto(name, arg_type))
31 def gen_event_send(name, arg_type):
37 Error *local_err = NULL;
38 QMPEventFuncEmit emit;
40 proto=gen_event_send_proto(name, arg_type))
42 if arg_type and arg_type.members:
44 QmpOutputVisitor *qov;
51 emit = qmp_event_get_func_emit();
56 qmp = qmp_event_build_dict("%(name)s");
61 if arg_type and arg_type.members:
63 qov = qmp_output_visitor_new();
66 v = qmp_output_get_visitor(qov);
69 /* Fake visit, as if all members are under a structure */
70 visit_start_struct(v, NULL, "", "%(name)s", 0, &local_err);
78 for memb in arg_type.members:
83 c_name=c_name(memb.name))
86 # Ugly: need to cast away the const
87 if memb.type.name == "str":
93 visit_type_%(c_type)s(v, %(cast)s&%(c_name)s, "%(name)s", &local_err);
99 c_name=c_name(memb.name),
100 c_type=memb.type.c_name(),
111 visit_end_struct(v, &local_err);
116 obj = qmp_output_get_qobject(qov);
117 g_assert(obj != NULL);
119 qdict_put_obj(qmp, "data", obj);
123 emit(%(c_enum)s, qmp, &local_err);
126 c_enum=c_enum_const(event_enum_name, name))
128 if arg_type and arg_type.members:
131 qmp_output_visitor_cleanup(qov);
134 error_propagate(errp, local_err);
141 class QAPISchemaGenEventVisitor(QAPISchemaVisitor):
145 self._event_names = None
147 def visit_begin(self, schema):
150 self._event_names = []
153 self.decl += gen_enum(event_enum_name, self._event_names)
154 self.defn += gen_enum_lookup(event_enum_name, self._event_names)
155 self._event_names = None
157 def visit_event(self, name, info, arg_type):
158 self.decl += gen_event_send_decl(name, arg_type)
159 self.defn += gen_event_send(name, arg_type)
160 self._event_names.append(name)
163 (input_file, output_dir, do_c, do_h, prefix, dummy) = parse_command_line()
167 * schema-defined QAPI event functions
169 * Copyright (c) 2014 Wenchao Xia
174 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
175 * See the COPYING.LIB file in the top-level directory.
181 * schema-defined QAPI event functions
183 * Copyright (c) 2014 Wenchao Xia
188 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
189 * See the COPYING.LIB file in the top-level directory.
194 (fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix,
195 'qapi-event.c', 'qapi-event.h',
196 c_comment, h_comment)
199 #include "qemu-common.h"
200 #include "%(prefix)sqapi-event.h"
201 #include "%(prefix)sqapi-visit.h"
202 #include "qapi/qmp-output-visitor.h"
203 #include "qapi/qmp-event.h"
208 fdecl.write(mcgen('''
209 #include "qapi/error.h"
210 #include "qapi/qmp/qdict.h"
211 #include "%(prefix)sqapi-types.h"
216 event_enum_name = c_name(prefix + "QAPIEvent", protect=False)
218 schema = QAPISchema(input_file)
219 gen = QAPISchemaGenEventVisitor()
222 fdecl.write(gen.decl)
224 close_output(fdef, fdecl)