render / rpms / qemu

Forked from rpms/qemu 7 months ago
Clone

Blame 0006-char-Add-a-QemuChrHandlers-struct-to-initialise-char.patch

Justin M. Forbes 252f3a
>From 003cc09f8fc34e7571ebd4a89ea6aa6324a80b54 Mon Sep 17 00:00:00 2001
Justin M. Forbes 252f3a
From: Amit Shah <amit.shah@redhat.com>
Justin M. Forbes 252f3a
Date: Mon, 21 Mar 2011 20:31:45 +0100
Justin M. Forbes 252f3a
Subject: [PATCH 06/19] char: Add a QemuChrHandlers struct to initialise chardev handlers
Justin M. Forbes 252f3a
Justin M. Forbes 252f3a
Instead of passing each handler in the qemu_add_handlers() function,
Justin M. Forbes 252f3a
create a struct of handlers that can be passed to the function instead.
Justin M. Forbes 252f3a
Justin M. Forbes 252f3a
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Justin M. Forbes 252f3a
---
Justin M. Forbes 252f3a
 gdbstub.c            |    9 +++++++--
Justin M. Forbes 252f3a
 hw/debugcon.c        |    2 +-
Justin M. Forbes 252f3a
 hw/escc.c            |    9 +++++++--
Justin M. Forbes 252f3a
 hw/etraxfs_ser.c     |   13 +++++++++----
Justin M. Forbes 252f3a
 hw/grlib_apbuart.c   |   12 +++++++-----
Justin M. Forbes 252f3a
 hw/ivshmem.c         |   28 ++++++++++++++++++++++------
Justin M. Forbes 252f3a
 hw/mcf_uart.c        |    9 +++++++--
Justin M. Forbes 252f3a
 hw/pl011.c           |    9 +++++++--
Justin M. Forbes 252f3a
 hw/pxa2xx.c          |   13 +++++++++----
Justin M. Forbes 252f3a
 hw/serial.c          |    9 +++++++--
Justin M. Forbes 252f3a
 hw/sh_serial.c       |   12 +++++++++---
Justin M. Forbes 252f3a
 hw/syborg_serial.c   |    9 +++++++--
Justin M. Forbes 252f3a
 hw/usb-serial.c      |    9 +++++++--
Justin M. Forbes 252f3a
 hw/virtio-console.c  |    9 +++++++--
Justin M. Forbes 252f3a
 hw/xen_console.c     |   16 +++++++++++-----
Justin M. Forbes 252f3a
 hw/xilinx_uartlite.c |   11 +++++++++--
Justin M. Forbes 252f3a
 monitor.c            |   18 ++++++++++++++----
Justin M. Forbes 252f3a
 net/slirp.c          |    8 ++++++--
Justin M. Forbes 252f3a
 qemu-char.c          |   30 +++++++++++++++++++++---------
Justin M. Forbes 252f3a
 qemu-char.h          |   13 +++++++++----
Justin M. Forbes 252f3a
 20 files changed, 183 insertions(+), 65 deletions(-)
Justin M. Forbes 252f3a
Justin M. Forbes 252f3a
diff --git a/gdbstub.c b/gdbstub.c
Justin M. Forbes 252f3a
index 14e8b9b..4190ac7 100644
Justin M. Forbes 252f3a
--- a/gdbstub.c
Justin M. Forbes 252f3a
+++ b/gdbstub.c
Justin M. Forbes 252f3a
@@ -2634,6 +2634,12 @@ static void gdb_sigterm_handler(int signal)
Justin M. Forbes 252f3a
 }
Justin M. Forbes 252f3a
 #endif
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
+static const QemuChrHandlers gdb_handlers = {
Justin M. Forbes 252f3a
+    .fd_can_read = gdb_chr_can_receive,
Justin M. Forbes 252f3a
+    .fd_read = gdb_chr_receive,
Justin M. Forbes 252f3a
+    .fd_event = gdb_chr_event,
Justin M. Forbes 252f3a
+};
Justin M. Forbes 252f3a
+
Justin M. Forbes 252f3a
 int gdbserver_start(const char *device)
Justin M. Forbes 252f3a
 {
Justin M. Forbes 252f3a
     GDBState *s;
Justin M. Forbes 252f3a
@@ -2663,8 +2669,7 @@ int gdbserver_start(const char *device)
Justin M. Forbes 252f3a
         if (!chr)
Justin M. Forbes 252f3a
             return -1;
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
-        qemu_chr_add_handlers(chr, gdb_chr_can_receive, gdb_chr_receive,
Justin M. Forbes 252f3a
-                              gdb_chr_event, NULL);
Justin M. Forbes 252f3a
+        qemu_chr_add_handlers(chr, &gdb_handlers, NULL);
Justin M. Forbes 252f3a
     }
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
     s = gdbserver_state;
Justin M. Forbes 252f3a
diff --git a/hw/debugcon.c b/hw/debugcon.c
Justin M. Forbes 252f3a
index 5ee6821..e79a595 100644
Justin M. Forbes 252f3a
--- a/hw/debugcon.c
Justin M. Forbes 252f3a
+++ b/hw/debugcon.c
Justin M. Forbes 252f3a
@@ -73,7 +73,7 @@ static void debugcon_init_core(DebugconState *s)
Justin M. Forbes 252f3a
         exit(1);
Justin M. Forbes 252f3a
     }
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
-    qemu_chr_add_handlers(s->chr, NULL, NULL, NULL, s);
Justin M. Forbes 252f3a
+    qemu_chr_add_handlers(s->chr, NULL, s);
Justin M. Forbes 252f3a
 }
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
 static int debugcon_isa_initfn(ISADevice *dev)
Justin M. Forbes 252f3a
diff --git a/hw/escc.c b/hw/escc.c
Justin M. Forbes 252f3a
index f6fd919..dfa329a 100644
Justin M. Forbes 252f3a
--- a/hw/escc.c
Justin M. Forbes 252f3a
+++ b/hw/escc.c
Justin M. Forbes 252f3a
@@ -898,6 +898,12 @@ void slavio_serial_ms_kbd_init(target_phys_addr_t base, qemu_irq irq,
Justin M. Forbes 252f3a
     sysbus_mmio_map(s, 0, base);
Justin M. Forbes 252f3a
 }
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
+static const QemuChrHandlers serial_handlers = {
Justin M. Forbes 252f3a
+    .fd_can_read = serial_can_receive,
Justin M. Forbes 252f3a
+    .fd_read = serial_receive1,
Justin M. Forbes 252f3a
+    .fd_event = serial_event,
Justin M. Forbes 252f3a
+};
Justin M. Forbes 252f3a
+
Justin M. Forbes 252f3a
 static int escc_init1(SysBusDevice *dev)
