qapi: Generate QAPIEvent stuff into separate files
Having to include qapi-events.h just for QAPIEvent is suboptimal, but quite tolerable now. It'll become problematic when we have events conditional on the target, because then qapi-events.h won't be usable from target-independent code anymore. Avoid that by generating it into separate files. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20190214152251.2073-6-armbru@redhat.com>
This commit is contained in:
parent
c2e196a9b4
commit
5d75648b56
1
.gitignore
vendored
1
.gitignore
vendored
@ -32,6 +32,7 @@
|
||||
/qapi/qapi-builtin-visit.[ch]
|
||||
/qapi/qapi-commands-*.[ch]
|
||||
/qapi/qapi-commands.[ch]
|
||||
/qapi/qapi-emit-events.[ch]
|
||||
/qapi/qapi-events-*.[ch]
|
||||
/qapi/qapi-events.[ch]
|
||||
/qapi/qapi-introspect.[ch]
|
||||
|
1
Makefile
1
Makefile
@ -101,6 +101,7 @@ GENERATED_QAPI_FILES += $(QAPI_MODULES:%=qapi/qapi-visit-%.c)
|
||||
GENERATED_QAPI_FILES += qapi/qapi-commands.h qapi/qapi-commands.c
|
||||
GENERATED_QAPI_FILES += $(QAPI_MODULES:%=qapi/qapi-commands-%.h)
|
||||
GENERATED_QAPI_FILES += $(QAPI_MODULES:%=qapi/qapi-commands-%.c)
|
||||
GENERATED_QAPI_FILES += qapi/qapi-emit-events.h qapi/qapi-emit-events.c
|
||||
GENERATED_QAPI_FILES += qapi/qapi-events.h qapi/qapi-events.c
|
||||
GENERATED_QAPI_FILES += $(QAPI_MODULES:%=qapi/qapi-events-%.h)
|
||||
GENERATED_QAPI_FILES += $(QAPI_MODULES:%=qapi/qapi-events-%.c)
|
||||
|
@ -12,6 +12,7 @@ util-obj-y += $(QAPI_MODULES:%=qapi/qapi-types-%.o)
|
||||
util-obj-y += qapi/qapi-builtin-visit.o
|
||||
util-obj-y += qapi/qapi-visit.o
|
||||
util-obj-y += $(QAPI_MODULES:%=qapi/qapi-visit-%.o)
|
||||
util-obj-y += qapi/qapi-emit-events.o
|
||||
util-obj-y += qapi/qapi-events.o
|
||||
util-obj-y += $(QAPI_MODULES:%=qapi/qapi-events-%.o)
|
||||
util-obj-y += qapi/qapi-introspect.o
|
||||
|
@ -1381,11 +1381,15 @@ qapi_event_send_EVENT().
|
||||
|
||||
The following files are created:
|
||||
|
||||
$(prefix)qapi-events.h - Function prototypes for each event type, plus an
|
||||
enumeration of all event names
|
||||
$(prefix)qapi-events.h - Function prototypes for each event type
|
||||
|
||||
$(prefix)qapi-events.c - Implementation of functions to send an event
|
||||
|
||||
$(prefix)qapi-emit-events.h - Enumeration of all event names, and
|
||||
common event code declarations
|
||||
|
||||
$(prefix)qapi-emit-events.c - Common event code definitions
|
||||
|
||||
Example:
|
||||
|
||||
$ cat qapi-generated/example-qapi-events.h
|
||||
@ -1397,21 +1401,8 @@ Example:
|
||||
#include "qapi/util.h"
|
||||
#include "example-qapi-types.h"
|
||||
|
||||
|
||||
void qapi_event_send_my_event(void);
|
||||
|
||||
typedef enum example_QAPIEvent {
|
||||
EXAMPLE_QAPI_EVENT_MY_EVENT,
|
||||
EXAMPLE_QAPI_EVENT__MAX,
|
||||
} example_QAPIEvent;
|
||||
|
||||
#define example_QAPIEvent_str(val) \
|
||||
qapi_enum_lookup(&example_QAPIEvent_lookup, (val))
|
||||
|
||||
extern const QEnumLookup example_QAPIEvent_lookup;
|
||||
|
||||
void example_qapi_event_emit(example_QAPIEvent event, QDict *qdict);
|
||||
|
||||
#endif /* EXAMPLE_QAPI_EVENTS_H */
|
||||
$ cat qapi-generated/example-qapi-events.c
|
||||
[Uninteresting stuff omitted...]
|
||||
@ -1427,6 +1418,31 @@ Example:
|
||||
qobject_unref(qmp);
|
||||
}
|
||||
|
||||
[Uninteresting stuff omitted...]
|
||||
$ cat qapi-generated/example-qapi-emit-events.h
|
||||
[Uninteresting stuff omitted...]
|
||||
|
||||
#ifndef EXAMPLE_QAPI_EMIT_EVENTS_H
|
||||
#define EXAMPLE_QAPI_EMIT_EVENTS_H
|
||||
|
||||
#include "qapi/util.h"
|
||||
|
||||
typedef enum example_QAPIEvent {
|
||||
EXAMPLE_QAPI_EVENT_MY_EVENT,
|
||||
EXAMPLE_QAPI_EVENT__MAX,
|
||||
} example_QAPIEvent;
|
||||
|
||||
#define example_QAPIEvent_str(val) \
|
||||
qapi_enum_lookup(&example_QAPIEvent_lookup, (val))
|
||||
|
||||
extern const QEnumLookup example_QAPIEvent_lookup;
|
||||
|
||||
void example_qapi_event_emit(example_QAPIEvent event, QDict *qdict);
|
||||
|
||||
#endif /* EXAMPLE_QAPI_EMIT_EVENTS_H */
|
||||
$ cat qapi-generated/example-qapi-emit-events.c
|
||||
[Uninteresting stuff omitted...]
|
||||
|
||||
const QEnumLookup example_QAPIEvent_lookup = {
|
||||
.array = (const char *const[]) {
|
||||
[EXAMPLE_QAPI_EVENT_MY_EVENT] = "MY_EVENT",
|
||||
|
@ -75,7 +75,7 @@
|
||||
#include "qemu/thread.h"
|
||||
#include "block/qapi.h"
|
||||
#include "qapi/qapi-commands.h"
|
||||
#include "qapi/qapi-events.h"
|
||||
#include "qapi/qapi-emit-events.h"
|
||||
#include "qapi/error.h"
|
||||
#include "qapi/qmp-event.h"
|
||||
#include "qapi/qapi-introspect.h"
|
||||
|
@ -143,12 +143,14 @@ class QAPISchemaGenEventVisitor(QAPISchemaModularCVisitor):
|
||||
self._event_emit_name = c_name(prefix + 'qapi_event_emit')
|
||||
|
||||
def _begin_user_module(self, name):
|
||||
events = self._module_basename('qapi-events', name)
|
||||
types = self._module_basename('qapi-types', name)
|
||||
visit = self._module_basename('qapi-visit', name)
|
||||
self._genc.add(mcgen('''
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu-common.h"
|
||||
#include "%(prefix)sqapi-events.h"
|
||||
#include "%(prefix)sqapi-emit-events.h"
|
||||
#include "%(events)s.h"
|
||||
#include "%(visit)s.h"
|
||||
#include "qapi/error.h"
|
||||
#include "qapi/qmp/qdict.h"
|
||||
@ -156,26 +158,34 @@ class QAPISchemaGenEventVisitor(QAPISchemaModularCVisitor):
|
||||
#include "qapi/qmp-event.h"
|
||||
|
||||
''',
|
||||
visit=visit, prefix=self._prefix))
|
||||
events=events, visit=visit,
|
||||
prefix=self._prefix))
|
||||
self._genh.add(mcgen('''
|
||||
#include "qapi/util.h"
|
||||
#include "%(types)s.h"
|
||||
|
||||
''',
|
||||
types=types))
|
||||
|
||||
def visit_end(self):
|
||||
(genc, genh) = self._module[self._main_module]
|
||||
genh.add(gen_enum(self._event_enum_name,
|
||||
self._event_enum_members))
|
||||
genc.add(gen_enum_lookup(self._event_enum_name,
|
||||
self._event_enum_members))
|
||||
genh.add(mcgen('''
|
||||
self._add_system_module('emit', ' * QAPI Events emission')
|
||||
self._genc.preamble_add(mcgen('''
|
||||
#include "qemu/osdep.h"
|
||||
#include "%(prefix)sqapi-emit-events.h"
|
||||
''',
|
||||
prefix=self._prefix))
|
||||
self._genh.preamble_add(mcgen('''
|
||||
#include "qapi/util.h"
|
||||
'''))
|
||||
self._genh.add(gen_enum(self._event_enum_name,
|
||||
self._event_enum_members))
|
||||
self._genc.add(gen_enum_lookup(self._event_enum_name,
|
||||
self._event_enum_members))
|
||||
self._genh.add(mcgen('''
|
||||
|
||||
void %(event_emit)s(%(event_enum)s event, QDict *qdict);
|
||||
''',
|
||||
event_emit=self._event_emit_name,
|
||||
event_enum=self._event_enum_name))
|
||||
event_emit=self._event_emit_name,
|
||||
event_enum=self._event_enum_name))
|
||||
|
||||
def visit_event(self, name, info, ifcond, arg_type, boxed):
|
||||
with ifcontext(ifcond, self._genh, self._genc):
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "qemu/osdep.h"
|
||||
#include "qapi/error.h"
|
||||
#include "qapi/qapi-events.h"
|
||||
#include "qapi/qapi-emit-events.h"
|
||||
#include "qemu-common.h"
|
||||
#include "monitor/monitor.h"
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "qapi/qmp/qstring.h"
|
||||
#include "qapi/qmp-event.h"
|
||||
#include "test-qapi-events.h"
|
||||
#include "test-qapi-emit-events.h"
|
||||
|
||||
typedef struct TestEventData {
|
||||
QDict *expect;
|
||||
|
Loading…
Reference in New Issue
Block a user