From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MIxdB-0007xL-0U for qemu-devel@nongnu.org; Tue, 23 Jun 2009 00:29:13 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MIxd5-0007us-O9 for qemu-devel@nongnu.org; Tue, 23 Jun 2009 00:29:11 -0400 Received: from [199.232.76.173] (port=35676 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MIxd5-0007up-Cy for qemu-devel@nongnu.org; Tue, 23 Jun 2009 00:29:07 -0400 Received: from mx2.redhat.com ([66.187.237.31]:32806) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MIxd4-0003BG-P2 for qemu-devel@nongnu.org; Tue, 23 Jun 2009 00:29:07 -0400 Date: Tue, 23 Jun 2009 01:29:00 -0300 From: Luiz Capitulino Message-ID: <20090623012900.03c4e6ef@doriath> In-Reply-To: References: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH 05/11] QMP: Introduce control mode chardev handling List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aliguori@us.ibm.com, ehabkost@redhat.com, jan.kiszka@siemens.com, dlaor@redhat.com, avi@redhat.com 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 --- 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