diff options
author | Marc-André Lureau <marcandre.lureau@redhat.com> | 2016-10-21 20:49:37 +0300 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2017-01-27 18:07:58 +0100 |
commit | b68e956abe2ad0a1ecf53868e0bf1a61b418ded8 (patch) | |
tree | 2d25f219ee74ed5671959e92f9018ccd408cd35a /ui | |
parent | a1698bf183a2fc05ff980e06c798408d5898bc48 (diff) |
char: move callbacks in CharDriver
This makes the code more declarative, and avoids duplicating the
information on all instances.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'ui')
-rw-r--r-- | ui/console.c | 28 | ||||
-rw-r--r-- | ui/gtk.c | 11 |
2 files changed, 24 insertions, 15 deletions
diff --git a/ui/console.c b/ui/console.c index e4bb22fe87..f48ba26d2a 100644 --- a/ui/console.c +++ b/ui/console.c @@ -1051,6 +1051,10 @@ static int console_puts(CharDriverState *chr, const uint8_t *buf, int len) QemuConsole *s = chr->opaque; int i; + if (!s->ds) { + return 0; + } + s->update_x0 = s->width * FONT_WIDTH; s->update_y0 = s->height * FONT_HEIGHT; s->update_x1 = 0; @@ -2000,8 +2004,6 @@ static void text_console_do_init(CharDriverState *chr, DisplayState *ds) s = chr->opaque; - chr->chr_write = console_puts; - s->out_fifo.buf = s->out_fifo_buf; s->out_fifo.buf_size = sizeof(s->out_fifo_buf); s->kbd_timer = timer_new_ms(QEMU_CLOCK_REALTIME, kbd_send_chars, s); @@ -2048,6 +2050,8 @@ static void text_console_do_init(CharDriverState *chr, DisplayState *ds) qemu_chr_be_generic_open(chr); } +static const CharDriver vc_driver; + static CharDriverState *text_console_init(ChardevVC *vc, Error **errp) { ChardevCommon *common = qapi_ChardevVC_base(vc); @@ -2056,7 +2060,7 @@ static CharDriverState *text_console_init(ChardevVC *vc, Error **errp) unsigned width = 0; unsigned height = 0; - chr = qemu_chr_alloc(common, errp); + chr = qemu_chr_alloc(&vc_driver, common, errp); if (!chr) { return NULL; } @@ -2089,7 +2093,6 @@ static CharDriverState *text_console_init(ChardevVC *vc, Error **errp) s->chr = chr; chr->opaque = s; - chr->chr_set_echo = text_console_set_echo; if (display_state) { text_console_do_init(chr, display_state); @@ -2099,7 +2102,8 @@ static CharDriverState *text_console_init(ChardevVC *vc, Error **errp) static VcHandler *vc_handler = text_console_init; -static CharDriverState *vc_init(const char *id, ChardevBackend *backend, +static CharDriverState *vc_init(const CharDriver *driver, + const char *id, ChardevBackend *backend, ChardevReturn *ret, bool *be_opened, Error **errp) { @@ -2191,14 +2195,16 @@ static const TypeInfo qemu_console_info = { .class_size = sizeof(QemuConsoleClass), }; +static const CharDriver vc_driver = { + .kind = CHARDEV_BACKEND_KIND_VC, + .parse = qemu_chr_parse_vc, + .create = vc_init, + .chr_write = console_puts, + .chr_set_echo = text_console_set_echo, +}; + static void register_types(void) { - static const CharDriver vc_driver = { - .kind = CHARDEV_BACKEND_KIND_VC, - .parse = qemu_chr_parse_vc, - .create = vc_init, - }; - type_register_static(&qemu_console_info); register_char_driver(&vc_driver); } @@ -1703,6 +1703,12 @@ static CharDriverState *vcs[MAX_VCS]; static CharDriverState *gd_vc_handler(ChardevVC *vc, Error **errp) { + static const CharDriver gd_vc_driver = { + .kind = CHARDEV_BACKEND_KIND_VC, + .chr_write = gd_vc_chr_write, + .chr_set_echo = gd_vc_chr_set_echo, + }; + ChardevCommon *common = qapi_ChardevVC_base(vc); CharDriverState *chr; @@ -1711,14 +1717,11 @@ static CharDriverState *gd_vc_handler(ChardevVC *vc, Error **errp) return NULL; } - chr = qemu_chr_alloc(common, errp); + chr = qemu_chr_alloc(&gd_vc_driver, common, errp); if (!chr) { return NULL; } - chr->chr_write = gd_vc_chr_write; - chr->chr_set_echo = gd_vc_chr_set_echo; - /* Temporary, until gd_vc_vte_init runs. */ chr->opaque = g_new0(VirtualConsole, 1); |