]> Git Repo - qemu.git/blame - qapi/qmp-event.c
i386: add KnightsMill cpu model
[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 <[email protected]>
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"
452fcdbc 19#include "qapi/qmp/qdict.h"
f8821260
WX
20#include "qapi/qmp/qjson.h"
21
f8821260
WX
22static QMPEventFuncEmit qmp_emit;
23
24void qmp_event_set_func_emit(QMPEventFuncEmit emit)
25{
26 qmp_emit = emit;
27}
28
29QMPEventFuncEmit qmp_event_get_func_emit(void)
30{
31 return qmp_emit;
32}
33
34static void timestamp_put(QDict *qdict)
35{
36 int err;
37 QObject *obj;
38 qemu_timeval tv;
f8821260
WX
39
40 err = qemu_gettimeofday(&tv);
043b5a49
EB
41 /* Put -1 to indicate failure of getting host time */
42 obj = qobject_from_jsonf("{ 'seconds': %lld, 'microseconds': %lld }",
43 err < 0 ? -1LL : (long long)tv.tv_sec,
44 err < 0 ? -1LL : (long long)tv.tv_usec);
f8821260
WX
45 qdict_put_obj(qdict, "timestamp", obj);
46}
47
48/*
49 * Build a QDict, then fill event name and time stamp, caller should free the
50 * QDict after usage.
51 */
52QDict *qmp_event_build_dict(const char *event_name)
53{
54 QDict *dict = qdict_new();
46f5ac20 55 qdict_put_str(dict, "event", event_name);
f8821260
WX
56 timestamp_put(dict);
57 return dict;
58}
This page took 0.162517 seconds and 4 git commands to generate.