Patchwork [5/8] qemu-char: Cleanup: consolidate fe_open/fe_close into fe_set_open

login
register
mail settings
Submitter Hans de Goede
Date March 24, 2013, 12:39 p.m.
Message ID <1364128793-12689-6-git-send-email-hdegoede@redhat.com>
Download mbox | patch
Permalink /patch/230446/
State New
Headers show

Comments

Hans de Goede - March 24, 2013, 12:39 p.m.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 hw/virtio-console.c |  4 ++--
 include/char/char.h | 17 ++++-------------
 qemu-char.c         | 19 +++++--------------
 3 files changed, 11 insertions(+), 29 deletions(-)

Patch

diff --git a/hw/virtio-console.c b/hw/virtio-console.c
index 209ea38..c0d41c5 100644
--- a/hw/virtio-console.c
+++ b/hw/virtio-console.c
@@ -79,7 +79,7 @@  static void guest_open(VirtIOSerialPort *port)
     if (!vcon->chr) {
         return;
     }
-    qemu_chr_fe_open(vcon->chr);
+    qemu_chr_fe_set_open(vcon->chr, 1);
 }
 
 /* Callback function that's called when the guest closes the port */
@@ -90,7 +90,7 @@  static void guest_close(VirtIOSerialPort *port)
     if (!vcon->chr) {
         return;
     }
-    qemu_chr_fe_close(vcon->chr);
+    qemu_chr_fe_set_open(vcon->chr, 0);
 }
 
 /* Readiness of the guest to accept data on a port */
diff --git a/include/char/char.h b/include/char/char.h
index 27ebbc3..3c8dd28 100644
--- a/include/char/char.h
+++ b/include/char/char.h
@@ -129,21 +129,12 @@  void qemu_chr_delete(CharDriverState *chr);
 void qemu_chr_fe_set_echo(struct CharDriverState *chr, bool echo);
 
 /**
- * @qemu_chr_fe_open:
+ * @qemu_chr_fe_set_open:
  *
- * Open a character backend.  This function call is an indication that the
- * front end is ready to begin doing I/O.
+ * Set character frontend open status.  This is an indication that the
+ * front end is ready (or not) to begin doing I/O.
  */
-void qemu_chr_fe_open(struct CharDriverState *chr);
-
-/**
- * @qemu_chr_fe_close:
- *
- * Close a character backend.  This function call indicates that the front end
- * no longer is able to process I/O.  To process I/O again, the front end will
- * call @qemu_chr_fe_open.
- */
-void qemu_chr_fe_close(struct CharDriverState *chr);
+void qemu_chr_fe_set_open(struct CharDriverState *chr, int fe_open);
 
 /**
  * @qemu_chr_fe_printf:
diff --git a/qemu-char.c b/qemu-char.c
index 7c57971..713c154 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -211,11 +211,7 @@  void qemu_chr_add_handlers(CharDriverState *s,
         s->chr_update_read_handler(s);
 
     if (!s->explicit_fe_open) {
-        if (fe_open) {
-            qemu_chr_fe_open(s);
-        } else {
-            qemu_chr_fe_close(s);
-        }
+        qemu_chr_fe_set_open(s, fe_open);
     }
 
     /* We're connecting to an already opened device, so let's make sure we
@@ -3396,18 +3392,13 @@  void qemu_chr_fe_set_echo(struct CharDriverState *chr, bool echo)
     }
 }
 
-void qemu_chr_fe_open(struct CharDriverState *chr)
+void qemu_chr_fe_set_open(struct CharDriverState *chr, int fe_open)
 {
-    chr->fe_open = 1;
-    if (chr->chr_guest_open) {
+    chr->fe_open = fe_open;
+    if (fe_open && chr->chr_guest_open) {
         chr->chr_guest_open(chr);
     }
-}
-
-void qemu_chr_fe_close(struct CharDriverState *chr)
-{
-    chr->fe_open = 0;
-    if (chr->chr_guest_close) {
+    if (!fe_open && chr->chr_guest_close) {
         chr->chr_guest_close(chr);
     }
 }