From b68e956abe2ad0a1ecf53868e0bf1a61b418ded8 Mon Sep 17 00:00:00 2001 From: Marc-André Lureau Date: Fri, 21 Oct 2016 20:49:37 +0300 Subject: 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 Reviewed-by: Eric Blake Signed-off-by: Paolo Bonzini --- include/sysemu/char.h | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) (limited to 'include') diff --git a/include/sysemu/char.h b/include/sysemu/char.h index fee2c3493c..2dd05642fb 100644 --- a/include/sysemu/char.h +++ b/include/sysemu/char.h @@ -85,24 +85,11 @@ typedef struct CharBackend { int fe_open; } CharBackend; +typedef struct CharDriver CharDriver; + struct CharDriverState { + const CharDriver *driver; QemuMutex chr_write_lock; - int (*chr_write)(struct CharDriverState *s, const uint8_t *buf, int len); - int (*chr_sync_read)(struct CharDriverState *s, - const uint8_t *buf, int len); - GSource *(*chr_add_watch)(struct CharDriverState *s, GIOCondition cond); - void (*chr_update_read_handler)(struct CharDriverState *s, - GMainContext *context); - int (*chr_ioctl)(struct CharDriverState *s, int cmd, void *arg); - int (*get_msgfds)(struct CharDriverState *s, int* fds, int num); - int (*set_msgfds)(struct CharDriverState *s, int *fds, int num); - int (*chr_add_client)(struct CharDriverState *chr, int fd); - int (*chr_wait_connected)(struct CharDriverState *chr, Error **errp); - void (*chr_free)(struct CharDriverState *chr); - void (*chr_disconnect)(struct CharDriverState *chr); - void (*chr_accept_input)(struct CharDriverState *chr); - void (*chr_set_echo)(struct CharDriverState *chr, bool echo); - void (*chr_set_fe_open)(struct CharDriverState *chr, int fe_open); CharBackend *be; void *opaque; char *label; @@ -125,7 +112,8 @@ struct CharDriverState { * * Returns: a newly allocated CharDriverState, or NULL on error. */ -CharDriverState *qemu_chr_alloc(ChardevCommon *backend, Error **errp); +CharDriverState *qemu_chr_alloc(const CharDriver *driver, + ChardevCommon *backend, Error **errp); /** * @qemu_chr_new_from_opts: @@ -475,15 +463,33 @@ void qemu_chr_set_feature(CharDriverState *chr, CharDriverFeature feature); QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename); -typedef struct CharDriver { +struct CharDriver { ChardevBackendKind kind; const char *alias; void (*parse)(QemuOpts *opts, ChardevBackend *backend, Error **errp); - CharDriverState *(*create)(const char *id, + CharDriverState *(*create)(const CharDriver *driver, + const char *id, ChardevBackend *backend, ChardevReturn *ret, bool *be_opened, Error **errp); -} CharDriver; + + int (*chr_write)(struct CharDriverState *s, const uint8_t *buf, int len); + int (*chr_sync_read)(struct CharDriverState *s, + const uint8_t *buf, int len); + GSource *(*chr_add_watch)(struct CharDriverState *s, GIOCondition cond); + void (*chr_update_read_handler)(struct CharDriverState *s, + GMainContext *context); + int (*chr_ioctl)(struct CharDriverState *s, int cmd, void *arg); + int (*get_msgfds)(struct CharDriverState *s, int* fds, int num); + int (*set_msgfds)(struct CharDriverState *s, int *fds, int num); + int (*chr_add_client)(struct CharDriverState *chr, int fd); + int (*chr_wait_connected)(struct CharDriverState *chr, Error **errp); + void (*chr_free)(struct CharDriverState *chr); + void (*chr_disconnect)(struct CharDriverState *chr); + void (*chr_accept_input)(struct CharDriverState *chr); + void (*chr_set_echo)(struct CharDriverState *chr, bool echo); + void (*chr_set_fe_open)(struct CharDriverState *chr, int fe_open); +}; void register_char_driver(const CharDriver *driver); -- cgit v1.2.3-55-g7522