From patchwork Wed Apr 18 20:56:42 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 153596 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 83FD3B6EE6 for ; Thu, 19 Apr 2012 07:09:09 +1000 (EST) Received: from localhost ([::1]:54023 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SKbx6-0000JI-Pq for incoming@patchwork.ozlabs.org; Wed, 18 Apr 2012 16:58:12 -0400 Received: from eggs.gnu.org ([208.118.235.92]:33365) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SKbwK-0006Of-Kw for qemu-devel@nongnu.org; Wed, 18 Apr 2012 16:57:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SKbwJ-0006vG-0u for qemu-devel@nongnu.org; Wed, 18 Apr 2012 16:57:24 -0400 Received: from cpe-70-123-132-139.austin.res.rr.com ([70.123.132.139]:59627 helo=localhost6.localdomain6) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SKbwI-0006v3-Pr for qemu-devel@nongnu.org; Wed, 18 Apr 2012 16:57:22 -0400 Received: from localhost6.localdomain6 (localhost.localdomain [127.0.0.1]) by localhost6.localdomain6 (8.14.4/8.14.4/Debian-2ubuntu2) with ESMTP id q3IKvFcq019394; Wed, 18 Apr 2012 15:57:15 -0500 Received: (from anthony@localhost) by localhost6.localdomain6 (8.14.4/8.14.4/Submit) id q3IKvDvl019390; Wed, 18 Apr 2012 15:57:13 -0500 From: Anthony Liguori To: qemu-devel@nongnu.org Date: Wed, 18 Apr 2012 15:56:42 -0500 Message-Id: <1334782613-5421-4-git-send-email-aliguori@us.ibm.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1334782613-5421-1-git-send-email-aliguori@us.ibm.com> References: <1334782613-5421-1-git-send-email-aliguori@us.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 70.123.132.139 Cc: Wanpeng Li , Paolo Bonzini , Anthony Liguori , Andreas Faerber , Peter Maydell Subject: [Qemu-devel] [PATCH 03/14] qdev: add qdev_add_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 This allows a base class to easily add properties. Signed-off-by: Anthony Liguori --- hw/qdev.c | 25 ++++++++++++------------- hw/qdev.h | 2 ++ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/hw/qdev.c b/hw/qdev.c index 83a1db6..c8dda31 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -76,22 +76,26 @@ bool qdev_exists(const char *name) static void qdev_property_add_legacy(DeviceState *dev, Property *prop, Error **errp); -void qdev_set_parent_bus(DeviceState *dev, BusState *bus) +void qdev_add_properties(DeviceState *dev, Property *props) { Property *prop; + for (prop = props; prop && prop->name; prop++) { + qdev_property_add_legacy(dev, prop, NULL); + qdev_property_add_static(dev, prop, NULL); + } + qdev_prop_set_defaults(dev, props); +} + +void qdev_set_parent_bus(DeviceState *dev, BusState *bus) +{ if (qdev_hotplug) { assert(bus->allow_hotplug); } dev->parent_bus = bus; QTAILQ_INSERT_HEAD(&bus->children, dev, sibling); - - for (prop = qdev_get_bus_info(dev)->props; prop && prop->name; prop++) { - qdev_property_add_legacy(dev, prop, NULL); - qdev_property_add_static(dev, prop, NULL); - } - qdev_prop_set_defaults(dev, dev->parent_bus->info->props); + qdev_add_properties(dev, dev->parent_bus->info->props); } /* Create a new device. This only initializes the device state structure @@ -632,13 +636,8 @@ static void device_initfn(Object *obj) dev->instance_id_alias = -1; dev->state = DEV_STATE_CREATED; - for (prop = qdev_get_props(dev); prop && prop->name; prop++) { - qdev_property_add_legacy(dev, prop, NULL); - qdev_property_add_static(dev, prop, NULL); - } - + qdev_add_properties(dev, qdev_get_props(dev)); object_property_add_str(OBJECT(dev), "type", qdev_get_type, NULL, NULL); - qdev_prop_set_defaults(dev, qdev_get_props(dev)); } /* Unlink device from bus and free the structure. */ diff --git a/hw/qdev.h b/hw/qdev.h index 4e90119..ca8386a 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -360,4 +360,6 @@ void qdev_set_parent_bus(DeviceState *dev, BusState *bus); extern int qdev_hotplug; +void qdev_add_properties(DeviceState *dev, Property *props); + #endif