qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 05/11] QMP: Introduce control mode chardev handling


From: Luiz Capitulino
Subject: [Qemu-devel] [PATCH 05/11] QMP: Introduce control mode chardev handling
Date: Tue, 23 Jun 2009 01:29:00 -0300

Control mode disables readline support and handles Monitor's
chardev by itself.

In order to this this change adds:

 o MonitorControl type: used to store input from the client
 o monitor_control_read(): read input from the chardev
 o monitor_control_event(): prints our greeting message

Support to control mode is also added to monitor_init().

Also note that monitor_control_read() is a bit simple right now,
will be improved in future versions.

Signed-off-by: Luiz Capitulino <address@hidden>
---
 monitor.c |   51 +++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/monitor.c b/monitor.c
index 6d40b9b..462f60b 100644
--- a/monitor.c
+++ b/monitor.c
@@ -70,6 +70,11 @@ typedef struct mon_cmd_t {
     const char *help;
 } mon_cmd_t;
 
+typedef struct MonitorControl {
+    uint8_t buf[128];
+    int size;
+} MonitorControl;
+
 struct Monitor {
     CharDriverState *chr;
     int flags;
@@ -77,6 +82,7 @@ struct Monitor {
     uint8_t outbuf[1024];
     int outbuf_index;
     ReadLineState *rs;
+    MonitorControl *mc;
     CPUState *mon_cpu;
     BlockDriverCompletionFunc *password_completion_cb;
     void *password_opaque;
@@ -3038,6 +3044,31 @@ static int monitor_can_read(void *opaque)
     return (mon->suspend_cnt == 0) ? 128 : 0;
 }
 
+static void monitor_control_read(void *opaque, const uint8_t *buf, int size)
+{
+    Monitor *old_mon = cur_mon;
+    int i;
+
+    cur_mon = opaque;
+
+    for (i = 0; i < size; i++) {
+        if (buf[i] == '\r' || buf[i] == '\n') {
+            cur_mon->mc->buf[cur_mon->mc->size] = '\0';
+            cur_mon->mc->size = 0;
+            monitor_handle_command(cur_mon, (char *)cur_mon->mc->buf);
+        } else {
+            cur_mon->mc->buf[cur_mon->mc->size++] = buf[i];
+            if (cur_mon->mc->size == sizeof(cur_mon->mc->buf)) {
+                monitor_printf_bad(cur_mon, "command too long\n");
+                cur_mon->mc->size = 0;
+                return;
+            }
+        }
+    }
+
+    cur_mon = old_mon;
+}
+
 static void monitor_read(void *opaque, const uint8_t *buf, int size)
 {
     Monitor *old_mon = cur_mon;
@@ -3081,6 +3112,15 @@ void monitor_resume(Monitor *mon)
         readline_show_prompt(mon->rs);
 }
 
+static void monitor_control_event(void *opaque, int event)
+{
+    if (event == CHR_EVENT_RESET) {
+        Monitor *mon = opaque;
+        mon->mc->size = 0;
+        monitor_printf(mon, "+ QEMU %s QMP 0.1\n", QEMU_VERSION);
+    }
+}
+
 static void monitor_event(void *opaque, int event)
 {
     Monitor *mon = opaque;
@@ -3138,8 +3178,15 @@ void monitor_init(CharDriverState *chr, int flags)
         monitor_read_command(mon, 0);
     }
 
-    qemu_chr_add_handlers(chr, monitor_can_read, monitor_read, monitor_event,
-                          mon);
+    if (monitor_ctrl_mode(mon)) {
+        mon->mc = qemu_mallocz(sizeof(MonitorControl));
+        /* 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);
+    }
 
     LIST_INSERT_HEAD(&mon_list, mon, entry);
     if (!cur_mon || (flags & MONITOR_IS_DEFAULT))
-- 
1.6.3.GIT





reply via email to

[Prev in Thread] Current Thread [Next in Thread]