mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-05 08:43:55 -06:00
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>
This commit is contained in:
parent
a1698bf183
commit
b68e956abe
10 changed files with 381 additions and 260 deletions
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue