[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 08/15] QMP: Asynchronous events infrastructure
From: |
Luiz Capitulino |
Subject: |
[Qemu-devel] [PATCH 08/15] QMP: Asynchronous events infrastructure |
Date: |
Thu, 19 Nov 2009 13:13:36 -0200 |
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 <address@hidden>.
Signed-off-by: Luiz Capitulino <address@hidden>
---
monitor.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
monitor.h | 6 ++++++
qemu-tool.c | 4 ++++
3 files changed, 60 insertions(+), 0 deletions(-)
diff --git a/monitor.c b/monitor.c
index 5c5ae97..616f712 100644
--- a/monitor.c
+++ b/monitor.c
@@ -306,6 +306,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 556507c..a1d8b7a 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 b35ea8e..18b48af 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;
--
1.6.5.3.148.g785c5
- [Qemu-devel] [RFC v0 00/15] QEMU Monitor Protocol, Luiz Capitulino, 2009/11/19
- [Qemu-devel] [PATCH 01/15] monitor: Introduce MONITOR_USE_CONTROL flag, Luiz Capitulino, 2009/11/19
- [Qemu-devel] [PATCH 02/15] monitor: Command-line flag to enable control mode, Luiz Capitulino, 2009/11/19
- [Qemu-devel] [PATCH 03/15] monitor: Move handler calling code to its own function, Luiz Capitulino, 2009/11/19
- [Qemu-devel] [PATCH 04/15] QError: Add errors used by QMP, Luiz Capitulino, 2009/11/19
- [Qemu-devel] [PATCH 05/15] QMP: chardev handling, Luiz Capitulino, 2009/11/19
- [Qemu-devel] [PATCH 06/15] QMP: Output support, Luiz Capitulino, 2009/11/19
- [Qemu-devel] [PATCH 07/15] QMP: Input support, Luiz Capitulino, 2009/11/19
- [Qemu-devel] [PATCH 08/15] QMP: Asynchronous events infrastructure,
Luiz Capitulino <=
- [Qemu-devel] [PATCH 09/15] QMP: Introduce basic asynchronous events, Luiz Capitulino, 2009/11/19
- [Qemu-devel] [PATCH 10/15] QMP: Disable monitor print functions, Luiz Capitulino, 2009/11/19
- [Qemu-devel] [PATCH 11/15] QMP: Introduce README file, Luiz Capitulino, 2009/11/19
- [Qemu-devel] [PATCH 12/15] QMP: Introduce specification, Luiz Capitulino, 2009/11/19
- [Qemu-devel] [PATCH 13/15] QMP: Introduce qmp-events.txt, Luiz Capitulino, 2009/11/19
- [Qemu-devel] [PATCH 14/15] QMP: Introduce qmp-shell, Luiz Capitulino, 2009/11/19
- [Qemu-devel] [PATCH 15/15] QMP: Introduce vm-info, Luiz Capitulino, 2009/11/19
- [Qemu-devel] Re: [RFC v0 00/15] QEMU Monitor Protocol, Avi Kivity, 2009/11/19