diff options
Diffstat (limited to 'backends')
-rw-r--r-- | backends/baum.c | 66 | ||||
-rw-r--r-- | backends/msmouse.c | 57 | ||||
-rw-r--r-- | backends/testdev.c | 34 |
3 files changed, 82 insertions, 75 deletions
diff --git a/backends/baum.c b/backends/baum.c index 8842936..0f418ed 100644 --- a/backends/baum.c +++ b/backends/baum.c @@ -100,6 +100,9 @@ typedef struct { QEMUTimer *cellCount_timer; } BaumChardev; +#define TYPE_CHARDEV_BRAILLE "chardev-braille" +#define BAUM_CHARDEV(obj) OBJECT_CHECK(BaumChardev, (obj), TYPE_CHARDEV_BRAILLE) + /* Let's assume NABCC by default */ enum way { DOTS2ASCII, @@ -255,7 +258,7 @@ static int baum_deferred_init(BaumChardev *baum) /* The serial port can receive more of our data */ static void baum_chr_accept_input(struct Chardev *chr) { - BaumChardev *baum = (BaumChardev *)chr; + BaumChardev *baum = BAUM_CHARDEV(chr); int room, first; if (!baum->out_buf_used) @@ -281,7 +284,7 @@ static void baum_chr_accept_input(struct Chardev *chr) /* We want to send a packet */ static void baum_write_packet(BaumChardev *baum, const uint8_t *buf, int len) { - Chardev *chr = (Chardev *)baum; + Chardev *chr = CHARDEV(baum); uint8_t io_buf[1 + 2 * len], *cur = io_buf; int room; *cur++ = ESC; @@ -322,7 +325,7 @@ static void baum_write_packet(BaumChardev *baum, const uint8_t *buf, int len) /* Called when the other end seems to have a wrong idea of our display size */ static void baum_cellCount_timer_cb(void *opaque) { - BaumChardev *baum = opaque; + BaumChardev *baum = BAUM_CHARDEV(opaque); uint8_t cell_count[] = { BAUM_RSP_CellCount, baum->x * baum->y }; DPRINTF("Timeout waiting for DisplayData, sending cell count\n"); baum_write_packet(baum, cell_count, sizeof(cell_count)); @@ -472,7 +475,7 @@ static int baum_eat_packet(BaumChardev *baum, const uint8_t *buf, int len) /* The other end is writing some data. Store it and try to interpret */ static int baum_chr_write(Chardev *chr, const uint8_t *buf, int len) { - BaumChardev *baum = (BaumChardev *)chr; + BaumChardev *baum = BAUM_CHARDEV(chr); int tocopy, cur, eaten, orig_len = len; if (!len) @@ -529,7 +532,7 @@ static void baum_send_key2(BaumChardev *baum, uint8_t type, uint8_t value, /* We got some data on the BrlAPI socket */ static void baum_chr_read(void *opaque) { - BaumChardev *baum = opaque; + BaumChardev *baum = BAUM_CHARDEV(opaque); brlapi_keyCode_t code; int ret; if (!baum->brlapi) @@ -613,9 +616,9 @@ static void baum_chr_read(void *opaque) } } -static void baum_chr_free(struct Chardev *chr) +static void baum_chr_free(Chardev *chr) { - BaumChardev *baum = (BaumChardev *)chr; + BaumChardev *baum = BAUM_CHARDEV(chr); timer_free(baum->cellCount_timer); if (baum->brlapi) { @@ -624,24 +627,14 @@ static void baum_chr_free(struct Chardev *chr) } } -static Chardev *baum_chr_init(const CharDriver *driver, - const char *id, - ChardevBackend *backend, - ChardevReturn *ret, - bool *be_opened, - Error **errp) +static void baum_chr_open(Chardev *chr, + ChardevBackend *backend, + bool *be_opened, + Error **errp) { - ChardevCommon *common = backend->u.braille.data; - BaumChardev *baum; - Chardev *chr; + BaumChardev *baum = BAUM_CHARDEV(chr); brlapi_handle_t *handle; - chr = qemu_chr_alloc(driver, common, errp); - if (!chr) { - return NULL; - } - baum = (BaumChardev *)chr; - handle = g_malloc0(brlapi_getHandleSize()); baum->brlapi = handle; @@ -649,34 +642,41 @@ static Chardev *baum_chr_init(const CharDriver *driver, if (baum->brlapi_fd == -1) { error_setg(errp, "brlapi__openConnection: %s", brlapi_strerror(brlapi_error_location())); - goto fail_handle; + g_free(handle); + return; } baum->deferred_init = 0; baum->cellCount_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, baum_cellCount_timer_cb, baum); qemu_set_fd_handler(baum->brlapi_fd, baum_chr_read, NULL, baum); +} - return chr; +static void char_braille_class_init(ObjectClass *oc, void *data) +{ + ChardevClass *cc = CHARDEV_CLASS(oc); -fail_handle: - g_free(handle); - g_free(chr); - return NULL; + cc->open = baum_chr_open; + cc->chr_write = baum_chr_write; + cc->chr_accept_input = baum_chr_accept_input; + cc->chr_free = baum_chr_free; } +static const TypeInfo char_braille_type_info = { + .name = TYPE_CHARDEV_BRAILLE, + .parent = TYPE_CHARDEV, + .instance_size = sizeof(BaumChardev), + .class_init = char_braille_class_init, +}; + static void register_types(void) { static const CharDriver driver = { - .instance_size = sizeof(BaumChardev), .kind = CHARDEV_BACKEND_KIND_BRAILLE, - .create = baum_chr_init, - .chr_write = baum_chr_write, - .chr_accept_input = baum_chr_accept_input, - .chr_free = baum_chr_free, }; register_char_driver(&driver); + type_register_static(&char_braille_type_info); } type_init(register_types); diff --git a/backends/msmouse.c b/backends/msmouse.c index 4e474da..936a547 100644 --- a/backends/msmouse.c +++ b/backends/msmouse.c @@ -41,9 +41,13 @@ typedef struct { int outlen; } MouseChardev; +#define TYPE_CHARDEV_MSMOUSE "chardev-msmouse" +#define MOUSE_CHARDEV(obj) \ + OBJECT_CHECK(MouseChardev, (obj), TYPE_CHARDEV_MSMOUSE) + static void msmouse_chr_accept_input(Chardev *chr) { - MouseChardev *mouse = (MouseChardev *)chr; + MouseChardev *mouse = MOUSE_CHARDEV(chr); int len; len = qemu_chr_be_can_write(chr); @@ -98,7 +102,7 @@ static void msmouse_queue_event(MouseChardev *mouse) static void msmouse_input_event(DeviceState *dev, QemuConsole *src, InputEvent *evt) { - MouseChardev *mouse = (MouseChardev *)dev; + MouseChardev *mouse = MOUSE_CHARDEV(dev); InputMoveEvent *move; InputBtnEvent *btn; @@ -122,8 +126,8 @@ static void msmouse_input_event(DeviceState *dev, QemuConsole *src, static void msmouse_input_sync(DeviceState *dev) { - MouseChardev *mouse = (MouseChardev *)dev; - Chardev *chr = (Chardev *)dev; + MouseChardev *mouse = MOUSE_CHARDEV(dev); + Chardev *chr = CHARDEV(dev); msmouse_queue_event(mouse); msmouse_chr_accept_input(chr); @@ -137,7 +141,7 @@ static int msmouse_chr_write(struct Chardev *s, const uint8_t *buf, int len) static void msmouse_chr_free(struct Chardev *chr) { - MouseChardev *mouse = (MouseChardev *)chr; + MouseChardev *mouse = MOUSE_CHARDEV(chr); qemu_input_handler_unregister(mouse->hs); } @@ -149,42 +153,43 @@ static QemuInputHandler msmouse_handler = { .sync = msmouse_input_sync, }; -static Chardev *qemu_chr_open_msmouse(const CharDriver *driver, - const char *id, - ChardevBackend *backend, - ChardevReturn *ret, - bool *be_opened, - Error **errp) +static void msmouse_chr_open(Chardev *chr, + ChardevBackend *backend, + bool *be_opened, + Error **errp) { - ChardevCommon *common = backend->u.msmouse.data; - MouseChardev *mouse; - Chardev *chr; + MouseChardev *mouse = MOUSE_CHARDEV(chr); - chr = qemu_chr_alloc(driver, common, errp); - if (!chr) { - return NULL; - } *be_opened = false; - - mouse = (MouseChardev *)chr; mouse->hs = qemu_input_handler_register((DeviceState *)mouse, &msmouse_handler); +} +static void char_msmouse_class_init(ObjectClass *oc, void *data) +{ + ChardevClass *cc = CHARDEV_CLASS(oc); - return chr; + cc->open = msmouse_chr_open; + cc->chr_write = msmouse_chr_write; + cc->chr_accept_input = msmouse_chr_accept_input; + cc->chr_free = msmouse_chr_free; } +static const TypeInfo char_msmouse_type_info = { + .name = TYPE_CHARDEV_MSMOUSE, + .parent = TYPE_CHARDEV, + .instance_size = sizeof(MouseChardev), + .class_init = char_msmouse_class_init, +}; + static void register_types(void) { static const CharDriver driver = { - .instance_size = sizeof(MouseChardev), .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); + type_register_static(&char_msmouse_type_info); } type_init(register_types); diff --git a/backends/testdev.c b/backends/testdev.c index 268b380..ea15143 100644 --- a/backends/testdev.c +++ b/backends/testdev.c @@ -36,6 +36,10 @@ typedef struct { int in_buf_used; } TestdevChardev; +#define TYPE_CHARDEV_TESTDEV "chardev-testdev" +#define TESTDEV_CHARDEV(obj) \ + OBJECT_CHECK(TestdevChardev, (obj), TYPE_CHARDEV_TESTDEV) + /* Try to interpret a whole incoming packet */ static int testdev_eat_packet(TestdevChardev *testdev) { @@ -78,9 +82,9 @@ static int testdev_eat_packet(TestdevChardev *testdev) } /* The other end is writing some data. Store it and try to interpret */ -static int testdev_write(Chardev *chr, const uint8_t *buf, int len) +static int testdev_chr_write(Chardev *chr, const uint8_t *buf, int len) { - TestdevChardev *testdev = (TestdevChardev *)chr; + TestdevChardev *testdev = TESTDEV_CHARDEV(chr); int tocopy, eaten, orig_len = len; while (len) { @@ -103,30 +107,28 @@ static int testdev_write(Chardev *chr, const uint8_t *buf, int len) return orig_len; } -static Chardev *chr_testdev_init(const CharDriver *driver, - const char *id, - ChardevBackend *backend, - ChardevReturn *ret, - bool *be_opened, - Error **errp) +static void char_testdev_class_init(ObjectClass *oc, void *data) { - TestdevChardev *testdev = g_new0(TestdevChardev, 1);; - Chardev *chr = (Chardev *)testdev; - - chr->driver = driver; + ChardevClass *cc = CHARDEV_CLASS(oc); - return chr; + cc->chr_write = testdev_chr_write; } +static const TypeInfo char_testdev_type_info = { + .name = TYPE_CHARDEV_TESTDEV, + .parent = TYPE_CHARDEV, + .instance_size = sizeof(TestdevChardev), + .class_init = char_testdev_class_init, +}; + static void register_types(void) { static const CharDriver driver = { - .instance_size = sizeof(TestdevChardev), .kind = CHARDEV_BACKEND_KIND_TESTDEV, - .create = chr_testdev_init, - .chr_write = testdev_write, }; + register_char_driver(&driver); + type_register_static(&char_testdev_type_info); } type_init(register_types); |