Justin M. Forbes 252f3a
 {
Justin M. Forbes 252f3a
     SerialState *s = FROM_SYSBUS(SerialState, dev);
Justin M. Forbes 252f3a
@@ -911,8 +917,7 @@ static int escc_init1(SysBusDevice *dev)
Justin M. Forbes 252f3a
         s->chn[i].chn = 1 - i;
Justin M. Forbes 252f3a
         s->chn[i].clock = s->frequency / 2;
Justin M. Forbes 252f3a
         if (s->chn[i].chr) {
Justin M. Forbes 252f3a
-            qemu_chr_add_handlers(s->chn[i].chr, serial_can_receive,
Justin M. Forbes 252f3a
-                                  serial_receive1, serial_event, &s->chn[i]);
Justin M. Forbes 252f3a
+            qemu_chr_add_handlers(s->chn[i].chr, &serial_handlers, &s->chn[i]);
Justin M. Forbes 252f3a
         }
Justin M. Forbes 252f3a
     }
Justin M. Forbes 252f3a
     s->chn[0].otherchn = &s->chn[1];
Justin M. Forbes 252f3a
diff --git a/hw/etraxfs_ser.c b/hw/etraxfs_ser.c
Justin M. Forbes 252f3a
index 2787ebd..406121c 100644
Justin M. Forbes 252f3a
--- a/hw/etraxfs_ser.c
Justin M. Forbes 252f3a
+++ b/hw/etraxfs_ser.c
Justin M. Forbes 252f3a
@@ -190,6 +190,12 @@ static void serial_event(void *opaque, int event)
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
 }
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
+static const QemuChrHandlers serial_handlers = {
Justin M. Forbes 252f3a
+    .fd_can_read = serial_can_receive,
Justin M. Forbes 252f3a
+    .fd_read = serial_receive,
Justin M. Forbes 252f3a
+    .fd_event = serial_event,
Justin M. Forbes 252f3a
+};
Justin M. Forbes 252f3a
+
Justin M. Forbes 252f3a
 static int etraxfs_ser_init(SysBusDevice *dev)
Justin M. Forbes 252f3a
 {
Justin M. Forbes 252f3a
     struct etrax_serial *s = FROM_SYSBUS(typeof (*s), dev);
Justin M. Forbes 252f3a
@@ -204,10 +210,9 @@ static int etraxfs_ser_init(SysBusDevice *dev)
Justin M. Forbes 252f3a
                                       DEVICE_NATIVE_ENDIAN);
Justin M. Forbes 252f3a
     sysbus_init_mmio(dev, R_MAX * 4, ser_regs);
Justin M. Forbes 252f3a
     s->chr = qdev_init_chardev(&dev->qdev);
Justin M. Forbes 252f3a
-    if (s->chr)
Justin M. Forbes 252f3a
-        qemu_chr_add_handlers(s->chr,
Justin M. Forbes 252f3a
-                      serial_can_receive, serial_receive,
Justin M. Forbes 252f3a
-                      serial_event, s);
Justin M. Forbes 252f3a
+    if (s->chr) {
Justin M. Forbes 252f3a
+        qemu_chr_add_handlers(s->chr, &serial_handlers, s);
Justin M. Forbes 252f3a
+    }
Justin M. Forbes 252f3a
     return 0;
Justin M. Forbes 252f3a
 }
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
diff --git a/hw/grlib_apbuart.c b/hw/grlib_apbuart.c
Justin M. Forbes 252f3a
index 101b150..40d6968 100644
Justin M. Forbes 252f3a
--- a/hw/grlib_apbuart.c
Justin M. Forbes 252f3a
+++ b/hw/grlib_apbuart.c
Justin M. Forbes 252f3a
@@ -144,16 +144,18 @@ static CPUWriteMemoryFunc * const grlib_apbuart_write[] = {
Justin M. Forbes 252f3a
     NULL, NULL, grlib_apbuart_writel,
Justin M. Forbes 252f3a
 };
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
+static const QemuChrHandlers grlib_handlers = {
Justin M. Forbes 252f3a
+    .fd_can_read = grlib_apbuart_can_receive,
Justin M. Forbes 252f3a
+    .fd_read = grlib_apbuart_receive,
Justin M. Forbes 252f3a
+    .fd_event = grlib_apbuart_event,
Justin M. Forbes 252f3a
+};
Justin M. Forbes 252f3a
+
Justin M. Forbes 252f3a
 static int grlib_apbuart_init(SysBusDevice *dev)
