Patchwork [3/6] console: add qemu_console_lookup_by_device

login
register
mail settings
Submitter Gerd Hoffmann
Date April 25, 2013, 7:56 a.m.
Message ID <1366876575-23958-4-git-send-email-kraxel@redhat.com>
Download mbox | patch
Permalink /patch/239415/
State New
Headers show

Comments

Gerd Hoffmann - April 25, 2013, 7:56 a.m.
Look up the QemuConsole for a given device, using the new link.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 include/ui/console.h |    1 +
 ui/console.c         |   19 +++++++++++++++++++
 2 files changed, 20 insertions(+)

Patch

diff --git a/include/ui/console.h b/include/ui/console.h
index 22670d8..c74e791 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -300,6 +300,7 @@  void graphic_hw_invalidate(QemuConsole *con);
 void graphic_hw_text_update(QemuConsole *con, console_ch_t *chardata);
 
 QemuConsole *qemu_console_lookup_by_index(unsigned int index);
+QemuConsole *qemu_console_lookup_by_device(DeviceState *dev);
 bool qemu_console_is_visible(QemuConsole *con);
 bool qemu_console_is_graphic(QemuConsole *con);
 bool qemu_console_is_fixedsize(QemuConsole *con);
diff --git a/ui/console.c b/ui/console.c
index 4102e8c..e3ab985 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -1596,6 +1596,25 @@  QemuConsole *qemu_console_lookup_by_index(unsigned int index)
     return consoles[index];
 }
 
+QemuConsole *qemu_console_lookup_by_device(DeviceState *dev)
+{
+    Error *local_err = NULL;
+    Object *obj;
+    int i;
+
+    for (i = 0; i < nb_consoles; i++) {
+        if (!consoles[i]) {
+            continue;
+        }
+        obj = object_property_get_link(OBJECT(consoles[i]),
+                                       "device", &local_err);
+        if (DEVICE(obj) == dev) {
+            return consoles[i];
+        }
+    }
+    return NULL;
+}
+
 bool qemu_console_is_visible(QemuConsole *con)
 {
     return (con == active_console) || (con->dcls > 0);