Commit b68e956a authored by Marc-André Lureau's avatar Marc-André Lureau Committed by Paolo Bonzini
Browse files

char: move callbacks in CharDriver



This makes the code more declarative, and avoids duplicating the
information on all instances.

Signed-off-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: default avatarEric Blake <eblake@redhat.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent a1698bf1
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -622,7 +622,8 @@ static void baum_free(struct CharDriverState *chr)
    g_free(baum);
}

static CharDriverState *chr_baum_init(const char *id,
static CharDriverState *chr_baum_init(const CharDriver *driver,
                                      const char *id,
                                      ChardevBackend *backend,
                                      ChardevReturn *ret,
                                      bool *be_opened,
@@ -633,7 +634,7 @@ static CharDriverState *chr_baum_init(const char *id,
    CharDriverState *chr;
    brlapi_handle_t *handle;

    chr = qemu_chr_alloc(common, errp);
    chr = qemu_chr_alloc(driver, common, errp);
    if (!chr) {
        return NULL;
    }
@@ -641,9 +642,6 @@ static CharDriverState *chr_baum_init(const char *id,
    baum->chr = chr;

    chr->opaque = baum;
    chr->chr_write = baum_write;
    chr->chr_accept_input = baum_accept_input;
    chr->chr_free = baum_free;

    handle = g_malloc0(brlapi_getHandleSize());
    baum->brlapi = handle;
@@ -674,6 +672,9 @@ static void register_types(void)
    static const CharDriver driver = {
        .kind = CHARDEV_BACKEND_KIND_BRAILLE,
        .create = chr_baum_init,
        .chr_write = baum_write,
        .chr_accept_input = baum_accept_input,
        .chr_free = baum_free,
    };

    register_char_driver(&driver);
+6 −5
Original line number Diff line number Diff line
@@ -148,7 +148,8 @@ static QemuInputHandler msmouse_handler = {
    .sync  = msmouse_input_sync,
};

static CharDriverState *qemu_chr_open_msmouse(const char *id,
static CharDriverState *qemu_chr_open_msmouse(const CharDriver *driver,
                                              const char *id,
                                              ChardevBackend *backend,
                                              ChardevReturn *ret,
                                              bool *be_opened,
@@ -158,13 +159,10 @@ static CharDriverState *qemu_chr_open_msmouse(const char *id,
    MouseState *mouse;
    CharDriverState *chr;

    chr = qemu_chr_alloc(common, errp);
    chr = qemu_chr_alloc(driver, common, errp);
    if (!chr) {
        return NULL;
    }
    chr->chr_write = msmouse_chr_write;
    chr->chr_free = msmouse_chr_free;
    chr->chr_accept_input = msmouse_chr_accept_input;
    *be_opened = false;

    mouse = g_new0(MouseState, 1);
@@ -182,6 +180,9 @@ static void register_types(void)
    static const CharDriver driver = {
        .kind = CHARDEV_BACKEND_KIND_MSMOUSE,
        .create = qemu_chr_open_msmouse,
        .chr_write = msmouse_chr_write,
        .chr_accept_input = msmouse_chr_accept_input,
        .chr_free = msmouse_chr_free,
    };
    register_char_driver(&driver);
}
+5 −3
Original line number Diff line number Diff line
@@ -109,7 +109,8 @@ static void testdev_free(struct CharDriverState *chr)
    g_free(testdev);
}

static CharDriverState *chr_testdev_init(const char *id,
static CharDriverState *chr_testdev_init(const CharDriver *driver,
                                         const char *id,
                                         ChardevBackend *backend,
                                         ChardevReturn *ret,
                                         bool *be_opened,
@@ -121,9 +122,8 @@ static CharDriverState *chr_testdev_init(const char *id,
    testdev = g_new0(TestdevCharState, 1);
    testdev->chr = chr = g_new0(CharDriverState, 1);

    chr->driver = driver;
    chr->opaque = testdev;
    chr->chr_write = testdev_write;
    chr->chr_free = testdev_free;

    return chr;
}
@@ -133,6 +133,8 @@ static void register_types(void)
    static const CharDriver driver = {
        .kind = CHARDEV_BACKEND_KIND_TESTDEV,
        .create = chr_testdev_init,
        .chr_write = testdev_write,
        .chr_free = testdev_free,
    };
    register_char_driver(&driver);
}
+5 −2
Original line number Diff line number Diff line
@@ -1732,6 +1732,10 @@ int gdbserver_start(const char *device)
    CharDriverState *chr = NULL;
    CharDriverState *mon_chr;
    ChardevCommon common = { 0 };
    static const CharDriver driver = {
        .kind = -1,
        .chr_write = gdb_monitor_write,
    };

    if (!first_cpu) {
        error_report("gdbstub: meaningless to attach gdb to a "
@@ -1770,8 +1774,7 @@ int gdbserver_start(const char *device)
        qemu_add_vm_change_state_handler(gdb_vm_state_change, NULL);

        /* Initialize a monitor terminal for gdb */
        mon_chr = qemu_chr_alloc(&common, &error_abort);
        mon_chr->chr_write = gdb_monitor_write;
        mon_chr = qemu_chr_alloc(&driver, &common, &error_abort);
        monitor_init(mon_chr, 0);
    } else {
        if (qemu_chr_fe_get_driver(&s->chr)) {
+6 −2
Original line number Diff line number Diff line
@@ -462,12 +462,16 @@ qemu_irq *csrhci_pins_get(CharDriverState *chr)

CharDriverState *uart_hci_init(void)
{
    static const CharDriver hci_driver = {
        .kind = -1,
        .chr_write = csrhci_write,
        .chr_ioctl = csrhci_ioctl,
    };
    struct csrhci_s *s = (struct csrhci_s *)
            g_malloc0(sizeof(struct csrhci_s));

    s->chr.opaque = s;
    s->chr.chr_write = csrhci_write;
    s->chr.chr_ioctl = csrhci_ioctl;
    s->chr.driver = &hci_driver;

    s->hci = qemu_next_hci();
    s->hci->opaque = s;
Loading