From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50734) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V4jLk-0008Nj-7R for qemu-devel@nongnu.org; Wed, 31 Jul 2013 23:14:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V4ijn-0002hj-3S for qemu-devel@nongnu.org; Wed, 31 Jul 2013 22:35:39 -0400 Received: from cantor2.suse.de ([195.135.220.15]:33334 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V4ijm-0002hJ-G3 for qemu-devel@nongnu.org; Wed, 31 Jul 2013 22:35:34 -0400 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Thu, 1 Aug 2013 04:35:22 +0200 Message-Id: <1375324524-3353-2-git-send-email-afaerber@suse.de> In-Reply-To: <1375324524-3353-1-git-send-email-afaerber@suse.de> References: <1375324524-3353-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH for-next v2 1/2] virtio-console: QOM cast cleanup for VirtConsole List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Amit Shah , Anthony Liguori , =?UTF-8?q?Andreas=20F=C3=A4rber?= Introduce type constant, cast macro and rename parent field. Signed-off-by: Andreas F=C3=A4rber --- hw/char/virtio-console.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/hw/char/virtio-console.c b/hw/char/virtio-console.c index 2e00ad2..73e18f2 100644 --- a/hw/char/virtio-console.c +++ b/hw/char/virtio-console.c @@ -15,8 +15,13 @@ #include "trace.h" #include "hw/virtio/virtio-serial.h" =20 +#define TYPE_VIRTIO_CONSOLE "virtconsole" +#define VIRTIO_CONSOLE(obj) \ + OBJECT_CHECK(VirtConsole, (obj), TYPE_VIRTIO_CONSOLE) + typedef struct VirtConsole { - VirtIOSerialPort port; + VirtIOSerialPort parent_obj; + CharDriverState *chr; guint watch; } VirtConsole; @@ -31,7 +36,7 @@ static gboolean chr_write_unblocked(GIOChannel *chan, G= IOCondition cond, VirtConsole *vcon =3D opaque; =20 vcon->watch =3D 0; - virtio_serial_throttle_port(&vcon->port, false); + virtio_serial_throttle_port(VIRTIO_SERIAL_PORT(vcon), false); return FALSE; } =20 @@ -39,7 +44,7 @@ static gboolean chr_write_unblocked(GIOChannel *chan, G= IOCondition cond, static ssize_t flush_buf(VirtIOSerialPort *port, const uint8_t *buf, ssize_t len) { - VirtConsole *vcon =3D DO_UPCAST(VirtConsole, port, port); + VirtConsole *vcon =3D VIRTIO_CONSOLE(port); ssize_t ret; =20 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 = */ static void set_guest_connected(VirtIOSerialPort *port, int guest_connec= ted) { - VirtConsole *vcon =3D DO_UPCAST(VirtConsole, port, port); + VirtConsole *vcon =3D VIRTIO_CONSOLE(port); =20 if (!vcon->chr) { return; @@ -88,40 +93,42 @@ static int chr_can_read(void *opaque) { VirtConsole *vcon =3D opaque; =20 - return virtio_serial_guest_ready(&vcon->port); + return virtio_serial_guest_ready(VIRTIO_SERIAL_PORT(vcon)); } =20 /* Send data from a char device over to the guest */ static void chr_read(void *opaque, const uint8_t *buf, int size) { VirtConsole *vcon =3D opaque; + VirtIOSerialPort *port =3D VIRTIO_SERIAL_PORT(vcon); =20 - trace_virtio_console_chr_read(vcon->port.id, size); - virtio_serial_write(&vcon->port, buf, size); + trace_virtio_console_chr_read(port->id, size); + virtio_serial_write(port, buf, size); } =20 static void chr_event(void *opaque, int event) { VirtConsole *vcon =3D opaque; + VirtIOSerialPort *port =3D VIRTIO_SERIAL_PORT(vcon); =20 - trace_virtio_console_chr_event(vcon->port.id, event); + trace_virtio_console_chr_event(port->id, event); switch (event) { case CHR_EVENT_OPENED: - virtio_serial_open(&vcon->port); + virtio_serial_open(port); break; case CHR_EVENT_CLOSED: if (vcon->watch) { g_source_remove(vcon->watch); vcon->watch =3D 0; } - virtio_serial_close(&vcon->port); + virtio_serial_close(port); break; } } =20 static int virtconsole_initfn(VirtIOSerialPort *port) { - VirtConsole *vcon =3D DO_UPCAST(VirtConsole, port, port); + VirtConsole *vcon =3D VIRTIO_CONSOLE(port); VirtIOSerialPortClass *k =3D VIRTIO_SERIAL_PORT_GET_CLASS(port); =20 if (port->id =3D=3D 0 && !k->is_console) { @@ -140,7 +147,7 @@ static int virtconsole_initfn(VirtIOSerialPort *port) =20 static int virtconsole_exitfn(VirtIOSerialPort *port) { - VirtConsole *vcon =3D DO_UPCAST(VirtConsole, port, port); + VirtConsole *vcon =3D VIRTIO_CONSOLE(port); =20 if (vcon->watch) { g_source_remove(vcon->watch); @@ -168,7 +175,7 @@ static void virtconsole_class_init(ObjectClass *klass= , void *data) } =20 static const TypeInfo virtconsole_info =3D { - .name =3D "virtconsole", + .name =3D TYPE_VIRTIO_CONSOLE, .parent =3D TYPE_VIRTIO_SERIAL_PORT, .instance_size =3D sizeof(VirtConsole), .class_init =3D virtconsole_class_init, --=20 1.8.1.4