add direct support of event in qapi schema
v4 cover add direct support of event in qapi schema
This series add support for tag/keyword 'event' in qapi-schema. A new file was created to store some helper functions in patch 2, patch 4 is the test case, patch 5 is a convert example.
The implemention is done by generate API and a batch of parameters for each event define, it doesn't generate a struture and visit function in the background for every event, so it doesn't support nested structure in the define to avoid trouble. A callback layer is added to control the behavior. More detail can be found in patch 3's message and incode comments.
v2:
Address Luiz's comments:
patch 3: rename *err to *local_err, do not initialize *qmp = NULL, create
a new function qmp_build_evet_dict().
Other change:
reorgnized script in patch 3, it have a clear three steps, see patch 3's
incode comments.
v3:
Address Luiz's comments:
2/5: use -1 when fail to get host timestamp.
3/5: typo fix and better incode comments. all unchanged functions are moved
into qmp-event.c, from generated file. To do so without include issue, 'int' was used intead of 'enum' in function prototype declaration, since the 'enum' define is a generated type.
Address Eric's comments:
2/5: use -1 when fail to get host timestamp.
3/5: typo fix, add docs/qapi-code-gen.txt.
4/5: typo fix, verify no other fields in member 'timestamp'. 5/5: add doc in qapi-schema.json.
fix license, all script using GPL2, all C code use LGPL, just as other
similar files in upstream.
v4:
Address Eric's comments:
2/5: typo fix, add copyright declaration, use a static function pointer
instead of a struct in C file, assign -1 in two line of codes to avoid issue when tv_sec and tv_usec are not in same data width, fix indention.
3/5: typo fix, add copyright declaration.
4/5: add copyright declaration, simplify string compare with
"d->result = g_strcmp0(...) == 0;", add check for tv_usec's range and value.
Other:
3/5: all error check code was moved from qapi-event.py to qapi.py, and it
reports better message with line number info. Added related test case.
Note:
Benoit's series which track input file better seems not the final version,
so I didn't rebase this series ontop for now, will do it once Benoit's ones get ACKed.
Wenchao Xia (5):
1 os-posix: include sys/time.h
2 qapi: add event helper functions
3 qapi script: add event support
4 test: add test cases for qapi event
5 qapi event: convert RTC_CHANGE
Makefile | 9 +- Makefile.objs | 2 +- docs/qapi-code-gen.txt | 18 ++ include/qapi/qmp-event.h | 27 +++ include/sysemu/os-posix.h | 2 + monitor.c | 15 ++ qapi-schema.json | 13 + qapi/Makefile.objs | 1 + qapi/qmp-event.c | 70 ++++++ scripts/qapi-event.py | 366 ++++++++++++++++++++++++++++++ scripts/qapi.py | 12 + tests/Makefile | 17 +- tests/qapi-schema/event-nest-struct.err | 1 + tests/qapi-schema/event-nest-struct.exit | 1 + tests/qapi-schema/event-nest-struct.json | 2 + tests/qapi-schema/qapi-schema-test.json | 12 + tests/qapi-schema/qapi-schema-test.out | 10 +- tests/test-qmp-event.c | 265 +++++++++++++++++++++ vl.c | 7 +- 19 files changed, 835 insertions(+), 15 deletions(-) create mode 100644 include/qapi/qmp-event.h create mode 100644 qapi/qmp-event.c create mode 100644 scripts/qapi-event.py create mode 100644 tests/qapi-schema/event-nest-struct.err create mode 100644 tests/qapi-schema/event-nest-struct.exit create mode 100644 tests/qapi-schema/event-nest-struct.json create mode 100644 tests/qapi-schema/event-nest-struct.out create mode 100644 tests/test-qmp-event.c
RFC PATCH v4 1/5 os-posix: include sys/time.h
Since gettimeofday() is used in this header file as a macro define, include the function's define header file, to avoid compile warning when other file include os-posix.h.
--- include/sysemu/os-posix.h | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
include/sysemu/os-posix.h +2 -0
@@ -26,6 +26,8 @@#ifndef QEMU_OS_POSIX_H #define QEMU_OS_POSIX_H +#include <sys/time.h> +void os_set_line_buffering (void );void os_set_proc_name (const char *s);void os_setup_signal_handling (void );
Signature · 1 line
1.7.1
RFC PATCH v4 2/5 qapi: add event helper functions
In reply to Wenchao XiaThis file holds some functions that do not need to be generated.
--- include/qapi/qmp-event.h | 27 +++++++++++++++++ qapi/Makefile.objs | 1 + qapi/qmp-event.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 0 deletions(-) create mode 100644 include/qapi/qmp-event.h create mode 100644 qapi/qmp-event.c
include/qapi/qmp-event.h new file +27 -0
@@ -0,0 +1,27 @@ +/* +* QMP Event related +* +* Copyright (c) 2014 Wenchao Xia +* +* Authors: +* Wenchao Xia <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2.1 or later. +* See the COPYING.LIB file in the top-level directory. +* +*/ + +#ifndef QMP_EVENT_H +#define QMP_EVENT_H + +#include "qapi/error.h" +#include "qapi/qmp/qdict.h" + +typedef void (*QMPEventFuncEmit )(int event_kind,QDict *dict,Error **errp); + +void qmp_event_set_func_emit (QMPEventFuncEmit emit); + +QMPEventFuncEmit qmp_event_get_func_emit (void ); + +QDict *qmp_event_build_dict (const char *event_name); +#endif
qapi/Makefile.objs +1 -0
@@ -3,3 +3,4 @@ util-obj-y += qmp-output-visitor.o qmp-registry.o qmp-dispatch.o util-obj-y += string-input-visitor.o string-output-visitor.o util-obj-y += opts-visitor.o +util-obj-y += qmp-event.o
qapi/qmp-event.c new file +70 -0
70 lines not on this page · raw message
Signature · 1 line
1.7.1
Re: [Qemu-devel] [RFC PATCH V4 2/5] qapi: add event helper functions
Quoted 12 lines · Wenchao Xia
This file holds some functions that do not need to be generated.
Signed-off-by Wenchao Xia <[email protected]>--- include/qapi/qmp-event.h | 27 +++++++++++++++++ qapi/Makefile.objs | 1 + qapi/qmp-event.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 0 deletions(-) create mode 100644 include/qapi/qmp-event.h create mode 100644 qapi/qmp-event.c
qapi/qmp-event.c line 51
Quoted 5 lines
qapi/qmp-event.c new file +5
-0+ err =qemu_gettimeofday (&tv); +if (err <0 ) { +/* Put -1 to indicate failure of getting host time */ + tv.tv_sec =-1 ; + tv.tv_usec =-1 ;
You fixed the problem with C promotion here, but...
qapi/qmp-event.c line 56
Quoted 5 lines
qapi/qmp-event.c new file +5
-0+ } + + obj =qobject_from_jsonf ("{ 'seconds': %" PRId64", " +"'microseconds': %" PRId64" }" , + (int64_t ) tv.tv_sec, (int64_t ) tv.tv_usec);
...here, C promotion rules bite once again :( If tv_usec is uint32_t, then it zero-extends rather than sign-extends into int64_t, and you may end up with 0xffffffff instead of the intended -1. When doing potentially widening casts, it is only safe if you know the signedness of the pre-cast value; but with struct timeval, POSIX doesn't make that easy.
Maybe it's easier to just rewrite things with known types:
int64_t sec;
int usec;qemu_timval tv;
err = qemu_gettimeofday(&tv);
if (err < 0) {
sec = -1;
usec = -1;
} else {
sec = tv.tv_sec;
usec = tv.tv_usec;
}qobject_from_jsonf("... %"PRId64 ", ...%d", sec, usec)
since 'int' is guaranteed to be large enough for all the usec values we care about on all platforms we compile on (that is, we require 32-bit int, even if C allows for a 16-bit int implementation).
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [RFC PATCH V4 2/5] qapi: add event helper functions
Quoted 47 lines · Eric Blake
Quoted 12 lines · Wenchao Xia
This file holds some functions that do not need to be generated.
Signed-off-by Wenchao Xia <[email protected]>--- include/qapi/qmp-event.h | 27 +++++++++++++++++ qapi/Makefile.objs | 1 + qapi/qmp-event.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 0 deletions(-) create mode 100644 include/qapi/qmp-event.h create mode 100644 qapi/qmp-event.cqapi/qmp-event.c line 51
Quoted 5 lines
qapi/qmp-event.c new file +5
-0+ err =qemu_gettimeofday (&tv); +if (err <0 ) { +/* Put -1 to indicate failure of getting host time */ + tv.tv_sec =-1 ; + tv.tv_usec =-1 ;You fixed the problem with C promotion here, but...
qapi/qmp-event.c line 56
Quoted 5 lines
qapi/qmp-event.c new file +5
-0+ } + + obj =qobject_from_jsonf ("{ 'seconds': %" PRId64", " +"'microseconds': %" PRId64" }" , + (int64_t ) tv.tv_sec, (int64_t ) tv.tv_usec);...here, C promotion rules bite once again :( If
tv_usecisuint32_t, then it zero-extends rather than sign-extends intoint64_t, and you may end up with0xffffffffinstead of the intended -1. When doing potentially widening casts, it is only safe if you know the signedness of the pre-cast value; but with struct timeval, POSIX doesn't make that easy.Maybe it's easier to just rewrite things with known types:
int64_tsec;
int usec;qemu_timvaltv;
err =qemu_gettimeofday(&tv);if (err < 0) { sec = -1; usec = -1; } else { sec = tv.tv_sec; usec = tv.tv_usec; }
Quoted 5 lines
qobject_from_jsonf("... %"PRId64 ", ...%d", sec, usec)
since 'int' is guaranteed to be large enough for all the usec values we care about on all platforms we compile on (that is, we require 32-bit int, even if C allows for a 16-bit int implementation).
If you go that route, then why not go all the way nad make both sec and usec int64_t? Look ma, no type casts!
Re: [Qemu-devel] [RFC PATCH V4 2/5] qapi: add event helper functions
Quoted 51 lines · Markus Armbruster
Quoted 49 lines · Eric Blake
Quoted 12 lines · Wenchao Xia
This file holds some functions that do not need to be generated.
Signed-off-by Wenchao Xia <[email protected]>--- include/qapi/qmp-event.h | 27 +++++++++++++++++ qapi/Makefile.objs | 1 + qapi/qmp-event.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 0 deletions(-)create mode 100644
include/qapi/qmp-event.h
create mode 100644qapi/qmp-event.cqapi/qmp-event.c line 51
Quoted 5 lines
qapi/qmp-event.c new file +5
-0+ err =qemu_gettimeofday (&tv); +if (err <0 ) { +/* Put -1 to indicate failure of getting host time */ + tv.tv_sec =-1 ; + tv.tv_usec =-1 ;You fixed the problem with C promotion here, but...
qapi/qmp-event.c line 56
Quoted 5 lines
qapi/qmp-event.c new file +5
-0+ } + + obj =qobject_from_jsonf ("{ 'seconds': %" PRId64", " +"'microseconds': %" PRId64" }" , + (int64_t ) tv.tv_sec, (int64_t ) tv.tv_usec);...here, C promotion rules bite once again :( If
tv_usecisuint32_t, then it zero-extends rather than sign-extends intoint64_t, and you may end up with0xffffffffinstead of the intended -1. When doing potentially widening casts, it is only safe if you know the signedness of the pre-cast value; but with struct timeval, POSIX doesn't make that easy.Maybe it's easier to just rewrite things with known types:
int64_tsec;
int usec;qemu_timvaltv;
err =qemu_gettimeofday(&tv);if (err < 0) { sec = -1; usec = -1; } else { sec = tv.tv_sec; usec = tv.tv_usec; }qobject_from_jsonf("... %"PRId64 ", ...%d", sec, usec)
Quoted 7 lines
Quoted 3 lines
since 'int' is guaranteed to be large enough for all the usec values we care about on all platforms we compile on (that is, we require 32-bit int, even if C allows for a 16-bit int implementation).
If you go that route, then why not go all the way nad make both sec and usec
int64_t? Look ma, no type casts!
Yep, in this way code looks better... I will respin it later with a
full conversion.
RFC PATCH v4 3/5 qapi script: add event support
In reply to Wenchao Xiaqapi-event.py will parse the schema and generate qapi-event.c, then the API in qapi-event.c can be used to handle event in qemu code. All API have prefix "qapi_event".
The script mainly includes two parts: generate API for each event define, generate an enum type for all defined events.
Since in some cases the real emit behavior may change, for example, qemu-img would not send a event, a callback layer is used to control the behavior. As a result, the stubs at compile time can be saved, the binding of block layer code and monitor code will become looser.
--- Makefile | 9 +- Makefile.objs | 2 +- docs/qapi-code-gen.txt | 18 ++ scripts/qapi-event.py | 366 ++++++++++++++++++++++++++++++ scripts/qapi.py | 12 + tests/Makefile | 3 +- tests/qapi-schema/event-nest-struct.err | 1 + tests/qapi-schema/event-nest-struct.exit | 1 + tests/qapi-schema/event-nest-struct.json | 2 + 9 files changed, 409 insertions(+), 5 deletions(-) create mode 100644 scripts/qapi-event.py create mode 100644 tests/qapi-schema/event-nest-struct.err create mode 100644 tests/qapi-schema/event-nest-struct.exit create mode 100644 tests/qapi-schema/event-nest-struct.json create mode 100644 tests/qapi-schema/event-nest-struct.out
Makefile +6 -3
@@ -45,8 +45,8 @@ endif endif GENERATED_HEADERS = config-host.h qemu-options.def -GENERATED_HEADERS += qmp-commands.h qapi-types.h qapi-visit.h -GENERATED_SOURCES += qmp-marshal.c qapi-types.c qapi-visit.c +GENERATED_HEADERS += qmp-commands.h qapi-types.h qapi-visit.h qapi-event.h +GENERATED_SOURCES += qmp-marshal.c qapi-types.c qapi-visit.c qapi-event.c GENERATED_HEADERS += trace/generated-events.h GENERATED_SOURCES += trace/generated-events.c
@@ -207,7 +207,7 @@ Makefile: $(version-obj-y) $(version-lobj-y) # Build libraries libqemustub.a: $(stub-obj-y) -libqemuutil.a: $(util-obj-y) qapi-types.o qapi-visit.o +libqemuutil.a: $(util-obj-y) qapi-types.o qapi-visit.o qapi-event.o block-modules = $(foreach o,$(block-obj-m),"$(basename $(subst /,-,$o))",) NULL util/module.o-cflags = -D'CONFIG_BLOCK_MODULES=$(block-modules)'
@@ -251,6 +251,9 @@ $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-types.py $(qapi-py) qapi-visit.c qapi-visit.h :\ $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-visit.py $(qapi-py) $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py $(gen-out-type) -o "." -b < $<, " GEN $@") +qapi-event.c qapi-event.h :\ +$(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-event.py $(qapi-py) + $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-event.py $(gen-out-type) -o "." -b < $<, " GEN $@") qmp-commands.h qmp-marshal.c :\ $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-commands.py $(qapi-py) $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py $(gen-out-type) -m -o "." < $<, " GEN $@")
Makefile.objs +1 -1
@@ -12,7 +12,7 @@ block-obj-y += main-loop.o iohandler.o qemu-timer.o block-obj-$(CONFIG_POSIX) += aio-posix.o block-obj-$(CONFIG_WIN32) += aio-win32.o block-obj-y += block/ -block-obj-y += qapi-types.o qapi-visit.o +block-obj-y += qapi-types.o qapi-visit.o qapi-event.o block-obj-y += qemu-io-cmds.o block-obj-y += qemu-coroutine.o qemu-coroutine-lock.o qemu-coroutine-io.o
docs/qapi-code-gen.txt +18 -0
@@ -180,6 +180,24 @@ An example command is: 'data': { 'arg1': 'str', '*arg2': 'str' }, 'returns': 'str' } +=== Events === + +Events are defined with key word 'event'. When 'data' is also specified, +additional info will be carried on. Finally there will be C API generated +in qapi-event.h, and when called by QEMU code, a message with timestamp will +be emitted on the wire. If timestamp is -1, it means failure to retrieve host +time. + +An example event is: + +{ 'event': 'EVENT_C', + 'data': { '*a': 'int', 'b': 'str' } } + +Resulting in this JSON object: + +{ "event": "EVENT_C", + "data": { "b": "test string" }, + "timestamp": { "seconds": 1267020223, "microseconds": 435656 } } == Code generation ==
scripts/qapi-event.py new file +366 -0
366 lines not on this page · raw message
scripts/qapi.py +12 -0
@@ -199,6 +199,16 @@ def discriminator_find_enum_define(expr): return find_enum(discriminator_type) +def check_event(expr, expr_info): + params = expr.get('data') + if params: + for argname, argentry, optional, structured in parse_args(params): + if structured: + raise QAPIExprError(expr_info, + "Nested structure define in event is not " + "supported now, event '%s', argname '%s'" + % (expr['event'], argname)) + def check_union(expr, expr_info): name = expr['union'] base = expr.get('base')
@@ -262,6 +272,8 @@ def check_exprs(schema): expr = expr_elem['expr'] if expr.has_key('union'): check_union(expr, expr_elem['info']) + if expr.has_key('event'): + check_event(expr, expr_elem['info']) def parse_schema(fp): try:
tests/Makefile +2 -1
@@ -164,7 +164,8 @@ check-qapi-schema-y := $(addprefix tests/qapi-schema/, \ duplicate-key.json union-invalid-base.json flat-union-no-base.json \ flat-union-invalid-discriminator.json \ flat-union-invalid-branch-key.json flat-union-reverse-define.json \ - flat-union-string-discriminator.json) + flat-union-string-discriminator.json \ + event-nest-struct.json) GENERATED_HEADERS += tests/test-qapi-types.h tests/test-qapi-visit.h tests/test-qmp-commands.h
tests/qapi-schema/event-nest-struct.err new file +1 -0
@@ -0,0 +1 @@ +<stdin>:1: Nested structure define in event is not supported now, event 'EVENT_A', argname 'a'
tests/qapi-schema/event-nest-struct.exit new file +1 -0
@@ -0,0 +1 @@ +1
tests/qapi-schema/event-nest-struct.json new file +2 -0
@@ -0,0 +1,2 @@ +{ 'event': 'EVENT_A', + 'data': { 'a' : { 'string' : 'str', 'integer': 'int' }, 'b' : 'str' } }
tests/qapi-schema/event-nest-struct.out new file +0 -0
Signature · 1 line
1.7.1
RFC PATCH v4 4/5 test: add test cases for qapi event
In reply to Wenchao XiaThese cases will verify whether the expected qdict is built.
--- tests/Makefile | 14 ++- tests/qapi-schema/qapi-schema-test.json | 12 ++ tests/qapi-schema/qapi-schema-test.out | 10 +- tests/test-qmp-event.c | 265 +++++++++++++++++++++++++++++++ 4 files changed, 296 insertions(+), 5 deletions(-) create mode 100644 tests/test-qmp-event.c
tests/Makefile +11 -3
@@ -27,6 +27,8 @@ check-unit-y += tests/test-string-input-visitor$(EXESUF) gcov-files-test-string-input-visitor-y = qapi/string-input-visitor.c check-unit-y += tests/test-string-output-visitor$(EXESUF) gcov-files-test-string-output-visitor-y = qapi/string-output-visitor.c +check-unit-y += tests/test-qmp-event$(EXESUF) +gcov-files-test-qmp-event-y += qapi/qmp-event.c check-unit-y += tests/test-opts-visitor$(EXESUF) gcov-files-test-opts-visitor-y = qapi/opts-visitor.c check-unit-y += tests/test-coroutine$(EXESUF)
@@ -167,7 +169,8 @@ check-qapi-schema-y := $(addprefix tests/qapi-schema/, \ flat-union-string-discriminator.json \ event-nest-struct.json) -GENERATED_HEADERS += tests/test-qapi-types.h tests/test-qapi-visit.h tests/test-qmp-commands.h +GENERATED_HEADERS += tests/test-qapi-types.h tests/test-qapi-visit.h \ + tests/test-qapi-event.h tests/test-qmp-commands.h test-obj-y = tests/check-qint.o tests/check-qstring.o tests/check-qdict.o \ tests/check-qlist.o tests/check-qfloat.o tests/check-qjson.o \
@@ -176,9 +179,10 @@ test-obj-y = tests/check-qint.o tests/check-qstring.o tests/check-qdict.o \ tests/test-qmp-input-visitor.o tests/test-qmp-input-strict.o \ tests/test-qmp-commands.o tests/test-visitor-serialization.o \ tests/test-x86-cpuid.o tests/test-mul64.o tests/test-int128.o \ - tests/test-opts-visitor.o + tests/test-opts-visitor.o tests/test-qmp-event.o -test-qapi-obj-y = tests/test-qapi-visit.o tests/test-qapi-types.o +test-qapi-obj-y = tests/test-qapi-visit.o tests/test-qapi-types.o \ + tests/test-qapi-event.o $(test-obj-y): QEMU_INCLUDES += -Itests QEMU_CFLAGS += -I$(SRC_PATH)/tests
@@ -221,12 +225,16 @@ $(SRC_PATH)/tests/qapi-schema/qapi-schema-test.json $(SRC_PATH)/scripts/qapi-typ tests/test-qapi-visit.c tests/test-qapi-visit.h :\ $(SRC_PATH)/tests/qapi-schema/qapi-schema-test.json $(SRC_PATH)/scripts/qapi-visit.py $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py $(gen-out-type) -o tests -p "test-" < $<, " GEN $@") +tests/test-qapi-event.c tests/test-qapi-event.h :\ +$(SRC_PATH)/tests/qapi-schema/qapi-schema-test.json $(SRC_PATH)/scripts/qapi-event.py + $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-event.py $(gen-out-type) -o tests -p "test-" < $<, " GEN $@") tests/test-qmp-commands.h tests/test-qmp-marshal.c :\ $(SRC_PATH)/tests/qapi-schema/qapi-schema-test.json $(SRC_PATH)/scripts/qapi-commands.py $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py $(gen-out-type) -o tests -p "test-" < $<, " GEN $@") tests/test-string-output-visitor$(EXESUF): tests/test-string-output-visitor.o $(test-qapi-obj-y) libqemuutil.a libqemustub.a tests/test-string-input-visitor$(EXESUF): tests/test-string-input-visitor.o $(test-qapi-obj-y) libqemuutil.a libqemustub.a +tests/test-qmp-event$(EXESUF): tests/test-qmp-event.o $(test-qapi-obj-y) libqemuutil.a libqemustub.a tests/test-qmp-output-visitor$(EXESUF): tests/test-qmp-output-visitor.o $(test-qapi-obj-y) libqemuutil.a libqemustub.a tests/test-qmp-input-visitor$(EXESUF): tests/test-qmp-input-visitor.o $(test-qapi-obj-y) libqemuutil.a libqemustub.a tests/test-qmp-input-strict$(EXESUF): tests/test-qmp-input-strict.o $(test-qapi-obj-y) libqemuutil.a libqemustub.a
tests/qapi-schema/qapi-schema-test.json +12 -0
@@ -89,3 +89,15 @@ '*u16' : [ 'uint16' ], '*i64x': 'int' , '*u64x': 'uint64' } } + +# testing event +{ 'type': 'EventStructOne', + 'data': { 'struct1': 'UserDefOne', 'string': 'str', '*enum2': 'EnumOne' } } + +{ 'event': 'EVENT_A' } +{ 'event': 'EVENT_B', + 'data': { } } +{ 'event': 'EVENT_C', + 'data': { '*a': 'int', '*b': 'UserDefOne', 'c': 'str' } } +{ 'event': 'EVENT_D', + 'data': { 'a' : 'EventStructOne', 'b' : 'str', '*c': 'str', '*enum3': 'EnumOne' } }
tests/qapi-schema/qapi-schema-test.out +8 -2
@@ -15,7 +15,12 @@ OrderedDict([('command', 'user_def_cmd1'), ('data', OrderedDict([('ud1a', 'UserDefOne')]))]), OrderedDict([('command', 'user_def_cmd2'), ('data', OrderedDict([('ud1a', 'UserDefOne'), ('*ud1b', 'UserDefOne')])), ('returns', 'UserDefTwo')]), OrderedDict([('command', 'user_def_cmd3'), ('data', OrderedDict([('a', 'int'), ('*b', 'int')])), ('returns', 'int')]), - OrderedDict([('type', 'UserDefOptions'), ('data', OrderedDict([('*i64', ['int']), ('*u64', ['uint64']), ('*u16', ['uint16']), ('*i64x', 'int'), ('*u64x', 'uint64')]))])] + OrderedDict([('type', 'UserDefOptions'), ('data', OrderedDict([('*i64', ['int']), ('*u64', ['uint64']), ('*u16', ['uint16']), ('*i64x', 'int'), ('*u64x', 'uint64')]))]), + OrderedDict([('type', 'EventStructOne'), ('data', OrderedDict([('struct1', 'UserDefOne'), ('string', 'str'), ('*enum2', 'EnumOne')]))]), + OrderedDict([('event', 'EVENT_A')]), + OrderedDict([('event', 'EVENT_B'), ('data', OrderedDict())]), + OrderedDict([('event', 'EVENT_C'), ('data', OrderedDict([('*a', 'int'), ('*b', 'UserDefOne'), ('c', 'str')]))]), + OrderedDict([('event', 'EVENT_D'), ('data', OrderedDict([('a', 'EventStructOne'), ('b', 'str'), ('*c', 'str'), ('*enum3', 'EnumOne')]))])] [{'enum_name': 'EnumOne', 'enum_values': ['value1', 'value2', 'value3']}, {'enum_name': 'UserDefUnionKind', 'enum_values': None}, {'enum_name': 'UserDefAnonUnionKind', 'enum_values': None},
@@ -28,4 +33,5 @@ OrderedDict([('type', 'UserDefA'), ('data', OrderedDict([('boolean', 'bool')]))]), OrderedDict([('type', 'UserDefB'), ('data', OrderedDict([('integer', 'int')]))]), OrderedDict([('type', 'UserDefUnionBase'), ('data', OrderedDict([('string', 'str'), ('enum1', 'EnumOne')]))]), - OrderedDict([('type', 'UserDefOptions'), ('data', OrderedDict([('*i64', ['int']), ('*u64', ['uint64']), ('*u16', ['uint16']), ('*i64x', 'int'), ('*u64x', 'uint64')]))])] + OrderedDict([('type', 'UserDefOptions'), ('data', OrderedDict([('*i64', ['int']), ('*u64', ['uint64']), ('*u16', ['uint16']), ('*i64x', 'int'), ('*u64x', 'uint64')]))]), + OrderedDict([('type', 'EventStructOne'), ('data', OrderedDict([('struct1', 'UserDefOne'), ('string', 'str'), ('*enum2', 'EnumOne')]))])]
tests/test-qmp-event.c new file +265 -0
265 lines not on this page · raw message
Signature · 1 line
1.7.1
RFC PATCH v4 5/5 qapi event: convert RTC_CHANGE
In reply to Wenchao XiaThis is just an example of how to use qapi event API, and it bypassed the event throttle queue. A complete convert should be first define all events in qapi-schema.json, use qapi event types in monitor functions, then change caller one by one.
--- monitor.c | 15 +++++++++++++++ qapi-schema.json | 13 +++++++++++++ vl.c | 7 ++----- 3 files changed, 30 insertions(+), 5 deletions(-)
monitor.c +15 -0
@@ -57,6 +57,7 @@#include "qapi/qmp/qjson.h" #include "qapi/qmp/json-streamer.h" #include "qapi/qmp/json-parser.h" +#include "qapi/qmp-event.h" #include <qom/object_interfaces.h> #include "qemu/osdep.h" #include "cpu.h"
@@ -76,6 +77,8 @@#endif #include "hw/lm32/lm32_pic.h" +#include "qapi-event.h" +//#define DEBUG //#define DEBUG_COMPLETION
@@ -632,6 +635,16 @@ monitor_protocol_event_throttle(MonitorEvent event, evstate->data =NULL ; } +static void monitor_event_emit (int event_kind,QDict *d,Error **errp) +{ +Monitor *mon; + + QLIST_FOREACH(mon, &mon_list, entry) { +if (monitor_ctrl_mode (mon) &&qmp_cmd_mode (mon)) { +monitor_json_emitter (mon,QOBJECT (d)); + } + } +}/* Global, one-time initializer to configure the rate limiting * and initialize state */
@@ -644,6 +657,8 @@ static void monitor_protocol_event_init(void)/* limit the rate of quorum events to avoid hammering the management */ monitor_protocol_event_throttle (QEVENT_QUORUM_REPORT_BAD ,1000 );monitor_protocol_event_throttle (QEVENT_QUORUM_FAILURE ,1000 ); + +qmp_event_set_func_emit (monitor_event_emit); }/**
qapi-schema.json +13 -0
@@ -4689,3 +4689,16 @@ 'btn' : 'InputBtnEvent', 'rel' : 'InputMoveEvent', 'abs' : 'InputMoveEvent' } } + +## +# @RTC_CHANGE +# +# Emitted when the guest changes the RTC time. +# +# @offset: Offset between base RTC clock (as specified by -rtc base), and +# new RTC clock value +# +# Since: 2.1 +## +{ 'event': 'RTC_CHANGE', + 'data': { 'offset' : 'int' } }
vl.c +2 -5
@@ -117,6 +117,7 @@ int main(int argc, char **argv)#include "ui/qemu-spice.h" #include "qapi/string-input-visitor.h" #include "qom/object_interfaces.h" +#include "qapi-event.h" #define DEFAULT_RAM_SIZE 128
@@ -723,11 +724,7 @@ int qemu_timedate_diff(struct tm *tm)void rtc_change_mon_event (struct tm *tm) { -QObject *data; - - data =qobject_from_jsonf ("{ 'offset': %d }" ,qemu_timedate_diff (tm)); -monitor_protocol_event (QEVENT_RTC_CHANGE , data); -qobject_decref (data); +qapi_event_send_rtc_change (qemu_timedate_diff (tm),NULL ); }static void configure_rtc_date_offset (const char *startdate,int legacy)
Signature · 1 line
1.7.1