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 build_event_send_proto(name
, arg_type
, boxed
):
18 return 'void qapi_event_send_%(c_name)s(%(param)s)' % {
19 'c_name': c_name(name
.lower()),
20 'param': build_params(arg_type
, boxed
, 'Error **errp')}
23 def gen_event_send_decl(name
, arg_type
, boxed
):
28 proto
=build_event_send_proto(name
, arg_type
, boxed
))
31 # Declare and initialize an object 'qapi' using parameters from build_params()
32 def gen_param_var(typ
):
33 assert not typ
.variants
39 for memb
in typ
.members
:
43 ret
+= 'has_' + c_name(memb
.name
) + sep
44 if memb
.type.name
== 'str':
45 # Cast away const added in build_params()
47 ret
+= c_name(memb
.name
)
52 if not typ
.is_implicit():
54 %(c_name)s *arg = ¶m;
60 def gen_event_send(name
, arg_type
, boxed
):
61 # FIXME: Our declaration of local variables (and of 'errp' in the
62 # parameter list) can collide with exploded members of the event's
63 # data type passed in as parameters. If this collision ever hits in
64 # practice, we can rename our local variables with a leading _ prefix,
65 # or split the code into a wrapper function that creates a boxed
66 # 'param' object then calls another to do the real work.
73 QMPEventFuncEmit emit;
75 proto
=build_event_send_proto(name
, arg_type
, boxed
))
77 if arg_type
and not arg_type
.is_empty():
83 ret
+= gen_param_var(arg_type
)
89 emit = qmp_event_get_func_emit();
94 qmp = qmp_event_build_dict("%(name)s");
99 if arg_type
and not arg_type
.is_empty():
101 v = qobject_output_visitor_new(&obj);
103 if not arg_type
.is_implicit():
105 visit_type_%(c_name)s(v, "%(name)s", &arg, &err);
107 name
=name
, c_name
=arg_type
.c_name())
111 visit_start_struct(v, "%(name)s", NULL, 0, &err);
115 visit_type_%(c_name)s_members(v, ¶m, &err);
117 visit_check_struct(v, &err);
119 visit_end_struct(v, NULL);
121 name
=name
, c_name
=arg_type
.c_name())
127 visit_complete(v, &obj);
128 qdict_put_obj(qmp, "data", obj);
132 emit(%(c_enum)s, qmp, &err);
135 c_enum
=c_enum_const(event_enum_name
, name
))
137 if arg_type
and not arg_type
.is_empty():
143 error_propagate(errp, err);
150 class QAPISchemaGenEventVisitor(QAPISchemaVisitor
):
154 self
._event
_names
= None
156 def visit_begin(self
, schema
):
159 self
._event
_names
= []
162 self
.decl
+= gen_enum(event_enum_name
, self
._event
_names
)
163 self
.defn
+= gen_enum_lookup(event_enum_name
, self
._event
_names
)
164 self
._event
_names
= None
166 def visit_event(self
, name
, info
, arg_type
, boxed
):
167 self
.decl
+= gen_event_send_decl(name
, arg_type
, boxed
)
168 self
.defn
+= gen_event_send(name
, arg_type
, boxed
)
169 self
._event
_names
.append(name
)
172 (input_file
, output_dir
, do_c
, do_h
, prefix
, dummy
) = parse_command_line()
176 * schema-defined QAPI event functions
178 * Copyright (c) 2014 Wenchao Xia
181 * Wenchao Xia <wenchaoqemu@gmail.com>
183 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
184 * See the COPYING.LIB file in the top-level directory.
190 * schema-defined QAPI event functions
192 * Copyright (c) 2014 Wenchao Xia
195 * Wenchao Xia <wenchaoqemu@gmail.com>
197 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
198 * See the COPYING.LIB file in the top-level directory.
203 (fdef
, fdecl
) = open_output(output_dir
, do_c
, do_h
, prefix
,
204 'qapi-event.c', 'qapi-event.h',
205 c_comment
, h_comment
)
208 #include "qemu/osdep.h"
209 #include "qemu-common.h"
210 #include "%(prefix)sqapi-event.h"
211 #include "%(prefix)sqapi-visit.h"
212 #include "qapi/qobject-output-visitor.h"
213 #include "qapi/qmp-event.h"
218 fdecl
.write(mcgen('''
219 #include "qapi/error.h"
220 #include "qapi/qmp/qdict.h"
221 #include "%(prefix)sqapi-types.h"
226 event_enum_name
= c_name(prefix
+ 'QAPIEvent', protect
=False)
228 schema
= QAPISchema(input_file
)
229 gen
= QAPISchemaGenEventVisitor()
232 fdecl
.write(gen
.decl
)
234 close_output(fdef
, fdecl
)