aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2016-10-21 20:49:37 +0300
committerPaolo Bonzini <pbonzini@redhat.com>2017-01-27 18:07:58 +0100
commitb68e956abe2ad0a1ecf53868e0bf1a61b418ded8 (patch)
tree2d25f219ee74ed5671959e92f9018ccd408cd35a /include
parenta1698bf183a2fc05ff980e06c798408d5898bc48 (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 'include')
-rw-r--r--include/sysemu/char.h46
1 files changed, 26 insertions, 20 deletions
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);