Commit 777357d7 authored by Marc-André Lureau's avatar Marc-André Lureau Committed by Paolo Bonzini

chardev: qom-ify

Turn Chardev into Object.

qemu_chr_alloc() is replaced by the qemu_chardev_new() constructor. It
will call qemu_char_open() to open/intialize the chardev with the
ChardevCommon *backend settings.

The CharDriver::create() callback is turned into a ChardevClass::open()
which is called from the newly introduced qemu_chardev_open().

"chardev-gdb" and "chardev-hci" are internal chardev and aren't
creatable directly with -chardev. Use a new internal flag to disable
them. We may want to use TYPE_USER_CREATABLE interface instead, or
perhaps allow -chardev usage.

Although in general we keep typename and macros private, unless the type
is being used by some other file, in this patch, all types and common
helper macros for qemu-char.c are in char.h. This is to help transition
now (some types must be declared early, while some aren't shared) and
when splitting in several units. This is to be improved later.
Signed-off-by: 's avatarMarc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: 's avatarEric Blake <eblake@redhat.com>
Signed-off-by: 's avatarPaolo Bonzini <pbonzini@redhat.com>
parent 5bf5adae
......@@ -100,6 +100,9 @@ typedef struct {
QEMUTimer *cellCount_timer;
} BaumChardev;
#define TYPE_CHARDEV_BRAILLE "chardev-braille"
#define BAUM_CHARDEV(obj) OBJECT_CHECK(BaumChardev, (obj), TYPE_CHARDEV_BRAILLE)
/* Let's assume NABCC by default */
enum way {
DOTS2ASCII,
......@@ -255,7 +258,7 @@ static int baum_deferred_init(BaumChardev *baum)
/* The serial port can receive more of our data */
static void baum_chr_accept_input(struct Chardev *chr)
{
BaumChardev *baum = (BaumChardev *)chr;
BaumChardev *baum = BAUM_CHARDEV(chr);
int room, first;
if (!baum->out_buf_used)
......@@ -281,7 +284,7 @@ static void baum_chr_accept_input(struct Chardev *chr)
/* We want to send a packet */
static void baum_write_packet(BaumChardev *baum, const uint8_t *buf, int len)
{
Chardev *chr = (Chardev *)baum;
Chardev *chr = CHARDEV(baum);
uint8_t io_buf[1 + 2 * len], *cur = io_buf;
int room;
*cur++ = ESC;
......@@ -322,7 +325,7 @@ static void baum_write_packet(BaumChardev *baum, const uint8_t *buf, int len)
/* Called when the other end seems to have a wrong idea of our display size */
static void baum_cellCount_timer_cb(void *opaque)
{
BaumChardev *baum = opaque;
BaumChardev *baum = BAUM_CHARDEV(opaque);
uint8_t cell_count[] = { BAUM_RSP_CellCount, baum->x * baum->y };
DPRINTF("Timeout waiting for DisplayData, sending cell count\n");
baum_write_packet(baum, cell_count, sizeof(cell_count));
......@@ -472,7 +475,7 @@ static int baum_eat_packet(BaumChardev *baum, const uint8_t *buf, int len)
/* The other end is writing some data. Store it and try to interpret */
static int baum_chr_write(Chardev *chr, const uint8_t *buf, int len)
{
BaumChardev *baum = (BaumChardev *)chr;
BaumChardev *baum = BAUM_CHARDEV(chr);
int tocopy, cur, eaten, orig_len = len;
if (!len)
......@@ -529,7 +532,7 @@ static void baum_send_key2(BaumChardev *baum, uint8_t type, uint8_t value,
/* We got some data on the BrlAPI socket */
static void baum_chr_read(void *opaque)
{
BaumChardev *baum = opaque;
BaumChardev *baum = BAUM_CHARDEV(opaque);
brlapi_keyCode_t code;
int ret;
if (!baum->brlapi)
......@@ -613,9 +616,9 @@ static void baum_chr_read(void *opaque)
}
}
static void baum_chr_free(struct Chardev *chr)
static void baum_chr_free(Chardev *chr)
{
BaumChardev *baum = (BaumChardev *)chr;
BaumChardev *baum = BAUM_CHARDEV(chr);
timer_free(baum->cellCount_timer);
if (baum->brlapi) {
......@@ -624,24 +627,14 @@ static void baum_chr_free(struct Chardev *chr)
}
}
static Chardev *baum_chr_init(const CharDriver *driver,
const char *id,
ChardevBackend *backend,
ChardevReturn *ret,
bool *be_opened,
Error **errp)
static void baum_chr_open(Chardev *chr,
ChardevBackend *backend,
bool *be_opened,
Error **errp)
{
ChardevCommon *common = backend->u.braille.data;
BaumChardev *baum;
Chardev *chr;
BaumChardev *baum = BAUM_CHARDEV(chr);
brlapi_handle_t *handle;
chr = qemu_chr_alloc(driver, common, errp);
if (!chr) {
return NULL;
}
baum = (BaumChardev *)chr;
handle = g_malloc0(brlapi_getHandleSize());
baum->brlapi = handle;
......@@ -649,34 +642,41 @@ static Chardev *baum_chr_init(const CharDriver *driver,
if (baum->brlapi_fd == -1) {
error_setg(errp, "brlapi__openConnection: %s",
brlapi_strerror(brlapi_error_location()));
goto fail_handle;
g_free(handle);
return;
}
baum->deferred_init = 0;
baum->cellCount_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, baum_cellCount_timer_cb, baum);
qemu_set_fd_handler(baum->brlapi_fd, baum_chr_read, NULL, baum);
}
return chr;
static void char_braille_class_init(ObjectClass *oc, void *data)
{
ChardevClass *cc = CHARDEV_CLASS(oc);
fail_handle:
g_free(handle);
g_free(chr);
return NULL;
cc->open = baum_chr_open;
cc->chr_write = baum_chr_write;
cc->chr_accept_input = baum_chr_accept_input;
cc->chr_free = baum_chr_free;
}
static const TypeInfo char_braille_type_info = {
.name = TYPE_CHARDEV_BRAILLE,
.parent = TYPE_CHARDEV,
.instance_size = sizeof(BaumChardev),
.class_init = char_braille_class_init,
};
static void register_types(void)
{
static const CharDriver driver = {
.instance_size = sizeof(BaumChardev),
.kind = CHARDEV_BACKEND_KIND_BRAILLE,
.create = baum_chr_init,
.chr_write = baum_chr_write,
.chr_accept_input = baum_chr_accept_input,
.chr_free = baum_chr_free,
};
register_char_driver(&driver);
type_register_static(&char_braille_type_info);
}
type_init(register_types);
......@@ -41,9 +41,13 @@ typedef struct {
int outlen;
} MouseChardev;
#define TYPE_CHARDEV_MSMOUSE "chardev-msmouse"
#define MOUSE_CHARDEV(obj) \
OBJECT_CHECK(MouseChardev, (obj), TYPE_CHARDEV_MSMOUSE)
static void msmouse_chr_accept_input(Chardev *chr)
{
MouseChardev *mouse = (MouseChardev *)chr;
MouseChardev *mouse = MOUSE_CHARDEV(chr);
int len;
len = qemu_chr_be_can_write(chr);
......@@ -98,7 +102,7 @@ static void msmouse_queue_event(MouseChardev *mouse)
static void msmouse_input_event(DeviceState *dev, QemuConsole *src,
InputEvent *evt)
{
MouseChardev *mouse = (MouseChardev *)dev;
MouseChardev *mouse = MOUSE_CHARDEV(dev);
InputMoveEvent *move;
InputBtnEvent *btn;
......@@ -122,8 +126,8 @@ static void msmouse_input_event(DeviceState *dev, QemuConsole *src,
static void msmouse_input_sync(DeviceState *dev)
{
MouseChardev *mouse = (MouseChardev *)dev;
Chardev *chr = (Chardev *)dev;
MouseChardev *mouse = MOUSE_CHARDEV(dev);
Chardev *chr = CHARDEV(dev);
msmouse_queue_event(mouse);
msmouse_chr_accept_input(chr);
......@@ -137,7 +141,7 @@ static int msmouse_chr_write(struct Chardev *s, const uint8_t *buf, int len)
static void msmouse_chr_free(struct Chardev *chr)
{
MouseChardev *mouse = (MouseChardev *)chr;
MouseChardev *mouse = MOUSE_CHARDEV(chr);
qemu_input_handler_unregister(mouse->hs);
}
......@@ -149,42 +153,43 @@ static QemuInputHandler msmouse_handler = {
.sync = msmouse_input_sync,
};
static Chardev *qemu_chr_open_msmouse(const CharDriver *driver,
const char *id,
ChardevBackend *backend,
ChardevReturn *ret,
bool *be_opened,
Error **errp)
static void msmouse_chr_open(Chardev *chr,
ChardevBackend *backend,
bool *be_opened,
Error **errp)
{
ChardevCommon *common = backend->u.msmouse.data;
MouseChardev *mouse;
Chardev *chr;
MouseChardev *mouse = MOUSE_CHARDEV(chr);
chr = qemu_chr_alloc(driver, common, errp);
if (!chr) {
return NULL;
}
*be_opened = false;
mouse = (MouseChardev *)chr;
mouse->hs = qemu_input_handler_register((DeviceState *)mouse,
&msmouse_handler);
}
static void char_msmouse_class_init(ObjectClass *oc, void *data)
{
ChardevClass *cc = CHARDEV_CLASS(oc);
return chr;
cc->open = msmouse_chr_open;
cc->chr_write = msmouse_chr_write;
cc->chr_accept_input = msmouse_chr_accept_input;
cc->chr_free = msmouse_chr_free;
}
static const TypeInfo char_msmouse_type_info = {
.name = TYPE_CHARDEV_MSMOUSE,
.parent = TYPE_CHARDEV,
.instance_size = sizeof(MouseChardev),
.class_init = char_msmouse_class_init,
};
static void register_types(void)
{
static const CharDriver driver = {
.instance_size = sizeof(MouseChardev),
.kind = CHARDEV_BACKEND_KIND_MSMOUSE,
.create = qemu_chr_open_msmouse,
.chr_write = msmouse_chr_write,
.chr_accept_input = msmouse_chr_accept_input,
.chr_free = msmouse_chr_free,
};
register_char_driver(&driver);
type_register_static(&char_msmouse_type_info);
}
type_init(register_types);
......@@ -36,6 +36,10 @@ typedef struct {
int in_buf_used;
} TestdevChardev;
#define TYPE_CHARDEV_TESTDEV "chardev-testdev"
#define TESTDEV_CHARDEV(obj) \
OBJECT_CHECK(TestdevChardev, (obj), TYPE_CHARDEV_TESTDEV)
/* Try to interpret a whole incoming packet */
static int testdev_eat_packet(TestdevChardev *testdev)
{
......@@ -78,9 +82,9 @@ static int testdev_eat_packet(TestdevChardev *testdev)
}
/* The other end is writing some data. Store it and try to interpret */
static int testdev_write(Chardev *chr, const uint8_t *buf, int len)
static int testdev_chr_write(Chardev *chr, const uint8_t *buf, int len)
{
TestdevChardev *testdev = (TestdevChardev *)chr;
TestdevChardev *testdev = TESTDEV_CHARDEV(chr);
int tocopy, eaten, orig_len = len;
while (len) {
......@@ -103,30 +107,28 @@ static int testdev_write(Chardev *chr, const uint8_t *buf, int len)
return orig_len;
}
static Chardev *chr_testdev_init(const CharDriver *driver,
const char *id,
ChardevBackend *backend,
ChardevReturn *ret,
bool *be_opened,
Error **errp)
static void char_testdev_class_init(ObjectClass *oc, void *data)
{
TestdevChardev *testdev = g_new0(TestdevChardev, 1);;
Chardev *chr = (Chardev *)testdev;
chr->driver = driver;
ChardevClass *cc = CHARDEV_CLASS(oc);
return chr;
cc->chr_write = testdev_chr_write;
}
static const TypeInfo char_testdev_type_info = {
.name = TYPE_CHARDEV_TESTDEV,
.parent = TYPE_CHARDEV,
.instance_size = sizeof(TestdevChardev),
.class_init = char_testdev_class_init,
};
static void register_types(void)
{
static const CharDriver driver = {
.instance_size = sizeof(TestdevChardev),
.kind = CHARDEV_BACKEND_KIND_TESTDEV,
.create = chr_testdev_init,
.chr_write = testdev_write,
};
register_char_driver(&driver);
type_register_static(&char_testdev_type_info);
}
type_init(register_types);
......@@ -1725,18 +1725,35 @@ static void gdb_sigterm_handler(int signal)
}
#endif
static void gdb_monitor_open(Chardev *chr, ChardevBackend *backend,
bool *be_opened, Error **errp)
{
*be_opened = false;
}
static void char_gdb_class_init(ObjectClass *oc, void *data)
{
ChardevClass *cc = CHARDEV_CLASS(oc);
cc->internal = true;
cc->open = gdb_monitor_open;
cc->chr_write = gdb_monitor_write;
}
#define TYPE_CHARDEV_GDB "chardev-gdb"
static const TypeInfo char_gdb_type_info = {
.name = TYPE_CHARDEV_GDB,
.parent = TYPE_CHARDEV,
.class_init = char_gdb_class_init,
};
int gdbserver_start(const char *device)
{
GDBState *s;
char gdbstub_device_name[128];
Chardev *chr = NULL;
Chardev *mon_chr;
ChardevCommon common = { 0 };
static const CharDriver driver = {
.instance_size = sizeof(Chardev),
.kind = -1,
.chr_write = gdb_monitor_write,
};
if (!first_cpu) {
error_report("gdbstub: meaningless to attach gdb to a "
......@@ -1775,7 +1792,8 @@ int gdbserver_start(const char *device)
qemu_add_vm_change_state_handler(gdb_vm_state_change, NULL);
/* Initialize a monitor terminal for gdb */
mon_chr = qemu_chr_alloc(&driver, &common, &error_abort);
mon_chr = qemu_chardev_new(NULL, TYPE_CHARDEV_GDB,
NULL, &error_abort);
monitor_init(mon_chr, 0);
} else {
if (qemu_chr_fe_get_driver(&s->chr)) {
......@@ -1798,4 +1816,11 @@ int gdbserver_start(const char *device)
return 0;
}
static void register_types(void)
{
type_register_static(&char_gdb_type_info);
}
type_init(register_types);
#endif
......@@ -55,6 +55,9 @@ struct csrhci_s {
struct HCIInfo *hci;
};
#define TYPE_CHARDEV_HCI "chardev-hci"
#define HCI_CHARDEV(obj) OBJECT_CHECK(struct csrhci_s, (obj), TYPE_CHARDEV_HCI)
/* H4+ packet types */
enum {
H4_CMD_PKT = 1,
......@@ -462,23 +465,12 @@ qemu_irq *csrhci_pins_get(Chardev *chr)
return s->pins;
}
Chardev *uart_hci_init(void)
static void csrhci_open(Chardev *chr,
ChardevBackend *backend,
bool *be_opened,
Error **errp)
{
static const CharDriver hci_driver = {
.instance_size = sizeof(struct csrhci_s),
.kind = -1,
.chr_write = csrhci_write,
.chr_ioctl = csrhci_ioctl,
};
Error *err = NULL;
ChardevCommon common = { 0, };
Chardev *chr = qemu_chr_alloc(&hci_driver, &common, &err);
struct csrhci_s *s = (struct csrhci_s *)chr;
if (err) {
error_report_err(err);
return NULL;
}
struct csrhci_s *s = HCI_CHARDEV(chr);
s->hci = qemu_next_hci();
s->hci->opaque = s;
......@@ -488,6 +480,35 @@ Chardev *uart_hci_init(void)
s->out_tm = timer_new_ns(QEMU_CLOCK_VIRTUAL, csrhci_out_tick, s);
s->pins = qemu_allocate_irqs(csrhci_pins, s, __csrhci_pins);
csrhci_reset(s);
*be_opened = false;
}
static void char_hci_class_init(ObjectClass *oc, void *data)
{
ChardevClass *cc = CHARDEV_CLASS(oc);
cc->internal = true;
cc->open = csrhci_open;
cc->chr_write = csrhci_write;
cc->chr_ioctl = csrhci_ioctl;
}
static const TypeInfo char_hci_type_info = {
.name = TYPE_CHARDEV_HCI,
.parent = TYPE_CHARDEV,
.instance_size = sizeof(struct csrhci_s),
.class_init = char_hci_class_init,
};
return chr;
Chardev *uart_hci_init(void)
{
return qemu_chardev_new(NULL, TYPE_CHARDEV_HCI,
NULL, &error_abort);
}
static void register_types(void)
{
type_register_static(&char_hci_type_info);
}
type_init(register_types);
......@@ -10,6 +10,7 @@
#include "qapi/qmp/qstring.h"
#include "qemu/main-loop.h"
#include "qemu/bitmap.h"
#include "qom/object.h"
/* character device */
......@@ -90,7 +91,8 @@ typedef struct CharBackend {
typedef struct CharDriver CharDriver;
struct Chardev {
const CharDriver *driver;
Object parent_obj;
QemuMutex chr_write_lock;
CharBackend *be;
char *label;
......@@ -102,18 +104,6 @@ struct Chardev {
QTAILQ_ENTRY(Chardev) next;
};
/**
* qemu_chr_alloc:
* @backend: the common backend config
* @errp: pointer to a NULL-initialized error object
*
* Allocate and initialize a new Chardev.
*
* Returns: a newly allocated Chardev, or NULL on error.
*/
Chardev *qemu_chr_alloc(const CharDriver *driver,
ChardevCommon *backend, Error **errp);
/**
* @qemu_chr_new_from_opts:
*
......@@ -455,54 +445,73 @@ void qemu_chr_fe_accept_input(CharBackend *be);
int qemu_chr_add_client(Chardev *s, int fd);
Chardev *qemu_chr_find(const char *name);
/**
* @qemu_chr_get_kind:
*
* Returns the kind of char backend, or -1 if unspecified.
*/
ChardevBackendKind qemu_chr_get_kind(const Chardev *chr);
static inline bool qemu_chr_is_ringbuf(const Chardev *chr)
{
return qemu_chr_get_kind(chr) == CHARDEV_BACKEND_KIND_RINGBUF ||
qemu_chr_get_kind(chr) == CHARDEV_BACKEND_KIND_MEMORY;
}
bool qemu_chr_has_feature(Chardev *chr,
CharDriverFeature feature);
void qemu_chr_set_feature(Chardev *chr,
CharDriverFeature feature);
QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename);
#define TYPE_CHARDEV "chardev"
#define CHARDEV(obj) OBJECT_CHECK(Chardev, (obj), TYPE_CHARDEV)
#define CHARDEV_CLASS(klass) \
OBJECT_CLASS_CHECK(ChardevClass, (klass), TYPE_CHARDEV)
#define CHARDEV_GET_CLASS(obj) \
OBJECT_GET_CLASS(ChardevClass, (obj), TYPE_CHARDEV)
#define TYPE_CHARDEV_NULL "chardev-null"
#define TYPE_CHARDEV_MUX "chardev-mux"
#define TYPE_CHARDEV_RINGBUF "chardev-ringbuf"
#define TYPE_CHARDEV_PTY "chardev-pty"
#define TYPE_CHARDEV_CONSOLE "chardev-console"
#define TYPE_CHARDEV_STDIO "chardev-stdio"
#define TYPE_CHARDEV_PIPE "chardev-pipe"
#define TYPE_CHARDEV_MEMORY "chardev-memory"
#define TYPE_CHARDEV_PARALLEL "chardev-parallel"
#define TYPE_CHARDEV_FILE "chardev-file"
#define TYPE_CHARDEV_SERIAL "chardev-serial"
#define TYPE_CHARDEV_SOCKET "chardev-socket"
#define TYPE_CHARDEV_UDP "chardev-udp"
#define CHARDEV_IS_MUX(chr) \
object_dynamic_cast(OBJECT(chr), TYPE_CHARDEV_MUX)
#define CHARDEV_IS_RINGBUF(chr) \
object_dynamic_cast(OBJECT(chr), TYPE_CHARDEV_RINGBUF)
#define CHARDEV_IS_PTY(chr) \
object_dynamic_cast(OBJECT(chr), TYPE_CHARDEV_PTY)
typedef struct ChardevClass {
ObjectClass parent_class;
bool internal; /* TODO: eventually use TYPE_USER_CREATABLE */
void (*open)(Chardev *chr, ChardevBackend *backend,
bool *be_opened, Error **errp);
int (*chr_write)(Chardev *s, const uint8_t *buf, int len);
int (*chr_sync_read)(Chardev *s, const uint8_t *buf, int len);
GSource *(*chr_add_watch)(Chardev *s, GIOCondition cond);
void (*chr_update_read_handler)(Chardev *s, GMainContext *context);
int (*chr_ioctl)(Chardev *s, int cmd, void *arg);
int (*get_msgfds)(Chardev *s, int* fds, int num);
int (*set_msgfds)(Chardev *s, int *fds, int num);
int (*chr_add_client)(Chardev *chr, int fd);
int (*chr_wait_connected)(Chardev *chr, Error **errp);
void (*chr_free)(Chardev *chr);
void (*chr_disconnect)(Chardev *chr);
void (*chr_accept_input)(Chardev *chr);
void (*chr_set_echo)(Chardev *chr, bool echo);
void (*chr_set_fe_open)(Chardev *chr, int fe_open);
} ChardevClass;
struct CharDriver {
ChardevBackendKind kind;
const char *alias;
void (*parse)(QemuOpts *opts, ChardevBackend *backend, Error **errp);
Chardev *(*create)(const CharDriver *driver,
const char *id,
ChardevBackend *backend,
ChardevReturn *ret, bool *be_opened,
Error **errp);
size_t instance_size;
int (*chr_write)(struct Chardev *s, const uint8_t *buf, int len);
int (*chr_sync_read)(struct Chardev *s,
const uint8_t *buf, int len);
GSource *(*chr_add_watch)(struct Chardev *s, GIOCondition cond);
void (*chr_update_read_handler)(struct Chardev *s,
GMainContext *context);
int (*chr_ioctl)(struct Chardev *s, int cmd, void *arg);
int (*get_msgfds)(struct Chardev *s, int* fds, int num);
int (*set_msgfds)(struct Chardev *s, int *fds, int num);
int (*chr_add_client)(struct Chardev *chr, int fd);
int (*chr_wait_connected)(struct Chardev *chr, Error **errp);
void (*chr_free)(struct Chardev *chr);
void (*chr_disconnect)(struct Chardev *chr);
void (*chr_accept_input)(struct Chardev *chr);
void (*chr_set_echo)(struct Chardev *chr, bool echo);
void (*chr_set_fe_open)(struct Chardev *chr, int fe_open);
};
Chardev *qemu_chardev_new(const char *id, const char *typename,
ChardevBackend *backend, Error **errp);
void register_char_driver(const CharDriver *driver);
extern int term_escape_char;
......
......@@ -383,6 +383,8 @@ void graphic_hw_invalidate(QemuConsole *con);
void graphic_hw_text_update(QemuConsole *con, console_ch_t *chardata);
void graphic_hw_gl_block(QemuConsole *con, bool block);
void qemu_console_early_init(void);
QemuConsole *qemu_console_lookup_by_index(unsigned int index);
QemuConsole *qemu_console_lookup_by_device(DeviceState *dev, uint32_t head);
QemuConsole *qemu_console_lookup_by_device_name(const char *device_id,
......
......@@ -3196,7 +3196,7 @@ static void ringbuf_completion(ReadLineState *rs, const char *str)
if (!strncmp(chr_info->label, str, len)) {
Chardev *chr = qemu_chr_find(chr_info->label);
if (chr && qemu_chr_is_ringbuf(chr)) {
if (chr && CHARDEV_IS_RINGBUF(chr)) {
readline_add_completion(rs, chr_info->label);
}
}
......
This diff is collapsed.
......@@ -18,6 +18,12 @@ typedef struct SpiceChardev {
QLIST_ENTRY(SpiceChardev) next;
} SpiceChardev;
#define TYPE_CHARDEV_SPICE "chardev-spice"
#define TYPE_CHARDEV_SPICEVMC "chardev-spicevmc"
#define TYPE_CHARDEV_SPICEPORT "chardev-spiceport"
#define SPICE_CHARDEV(obj) OBJECT_CHECK(SpiceChardev, (obj), TYPE_CHARDEV_SPICE)
typedef struct SpiceCharSource {
GSource source;
SpiceChardev *scd;
......@@ -29,7 +35,7 @@ static QLIST_HEAD(, SpiceChardev) spice_chars =
static int vmc_write(SpiceCharDeviceInstance *sin, const uint8_t *buf, int len)
{
SpiceChardev *scd = container_of(sin, SpiceChardev, sin);
Chardev *chr = (Chardev *)scd;
Chardev *chr = CHARDEV(scd);
ssize_t out = 0;
ssize_t last_out;
uint8_t* p = (uint8_t*)buf;
......@@ -73,7 +79,7 @@ static int vmc_read(SpiceCharDeviceInstance *sin, uint8_t *buf, int len)
static void vmc_event(SpiceCharDeviceInstance *sin, uint8_t event)
{
SpiceChardev *scd = container_of(sin, SpiceChardev, sin);
Chardev *chr = (Chardev *)scd;
Chardev *chr = CHARDEV(scd);
int chr_event;
switch (event) {
......@@ -92,7 +98,7 @@ static void vmc_event(SpiceCharDeviceInstance *sin, uint8_t event)
static void vmc_state(SpiceCharDeviceInstance *sin, int connected)
{
SpiceChardev *scd = container_of(sin, SpiceChardev, sin);
Chardev *chr = (Chardev *)scd;
Chardev *chr = CHARDEV(scd);
if ((chr->be_open && connected) ||
(!chr->be_open && !connected)) {
......@@ -173,7 +179,7 @@ static GSourceFuncs SpiceCharSourceFuncs = {
static GSource *spice_chr_add_watch(Chardev *chr, GIOCondition cond)
{
SpiceChardev *scd = (SpiceChardev *)chr;
SpiceChardev *scd = SPICE_CHARDEV(chr);
SpiceCharSource *src;
assert(cond & G_IO_OUT);
......@@ -187,7 +193,7 @@ static GSource *spice_chr_add_watch(Chardev *chr, GIOCondition cond)
static int spice_chr_write(Chardev *chr, const uint8_t *buf, int len)
{
SpiceChardev *s = (SpiceChardev *)chr;
SpiceChardev *s = SPICE_CHARDEV(chr);
int read_bytes;
assert(s->datalen == 0);
......@@ -206,7 +212,7 @@ static int spice_chr_write(Chardev *chr, const uint8_t *buf, int len)
static void spice_chr_free(struct Chardev *chr)
{
SpiceChardev *s = (SpiceChardev *)chr;
SpiceChardev *s = SPICE_CHARDEV(chr);
vmc_unregister_interface(s);
QLIST_REMOVE(s, next);
......@@ -219,7 +225,7 @@ static void spice_chr_free(struct Chardev *chr)
static void spice_vmc_set_fe_open(struct Chardev *chr, int fe_open)
{
SpiceChardev *s = (SpiceChardev *)chr;
SpiceChardev *s = SPICE_CHARDEV(chr);
if (fe_open) {
vmc_register_interface(s);
} else {
......@@ -230,7 +236,7 @@ static void spice_vmc_set_fe_open(struct Chardev *chr, int fe_open)
static void spice_port_set_fe_open(struct Chardev *chr, int fe_open)
{
#if SPICE_SERVER_VERSION >= 0x000c02
SpiceChardev *s = (SpiceChardev *)chr;
SpiceChardev *s = SPICE_CHARDEV(chr);
if (fe_open) {
spice_server_port_event(&s->sin, SPICE_PORT_EVENT_OPENED);
......@@ -242,43 +248,29 @@ static void spice_port_set_fe_open(struct Chardev *chr, int fe_open)
static void spice_chr_accept_input(struct Chardev *chr)
{
SpiceChardev *s = (SpiceChardev *)chr;
SpiceChardev *s = SPICE_CHARDEV(chr);
spice_server_char_device_wakeup(&s->sin);
}
static Chardev *chr_open(const CharDriver *driver,
const char *subtype,
ChardevCommon *backend,
Error **errp)
static void chr_open(Chardev *chr, const char *subtype)
{
Chardev *chr;
SpiceChardev *s;
SpiceChardev *s = SPICE_CHARDEV(chr);
chr = qemu_chr_alloc(driver, backend, errp);
if (!chr) {
return NULL;
}
s = (SpiceChardev *)chr;
s->active = false;
s->sin.subtype = g_strdup(subtype);
QLIST_INSERT_HEAD(&spice_chars, s, next);
return chr;
}