Justin M. Forbes 252f3a
 {
Justin M. Forbes 252f3a
     UART *uart      = FROM_SYSBUS(typeof(*uart), dev);
Justin M. Forbes 252f3a
     int   uart_regs = 0;
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
-    qemu_chr_add_handlers(uart->chr,
Justin M. Forbes 252f3a
-                          grlib_apbuart_can_receive,
Justin M. Forbes 252f3a
-                          grlib_apbuart_receive,
Justin M. Forbes 252f3a
-                          grlib_apbuart_event,
Justin M. Forbes 252f3a
-                          uart);
Justin M. Forbes 252f3a
+    qemu_chr_add_handlers(uart->chr, &grlib_handlers, uart);
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
     sysbus_init_irq(dev, &uart->irq);
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
diff --git a/hw/ivshmem.c b/hw/ivshmem.c
Justin M. Forbes 252f3a
index 7b19a81..ef8e5ce 100644
Justin M. Forbes 252f3a
--- a/hw/ivshmem.c
Justin M. Forbes 252f3a
+++ b/hw/ivshmem.c
Justin M. Forbes 252f3a
@@ -312,6 +312,18 @@ static void fake_irqfd(void *opaque, const uint8_t *buf, int size) {
Justin M. Forbes 252f3a
     msix_notify(pdev, entry->vector);
Justin M. Forbes 252f3a
 }
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
+static const QemuChrHandlers ivshmem_handlers = {
Justin M. Forbes 252f3a
+    .fd_can_read = ivshmem_can_receive,
Justin M. Forbes 252f3a
+    .fd_read = ivshmem_receive,
Justin M. Forbes 252f3a
+    .fd_event = ivshmem_event,
Justin M. Forbes 252f3a
+};
Justin M. Forbes 252f3a
+
Justin M. Forbes 252f3a
+static const QemuChrHandlers ivshmem_msi_handlers = {
Justin M. Forbes 252f3a
+    .fd_can_read = ivshmem_can_receive,
Justin M. Forbes 252f3a
+    .fd_read = fake_irqfd,
Justin M. Forbes 252f3a
+    .fd_event = ivshmem_event,
Justin M. Forbes 252f3a
+};
Justin M. Forbes 252f3a
+
Justin M. Forbes 252f3a
 static CharDriverState* create_eventfd_chr_device(void * opaque, int eventfd,
Justin M. Forbes 252f3a
                                                                     int vector)
Justin M. Forbes 252f3a
 {
Justin M. Forbes 252f3a
@@ -331,11 +343,10 @@ static CharDriverState* create_eventfd_chr_device(void * opaque, int eventfd,
Justin M. Forbes 252f3a
         s->eventfd_table[vector].pdev = &s->dev;
Justin M. Forbes 252f3a
         s->eventfd_table[vector].vector = vector;
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
-        qemu_chr_add_handlers(chr, ivshmem_can_receive, fake_irqfd,
Justin M. Forbes 252f3a
-                      ivshmem_event, &s->eventfd_table[vector]);
Justin M. Forbes 252f3a
+        qemu_chr_add_handlers(chr, &ivshmem_msi_handlers,
Justin M. Forbes 252f3a
+                              &s->eventfd_table[vector]);
Justin M. Forbes 252f3a
     } else {
Justin M. Forbes 252f3a
-        qemu_chr_add_handlers(chr, ivshmem_can_receive, ivshmem_receive,
Justin M. Forbes 252f3a
-                      ivshmem_event, s);
Justin M. Forbes 252f3a
+        qemu_chr_add_handlers(chr, &ivshmem_handlers, s);
Justin M. Forbes 252f3a
     }
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
     return chr;
Justin M. Forbes 252f3a
@@ -666,6 +677,12 @@ static int ivshmem_load(QEMUFile* f, void *opaque, int version_id)
Justin M. Forbes 252f3a
     return 0;
Justin M. Forbes 252f3a
 }
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
+static const QemuChrHandlers ivshmem_server_handlers = {
Justin M. Forbes 252f3a
+    .fd_can_read = ivshmem_can_receive,
Justin M. Forbes 252f3a
+    .fd_read = ivshmem_read,
Justin M. Forbes 252f3a
+    .fd_event = ivshmem_event,
Justin M. Forbes 252f3a
+};
Justin M. Forbes 252f3a
+
Justin M. Forbes 252f3a
 static int pci_ivshmem_init(PCIDevice *dev)
Justin M. Forbes 252f3a
 {
Justin M. Forbes 252f3a
     IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
Justin M. Forbes 252f3a
@@ -754,8 +771,7 @@ static int pci_ivshmem_init(PCIDevice *dev)
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
         s->eventfd_chr = qemu_mallocz(s->vectors * sizeof(CharDriverState *));
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
-        qemu_chr_add_handlers(s->server_chr, ivshmem_can_receive, ivshmem_read,
Justin M. Forbes 252f3a
-                     ivshmem_event, s);
Justin M. Forbes 252f3a
+        qemu_chr_add_handlers(s->server_chr, &ivshmem_server_handlers, s);
Justin M. Forbes 252f3a
     } else {
Justin M. Forbes 252f3a
         /* just map the file immediately, we're not using a server */
Justin M. Forbes 252f3a
         int fd;
Justin M. Forbes 252f3a
diff --git a/hw/mcf_uart.c b/hw/mcf_uart.c
Justin M. Forbes 252f3a
index db57096..9928c11 100644
Justin M. Forbes 252f3a
--- a/hw/mcf_uart.c
Justin M. Forbes 252f3a
+++ b/hw/mcf_uart.c
Justin M. Forbes 252f3a
@@ -268,6 +268,12 @@ static void mcf_uart_receive(void *opaque, const uint8_t *buf, int size)
Justin M. Forbes 252f3a
     mcf_uart_push_byte(s, buf[0]);
Justin M. Forbes 252f3a
 }
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
+static const QemuChrHandlers mcf_uart_handlers = {
Justin M. Forbes 252f3a
+    .fd_can_read = mcf_uart_can_receive,
Justin M. Forbes 252f3a
+    .fd_read = mcf_uart_receive,
Justin M. Forbes 252f3a
+    .fd_event = mcf_uart_event,
Justin M. Forbes 252f3a
+};
Justin M. Forbes 252f3a
+
Justin M. Forbes 252f3a
 void *mcf_uart_init(qemu_irq irq, CharDriverState *chr)
Justin M. Forbes 252f3a
 {
Justin M. Forbes 252f3a
     mcf_uart_state *s;
Justin M. Forbes 252f3a
@@ -276,8 +282,7 @@ void *mcf_uart_init(qemu_irq irq, CharDriverState *chr)
Justin M. Forbes 252f3a
     s->chr = chr;
Justin M. Forbes 252f3a
     s->irq = irq;
Justin M. Forbes 252f3a
     if (chr) {
Justin M. Forbes 252f3a
-        qemu_chr_add_handlers(chr, mcf_uart_can_receive, mcf_uart_receive,
Justin M. Forbes 252f3a
-                              mcf_uart_event, s);
Justin M. Forbes 252f3a
+        qemu_chr_add_handlers(chr, &mcf_uart_handlers, s);
Justin M. Forbes 252f3a
     }
Justin M. Forbes 252f3a
     mcf_uart_reset(s);
Justin M. Forbes 252f3a
     return s;
Justin M. Forbes 252f3a
diff --git a/hw/pl011.c b/hw/pl011.c
Justin M. Forbes 252f3a
index 77f0dbf..d93c655 100644
Justin M. Forbes 252f3a
--- a/hw/pl011.c
Justin M. Forbes 252f3a
+++ b/hw/pl011.c
Justin M. Forbes 252f3a
@@ -286,6 +286,12 @@ static int pl011_load(QEMUFile *f, void *opaque, int version_id)
Justin M. Forbes 252f3a
     return 0;
Justin M. Forbes 252f3a
 }
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
+static const QemuChrHandlers pl011_handlers = {
Justin M. Forbes 252f3a
+    .fd_can_read = pl011_can_receive,
Justin M. Forbes 252f3a
+    .fd_read = pl011_receive,
Justin M. Forbes 252f3a
+    .fd_event = pl011_event,
Justin M. Forbes 252f3a
+};
Justin M. Forbes 252f3a
+
Justin M. Forbes 252f3a
 static int pl011_init(SysBusDevice *dev, const unsigned char *id)
Justin M. Forbes 252f3a
 {
Justin M. Forbes 252f3a
     int iomemtype;
Justin M. Forbes 252f3a
@@ -304,8 +310,7 @@ static int pl011_init(SysBusDevice *dev, const unsigned char *id)
Justin M. Forbes 252f3a
     s->cr = 0x300;
Justin M. Forbes 252f3a
     s->flags = 0x90;
Justin M. Forbes 252f3a
     if (s->chr) {
Justin M. Forbes 252f3a
-        qemu_chr_add_handlers(s->chr, pl011_can_receive, pl011_receive,
Justin M. Forbes 252f3a
-                              pl011_event, s);
Justin M. Forbes 252f3a
+        qemu_chr_add_handlers(s->chr, &pl011_handlers, s);
Justin M. Forbes 252f3a
     }
Justin M. Forbes 252f3a
     register_savevm(&dev->qdev, "pl011_uart", -1, 1, pl011_save, pl011_load, s);
Justin M. Forbes 252f3a
     return 0;
Justin M. Forbes 252f3a
diff --git a/hw/pxa2xx.c b/hw/pxa2xx.c
Justin M. Forbes 252f3a
index d966846..d7ebf33 100644
Justin M. Forbes 252f3a
--- a/hw/pxa2xx.c
Justin M. Forbes 252f3a
+++ b/hw/pxa2xx.c
Justin M. Forbes 252f3a
@@ -1995,6 +1995,12 @@ static int pxa2xx_fir_load(QEMUFile *f, void *opaque, int version_id)
Justin M. Forbes 252f3a
     return 0;
Justin M. Forbes 252f3a
 }
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
+static const QemuChrHandlers pxa2xx_handlers = {
Justin M. Forbes 252f3a
+    .fd_can_read = pxa2xx_fir_is_empty,
Justin M. Forbes 252f3a
+    .fd_read = pxa2xx_fir_rx,
Justin M. Forbes 252f3a
+    .fd_event = pxa2xx_fir_event,
Justin M. Forbes 252f3a
+};
Justin M. Forbes 252f3a
+
Justin M. Forbes 252f3a
 static PXA2xxFIrState *pxa2xx_fir_init(target_phys_addr_t base,
Justin M. Forbes 252f3a
                 qemu_irq irq, PXA2xxDMAState *dma,
Justin M. Forbes 252f3a
                 CharDriverState *chr)
Justin M. Forbes 252f3a
@@ -2013,10 +2019,9 @@ static PXA2xxFIrState *pxa2xx_fir_init(target_phys_addr_t base,
Justin M. Forbes 252f3a
                     pxa2xx_fir_writefn, s, DEVICE_NATIVE_ENDIAN);
Justin M. Forbes 252f3a
     cpu_register_physical_memory(base, 0x1000, iomemtype);
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
-    if (chr)
Justin M. Forbes 252f3a
-        qemu_chr_add_handlers(chr, pxa2xx_fir_is_empty,
Justin M. Forbes 252f3a
-                        pxa2xx_fir_rx, pxa2xx_fir_event, s);
Justin M. Forbes 252f3a
-
Justin M. Forbes 252f3a
+    if (chr) {
Justin M. Forbes 252f3a
+        qemu_chr_add_handlers(chr, &pxa2xx_handlers, s);
Justin M. Forbes 252f3a
+    }
Justin M. Forbes 252f3a
     register_savevm(NULL, "pxa2xx_fir", 0, 0, pxa2xx_fir_save,
Justin M. Forbes 252f3a
                     pxa2xx_fir_load, s);
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
diff --git a/hw/serial.c b/hw/serial.c
Justin M. Forbes 252f3a
index 2c4af61..65265e2 100644
Justin M. Forbes 252f3a
--- a/hw/serial.c
Justin M. Forbes 252f3a
+++ b/hw/serial.c
Justin M. Forbes 252f3a
@@ -727,6 +727,12 @@ static void serial_reset(void *opaque)
Justin M. Forbes 252f3a
     qemu_irq_lower(s->irq);
Justin M. Forbes 252f3a
 }
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
+static const QemuChrHandlers serial_handlers = {
Justin M. Forbes 252f3a
+    .fd_can_read = serial_can_receive1,
Justin M. Forbes 252f3a
+    .fd_read = serial_receive1,
Justin M. Forbes 252f3a
+    .fd_event = serial_event,
Justin M. Forbes 252f3a
+};
Justin M. Forbes 252f3a
+
Justin M. Forbes 252f3a
 static void serial_init_core(SerialState *s)
