]> git.proxmox.com Git - mirror_qemu.git/blame - qapi/qmp-event.c
Merge tag 'pull-aspeed-20240201' of https://github.com/legoater/qemu 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 15
f8821260
WX
16#include "qapi/qmp-event.h"
17#include "qapi/qmp/qstring.h"
452fcdbc 18#include "qapi/qmp/qdict.h"
f8821260
WX
19#include "qapi/qmp/qjson.h"
20
f8821260
WX
21static void timestamp_put(QDict *qdict)
22{
cd499d20 23 QDict *ts;
f793dde0 24 int64_t rt = g_get_real_time();
f8821260 25
cd499d20 26 ts = qdict_from_jsonf_nofail("{ 'seconds': %lld, 'microseconds': %lld }",
f793dde0
MAL
27 (long long)rt / G_USEC_PER_SEC,
28 (long long)rt % G_USEC_PER_SEC);
cd499d20 29 qdict_put(qdict, "timestamp", ts);
f8821260
WX
30}
31
32/*
33 * Build a QDict, then fill event name and time stamp, caller should free the
34 * QDict after usage.
35 */
36QDict *qmp_event_build_dict(const char *event_name)
37{
38 QDict *dict = qdict_new();
46f5ac20 39 qdict_put_str(dict, "event", event_name);
f8821260
WX
40 timestamp_put(dict);
41 return dict;
42}