diff options
| author | Peter Maydell <peter.maydell@linaro.org> | 2014-06-24 13:06:13 +0100 |
|---|---|---|
| committer | Peter Maydell <peter.maydell@linaro.org> | 2014-06-24 13:06:13 +0100 |
| commit | 089a39486f2c47994c6c0d34ac7abf34baf40d9d (patch) | |
| tree | 07bf9220989162df8d29b99568d13ce6d5261822 /qapi/qmp-event.c | |
| parent | 27acb9dd2407f41550e453b85aa5ebf1bd618b79 (diff) | |
| parent | d622cb5879ca8006d5482158e4e3b272a068c301 (diff) | |
| download | focaccia-qemu-089a39486f2c47994c6c0d34ac7abf34baf40d9d.tar.gz focaccia-qemu-089a39486f2c47994c6c0d34ac7abf34baf40d9d.zip | |
Merge remote-tracking branch 'remotes/qmp-unstable/queue/qmp' into staging
* remotes/qmp-unstable/queue/qmp: (43 commits) monitor: protect event emission monitor: protect outbuf and mux_out with mutex qemu-char: make writes thread-safe qemu-char: move pty_chr_update_read_handler around qemu-char: do not call chr_write directly qemu-char: introduce qemu_chr_alloc qapi event: clean up qapi event: convert QUORUM events qapi event: convert GUEST_PANICKED qapi event: convert BALLOON_CHANGE qmp: convert ACPI_DEVICE_OST event qapi event: convert SPICE events qapi event: convert VNC events qapi event: convert NIC_RX_FILTER_CHANGED qapi event: convert other BLOCK_JOB events qapi event: convert BLOCK_IMAGE_CORRUPTED qapi event: convert BLOCK_IO_ERROR and BLOCK_JOB_ERROR qapi event: convert DEVICE_TRAY_MOVED qapi event: convert DEVICE_DELETED qapi event: convert WATCHDOG ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'qapi/qmp-event.c')
| -rw-r--r-- | qapi/qmp-event.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/qapi/qmp-event.c b/qapi/qmp-event.c new file mode 100644 index 0000000000..0d1ce0bd18 --- /dev/null +++ b/qapi/qmp-event.c @@ -0,0 +1,74 @@ +/* + * QMP Event related + * + * Copyright (c) 2014 Wenchao Xia + * + * Authors: + * Wenchao Xia <wenchaoqemu@gmail.com> + * + * 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. + * + */ + +#include <inttypes.h> + +#include "qemu-common.h" +#include "qapi/qmp-event.h" +#include "qapi/qmp/qstring.h" +#include "qapi/qmp/qjson.h" + +#ifdef _WIN32 +#include "sysemu/os-win32.h" +#endif + +#ifdef CONFIG_POSIX +#include "sysemu/os-posix.h" +#endif + +static QMPEventFuncEmit qmp_emit; + +void qmp_event_set_func_emit(QMPEventFuncEmit emit) +{ + qmp_emit = emit; +} + +QMPEventFuncEmit qmp_event_get_func_emit(void) +{ + return qmp_emit; +} + +static void timestamp_put(QDict *qdict) +{ + int err; + QObject *obj; + qemu_timeval tv; + int64_t sec, usec; + + err = qemu_gettimeofday(&tv); + if (err < 0) { + /* Put -1 to indicate failure of getting host time */ + sec = -1; + usec = -1; + } else { + sec = tv.tv_sec; + usec = tv.tv_usec; + } + + obj = qobject_from_jsonf("{ 'seconds': %" PRId64 ", " + "'microseconds': %" PRId64 " }", + sec, usec); + qdict_put_obj(qdict, "timestamp", obj); +} + +/* + * Build a QDict, then fill event name and time stamp, caller should free the + * QDict after usage. + */ +QDict *qmp_event_build_dict(const char *event_name) +{ + QDict *dict = qdict_new(); + qdict_put(dict, "event", qstring_from_str(event_name)); + timestamp_put(dict); + return dict; +} |