Justin M. Forbes 252f3a
 {
Justin M. Forbes 252f3a
     if (!s->chr) {
Justin M. Forbes 252f3a
@@ -741,8 +747,7 @@ static void serial_init_core(SerialState *s)
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
     qemu_register_reset(serial_reset, s);
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
-    qemu_chr_add_handlers(s->chr, serial_can_receive1, serial_receive1,
Justin M. Forbes 252f3a
-                          serial_event, s);
Justin M. Forbes 252f3a
+    qemu_chr_add_handlers(s->chr, &serial_handlers, s);
Justin M. Forbes 252f3a
 }
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
 /* Change the main reference oscillator frequency. */
Justin M. Forbes 252f3a
diff --git a/hw/sh_serial.c b/hw/sh_serial.c
Justin M. Forbes 252f3a
index 191f4a6..8b6460d 100644
Justin M. Forbes 252f3a
--- a/hw/sh_serial.c
Justin M. Forbes 252f3a
+++ b/hw/sh_serial.c
Justin M. Forbes 252f3a
@@ -350,6 +350,12 @@ static CPUWriteMemoryFunc * const sh_serial_writefn[] = {
Justin M. Forbes 252f3a
     &sh_serial_write,
Justin M. Forbes 252f3a
 };
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
+static const QemuChrHandlers sh_serial_handlers = {
Justin M. Forbes 252f3a
+    .fd_can_read = sh_serial_can_receive1,
Justin M. Forbes 252f3a
+    .fd_read = sh_serial_receive1,
Justin M. Forbes 252f3a
+    .fd_event = sh_serial_event,
Justin M. Forbes 252f3a
+};
Justin M. Forbes 252f3a
+
Justin M. Forbes 252f3a
 void sh_serial_init (target_phys_addr_t base, int feat,
Justin M. Forbes 252f3a
 		     uint32_t freq, CharDriverState *chr,
Justin M. Forbes 252f3a
 		     qemu_irq eri_source,
Justin M. Forbes 252f3a
@@ -389,9 +395,9 @@ void sh_serial_init (target_phys_addr_t base, int feat,
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
     s->chr = chr;
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
-    if (chr)
Justin M. Forbes 252f3a
-        qemu_chr_add_handlers(chr, sh_serial_can_receive1, sh_serial_receive1,
Justin M. Forbes 252f3a
-			      sh_serial_event, s);
Justin M. Forbes 252f3a
+    if (chr) {
Justin M. Forbes 252f3a
+        qemu_chr_add_handlers(chr, &sh_serial_handlers, s);
Justin M. Forbes 252f3a
+    }
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
     s->eri = eri_source;
Justin M. Forbes 252f3a
     s->rxi = rxi_source;
Justin M. Forbes 252f3a
diff --git a/hw/syborg_serial.c b/hw/syborg_serial.c
Justin M. Forbes 252f3a
index 34ce076..124b636 100644
Justin M. Forbes 252f3a
--- a/hw/syborg_serial.c
Justin M. Forbes 252f3a
+++ b/hw/syborg_serial.c
Justin M. Forbes 252f3a
@@ -315,6 +315,12 @@ static int syborg_serial_load(QEMUFile *f, void *opaque, int version_id)
Justin M. Forbes 252f3a
     return 0;
Justin M. Forbes 252f3a
 }
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
+static const QemuChrHandlers syborg_serial_handlers = {
Justin M. Forbes 252f3a
+    .fd_can_read = syborg_serial_can_receive,
Justin M. Forbes 252f3a
+    .fd_read = syborg_serial_receive,
Justin M. Forbes 252f3a
+    .fd_event = syborg_serial_event,
Justin M. Forbes 252f3a
+};
Justin M. Forbes 252f3a
+
Justin M. Forbes 252f3a
 static int syborg_serial_init(SysBusDevice *dev)
Justin M. Forbes 252f3a
 {
Justin M. Forbes 252f3a
     SyborgSerialState *s = FROM_SYSBUS(SyborgSerialState, dev);
Justin M. Forbes 252f3a
@@ -327,8 +333,7 @@ static int syborg_serial_init(SysBusDevice *dev)
Justin M. Forbes 252f3a
     sysbus_init_mmio(dev, 0x1000, iomemtype);
Justin M. Forbes 252f3a
     s->chr = qdev_init_chardev(&dev->qdev);
Justin M. Forbes 252f3a
     if (s->chr) {
Justin M. Forbes 252f3a
-        qemu_chr_add_handlers(s->chr, syborg_serial_can_receive,
Justin M. Forbes 252f3a
-                              syborg_serial_receive, syborg_serial_event, s);
Justin M. Forbes 252f3a
+        qemu_chr_add_handlers(s->chr, &syborg_serial_handlers, s);
Justin M. Forbes 252f3a
     }
Justin M. Forbes 252f3a
     if (s->fifo_size <= 0) {
Justin M. Forbes 252f3a
         fprintf(stderr, "syborg_serial: fifo too small\n");
Justin M. Forbes 252f3a
diff --git a/hw/usb-serial.c b/hw/usb-serial.c
Justin M. Forbes 252f3a
index 6763d52..2435d9d 100644
Justin M. Forbes 252f3a
--- a/hw/usb-serial.c
Justin M. Forbes 252f3a
+++ b/hw/usb-serial.c
Justin M. Forbes 252f3a
@@ -475,6 +475,12 @@ static void usb_serial_event(void *opaque, int event)
Justin M. Forbes 252f3a
     }
Justin M. Forbes 252f3a
 }
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
+static const QemuChrHandlers usb_serial_handlers = {
Justin M. Forbes 252f3a
+    .fd_can_read = usb_serial_can_read,
Justin M. Forbes 252f3a
+    .fd_read = usb_serial_read,
Justin M. Forbes 252f3a
+    .fd_event = usb_serial_event,
Justin M. Forbes 252f3a
+};
Justin M. Forbes 252f3a
+
Justin M. Forbes 252f3a
 static int usb_serial_initfn(USBDevice *dev)
Justin M. Forbes 252f3a
 {
Justin M. Forbes 252f3a
     USBSerialState *s = DO_UPCAST(USBSerialState, dev, dev);
Justin M. Forbes 252f3a
@@ -486,8 +492,7 @@ static int usb_serial_initfn(USBDevice *dev)
Justin M. Forbes 252f3a
         return -1;
Justin M. Forbes 252f3a
     }
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
-    qemu_chr_add_handlers(s->cs, usb_serial_can_read, usb_serial_read,
Justin M. Forbes 252f3a
-                          usb_serial_event, s);
Justin M. Forbes 252f3a
+    qemu_chr_add_handlers(s->cs, &usb_serial_handlers, s);
Justin M. Forbes 252f3a
     usb_serial_handle_reset(dev);
Justin M. Forbes 252f3a
     return 0;
Justin M. Forbes 252f3a
 }
Justin M. Forbes 252f3a
diff --git a/hw/virtio-console.c b/hw/virtio-console.c
Justin M. Forbes 252f3a
index 62624ec..22cf28c 100644
Justin M. Forbes 252f3a
--- a/hw/virtio-console.c
Justin M. Forbes 252f3a
+++ b/hw/virtio-console.c
Justin M. Forbes 252f3a
@@ -57,13 +57,18 @@ static void chr_event(void *opaque, int event)
Justin M. Forbes 252f3a
     }
