Received: from eggs.gnu.org ([2001:4830:134:3::10]:40951) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UxREb-00072Z-Mr for qemu-devel@nongnu.org; Thu, 11 Jul 2013 20:29:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UxREY-0003Os-Pt for qemu-devel@nongnu.org; Thu, 11 Jul 2013 20:29:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:11857) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UxREY-0003Og-I9 for qemu-devel@nongnu.org; Thu, 11 Jul 2013 20:29:14 -0400 Date: Thu, 11 Jul 2013 21:29:10 -0300 From: Eduardo Habkost Message-ID: <20130712002910.GX11420@otherpad.lan.raisama.net> References: <51DC1F19.8030806@suse.de> <1373486922-24209-1-git-send-email-ehabkost@redhat.com> <1373486922-24209-3-git-send-email-ehabkost@redhat.com> <20130711082915.2ae4ef00@nial.usersys.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20130711082915.2ae4ef00@nial.usersys.redhat.com> Subject: Re: [Qemu-devel] [RFC 2/3 v2] qom: introduce post_init() function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Igor Mammedov Cc: Paolo Bonzini , Anthony Liguori , qemu-devel@nongnu.org, Andreas =?iso-8859-1?Q?F=E4rber?= On Thu, Jul 11, 2013 at 08:29:15AM +0200, Igor Mammedov wrote: > On Wed, 10 Jul 2013 17:08:41 -0300 > Eduardo Habkost wrote: > > > 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/qom/object.h | 3 +++ > > qom/object.c | 14 ++++++++++++++ > > 2 files changed, 17 insertions(+) > > > > diff --git a/include/qom/object.h b/include/qom/object.h > > index 23fc048..1a54f64 100644 > > --- a/include/qom/object.h > > +++ b/include/qom/object.h > > @@ -398,6 +398,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 > > @@ -433,6 +435,7 @@ struct TypeInfo > [...] > > > > +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)); > > + } > Is there a reason why post init called in opposite order than > instance_init() ? Because it seems more useful: if parent types want to initialize something before subclasses, they can use instance_init(). If they want to initialize something _after_ subclasses, then they can use instance_post_init(). > > > +} > > + > > void object_initialize_with_type(void *data, TypeImpl *type) > > { > > Object *obj = data; > > @@ -313,6 +326,7 @@ void object_initialize_with_type(void *data, TypeImpl *type) > > object_ref(obj); > > 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) > -- Eduardo