From patchwork Mon Mar 26 13:46:50 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 148752 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 7687EB6EEA for ; Tue, 27 Mar 2012 01:46:01 +1100 (EST) Received: from localhost ([::1]:34158 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SCAGp-0002Dp-1B for incoming@patchwork.ozlabs.org; Mon, 26 Mar 2012 09:47:39 -0400 Received: from eggs.gnu.org ([208.118.235.92]:59325) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SCAGM-0001YB-K6 for qemu-devel@nongnu.org; Mon, 26 Mar 2012 09:47:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SCAGB-0003fx-VZ for qemu-devel@nongnu.org; Mon, 26 Mar 2012 09:47:10 -0400 Received: from cantor2.suse.de ([195.135.220.15]:41048 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SCAGB-0003cr-Mn for qemu-devel@nongnu.org; Mon, 26 Mar 2012 09:46:59 -0400 Received: from relay2.suse.de (unknown [195.135.220.254]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id 4AA9C8FFEB; Mon, 26 Mar 2012 15:46:58 +0200 (CEST) From: =?UTF-8?q?Andreas=20F=C3=A4rber?= To: qemu-devel@nongnu.org Date: Mon, 26 Mar 2012 15:46:50 +0200 Message-Id: <1332769612-4247-2-git-send-email-afaerber@suse.de> X-Mailer: git-send-email 1.7.7 In-Reply-To: <1332769612-4247-1-git-send-email-afaerber@suse.de> References: <1332769612-4247-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 X-Received-From: 195.135.220.15 Cc: Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Anthony Liguori Subject: [Qemu-devel] [PATCH RFC 1/3] qom: Add "realized" property to Object 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 The Object::realized property can only be set once and, on setting it, invokes the ObjectClass::realize callback. Signed-off-by: Andreas Färber Cc: Anthony Liguori Cc: Paolo Bonzini --- include/qemu/object.h | 2 ++ qom/object.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 0 deletions(-) diff --git a/include/qemu/object.h b/include/qemu/object.h index e8fc126..742b5b6 100644 --- a/include/qemu/object.h +++ b/include/qemu/object.h @@ -239,6 +239,7 @@ struct ObjectClass { /*< private >*/ Type type; + int (*realize)(Object *obj); }; /** @@ -264,6 +265,7 @@ struct Object QTAILQ_HEAD(, ObjectProperty) properties; uint32_t ref; Object *parent; + bool realized; }; /** diff --git a/qom/object.c b/qom/object.c index 9cd9506..ec143ad 100644 --- a/qom/object.c +++ b/qom/object.c @@ -273,6 +273,34 @@ static void object_init_with_type(Object *obj, TypeImpl *ti) } } +static void object_get_realized(Object *obj, Visitor *v, void *opaque, + const char *name, Error **errp) +{ + visit_type_bool(v, &obj->realized, name, errp); +} + +static void object_set_realized(Object *obj, Visitor *v, void *opaque, + const char *name, Error **errp) +{ + bool value; + + if (obj->realized) { + error_set(errp, QERR_PERMISSION_DENIED); + return; + } + + visit_type_bool(v, &value, name, errp); + if (error_is_set(errp) || !value) { + return; + } + + if (obj->class->realize != NULL && obj->class->realize(obj) != 0) { + error_set(errp, QERR_DEVICE_INIT_FAILED, object_get_typename(obj)); + return; + } + obj->realized = true; +} + void object_initialize_with_type(void *data, TypeImpl *type) { Object *obj = data; @@ -287,6 +315,9 @@ void object_initialize_with_type(void *data, TypeImpl *type) obj->class = type->class; QTAILQ_INIT(&obj->properties); object_init_with_type(obj, type); + object_property_add(obj, "realized", "boolean", + object_get_realized, object_set_realized, + NULL, NULL, NULL); } void object_initialize(void *data, const char *typename)