Justin M. Forbes 252f3a
 }
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
+static const QemuChrHandlers chr_handlers = {
Justin M. Forbes 252f3a
+    .fd_can_read = chr_can_read,
Justin M. Forbes 252f3a
+    .fd_read = chr_read,
Justin M. Forbes 252f3a
+    .fd_event = chr_event,
Justin M. Forbes 252f3a
+};
Justin M. Forbes 252f3a
+
Justin M. Forbes 252f3a
 static int generic_port_init(VirtConsole *vcon, VirtIOSerialDevice *dev)
Justin M. Forbes 252f3a
 {
Justin M. Forbes 252f3a
     vcon->port.info = dev->info;
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
     if (vcon->chr) {
Justin M. Forbes 252f3a
-        qemu_chr_add_handlers(vcon->chr, chr_can_read, chr_read, chr_event,
Justin M. Forbes 252f3a
-                              vcon);
Justin M. Forbes 252f3a
+        qemu_chr_add_handlers(vcon->chr, &chr_handlers, vcon);
Justin M. Forbes 252f3a
         vcon->port.info->have_data = flush_buf;
Justin M. Forbes 252f3a
     }
Justin M. Forbes 252f3a
     return 0;
Justin M. Forbes 252f3a
diff --git a/hw/xen_console.c b/hw/xen_console.c
Justin M. Forbes 252f3a
index d2261f4..8327e4e 100644
Justin M. Forbes 252f3a
--- a/hw/xen_console.c
Justin M. Forbes 252f3a
+++ b/hw/xen_console.c
Justin M. Forbes 252f3a
@@ -202,6 +202,11 @@ static int con_init(struct XenDevice *xendev)
Justin M. Forbes 252f3a
     return 0;
Justin M. Forbes 252f3a
 }
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
+static const QemuChrHandlers xencons_handlers = {
Justin M. Forbes 252f3a
+    .fd_can_read = xencons_can_receive,
Justin M. Forbes 252f3a
+    .fd_read = xencons_receive,
Justin M. Forbes 252f3a
+};
Justin M. Forbes 252f3a
+
Justin M. Forbes 252f3a
 static int con_connect(struct XenDevice *xendev)
