From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:57828) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TkaNA-0004v2-NM for qemu-devel@nongnu.org; Mon, 17 Dec 2012 08:04:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TkaN8-0004E5-Cx for qemu-devel@nongnu.org; Mon, 17 Dec 2012 08:04:44 -0500 Received: from mx1.redhat.com ([209.132.183.28]:18605) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TkaN8-0004De-41 for qemu-devel@nongnu.org; Mon, 17 Dec 2012 08:04:42 -0500 From: Gerd Hoffmann Date: Mon, 17 Dec 2012 14:04:35 +0100 Message-Id: <1355749479-25470-5-git-send-email-kraxel@redhat.com> In-Reply-To: <1355749479-25470-1-git-send-email-kraxel@redhat.com> References: <1355749479-25470-1-git-send-email-kraxel@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH 4/8] spice-qemu-char: factor out CharDriverState creation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Gerd Hoffmann From: Marc-Andr=C3=A9 Lureau Make the CharDriverState creation code reusable by spicevmc port. Signed-off-by: Gerd Hoffmann --- spice-qemu-char.c | 37 +++++++++++++++++++++++-------------- 1 files changed, 23 insertions(+), 14 deletions(-) diff --git a/spice-qemu-char.c b/spice-qemu-char.c index 665efd3..b86e83a 100644 --- a/spice-qemu-char.c +++ b/spice-qemu-char.c @@ -186,13 +186,32 @@ static void print_allowed_subtypes(void) fprintf(stderr, "\n"); } =20 -CharDriverState *qemu_chr_open_spice(QemuOpts *opts) +static CharDriverState *chr_open(QemuOpts *opts, const char *subtype) { CharDriverState *chr; SpiceCharDriver *s; - const char* name =3D qemu_opt_get(opts, "name"); uint32_t debug =3D qemu_opt_get_number(opts, "debug", 0); - const char** psubtype =3D spice_server_char_device_recognized_subtyp= es(); + + chr =3D g_malloc0(sizeof(CharDriverState)); + s =3D g_malloc0(sizeof(SpiceCharDriver)); + s->chr =3D chr; + s->debug =3D debug; + s->active =3D false; + s->sin.subtype =3D subtype; + chr->opaque =3D s; + chr->chr_write =3D spice_chr_write; + chr->chr_close =3D spice_chr_close; + chr->chr_guest_open =3D spice_chr_guest_open; + chr->chr_guest_close =3D spice_chr_guest_close; + + return chr; +} + +CharDriverState *qemu_chr_open_spice(QemuOpts *opts) +{ + CharDriverState *chr; + const char *name =3D qemu_opt_get(opts, "name"); + const char **psubtype =3D spice_server_char_device_recognized_subtyp= es(); const char *subtype =3D NULL; =20 if (name =3D=3D NULL) { @@ -212,17 +231,7 @@ CharDriverState *qemu_chr_open_spice(QemuOpts *opts) return NULL; } =20 - chr =3D g_malloc0(sizeof(CharDriverState)); - s =3D g_malloc0(sizeof(SpiceCharDriver)); - s->chr =3D chr; - s->debug =3D debug; - s->active =3D false; - s->sin.subtype =3D subtype; - chr->opaque =3D s; - chr->chr_write =3D spice_chr_write; - chr->chr_close =3D spice_chr_close; - chr->chr_guest_open =3D spice_chr_guest_open; - chr->chr_guest_close =3D spice_chr_guest_close; + chr =3D chr_open(opts, subtype); =20 #if SPICE_SERVER_VERSION < 0x000901 /* See comment in vmc_state() */ --=20 1.7.1