2
0

qmp-event.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. #include "qemu/osdep.h"
  14. #include "qapi/qmp-event.h"
  15. #include "qobject/qstring.h"
  16. #include "qobject/qdict.h"
  17. #include "qobject/qjson.h"
  18. static void timestamp_put(QDict *qdict)
  19. {
  20. QDict *ts;
  21. int64_t rt = g_get_real_time();
  22. ts = qdict_from_jsonf_nofail("{ 'seconds': %lld, 'microseconds': %lld }",
  23. (long long)rt / G_USEC_PER_SEC,
  24. (long long)rt % G_USEC_PER_SEC);
  25. qdict_put(qdict, "timestamp", ts);
  26. }
  27. /*
  28. * Build a QDict, then fill event name and time stamp, caller should free the
  29. * QDict after usage.
  30. */
  31. QDict *qmp_event_build_dict(const char *event_name)
  32. {
  33. QDict *dict = qdict_new();
  34. qdict_put_str(dict, "event", event_name);
  35. timestamp_put(dict);
  36. return dict;
  37. }