qemu-e2k/include
Eric Blake 3b098d5697 qapi: Add new visit_complete() function
Making each output visitor provide its own output collection
function was the only remaining reason for exposing visitor
sub-types to the rest of the code base.  Add a polymorphic
visit_complete() function which is a no-op for input visitors,
and which populates an opaque pointer for output visitors.  For
maximum type-safety, also add a parameter to the output visitor
constructors with a type-correct version of the output pointer,
and assert that the two uses match.

This approach was considered superior to either passing the
output parameter only during construction (action at a distance
during visit_free() feels awkward) or only during visit_complete()
(defeating type safety makes it easier to use incorrectly).

Most callers were function-local, and therefore a mechanical
conversion; the testsuite was a bit trickier, but the previous
cleanup patch minimized the churn here.

The visit_complete() function may be called at most once; doing
so lets us use transfer semantics rather than duplication or
ref-count semantics to get the just-built output back to the
caller, even though it means our behavior is not idempotent.

Generated code is simplified as follows for events:

|@@ -26,7 +26,7 @@ void qapi_event_send_acpi_device_ost(ACP
|     QDict *qmp;
|     Error *err = NULL;
|     QMPEventFuncEmit emit;
|-    QmpOutputVisitor *qov;
|+    QObject *obj;
|     Visitor *v;
|     q_obj_ACPI_DEVICE_OST_arg param = {
|         info
|@@ -39,8 +39,7 @@ void qapi_event_send_acpi_device_ost(ACP
|
|     qmp = qmp_event_build_dict("ACPI_DEVICE_OST");
|
|-    qov = qmp_output_visitor_new();
|-    v = qmp_output_get_visitor(qov);
|+    v = qmp_output_visitor_new(&obj);
|
|     visit_start_struct(v, "ACPI_DEVICE_OST", NULL, 0, &err);
|     if (err) {
|@@ -55,7 +54,8 @@ void qapi_event_send_acpi_device_ost(ACP
|         goto out;
|     }
|
|-    qdict_put_obj(qmp, "data", qmp_output_get_qobject(qov));
|+    visit_complete(v, &obj);
|+    qdict_put_obj(qmp, "data", obj);
|     emit(QAPI_EVENT_ACPI_DEVICE_OST, qmp, &err);

and for commands:

| {
|     Error *err = NULL;
|-    QmpOutputVisitor *qov = qmp_output_visitor_new();
|     Visitor *v;
|
|-    v = qmp_output_get_visitor(qov);
|+    v = qmp_output_visitor_new(ret_out);
|     visit_type_AddfdInfo(v, "unused", &ret_in, &err);
|-    if (err) {
|-        goto out;
|+    if (!err) {
|+        visit_complete(v, ret_out);
|     }
|-    *ret_out = qmp_output_get_qobject(qov);
|-
|-out:
|     error_propagate(errp, err);

Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1465490926-28625-13-git-send-email-eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-07-06 10:52:04 +02:00
..
block blockjob: add AioContext attached callback 2016-06-20 14:25:41 +01:00
crypto crypto: add support for TLS priority string override 2016-07-04 15:52:43 +01:00
disas qemu-common: push cpu.h inclusion out of qemu-common.h 2016-05-19 16:42:29 +02:00
exec memory: Assert that memory_region_init_rom_device() ops aren't NULL 2016-07-04 13:06:35 +01:00
fpu softfloat: Implement run-time-configurable meaning of signaling NaN bit 2016-06-24 13:40:37 +01:00
hw pc, pci, virtio: new features, cleanups, fixes 2016-07-05 16:48:24 +01:00
io socket: add listen feature 2016-06-29 16:49:41 +02:00
libdecnumber include: Clean up includes 2016-02-23 12:43:05 +00:00
migration scsi: esp: fix migration 2016-06-29 14:03:47 +02:00
monitor Use scripts/clean-includes to drop redundant qemu/typedefs.h 2016-03-22 22:20:16 +01:00
net vhost-net: save & restore vring enable state 2016-06-17 03:28:03 +03:00
qapi qapi: Add new visit_complete() function 2016-07-06 10:52:04 +02:00
qemu pc, pci, virtio: new features, cleanups, fixes 2016-07-05 16:48:24 +01:00
qom qom: API to get instance_size of a type 2016-06-17 16:33:48 +10:00
standard-headers linux-headers: update 2016-06-14 13:34:50 +02:00
sysemu hw/pci: delay bus_master_enable_region initialization 2016-07-04 14:50:01 +03:00
ui vnc: generalize "VNC server running on ..." message 2016-06-29 14:03:47 +02:00
elf.h linux-user: Update preprocessor constants for Mips-specific e_flags bits 2016-06-24 13:41:45 +01:00
glib-compat.h vhost-user-test: fix g_cond_wait_until compat implementation 2016-06-29 16:49:40 +02:00
qemu-common.h qemu-common.h: Drop WORDS_ALIGNED define 2016-06-07 18:19:24 +03:00
qemu-io.h qemu-io: Use BlockBackend 2015-02-16 15:07:19 +00:00
trace-tcg.h trace: [tcg] Generate TCG tracing routines 2014-08-12 14:26:12 +01:00
trace.h trace: [tcg] Include event definitions in "trace.h" 2014-08-12 14:26:12 +01:00