summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
4b9d468)
This commit adds initial QMP support in QEMU. It's important
to notice that most QMP code will be part of the Monitor.
Input will be read by monitor_control_read(). Currently it
does nothing but next patches will add proper input support.
The function monitor_json_emitter(), as its name implies, is
used by the Monitor to emit JSON output. In this commit it's
used by monitor_control_event() to print our greeting message.
Finally, control mode support is also added to monitor_init(),
allowing QMP to be really enabled.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
#include "qdict.h"
#include "qstring.h"
#include "qerror.h"
#include "qdict.h"
#include "qstring.h"
#include "qerror.h"
//#define DEBUG
//#define DEBUG_COMPLETION
//#define DEBUG
//#define DEBUG_COMPLETION
monitor_puts(mon, "\n");
}
monitor_puts(mon, "\n");
}
+static void monitor_json_emitter(Monitor *mon, const QObject *data)
+{
+ QString *json;
+
+ json = qobject_to_json(data);
+ assert(json != NULL);
+
+ monitor_printf(mon, "%s\n", qstring_get_str(json));
+ QDECREF(json);
+}
+
static int compare_cmd(const char *name, const char *list)
{
const char *p, *pstart;
static int compare_cmd(const char *name, const char *list)
{
const char *p, *pstart;
return (mon->suspend_cnt == 0) ? 128 : 0;
}
return (mon->suspend_cnt == 0) ? 128 : 0;
}
+/**
+ * monitor_control_read(): Read and handle QMP input
+ */
+static void monitor_control_read(void *opaque, const uint8_t *buf, int size)
+{
+ Monitor *old_mon = cur_mon;
+
+ cur_mon = opaque;
+
+ // TODO: read QMP input
+
+ cur_mon = old_mon;
+}
+
static void monitor_read(void *opaque, const uint8_t *buf, int size)
{
Monitor *old_mon = cur_mon;
static void monitor_read(void *opaque, const uint8_t *buf, int size)
{
Monitor *old_mon = cur_mon;
readline_show_prompt(mon->rs);
}
readline_show_prompt(mon->rs);
}
+/**
+ * monitor_control_event(): Print QMP gretting
+ */
+static void monitor_control_event(void *opaque, int event)
+{
+ if (event == CHR_EVENT_OPENED) {
+ QObject *data;
+ Monitor *mon = opaque;
+
+ data = qobject_from_jsonf("{ 'QMP': { 'capabilities': [] } }");
+ assert(data != NULL);
+
+ monitor_json_emitter(mon, data);
+ qobject_decref(data);
+ }
+}
+
static void monitor_event(void *opaque, int event)
{
Monitor *mon = opaque;
static void monitor_event(void *opaque, int event)
{
Monitor *mon = opaque;
monitor_read_command(mon, 0);
}
monitor_read_command(mon, 0);
}
- qemu_chr_add_handlers(chr, monitor_can_read, monitor_read, monitor_event,
- mon);
+ if (monitor_ctrl_mode(mon)) {
+ /* Control mode requires special handlers */
+ qemu_chr_add_handlers(chr, monitor_can_read, monitor_control_read,
+ monitor_control_event, mon);
+ } else {
+ qemu_chr_add_handlers(chr, monitor_can_read, monitor_read,
+ monitor_event, mon);
+ }
QLIST_INSERT_HEAD(&mon_list, mon, entry);
if (!cur_mon || (flags & MONITOR_IS_DEFAULT))
QLIST_INSERT_HEAD(&mon_list, mon, entry);
if (!cur_mon || (flags & MONITOR_IS_DEFAULT))