aboutsummaryrefslogtreecommitdiff
path: root/backends/baum.c
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2016-10-21 23:44:44 +0300
committerPaolo Bonzini <pbonzini@redhat.com>2017-01-27 18:07:59 +0100
commit41ac54b253f41df924c350ef63564df8e1d8ad88 (patch)
treea6d8fdcb913b558c4f5ecc698bd82ae1a195705c /backends/baum.c
parent5ebd67030c4e4bc702d07a3e10c909be4520f170 (diff)
char: allocate CharDriverState as a single object
Use a single allocation for CharDriverState, this avoids extra allocations & pointers, and is a step towards more object-oriented CharDriver. Gtk console is a bit peculiar, gd_vc_chr_set_echo() used to have a temporary VirtualConsole to save the echo bit. Instead now, we consider whether vcd->console is set or not, and restore the echo bit saved in VCDriverState when calling gd_vc_vte_init(). The casts added are temporary, they are replaced with QOM type-safe macros in a later patch in this series. 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 'backends/baum.c')
-rw-r--r--backends/baum.c23
1 files changed, 10 insertions, 13 deletions
diff --git a/backends/baum.c b/backends/baum.c
index 109469e8f7..4b48cf02b9 100644
--- a/backends/baum.c
+++ b/backends/baum.c
@@ -85,7 +85,7 @@
#define BUF_SIZE 256
typedef struct {
- CharDriverState *chr;
+ CharDriverState parent;
brlapi_handle_t *brlapi;
int brlapi_fd;
@@ -255,7 +255,7 @@ static int baum_deferred_init(BaumDriverState *baum)
/* The serial port can receive more of our data */
static void baum_accept_input(struct CharDriverState *chr)
{
- BaumDriverState *baum = chr->opaque;
+ BaumDriverState *baum = (BaumDriverState *)chr;
int room, first;
if (!baum->out_buf_used)
@@ -281,22 +281,23 @@ static void baum_accept_input(struct CharDriverState *chr)
/* We want to send a packet */
static void baum_write_packet(BaumDriverState *baum, const uint8_t *buf, int len)
{
+ CharDriverState *chr = (CharDriverState *)baum;
uint8_t io_buf[1 + 2 * len], *cur = io_buf;
int room;
*cur++ = ESC;
while (len--)
if ((*cur++ = *buf++) == ESC)
*cur++ = ESC;
- room = qemu_chr_be_can_write(baum->chr);
+ room = qemu_chr_be_can_write(chr);
len = cur - io_buf;
if (len <= room) {
/* Fits */
- qemu_chr_be_write(baum->chr, io_buf, len);
+ qemu_chr_be_write(chr, io_buf, len);
} else {
int first;
uint8_t out;
/* Can't fit all, send what can be, and store the rest. */
- qemu_chr_be_write(baum->chr, io_buf, room);
+ qemu_chr_be_write(chr, io_buf, room);
len -= room;
cur = io_buf + room;
if (len > BUF_SIZE - baum->out_buf_used) {
@@ -471,7 +472,7 @@ static int baum_eat_packet(BaumDriverState *baum, const uint8_t *buf, int len)
/* The other end is writing some data. Store it and try to interpret */
static int baum_write(CharDriverState *chr, const uint8_t *buf, int len)
{
- BaumDriverState *baum = chr->opaque;
+ BaumDriverState *baum = (BaumDriverState *)chr;
int tocopy, cur, eaten, orig_len = len;
if (!len)
@@ -612,14 +613,13 @@ static void baum_chr_read(void *opaque)
static void baum_free(struct CharDriverState *chr)
{
- BaumDriverState *baum = chr->opaque;
+ BaumDriverState *baum = (BaumDriverState *)chr;
timer_free(baum->cellCount_timer);
if (baum->brlapi) {
brlapi__closeConnection(baum->brlapi);
g_free(baum->brlapi);
}
- g_free(baum);
}
static CharDriverState *chr_baum_init(const CharDriver *driver,
@@ -638,10 +638,7 @@ static CharDriverState *chr_baum_init(const CharDriver *driver,
if (!chr) {
return NULL;
}
- baum = g_malloc0(sizeof(BaumDriverState));
- baum->chr = chr;
-
- chr->opaque = baum;
+ baum = (BaumDriverState *)chr;
handle = g_malloc0(brlapi_getHandleSize());
baum->brlapi = handle;
@@ -663,13 +660,13 @@ static CharDriverState *chr_baum_init(const CharDriver *driver,
fail_handle:
g_free(handle);
g_free(chr);
- g_free(baum);
return NULL;
}
static void register_types(void)
{
static const CharDriver driver = {
+ .instance_size = sizeof(BaumDriverState),
.kind = CHARDEV_BACKEND_KIND_BRAILLE,
.create = chr_baum_init,
.chr_write = baum_write,