From patchwork Fri Dec 16 16:47:33 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 131871 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 15A1F1007D7 for ; Sat, 17 Dec 2011 03:48:31 +1100 (EST) Received: from localhost ([::1]:51585 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RbaxP-0002VT-OM for incoming@patchwork.ozlabs.org; Fri, 16 Dec 2011 11:48:27 -0500 Received: from eggs.gnu.org ([140.186.70.92]:43648) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rbax2-0001p4-AL for qemu-devel@nongnu.org; Fri, 16 Dec 2011 11:48:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rbax0-0004nw-8S for qemu-devel@nongnu.org; Fri, 16 Dec 2011 11:48:03 -0500 Received: from mail-iy0-f173.google.com ([209.85.210.173]:41573) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rbawz-0004kD-UH for qemu-devel@nongnu.org; Fri, 16 Dec 2011 11:48:02 -0500 Received: by mail-iy0-f173.google.com with SMTP id j37so5244361iag.4 for ; Fri, 16 Dec 2011 08:48:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=se2eMbs2vPfOEK+AqKNnpV2gzBItXBapkwYAS9uPx3k=; b=Rqp1auLJfGaDqJIbHARCJNJPwZOzZz3sBEGawn/P9iCigtXtRrgA8WEgUY1mihj4A+ H7MCdYKV8tUbxCr8HZ+o+aTUkbUSzcCT7F83J9TOSAdxzzXteUCJ3XbfS+z64Tu5XDjm lmVfmgggJXGf+N6Nf43XdGBBrnMdIBvegXLCo= Received: by 10.50.159.161 with SMTP id xd1mr10291268igb.12.1324054081515; Fri, 16 Dec 2011 08:48:01 -0800 (PST) Received: from localhost.localdomain (93-34-178-147.ip50.fastwebnet.it. [93.34.178.147]) by mx.google.com with ESMTPS id py9sm15469890igc.2.2011.12.16.08.47.59 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 16 Dec 2011 08:48:00 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 16 Dec 2011 17:47:33 +0100 Message-Id: <1324054053-20484-9-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.7.1 In-Reply-To: <1324054053-20484-1-git-send-email-pbonzini@redhat.com> References: <1324054053-20484-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.210.173 Subject: [Qemu-devel] [PATCH v2 8/8] qom: register qdev properties also as non-legacy properties 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 Push legacy properties into a legacy<...> namespace, and make them available with correct types too. Signed-off-by: Paolo Bonzini --- hw/qdev.c | 28 +++++++++++++++++++++++++--- hw/qdev.h | 7 +++---- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/hw/qdev.c b/hw/qdev.c index 426ea71..2f7defc 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -80,6 +80,9 @@ static DeviceInfo *qdev_find_info(BusInfo *bus_info, const char *name) return NULL; } +static void qdev_property_add_legacy(DeviceState *dev, Property *prop, + Error **errp); + static DeviceState *qdev_create_from_info(BusState *bus, DeviceInfo *info) { DeviceState *dev; @@ -104,10 +107,12 @@ static DeviceState *qdev_create_from_info(BusState *bus, DeviceInfo *info) for (prop = dev->info->props; prop && prop->name; prop++) { qdev_property_add_legacy(dev, prop, NULL); + qdev_property_add_static(dev, prop, NULL); } for (prop = dev->info->bus_info->props; prop && prop->name; prop++) { qdev_property_add_legacy(dev, prop, NULL); + qdev_property_add_static(dev, prop, NULL); } qdev_property_add_str(dev, "type", qdev_get_type, NULL, NULL); @@ -1174,7 +1179,7 @@ static void qdev_set_legacy_property(DeviceState *dev, Visitor *v, void *opaque, * @qdev_add_legacy_property - adds a legacy property * * Do not use this is new code! Properties added through this interface will - * be given types in the "legacy<>" type namespace. + * be given names and types in the "legacy<>" type namespace. * * Legacy properties are always processed as strings. The format of the string * depends on the property type. @@ -1182,18 +1187,35 @@ static void qdev_set_legacy_property(DeviceState *dev, Visitor *v, void *opaque, void qdev_property_add_legacy(DeviceState *dev, Property *prop, Error **errp) { - gchar *type; + gchar *name, *type; + name = g_strdup_printf("legacy<%s>", prop->name); type = g_strdup_printf("legacy<%s>", prop->info->legacy_name ?: prop->info->name); - qdev_property_add(dev, prop->name, type, + qdev_property_add(dev, name, type, prop->info->print ? qdev_get_legacy_property : NULL, prop->info->parse ? qdev_set_legacy_property : NULL, NULL, prop, errp); g_free(type); + g_free(name); +} + +/** + * @qdev_property_add_static - add a @Property to a device. + * + * Static properties access data in a struct. The actual type of the + * property and the field depends on the property type. + */ +void qdev_property_add_static(DeviceState *dev, Property *prop, + Error **errp) +{ + qdev_property_add(dev, prop->name, prop->info->name, + prop->info->get, prop->info->set, + NULL, + prop, errp); } DeviceState *qdev_get_root(void) diff --git a/hw/qdev.h b/hw/qdev.h index 8002644..3410e77 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -487,11 +487,10 @@ const char *qdev_property_get_type(DeviceState *dev, const char *name, Error **errp); /** - * @qdev_property_add_legacy - add a legacy @Property to a device - * - * DO NOT USE THIS IN NEW CODE! + * @qdev_property_add_static - add a @Property to a device referencing a + * field in a struct. */ -void qdev_property_add_legacy(DeviceState *dev, Property *prop, Error **errp); +void qdev_property_add_static(DeviceState *dev, Property *prop, Error **errp); /** * @qdev_get_root - returns the root device of the composition tree