1f8821260SWenchao Xia /*
2f8821260SWenchao Xia * QMP Event related
3f8821260SWenchao Xia *
4f8821260SWenchao Xia * Copyright (c) 2014 Wenchao Xia
5f8821260SWenchao Xia *
6f8821260SWenchao Xia * Authors:
7f8821260SWenchao Xia * Wenchao Xia <wenchaoqemu@gmail.com>
8f8821260SWenchao Xia *
9f8821260SWenchao Xia * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
10f8821260SWenchao Xia * See the COPYING.LIB file in the top-level directory.
11f8821260SWenchao Xia *
12f8821260SWenchao Xia */
13f8821260SWenchao Xia
14cbf21151SPeter Maydell #include "qemu/osdep.h"
15f8821260SWenchao Xia
16f8821260SWenchao Xia #include "qapi/qmp-event.h"
17f8821260SWenchao Xia #include "qapi/qmp/qstring.h"
18452fcdbcSMarkus Armbruster #include "qapi/qmp/qdict.h"
19f8821260SWenchao Xia #include "qapi/qmp/qjson.h"
20f8821260SWenchao Xia
timestamp_put(QDict * qdict)21f8821260SWenchao Xia static void timestamp_put(QDict *qdict)
22f8821260SWenchao Xia {
23cd499d20SMarkus Armbruster QDict *ts;
24*f793dde0SMarc-André Lureau int64_t rt = g_get_real_time();
25f8821260SWenchao Xia
26cd499d20SMarkus Armbruster ts = qdict_from_jsonf_nofail("{ 'seconds': %lld, 'microseconds': %lld }",
27*f793dde0SMarc-André Lureau (long long)rt / G_USEC_PER_SEC,
28*f793dde0SMarc-André Lureau (long long)rt % G_USEC_PER_SEC);
29cd499d20SMarkus Armbruster qdict_put(qdict, "timestamp", ts);
30f8821260SWenchao Xia }
31f8821260SWenchao Xia
32f8821260SWenchao Xia /*
33f8821260SWenchao Xia * Build a QDict, then fill event name and time stamp, caller should free the
34f8821260SWenchao Xia * QDict after usage.
35f8821260SWenchao Xia */
qmp_event_build_dict(const char * event_name)36f8821260SWenchao Xia QDict *qmp_event_build_dict(const char *event_name)
37f8821260SWenchao Xia {
38f8821260SWenchao Xia QDict *dict = qdict_new();
3946f5ac20SEric Blake qdict_put_str(dict, "event", event_name);
40f8821260SWenchao Xia timestamp_put(dict);
41f8821260SWenchao Xia return dict;
42f8821260SWenchao Xia }
43