From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LfMZI-0008NW-10 for qemu-devel@nongnu.org; Thu, 05 Mar 2009 18:01:32 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LfMZG-0008Mn-Tl for qemu-devel@nongnu.org; Thu, 05 Mar 2009 18:01:31 -0500 Received: from [199.232.76.173] (port=37319 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LfMZG-0008Mk-R5 for qemu-devel@nongnu.org; Thu, 05 Mar 2009 18:01:30 -0500 Received: from savannah.gnu.org ([199.232.41.3]:59816 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LfMZG-0005d9-EK for qemu-devel@nongnu.org; Thu, 05 Mar 2009 18:01:30 -0500 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1LfMZF-0001w4-TF for qemu-devel@nongnu.org; Thu, 05 Mar 2009 23:01:30 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.69) (envelope-from ) id 1LfMZF-0001vL-Gk for qemu-devel@nongnu.org; Thu, 05 Mar 2009 23:01:29 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Thu, 05 Mar 2009 23:01:29 +0000 Subject: [Qemu-devel] [6712] monitor: Rework terminal management (Jan Kiszka) Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 6712 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6712 Author: aliguori Date: 2009-03-05 23:01:29 +0000 (Thu, 05 Mar 2009) Log Message: ----------- monitor: Rework terminal management (Jan Kiszka) Remove the static MAX_MON limit by managing monitor terminals in a linked list. Signed-off-by: Jan Kiszka Signed-off-by: Anthony Liguori Modified Paths: -------------- trunk/monitor.c Modified: trunk/monitor.c =================================================================== --- trunk/monitor.c 2009-03-05 23:01:23 UTC (rev 6711) +++ trunk/monitor.c 2009-03-05 23:01:29 UTC (rev 6712) @@ -67,8 +67,12 @@ const char *help; } mon_cmd_t; -#define MAX_MON 4 -static CharDriverState *monitor_hd[MAX_MON]; +struct Monitor { + CharDriverState *chr; + LIST_ENTRY(Monitor) entry; +}; + +static LIST_HEAD(mon_list, Monitor) mon_list; static int hide_banner; static const mon_cmd_t mon_cmds[]; @@ -79,7 +83,7 @@ static BlockDriverCompletionFunc *password_completion_cb; static void *password_opaque; -Monitor *cur_mon; +Monitor *cur_mon = NULL; static void monitor_start_input(void); @@ -93,11 +97,13 @@ void monitor_flush(Monitor *mon) { - int i; + Monitor *m; + if (term_outbuf_index > 0) { - for (i = 0; i < MAX_MON; i++) - if (monitor_hd[i] && monitor_hd[i]->focus == 0) - qemu_chr_write(monitor_hd[i], term_outbuf, term_outbuf_index); + LIST_FOREACH(m, &mon_list, entry) { + if (m->chr->focus == 0) + qemu_chr_write(m->chr, term_outbuf, term_outbuf_index); + } term_outbuf_index = 0; } } @@ -2921,28 +2927,25 @@ void monitor_init(CharDriverState *chr, int show_banner) { - int i; + Monitor *mon; if (is_first_init) { key_timer = qemu_new_timer(vm_clock, release_keys, NULL); - if (!key_timer) - return; - for (i = 0; i < MAX_MON; i++) { - monitor_hd[i] = NULL; - } is_first_init = 0; } - for (i = 0; i < MAX_MON; i++) { - if (monitor_hd[i] == NULL) { - monitor_hd[i] = chr; - break; - } - } + mon = qemu_mallocz(sizeof(*mon)); + hide_banner = !show_banner; - qemu_chr_add_handlers(chr, term_can_read, term_read, term_event, cur_mon); + mon->chr = chr; + qemu_chr_add_handlers(chr, term_can_read, term_read, term_event, mon); + + LIST_INSERT_HEAD(&mon_list, mon, entry); + if (!cur_mon) + cur_mon = mon; + readline_start("", 0, monitor_command_cb, NULL); }