From patchwork Wed Oct 3 17:48:37 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 188867 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 484C32C00A8 for ; Thu, 4 Oct 2012 03:48:07 +1000 (EST) Received: from localhost ([::1]:40280 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TJT37-0002lA-6r for incoming@patchwork.ozlabs.org; Wed, 03 Oct 2012 13:47:57 -0400 Received: from eggs.gnu.org ([208.118.235.92]:59749) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TJT2u-0002k2-2d for qemu-devel@nongnu.org; Wed, 03 Oct 2012 13:47:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TJT2s-0006T1-Gm for qemu-devel@nongnu.org; Wed, 03 Oct 2012 13:47:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37671) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TJT2s-0006Sn-7h for qemu-devel@nongnu.org; Wed, 03 Oct 2012 13:47:42 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q93HleJI016164 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 3 Oct 2012 13:47:40 -0400 Received: from blackpad.lan.raisama.net (vpn1-7-147.gru2.redhat.com [10.97.7.147]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q93HldJ5003207; Wed, 3 Oct 2012 13:47:40 -0400 Received: by blackpad.lan.raisama.net (Postfix, from userid 500) id 5334F20360B; Wed, 3 Oct 2012 14:48:41 -0300 (BRT) From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Wed, 3 Oct 2012 14:48:37 -0300 Message-Id: <1349286518-28123-6-git-send-email-ehabkost@redhat.com> In-Reply-To: <1349286518-28123-1-git-send-email-ehabkost@redhat.com> References: <1349286518-28123-1-git-send-email-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: Paolo Bonzini , Anthony Liguori , Igor Mammedov Subject: [Qemu-devel] [PATCH 5/6] qom: introduce post_init() function 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 will allow classes to specify a function to be called after all instance_init() functions were called. This will be used by DeviceState to call qdev_prop_set_globals() at the right moment. Signed-off-by: Eduardo Habkost --- include/qemu/object.h | 3 +++ qom/object.c | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/qemu/object.h b/include/qemu/object.h index cc75fee..ca7e38b 100644 --- a/include/qemu/object.h +++ b/include/qemu/object.h @@ -276,6 +276,8 @@ struct Object * @instance_init: This function is called to initialize an object. The parent * class will have already been initialized so the type is only responsible * for initializing its own members. + * @instance_post_init: This function is called to finish initialization of + * an object, after all instance_init functions were called. * @instance_finalize: This function is called during object destruction. This * is called before the parent @instance_finalize function has been called. * An object should only free the members that are unique to its type in this @@ -311,6 +313,7 @@ struct TypeInfo size_t instance_size; void (*instance_init)(Object *obj); + void (*instance_post_init)(Object *obj); void (*instance_finalize)(Object *obj); bool abstract; diff --git a/qom/object.c b/qom/object.c index e3e9242..eed5e05 100644 --- a/qom/object.c +++ b/qom/object.c @@ -49,6 +49,7 @@ struct TypeImpl void *class_data; void (*instance_init)(Object *obj); + void (*instance_post_init)(Object *obj); void (*instance_finalize)(Object *obj); bool abstract; @@ -109,6 +110,7 @@ static TypeImpl *type_register_internal(const TypeInfo *info) ti->class_data = info->class_data; ti->instance_init = info->instance_init; + ti->instance_post_init = info->instance_post_init; ti->instance_finalize = info->instance_finalize; ti->abstract = info->abstract; @@ -295,6 +297,17 @@ static void object_init_with_type(Object *obj, TypeImpl *ti) } } +static void object_post_init_with_type(Object *obj, TypeImpl *ti) +{ + if (ti->instance_post_init) { + ti->instance_post_init(obj); + } + + if (type_has_parent(ti)) { + object_post_init_with_type(obj, type_get_parent(ti)); + } +} + void object_initialize_with_type(void *data, TypeImpl *type) { Object *obj = data; @@ -309,6 +322,7 @@ void object_initialize_with_type(void *data, TypeImpl *type) obj->class = type->class; QTAILQ_INIT(&obj->properties); object_init_with_type(obj, type); + object_post_init_with_type(obj, type); } void object_initialize(void *data, const char *typename)