4 # Copyright (c) 2014 Wenchao Xia
5 # Copyright (c) 2015-2016 Red Hat Inc.
8 # Wenchao Xia <wenchaoqemu@gmail.com>
9 # Markus Armbruster <armbru@redhat.com>
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
):
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();
64 v = qmp_output_get_visitor(qov);
66 visit_start_struct(v, "%(name)s", NULL, 0, &err);
69 ret
+= gen_err_check()
70 ret
+= gen_visit_fields(arg_type
.members
, need_cast
=True,
74 visit_end_struct(v, err ? NULL : &err);
79 obj = qmp_output_get_qobject(qov);
82 qdict_put_obj(qmp, "data", obj);
86 emit(%(c_enum)s, qmp, &err);
89 c_enum
=c_enum_const(event_enum_name
, name
))
91 if arg_type
and arg_type
.members
:
94 qmp_output_visitor_cleanup(qov);
97 error_propagate(errp, err);
104 class QAPISchemaGenEventVisitor(QAPISchemaVisitor
):
108 self
._event
_names
= None
110 def visit_begin(self
, schema
):
113 self
._event
_names
= []
116 self
.decl
+= gen_enum(event_enum_name
, self
._event
_names
)
117 self
.defn
+= gen_enum_lookup(event_enum_name
, self
._event
_names
)
118 self
._event
_names
= None
120 def visit_event(self
, name
, info
, arg_type
):
121 self
.decl
+= gen_event_send_decl(name
, arg_type
)
122 self
.defn
+= gen_event_send(name
, arg_type
)
123 self
._event
_names
.append(name
)
126 (input_file
, output_dir
, do_c
, do_h
, prefix
, dummy
) = parse_command_line()
130 * schema-defined QAPI event functions
132 * Copyright (c) 2014 Wenchao Xia
135 * Wenchao Xia <wenchaoqemu@gmail.com>
137 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
138 * See the COPYING.LIB file in the top-level directory.
144 * schema-defined QAPI event functions
146 * Copyright (c) 2014 Wenchao Xia
149 * Wenchao Xia <wenchaoqemu@gmail.com>
151 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
152 * See the COPYING.LIB file in the top-level directory.
157 (fdef
, fdecl
) = open_output(output_dir
, do_c
, do_h
, prefix
,
158 'qapi-event.c', 'qapi-event.h',
159 c_comment
, h_comment
)
162 #include "qemu/osdep.h"
163 #include "qemu-common.h"
164 #include "%(prefix)sqapi-event.h"
165 #include "%(prefix)sqapi-visit.h"
166 #include "qapi/qmp-output-visitor.h"
167 #include "qapi/qmp-event.h"
172 fdecl
.write(mcgen('''
173 #include "qapi/error.h"
174 #include "qapi/qmp/qdict.h"
175 #include "%(prefix)sqapi-types.h"
180 event_enum_name
= c_name(prefix
+ "QAPIEvent", protect
=False)
182 schema
= QAPISchema(input_file
)
183 gen
= QAPISchemaGenEventVisitor()
186 fdecl
.write(gen
.decl
)
188 close_output(fdef
, fdecl
)