Justin M. Forbes 252f3a
 {
Justin M. Forbes 252f3a
     struct XenConsole *con = container_of(xendev, struct XenConsole, xendev);
Justin M. Forbes 252f3a
@@ -222,9 +227,9 @@ static int con_connect(struct XenDevice *xendev)
Justin M. Forbes 252f3a
 	return -1;
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
     xen_be_bind_evtchn(&con->xendev);
Justin M. Forbes 252f3a
-    if (con->chr)
Justin M. Forbes 252f3a
-        qemu_chr_add_handlers(con->chr, xencons_can_receive, xencons_receive,
Justin M. Forbes 252f3a
-                              NULL, con);
Justin M. Forbes 252f3a
+    if (con->chr) {
Justin M. Forbes 252f3a
+        qemu_chr_add_handlers(con->chr, &xencons_handlers, con);
Justin M. Forbes 252f3a
+    }
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
     xen_be_printf(xendev, 1, "ring mfn %d, remote port %d, local port %d, limit %zd\n",
Justin M. Forbes 252f3a
 		  con->ring_ref,
Justin M. Forbes 252f3a
@@ -238,8 +243,9 @@ static void con_disconnect(struct XenDevice *xendev)
Justin M. Forbes 252f3a
 {
Justin M. Forbes 252f3a
     struct XenConsole *con = container_of(xendev, struct XenConsole, xendev);
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
-    if (con->chr)
Justin M. Forbes 252f3a
-        qemu_chr_add_handlers(con->chr, NULL, NULL, NULL, NULL);
Justin M. Forbes 252f3a
+    if (con->chr) {
Justin M. Forbes 252f3a
+        qemu_chr_add_handlers(con->chr, NULL, NULL);
Justin M. Forbes 252f3a
+    }
Justin M. Forbes 252f3a
     xen_be_unbind_evtchn(&con->xendev);
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
     if (con->sring) {
Justin M. Forbes 252f3a
diff --git a/hw/xilinx_uartlite.c b/hw/xilinx_uartlite.c
Justin M. Forbes 252f3a
index 9b94e98..1845577 100644
Justin M. Forbes 252f3a
--- a/hw/xilinx_uartlite.c
Justin M. Forbes 252f3a
+++ b/hw/xilinx_uartlite.c
Justin M. Forbes 252f3a
@@ -193,6 +193,12 @@ static void uart_event(void *opaque, int event)
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
 }
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
+static const QemuChrHandlers uart_handlers = {
Justin M. Forbes 252f3a
+    .fd_can_read = uart_can_rx,
Justin M. Forbes 252f3a
+    .fd_read = uart_rx,
Justin M. Forbes 252f3a
+    .fd_event = uart_event,
Justin M. Forbes 252f3a
+};
Justin M. Forbes 252f3a
+
Justin M. Forbes 252f3a
 static int xilinx_uartlite_init(SysBusDevice *dev)
Justin M. Forbes 252f3a
 {
Justin M. Forbes 252f3a
     struct xlx_uartlite *s = FROM_SYSBUS(typeof (*s), dev);
Justin M. Forbes 252f3a
@@ -206,8 +212,9 @@ static int xilinx_uartlite_init(SysBusDevice *dev)
Justin M. Forbes 252f3a
     sysbus_init_mmio(dev, R_MAX * 4, uart_regs);
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
     s->chr = qdev_init_chardev(&dev->qdev);
Justin M. Forbes 252f3a
-    if (s->chr)
Justin M. Forbes 252f3a
-        qemu_chr_add_handlers(s->chr, uart_can_rx, uart_rx, uart_event, s);
Justin M. Forbes 252f3a
+    if (s->chr) {
Justin M. Forbes 252f3a
+        qemu_chr_add_handlers(s->chr, &uart_handlers, s);
Justin M. Forbes 252f3a
+    }
Justin M. Forbes 252f3a
     return 0;
Justin M. Forbes 252f3a
 }
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
diff --git a/monitor.c b/monitor.c
Justin M. Forbes 252f3a
index 096d42b..a00a233 100644
Justin M. Forbes 252f3a
--- a/monitor.c
Justin M. Forbes 252f3a
+++ b/monitor.c
Justin M. Forbes 252f3a
@@ -5179,6 +5179,18 @@ static void monitor_event(void *opaque, int event)
Justin M. Forbes 252f3a
  * End:
Justin M. Forbes 252f3a
  */
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
+static const QemuChrHandlers monitor_handlers = {
Justin M. Forbes 252f3a
+    .fd_can_read = monitor_can_read,
Justin M. Forbes 252f3a
+    .fd_read = monitor_read,
Justin M. Forbes 252f3a
+    .fd_event = monitor_event,
Justin M. Forbes 252f3a
+};
Justin M. Forbes 252f3a
+
Justin M. Forbes 252f3a
+static const QemuChrHandlers monitor_control_handlers = {
Justin M. Forbes 252f3a
+    .fd_can_read = monitor_can_read,
Justin M. Forbes 252f3a
+    .fd_read = monitor_control_read,
Justin M. Forbes 252f3a
+    .fd_event = monitor_control_event,
Justin M. Forbes 252f3a
+};
Justin M. Forbes 252f3a
+
Justin M. Forbes 252f3a
 void monitor_init(CharDriverState *chr, int flags)
Justin M. Forbes 252f3a
 {
Justin M. Forbes 252f3a
     static int is_first_init = 1;
Justin M. Forbes 252f3a
@@ -5201,12 +5213,10 @@ void monitor_init(CharDriverState *chr, int flags)
Justin M. Forbes 252f3a
     if (monitor_ctrl_mode(mon)) {
Justin M. Forbes 252f3a
         mon->mc = qemu_mallocz(sizeof(MonitorControl));
Justin M. Forbes 252f3a
         /* Control mode requires special handlers */
Justin M. Forbes 252f3a
-        qemu_chr_add_handlers(chr, monitor_can_read, monitor_control_read,
Justin M. Forbes 252f3a
-                              monitor_control_event, mon);
Justin M. Forbes 252f3a
+        qemu_chr_add_handlers(chr, &monitor_control_handlers, mon);
Justin M. Forbes 252f3a
         qemu_chr_set_echo(chr, true);
Justin M. Forbes 252f3a
     } else {
Justin M. Forbes 252f3a
-        qemu_chr_add_handlers(chr, monitor_can_read, monitor_read,
Justin M. Forbes 252f3a
-                              monitor_event, mon);
Justin M. Forbes 252f3a
+        qemu_chr_add_handlers(chr, &monitor_handlers, mon);
Justin M. Forbes 252f3a
     }
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
     QLIST_INSERT_HEAD(&mon_list, mon, entry);
Justin M. Forbes 252f3a
diff --git a/net/slirp.c b/net/slirp.c
Justin M. Forbes 252f3a
index b41c60a..437be46 100644
Justin M. Forbes 252f3a
--- a/net/slirp.c
Justin M. Forbes 252f3a
+++ b/net/slirp.c
Justin M. Forbes 252f3a
@@ -577,6 +577,11 @@ static void guestfwd_read(void *opaque, const uint8_t *buf, int size)
Justin M. Forbes 252f3a
     slirp_socket_recv(fwd->slirp, fwd->server, fwd->port, buf, size);
Justin M. Forbes 252f3a
 }
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
+static const QemuChrHandlers guestfwd_handlers = {
Justin M. Forbes 252f3a
+    .fd_can_read = guestfwd_can_read,
Justin M. Forbes 252f3a
+    .fd_read = guestfwd_read,
Justin M. Forbes 252f3a
+};
Justin M. Forbes 252f3a
+
Justin M. Forbes 252f3a
 static int slirp_guestfwd(SlirpState *s, const char *config_str,
Justin M. Forbes 252f3a
                           int legacy_format)
Justin M. Forbes 252f3a
 {
Justin M. Forbes 252f3a
@@ -633,8 +638,7 @@ static int slirp_guestfwd(SlirpState *s, const char *config_str,
Justin M. Forbes 252f3a
     fwd->port = port;
Justin M. Forbes 252f3a
     fwd->slirp = s->slirp;
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
-    qemu_chr_add_handlers(fwd->hd, guestfwd_can_read, guestfwd_read,
Justin M. Forbes 252f3a
-                          NULL, fwd);
Justin M. Forbes 252f3a
+    qemu_chr_add_handlers(fwd->hd, &guestfwd_handlers, fwd);
Justin M. Forbes 252f3a
     return 0;
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
  fail_syntax:
Justin M. Forbes 252f3a
diff --git a/qemu-char.c b/qemu-char.c
Justin M. Forbes 252f3a
index 4b57af9..3a31d8b 100644
Justin M. Forbes 252f3a
--- a/qemu-char.c
Justin M. Forbes 252f3a
+++ b/qemu-char.c
Justin M. Forbes 252f3a
@@ -191,15 +191,22 @@ void qemu_chr_send_event(CharDriverState *s, int event)
Justin M. Forbes 252f3a
         s->chr_send_event(s, event);
Justin M. Forbes 252f3a
 }
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
+static const QemuChrHandlers null_handlers = {
Justin M. Forbes 252f3a
+    /* All handlers are initialised to NULL */
Justin M. Forbes 252f3a
+};
Justin M. Forbes 252f3a
+
Justin M. Forbes 252f3a
 void qemu_chr_add_handlers(CharDriverState *s,
Justin M. Forbes 252f3a
-                           IOCanReadHandler *fd_can_read,
Justin M. Forbes 252f3a
-                           IOReadHandler *fd_read,
Justin M. Forbes 252f3a
-                           IOEventHandler *fd_event,
Justin M. Forbes 252f3a
-                           void *opaque)
Justin M. Forbes 252f3a
-{
Justin M. Forbes 252f3a
-    s->chr_can_read = fd_can_read;
Justin M. Forbes 252f3a
-    s->chr_read = fd_read;
Justin M. Forbes 252f3a
-    s->chr_event = fd_event;
Justin M. Forbes 252f3a
+                           const QemuChrHandlers *handlers, void *opaque)
Justin M. Forbes 252f3a
+{
Justin M. Forbes 252f3a
+    if (!s) {
Justin M. Forbes 252f3a
+        return;
Justin M. Forbes 252f3a
+    }
Justin M. Forbes 252f3a
+    if (!handlers) {
Justin M. Forbes 252f3a
+        handlers = &null_handlers;
Justin M. Forbes 252f3a
+    }
Justin M. Forbes 252f3a
+    s->chr_can_read = handlers->fd_can_read;
Justin M. Forbes 252f3a
+    s->chr_read = handlers->fd_read;
Justin M. Forbes 252f3a
+    s->chr_event = handlers->fd_event;
Justin M. Forbes 252f3a
     s->handler_opaque = opaque;
Justin M. Forbes 252f3a
     if (s->chr_update_read_handler)
Justin M. Forbes 252f3a
         s->chr_update_read_handler(s);
Justin M. Forbes 252f3a
@@ -437,6 +444,12 @@ static void mux_chr_event(void *opaque, int event)
Justin M. Forbes 252f3a
         mux_chr_send_event(d, i, event);
Justin M. Forbes 252f3a
 }
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
+static const QemuChrHandlers mux_chr_handlers = {
Justin M. Forbes 252f3a
+    .fd_can_read = mux_chr_can_read,
Justin M. Forbes 252f3a
+    .fd_read = mux_chr_read,
Justin M. Forbes 252f3a
+    .fd_event = mux_chr_event,
Justin M. Forbes 252f3a
+};
Justin M. Forbes 252f3a
+
Justin M. Forbes 252f3a
 static void mux_chr_update_read_handler(CharDriverState *chr)
Justin M. Forbes 252f3a
 {
Justin M. Forbes 252f3a
     MuxDriver *d = chr->opaque;
Justin M. Forbes 252f3a
@@ -451,8 +464,7 @@ static void mux_chr_update_read_handler(CharDriverState *chr)
Justin M. Forbes 252f3a
     d->chr_event[d->mux_cnt] = chr->chr_event;
Justin M. Forbes 252f3a
     /* Fix up the real driver with mux routines */
Justin M. Forbes 252f3a
     if (d->mux_cnt == 0) {
Justin M. Forbes 252f3a
-        qemu_chr_add_handlers(d->drv, mux_chr_can_read, mux_chr_read,
Justin M. Forbes 252f3a
-                              mux_chr_event, chr);
Justin M. Forbes 252f3a
+        qemu_chr_add_handlers(d->drv, &mux_chr_handlers, chr);
Justin M. Forbes 252f3a
     }
Justin M. Forbes 252f3a
     if (d->focus != -1) {
Justin M. Forbes 252f3a
         mux_chr_send_event(d, d->focus, CHR_EVENT_MUX_OUT);
Justin M. Forbes 252f3a
diff --git a/qemu-char.h b/qemu-char.h
Justin M. Forbes 252f3a
index 56d9954..7a1924c 100644
Justin M. Forbes 252f3a
--- a/qemu-char.h
Justin M. Forbes 252f3a
+++ b/qemu-char.h
Justin M. Forbes 252f3a
@@ -1,6 +1,7 @@
Justin M. Forbes 252f3a
 #ifndef QEMU_CHAR_H
Justin M. Forbes 252f3a
 #define QEMU_CHAR_H
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
+#include <stdbool.h>
Justin M. Forbes 252f3a
 #include "qemu-common.h"
Justin M. Forbes 252f3a
 #include "qemu-queue.h"
Justin M. Forbes 252f3a
 #include "qemu-option.h"
Justin M. Forbes 252f3a
@@ -73,6 +74,13 @@ struct CharDriverState {
Justin M. Forbes 252f3a
     QTAILQ_ENTRY(CharDriverState) next;
Justin M. Forbes 252f3a
 };
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
+typedef struct QemuChrHandlers {
Justin M. Forbes 252f3a
+    IOCanReadHandler *fd_can_read;
Justin M. Forbes 252f3a
+    IOReadHandler *fd_read;
Justin M. Forbes 252f3a
+    IOHandler *fd_write_unblocked;
Justin M. Forbes 252f3a
+    IOEventHandler *fd_event;
Justin M. Forbes 252f3a
+} QemuChrHandlers;
Justin M. Forbes 252f3a
+
Justin M. Forbes 252f3a
 QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename);
Justin M. Forbes 252f3a
 CharDriverState *qemu_chr_open_opts(QemuOpts *opts,
Justin M. Forbes 252f3a
                                     void (*init)(struct CharDriverState *s));
Justin M. Forbes 252f3a
@@ -83,10 +91,7 @@ void qemu_chr_printf(CharDriverState *s, const char *fmt, ...)
Justin M. Forbes 252f3a
     GCC_FMT_ATTR(2, 3);
Justin M. Forbes 252f3a
 int qemu_chr_write(CharDriverState *s, const uint8_t *buf, int len);
Justin M. Forbes 252f3a
 void qemu_chr_send_event(CharDriverState *s, int event);
Justin M. Forbes 252f3a
-void qemu_chr_add_handlers(CharDriverState *s,
Justin M. Forbes 252f3a
-                           IOCanReadHandler *fd_can_read,
Justin M. Forbes 252f3a
-                           IOReadHandler *fd_read,
Justin M. Forbes 252f3a
-                           IOEventHandler *fd_event,
Justin M. Forbes 252f3a
+void qemu_chr_add_handlers(CharDriverState *s, const QemuChrHandlers *handlers,
Justin M. Forbes 252f3a
                            void *opaque);
Justin M. Forbes 252f3a
 int qemu_chr_ioctl(CharDriverState *s, int cmd, void *arg);
Justin M. Forbes 252f3a
 void qemu_chr_generic_open(CharDriverState *s);
Justin M. Forbes 252f3a
-- 
Justin M. Forbes 252f3a
1.7.4.1
Justin M. Forbes 252f3a