From patchwork Tue Oct 20 07:13:43 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Shah X-Patchwork-Id: 36442 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 58D7BB7B90 for ; Tue, 20 Oct 2009 18:17:18 +1100 (EST) Received: from localhost ([127.0.0.1]:55581 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N08y2-00053x-MI for incoming@patchwork.ozlabs.org; Tue, 20 Oct 2009 03:17:14 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N08vS-0003ts-DJ for qemu-devel@nongnu.org; Tue, 20 Oct 2009 03:14:34 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N08vN-0003rF-7N for qemu-devel@nongnu.org; Tue, 20 Oct 2009 03:14:34 -0400 Received: from [199.232.76.173] (port=39791 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N08vN-0003r9-3g for qemu-devel@nongnu.org; Tue, 20 Oct 2009 03:14:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:11929) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N08vM-0007jJ-JG for qemu-devel@nongnu.org; Tue, 20 Oct 2009 03:14:28 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9K7ESPV012038 for ; Tue, 20 Oct 2009 03:14:28 -0400 Received: from localhost (vpn-12-92.rdu.redhat.com [10.11.12.92]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n9K7EP4P023411; Tue, 20 Oct 2009 03:14:27 -0400 From: Amit Shah To: qemu-devel@nongnu.org Date: Tue, 20 Oct 2009 12:43:43 +0530 Message-Id: <1256022825-16180-2-git-send-email-amit.shah@redhat.com> In-Reply-To: <1256022825-16180-1-git-send-email-amit.shah@redhat.com> References: <1256022825-16180-1-git-send-email-amit.shah@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Amit Shah , Gerd Hoffmann Subject: [Qemu-devel] [PATCH v9 1/3] qdev: add string property. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Gerd Hoffmann Signed-off-by: Gerd Hoffmann Signed-off-by: Amit Shah --- hw/qdev-properties.c | 28 ++++++++++++++++++++++++++++ hw/qdev.h | 4 ++++ 2 files changed, 32 insertions(+), 0 deletions(-) diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c index 5c627fa..8ca345a 100644 --- a/hw/qdev-properties.c +++ b/hw/qdev-properties.c @@ -193,6 +193,34 @@ PropertyInfo qdev_prop_hex64 = { .print = print_hex64, }; +/* --- string --- */ + +static int parse_string(DeviceState *dev, Property *prop, const char *str) +{ + char **ptr = qdev_get_prop_ptr(dev, prop); + + if (*ptr) + qemu_free(*ptr); + *ptr = qemu_strdup(str); + return 0; +} + +static int print_string(DeviceState *dev, Property *prop, char *dest, size_t len) +{ + char **ptr = qdev_get_prop_ptr(dev, prop); + if (!*ptr) + return snprintf(dest, len, ""); + return snprintf(dest, len, "\"%s\"", *ptr); +} + +PropertyInfo qdev_prop_string = { + .name = "string", + .type = PROP_TYPE_STRING, + .size = sizeof(char*), + .parse = parse_string, + .print = print_string, +}; + /* --- drive --- */ static int parse_drive(DeviceState *dev, Property *prop, const char *str) diff --git a/hw/qdev.h b/hw/qdev.h index 6d61b3a..b79f3e3 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -79,6 +79,7 @@ enum PropertyType { PROP_TYPE_MACADDR, PROP_TYPE_DRIVE, PROP_TYPE_CHR, + PROP_TYPE_STRING, PROP_TYPE_PTR, }; @@ -186,6 +187,7 @@ extern PropertyInfo qdev_prop_int32; extern PropertyInfo qdev_prop_uint64; extern PropertyInfo qdev_prop_hex32; extern PropertyInfo qdev_prop_hex64; +extern PropertyInfo qdev_prop_string; extern PropertyInfo qdev_prop_chr; extern PropertyInfo qdev_prop_ptr; extern PropertyInfo qdev_prop_macaddr; @@ -227,6 +229,8 @@ extern PropertyInfo qdev_prop_pci_devfn; DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, void*) #define DEFINE_PROP_CHR(_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharDriverState*) +#define DEFINE_PROP_STRING(_n, _s, _f) \ + DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*) #define DEFINE_PROP_DRIVE(_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_drive, DriveInfo*) #define DEFINE_PROP_MACADDR(_n, _s, _f) \