aboutsummaryrefslogtreecommitdiff
path: root/spice-qemu-char.c
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 /spice-qemu-char.c
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 'spice-qemu-char.c')
-rw-r--r--spice-qemu-char.c32
1 files changed, 19 insertions, 13 deletions
diff --git a/spice-qemu-char.c b/spice-qemu-char.c
index 30db420e2f..c7eb306f34 100644
--- a/spice-qemu-char.c
+++ b/spice-qemu-char.c
@@ -260,16 +260,15 @@ static void spice_chr_accept_input(struct CharDriverState *chr)
spice_server_char_device_wakeup(&s->sin);
}
-static CharDriverState *chr_open(const char *subtype,
- void (*set_fe_open)(struct CharDriverState *,
- int),
+static CharDriverState *chr_open(const CharDriver *driver,
+ const char *subtype,
ChardevCommon *backend,
Error **errp)
{
CharDriverState *chr;
SpiceCharDriver *s;
- chr = qemu_chr_alloc(backend, errp);
+ chr = qemu_chr_alloc(driver, backend, errp);
if (!chr) {
return NULL;
}
@@ -278,18 +277,14 @@ static CharDriverState *chr_open(const char *subtype,
s->active = false;
s->sin.subtype = g_strdup(subtype);
chr->opaque = s;
- chr->chr_write = spice_chr_write;
- chr->chr_add_watch = spice_chr_add_watch;
- chr->chr_free = spice_chr_free;
- chr->chr_set_fe_open = set_fe_open;
- chr->chr_accept_input = spice_chr_accept_input;
QLIST_INSERT_HEAD(&spice_chars, s, next);
return chr;
}
-static CharDriverState *qemu_chr_open_spice_vmc(const char *id,
+static CharDriverState *qemu_chr_open_spice_vmc(const CharDriver *driver,
+ const char *id,
ChardevBackend *backend,
ChardevReturn *ret,
bool *be_opened,
@@ -312,11 +307,12 @@ static CharDriverState *qemu_chr_open_spice_vmc(const char *id,
}
*be_opened = false;
- return chr_open(type, spice_vmc_set_fe_open, common, errp);
+ return chr_open(driver, type, common, errp);
}
#if SPICE_SERVER_VERSION >= 0x000c02
-static CharDriverState *qemu_chr_open_spice_port(const char *id,
+static CharDriverState *qemu_chr_open_spice_port(const CharDriver *driver,
+ const char *id,
ChardevBackend *backend,
ChardevReturn *ret,
bool *be_opened,
@@ -333,7 +329,7 @@ static CharDriverState *qemu_chr_open_spice_port(const char *id,
return NULL;
}
- chr = chr_open("port", spice_port_set_fe_open, common, errp);
+ chr = chr_open(driver, "port", common, errp);
if (!chr) {
return NULL;
}
@@ -393,11 +389,21 @@ static void register_types(void)
.kind = CHARDEV_BACKEND_KIND_SPICEVMC,
.parse = qemu_chr_parse_spice_vmc,
.create = qemu_chr_open_spice_vmc,
+ .chr_write = spice_chr_write,
+ .chr_add_watch = spice_chr_add_watch,
+ .chr_set_fe_open = spice_vmc_set_fe_open,
+ .chr_accept_input = spice_chr_accept_input,
+ .chr_free = spice_chr_free,
};
static const CharDriver port_driver = {
.kind = CHARDEV_BACKEND_KIND_SPICEPORT,
.parse = qemu_chr_parse_spice_port,
.create = qemu_chr_open_spice_port,
+ .chr_write = spice_chr_write,
+ .chr_add_watch = spice_chr_add_watch,
+ .chr_set_fe_open = spice_port_set_fe_open,
+ .chr_accept_input = spice_chr_accept_input,
+ .chr_free = spice_chr_free,
};
register_char_driver(&vmc_driver);
register_char_driver(&port_driver);