virtio-console: QOM cast cleanup for VirtConsole
Introduce type constant, cast macro and rename parent field. Signed-off-by: Andreas Färber <afaerber@suse.de>
This commit is contained in:
parent
6e8114a065
commit
0399a3819b
@ -15,8 +15,13 @@
|
|||||||
#include "trace.h"
|
#include "trace.h"
|
||||||
#include "hw/virtio/virtio-serial.h"
|
#include "hw/virtio/virtio-serial.h"
|
||||||
|
|
||||||
|
#define TYPE_VIRTIO_CONSOLE "virtconsole"
|
||||||
|
#define VIRTIO_CONSOLE(obj) \
|
||||||
|
OBJECT_CHECK(VirtConsole, (obj), TYPE_VIRTIO_CONSOLE)
|
||||||
|
|
||||||
typedef struct VirtConsole {
|
typedef struct VirtConsole {
|
||||||
VirtIOSerialPort port;
|
VirtIOSerialPort parent_obj;
|
||||||
|
|
||||||
CharDriverState *chr;
|
CharDriverState *chr;
|
||||||
guint watch;
|
guint watch;
|
||||||
} VirtConsole;
|
} VirtConsole;
|
||||||
@ -31,7 +36,7 @@ static gboolean chr_write_unblocked(GIOChannel *chan, GIOCondition cond,
|
|||||||
VirtConsole *vcon = opaque;
|
VirtConsole *vcon = opaque;
|
||||||
|
|
||||||
vcon->watch = 0;
|
vcon->watch = 0;
|
||||||
virtio_serial_throttle_port(&vcon->port, false);
|
virtio_serial_throttle_port(VIRTIO_SERIAL_PORT(vcon), false);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,7 +44,7 @@ static gboolean chr_write_unblocked(GIOChannel *chan, GIOCondition cond,
|
|||||||
static ssize_t flush_buf(VirtIOSerialPort *port,
|
static ssize_t flush_buf(VirtIOSerialPort *port,
|
||||||
const uint8_t *buf, ssize_t len)
|
const uint8_t *buf, ssize_t len)
|
||||||
{
|
{
|
||||||
VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port);
|
VirtConsole *vcon = VIRTIO_CONSOLE(port);
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
|
|
||||||
if (!vcon->chr) {
|
if (!vcon->chr) {
|
||||||
@ -75,7 +80,7 @@ static ssize_t flush_buf(VirtIOSerialPort *port,
|
|||||||
/* Callback function that's called when the guest opens/closes the port */
|
/* Callback function that's called when the guest opens/closes the port */
|
||||||
static void set_guest_connected(VirtIOSerialPort *port, int guest_connected)
|
static void set_guest_connected(VirtIOSerialPort *port, int guest_connected)
|
||||||
{
|
{
|
||||||
VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port);
|
VirtConsole *vcon = VIRTIO_CONSOLE(port);
|
||||||
|
|
||||||
if (!vcon->chr) {
|
if (!vcon->chr) {
|
||||||
return;
|
return;
|
||||||
@ -88,40 +93,42 @@ static int chr_can_read(void *opaque)
|
|||||||
{
|
{
|
||||||
VirtConsole *vcon = opaque;
|
VirtConsole *vcon = opaque;
|
||||||
|
|
||||||
return virtio_serial_guest_ready(&vcon->port);
|
return virtio_serial_guest_ready(VIRTIO_SERIAL_PORT(vcon));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Send data from a char device over to the guest */
|
/* Send data from a char device over to the guest */
|
||||||
static void chr_read(void *opaque, const uint8_t *buf, int size)
|
static void chr_read(void *opaque, const uint8_t *buf, int size)
|
||||||
{
|
{
|
||||||
VirtConsole *vcon = opaque;
|
VirtConsole *vcon = opaque;
|
||||||
|
VirtIOSerialPort *port = VIRTIO_SERIAL_PORT(vcon);
|
||||||
|
|
||||||
trace_virtio_console_chr_read(vcon->port.id, size);
|
trace_virtio_console_chr_read(port->id, size);
|
||||||
virtio_serial_write(&vcon->port, buf, size);
|
virtio_serial_write(port, buf, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void chr_event(void *opaque, int event)
|
static void chr_event(void *opaque, int event)
|
||||||
{
|
{
|
||||||
VirtConsole *vcon = opaque;
|
VirtConsole *vcon = opaque;
|
||||||
|
VirtIOSerialPort *port = VIRTIO_SERIAL_PORT(vcon);
|
||||||
|
|
||||||
trace_virtio_console_chr_event(vcon->port.id, event);
|
trace_virtio_console_chr_event(port->id, event);
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case CHR_EVENT_OPENED:
|
case CHR_EVENT_OPENED:
|
||||||
virtio_serial_open(&vcon->port);
|
virtio_serial_open(port);
|
||||||
break;
|
break;
|
||||||
case CHR_EVENT_CLOSED:
|
case CHR_EVENT_CLOSED:
|
||||||
if (vcon->watch) {
|
if (vcon->watch) {
|
||||||
g_source_remove(vcon->watch);
|
g_source_remove(vcon->watch);
|
||||||
vcon->watch = 0;
|
vcon->watch = 0;
|
||||||
}
|
}
|
||||||
virtio_serial_close(&vcon->port);
|
virtio_serial_close(port);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int virtconsole_initfn(VirtIOSerialPort *port)
|
static int virtconsole_initfn(VirtIOSerialPort *port)
|
||||||
{
|
{
|
||||||
VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port);
|
VirtConsole *vcon = VIRTIO_CONSOLE(port);
|
||||||
VirtIOSerialPortClass *k = VIRTIO_SERIAL_PORT_GET_CLASS(port);
|
VirtIOSerialPortClass *k = VIRTIO_SERIAL_PORT_GET_CLASS(port);
|
||||||
|
|
||||||
if (port->id == 0 && !k->is_console) {
|
if (port->id == 0 && !k->is_console) {
|
||||||
@ -140,7 +147,7 @@ static int virtconsole_initfn(VirtIOSerialPort *port)
|
|||||||
|
|
||||||
static int virtconsole_exitfn(VirtIOSerialPort *port)
|
static int virtconsole_exitfn(VirtIOSerialPort *port)
|
||||||
{
|
{
|
||||||
VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port);
|
VirtConsole *vcon = VIRTIO_CONSOLE(port);
|
||||||
|
|
||||||
if (vcon->watch) {
|
if (vcon->watch) {
|
||||||
g_source_remove(vcon->watch);
|
g_source_remove(vcon->watch);
|
||||||
@ -168,7 +175,7 @@ static void virtconsole_class_init(ObjectClass *klass, void *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const TypeInfo virtconsole_info = {
|
static const TypeInfo virtconsole_info = {
|
||||||
.name = "virtconsole",
|
.name = TYPE_VIRTIO_CONSOLE,
|
||||||
.parent = TYPE_VIRTIO_SERIAL_PORT,
|
.parent = TYPE_VIRTIO_SERIAL_PORT,
|
||||||
.instance_size = sizeof(VirtConsole),
|
.instance_size = sizeof(VirtConsole),
|
||||||
.class_init = virtconsole_class_init,
|
.class_init = virtconsole_class_init,
|
||||||
|
Loading…
Reference in New Issue
Block a user