qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH 10/17] monitor: Rework terminal management


From: Jan Kiszka
Subject: [Qemu-devel] [PATCH 10/17] monitor: Rework terminal management
Date: Sat, 07 Feb 2009 19:16:28 +0100
User-agent: StGIT/0.14.2

Remove the static MAX_MON limit by managing monitor terminals in a
linked list.

Signed-off-by: Jan Kiszka <address@hidden>
---

 monitor.c |   41 +++++++++++++++++++++--------------------
 monitor.h |    2 +-
 2 files changed, 22 insertions(+), 21 deletions(-)

diff --git a/monitor.c b/monitor.c
index cc814d5..c21ea8a 100644
--- a/monitor.c
+++ b/monitor.c
@@ -67,8 +67,12 @@ typedef struct term_cmd_t {
     const char *help;
 } term_cmd_t;
 
-#define MAX_MON 4
-static CharDriverState *monitor_hd[MAX_MON];
+typedef struct MonitorTerm {
+    CharDriverState *chr;
+    LIST_ENTRY(MonitorTerm) entry;
+} MonitorTerm;
+
+static LIST_HEAD(term_list, MonitorTerm) term_list;
 static int hide_banner;
 
 static const term_cmd_t term_cmds[];
@@ -85,11 +89,13 @@ static CPUState *mon_cpu = NULL;
 
 void monitor_flush(void)
 {
-    int i;
+    MonitorTerm *term;
+
     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(term, &term_list, entry) {
+            if (term->chr->focus == 0)
+                qemu_chr_write(term->chr, term_outbuf, term_outbuf_index);
+        }
         term_outbuf_index = 0;
     }
 }
@@ -2834,29 +2840,24 @@ static void term_event(void *opaque, int event)
 
 static int is_first_init = 1;
 
-void monitor_init(CharDriverState *hd, int show_banner)
+void monitor_init(CharDriverState *chr, int show_banner)
 {
-    int i;
+    MonitorTerm *term;
 
     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] = hd;
-            break;
-        }
-    }
+
+    term = qemu_mallocz(sizeof(*term));
 
     hide_banner = !show_banner;
 
-    qemu_chr_add_handlers(hd, term_can_read, term_read, term_event, NULL);
+    term->chr = chr;
+
+    qemu_chr_add_handlers(chr, term_can_read, term_read, term_event, NULL);
+
+    LIST_INSERT_HEAD(&term_list, term, entry);
 
     readline_start("", 0, monitor_handle_command1, NULL);
 }
diff --git a/monitor.h b/monitor.h
index 8f993f1..226f76c 100644
--- a/monitor.h
+++ b/monitor.h
@@ -4,7 +4,7 @@
 #include "qemu-char.h"
 #include "block.h"
 
-void monitor_init(CharDriverState *hd, int show_banner);
+void monitor_init(CharDriverState *chr, int show_banner);
 void monitor_suspend(void);
 void monitor_resume(void);
 





reply via email to

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