aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--monitor.c50
-rw-r--r--monitor.h6
-rw-r--r--qemu-tool.c4
3 files changed, 60 insertions, 0 deletions
diff --git a/monitor.c b/monitor.c
index beaff6425e..68b63cacc3 100644
--- a/monitor.c
+++ b/monitor.c
@@ -307,6 +307,56 @@ static void monitor_protocol_emitter(Monitor *mon, QObject *data)
QDECREF(qmp);
}
+static void timestamp_put(QDict *qdict)
+{
+ int err;
+ QObject *obj;
+ struct timeval tv;
+
+ err = gettimeofday(&tv, NULL);
+ if (err < 0)
+ return;
+
+ obj = qobject_from_jsonf("{ 'seconds': %" PRId64 ", "
+ "'microseconds': %" PRId64 " }",
+ (int64_t) tv.tv_sec, (int64_t) tv.tv_usec);
+ assert(obj != NULL);
+
+ qdict_put_obj(qdict, "timestamp", obj);
+}
+
+/**
+ * monitor_protocol_event(): Generate a Monitor event
+ *
+ * Event-specific data can be emitted through the (optional) 'data' parameter.
+ */
+void monitor_protocol_event(MonitorEvent event, QObject *data)
+{
+ QDict *qmp;
+ const char *event_name;
+ Monitor *mon = cur_mon;
+
+ assert(event < EVENT_MAX);
+
+ if (!monitor_ctrl_mode(mon))
+ return;
+
+ switch (event) {
+ default:
+ abort();
+ break;
+ }
+
+ qmp = qdict_new();
+ timestamp_put(qmp);
+ qdict_put(qmp, "event", qstring_from_str(event_name));
+ if (data)
+ qdict_put_obj(qmp, "data", data);
+
+ monitor_json_emitter(mon, QOBJECT(qmp));
+ QDECREF(qmp);
+}
+
static int compare_cmd(const char *name, const char *list)
{
const char *p, *pstart;
diff --git a/monitor.h b/monitor.h
index 556507ce89..a1d8b7a5f0 100644
--- a/monitor.h
+++ b/monitor.h
@@ -13,6 +13,12 @@ extern Monitor *cur_mon;
#define MONITOR_USE_READLINE 0x02
#define MONITOR_USE_CONTROL 0x04
+/* QMP events */
+typedef enum MonitorEvent {
+ EVENT_MAX,
+} MonitorEvent;
+
+void monitor_protocol_event(MonitorEvent event, QObject *data);
const char *monitor_cmdline_parse(const char *cmdline, int *flags);
void monitor_init(CharDriverState *chr, int flags);
diff --git a/qemu-tool.c b/qemu-tool.c
index b35ea8e1c2..18b48af319 100644
--- a/qemu-tool.c
+++ b/qemu-tool.c
@@ -56,6 +56,10 @@ int get_async_context_id(void)
return 0;
}
+void monitor_protocol_event(MonitorEvent event, QObject *data)
+{
+}
+
QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque)
{
QEMUBH *bh;