summaryrefslogtreecommitdiff
path: root/monitor.c
diff options
context:
space:
mode:
authorLuiz Capitulino <lcapitulino@redhat.com>2009-11-26 22:59:03 -0200
committerAnthony Liguori <aliguori@us.ibm.com>2009-12-03 09:41:23 -0600
commit0d1ea871b09fc74b4a2085150980b43bd1973744 (patch)
treea970f0e1751e0a6e9bb3751ef1d5b72fa8b0385b /monitor.c
parent5e23f480df7a451dab6f82c4f13520b089daaf0e (diff)
downloadqemu-0d1ea871b09fc74b4a2085150980b43bd1973744.tar.gz
QMP: Asynchronous events infrastructure
Asynchronous events are generated with a call to monitor_protocol_event(). This function builds the right data-type and emit the event right away. The emitted data is always a JSON object and its format is as follows: { "event": json-string, "timestamp": { "seconds": json-number, "microseconds": json-number }, "data": json-value } This design is based on ideas by Amit Shah <amit.shah@redhat.com>. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'monitor.c')
-rw-r--r--monitor.c50
1 files changed, 50 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;