From b68e956abe2ad0a1ecf53868e0bf1a61b418ded8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Fri, 21 Oct 2016 20:49:37 +0300 Subject: char: move callbacks in CharDriver MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes the code more declarative, and avoids duplicating the information on all instances. Signed-off-by: Marc-André Lureau Reviewed-by: Eric Blake Signed-off-by: Paolo Bonzini --- backends/baum.c | 11 ++++++----- backends/msmouse.c | 11 ++++++----- backends/testdev.c | 8 +++++--- 3 files changed, 17 insertions(+), 13 deletions(-) (limited to 'backends') diff --git a/backends/baum.c b/backends/baum.c index 2e404a1..109469e 100644 --- a/backends/baum.c +++ b/backends/baum.c @@ -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); diff --git a/backends/msmouse.c b/backends/msmouse.c index 2490b2c..2c238ba 100644 --- a/backends/msmouse.c +++ b/backends/msmouse.c @@ -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); } diff --git a/backends/testdev.c b/backends/testdev.c index cd25094..2339693 100644 --- a/backends/testdev.c +++ b/backends/testdev.c @@ -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); } -- cgit v1.1