From patchwork Fri Nov 30 13:25:44 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 202955 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 5E4632C008F for ; Sat, 1 Dec 2012 00:27:23 +1100 (EST) Received: from localhost ([::1]:52572 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TeQcj-0004O3-Gv for incoming@patchwork.ozlabs.org; Fri, 30 Nov 2012 08:27:21 -0500 Received: from eggs.gnu.org ([208.118.235.92]:53314) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TeQcN-0003b5-Kt for qemu-devel@nongnu.org; Fri, 30 Nov 2012 08:27:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TeQcJ-0002Ka-M5 for qemu-devel@nongnu.org; Fri, 30 Nov 2012 08:26:59 -0500 Received: from mail-da0-f45.google.com ([209.85.210.45]:40597) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TeQcJ-0002KW-FS for qemu-devel@nongnu.org; Fri, 30 Nov 2012 08:26:55 -0500 Received: by mail-da0-f45.google.com with SMTP id w4so214061dam.4 for ; Fri, 30 Nov 2012 05:26:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=o5NFFGEiZXGYO/7Hmv+32kIA6qlEFXwOzrWE7/1S/vg=; b=gRMsRNN8RMzD3gv71GUsjjkMmlIX2vLqnu/vrm1lQQAeO9XAXPAMYgiT04E0E9htmB YCtm9iiXS/F7va5Y8sZCh++MN8i+Z8oTWk2BSZBUU9BJdSV3e6BkSlb0SSzZlTdSlm2s I7GuUAX03A39Tuiut5PdOvLiVqrz+WXglBGPEnzaBESb9jeE+Vx2Lz+u9PEqq9j+4/4q jtD1OQTjVY0Ox5NpkFcCDfQOGlS71jS5Q3huN9vHaL8vTUW/7w6xRcUJVDv8FB5s5zMe gqBRHkkVyVLBvfy683cLeq0Fx549lVgRuWhAQ4hZKTfenLoePXDexAL0CVTVTHKmKDL+ I7Xg== Received: by 10.68.235.2 with SMTP id ui2mr5350736pbc.163.1354282014729; Fri, 30 Nov 2012 05:26:54 -0800 (PST) Received: from localhost (54.Red-88-0-20.dynamicIP.rima-tde.net. [88.0.20.54]) by mx.google.com with ESMTPS id hs2sm3054884pbc.22.2012.11.30.05.26.47 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 30 Nov 2012 05:26:54 -0800 (PST) From: "=?UTF-8?q?Marc-Andr=C3=A9=20Lureau?=" To: qemu-devel@nongnu.org Date: Fri, 30 Nov 2012 14:25:44 +0100 Message-Id: <1354281947-20227-4-git-send-email-marcandre.lureau@redhat.com> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1354281947-20227-1-git-send-email-marcandre.lureau@redhat.com> References: <1354281947-20227-1-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.210.45 Cc: spice-devel@lists.freedesktop.org, alevy@redhat.com, kraxel@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [Qemu-devel] [PATCH 3/6] spice-qemu-char: factor out CharDriverState creation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Make the CharDriverState creation code reusable by spicevmc port. Signed-off-by: Marc-André Lureau --- spice-qemu-char.c | 37 +++++++++++++++++++++++-------------- 1 file 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"); } -CharDriverState *qemu_chr_open_spice(QemuOpts *opts) +static CharDriverState *chr_open(QemuOpts *opts, const char *subtype) { CharDriverState *chr; SpiceCharDriver *s; - const char* name = qemu_opt_get(opts, "name"); uint32_t debug = qemu_opt_get_number(opts, "debug", 0); - const char** psubtype = spice_server_char_device_recognized_subtypes(); + + chr = g_malloc0(sizeof(CharDriverState)); + s = g_malloc0(sizeof(SpiceCharDriver)); + s->chr = chr; + s->debug = debug; + s->active = false; + s->sin.subtype = subtype; + chr->opaque = s; + chr->chr_write = spice_chr_write; + chr->chr_close = spice_chr_close; + chr->chr_guest_open = spice_chr_guest_open; + chr->chr_guest_close = spice_chr_guest_close; + + return chr; +} + +CharDriverState *qemu_chr_open_spice(QemuOpts *opts) +{ + CharDriverState *chr; + const char *name = qemu_opt_get(opts, "name"); + const char **psubtype = spice_server_char_device_recognized_subtypes(); const char *subtype = NULL; if (name == NULL) { @@ -212,17 +231,7 @@ CharDriverState *qemu_chr_open_spice(QemuOpts *opts) return NULL; } - chr = g_malloc0(sizeof(CharDriverState)); - s = g_malloc0(sizeof(SpiceCharDriver)); - s->chr = chr; - s->debug = debug; - s->active = false; - s->sin.subtype = subtype; - chr->opaque = s; - chr->chr_write = spice_chr_write; - chr->chr_close = spice_chr_close; - chr->chr_guest_open = spice_chr_guest_open; - chr->chr_guest_close = spice_chr_guest_close; + chr = chr_open(opts, subtype); #if SPICE_SERVER_VERSION < 0x000901 /* See comment in vmc_state() */