]> git.proxmox.com Git - mirror_qemu.git/blame - qapi/qmp-event.c
Merge remote-tracking branch 'dgibson/tags/ppc-for-2.8-20161201' into staging
[mirror_qemu.git] / qapi / qmp-event.c
CommitLineData
f8821260
WX
1/*
2 * QMP Event related
3 *
4 * Copyright (c) 2014 Wenchao Xia
5 *
6 * Authors:
7 * Wenchao Xia <wenchaoqemu@gmail.com>
8 *
9 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
10 * See the COPYING.LIB file in the top-level directory.
11 *
12 */
13
cbf21151 14#include "qemu/osdep.h"
f8821260
WX
15
16#include "qemu-common.h"
17#include "qapi/qmp-event.h"
18#include "qapi/qmp/qstring.h"
19#include "qapi/qmp/qjson.h"
20
f8821260
WX
21static QMPEventFuncEmit qmp_emit;
22
23void qmp_event_set_func_emit(QMPEventFuncEmit emit)
24{
25 qmp_emit = emit;
26}
27
28QMPEventFuncEmit qmp_event_get_func_emit(void)
29{
30 return qmp_emit;
31}
32
33static void timestamp_put(QDict *qdict)
34{
35 int err;
36 QObject *obj;
37 qemu_timeval tv;
38 int64_t sec, usec;
39
40 err = qemu_gettimeofday(&tv);
41 if (err < 0) {
42 /* Put -1 to indicate failure of getting host time */
43 sec = -1;
44 usec = -1;
45 } else {
46 sec = tv.tv_sec;
47 usec = tv.tv_usec;
48 }
49
50 obj = qobject_from_jsonf("{ 'seconds': %" PRId64 ", "
51 "'microseconds': %" PRId64 " }",
52 sec, usec);
53 qdict_put_obj(qdict, "timestamp", obj);
54}
55
56/*
57 * Build a QDict, then fill event name and time stamp, caller should free the
58 * QDict after usage.
59 */
60QDict *qmp_event_build_dict(const char *event_name)
61{
62 QDict *dict = qdict_new();
63 qdict_put(dict, "event", qstring_from_str(event_name));
64 timestamp_put(dict);
65 return dict;
66}