qemu-patch-raspberry4/include
Markus Armbruster a95291007b qapi: Eliminate indirection through qmp_event_get_func_emit()
The qapi_event_send_FOO() functions emit events like this:

    QMPEventFuncEmit emit;

    emit = qmp_event_get_func_emit();
    if (!emit) {
        return;
    }

    qmp = qmp_event_build_dict("FOO");
    [put event arguments into @qmp...]

    emit(QAPI_EVENT_FOO, qmp);

The value of qmp_event_get_func_emit() depends only on the program:

* In qemu-system-FOO, it's always monitor_qapi_event_queue.

* In tests/test-qmp-event, it's always event_test_emit.

* In all other programs, it's always null.

This is exactly the kind of dependence the linker is supposed to
resolve; we don't actually need an indirection.

Note that things would fall apart if we linked more than one QAPI
schema into a single program: each set of qapi_event_send_FOO() uses
its own event enumeration, yet they share a single emit function.
Which takes the event enumeration as an argument.  Which one if
there's more than one?

More seriously: how does this work even now?  qemu-system-FOO wants
QAPIEvent, and passes a function taking that to
qmp_event_set_func_emit().  test-qmp-event wants test_QAPIEvent, and
passes a function taking that to qmp_event_set_func_emit().

It works by type trickery, of course:

    typedef void (*QMPEventFuncEmit)(unsigned event, QDict *dict);

    void qmp_event_set_func_emit(QMPEventFuncEmit emit);

    QMPEventFuncEmit qmp_event_get_func_emit(void);

We use unsigned instead of the enumeration type.  Relies on both
enumerations boiling down to unsigned, which happens to be true for
the compilers we use.

Clean this up as follows:

* Generate qapi_event_send_FOO() that call PREFIX_qapi_event_emit()
  instead of the value of qmp_event_set_func_emit().

* Generate a prototype for PREFIX_qapi_event_emit() into
  qapi-events.h.

* PREFIX_ is empty for qapi/qapi-schema.json, and test_ for
  tests/qapi-schema/qapi-schema-test.json.  It's qga_ for
  qga/qapi-schema.json, and doc-good- for
  tests/qapi-schema/doc-good.json, but those don't define any events.

* Rename monitor_qapi_event_queue() to qapi_event_emit() instead of
  passing it to qmp_event_set_func_emit().  This takes care of
  qemu-system-FOO.

* Rename event_test_emit() to test_qapi_event_emit() instead of
  passing it to qmp_event_set_func_emit().  This takes care of
  tests/test-qmp-event.

* Add a qapi_event_emit() that does nothing to stubs/monitor.c.  This
  takes care of all other programs that link code emitting QMP events.

* Drop qmp_event_set_func_emit(), qmp_event_get_func_emit().

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20181218182234.28876-3-armbru@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
[Commit message typos fixed]
2019-01-24 10:01:05 +01:00
..
block nbd/client: Add meta contexts to nbd_receive_export_list() 2019-01-21 15:49:52 -06:00
chardev char: add a QEMU_CHAR_FEATURE_GCONTEXT flag 2018-12-12 09:55:57 +01:00
crypto crypto: support multiple threads accessing one QCryptoBlock 2018-12-12 11:16:49 +00:00
disas target/mips: Add disassembler support for nanoMIPS 2018-10-25 22:13:33 +02:00
exec qemu/queue.h: simplify reverse access to QTAILQ 2019-01-11 15:46:55 +01:00
fpu softfloat: add float{32,64}_is_zero_or_normal 2018-12-17 08:25:25 +00:00
hw virtio-net: Fix VirtIONet typedef redefinition 2019-01-22 06:26:05 +01:00
io io: return 0 for EOF in TLS session read after shutdown 2018-11-19 11:16:46 -06:00
libdecnumber Clean up ill-advised or unusual header guards 2016-07-12 16:20:46 +02:00
migration migration: Add post_save function to VMStateDescription 2019-01-21 10:38:55 +00:00
monitor monitor: Remove "x-oob", offer capability "oob" unconditionally 2018-12-12 10:28:27 +01:00
net virtio-net: support RSC v4/v6 tcp traffic for Windows HCK 2019-01-17 21:10:57 -05:00
qapi qapi: Eliminate indirection through qmp_event_get_func_emit() 2019-01-24 10:01:05 +01:00
qemu linux-user: Fix compilation with clang 3.4 2019-01-22 06:26:31 +01:00
qom qemu/queue.h: typedef QTAILQ heads 2019-01-11 15:46:55 +01:00
scsi avoid TABs in files that only contain a few 2019-01-11 15:46:56 +01:00
standard-headers linux-headers: update 2018-10-12 11:32:18 +02:00
sysemu hw/bt: Remove HCIInfo from "qemu/typedefs.h" 2019-01-22 05:14:32 +01:00
ui ui: highres logo for sdl and gtk, bugfixes for vnc and egl. 2019-01-23 17:57:47 +00:00
elf.h avoid TABs in files that only contain a few 2019-01-11 15:46:56 +01:00
glib-compat.h glib-compat: add g_spawn_async_with_fds() fallback 2019-01-14 00:44:29 +01:00
qemu-common.h qemu-common.h: update copyright date to 2018 2018-10-16 17:52:06 +02:00
qemu-io.h qemu-io: Let command functions return error code 2018-06-11 16:18:45 +02:00
trace-tcg.h trace: get rid of generated-events.h/generated-events.c 2016-10-12 09:54:52 +02:00