From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51954) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VANKr-0002hi-Kv for qemu-devel@nongnu.org; Fri, 16 Aug 2013 12:57:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VANKg-0000d2-1P for qemu-devel@nongnu.org; Fri, 16 Aug 2013 12:57:13 -0400 Received: from cantor2.suse.de ([195.135.220.15]:55461 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VANKf-0000ca-Nr for qemu-devel@nongnu.org; Fri, 16 Aug 2013 12:57:01 -0400 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Fri, 16 Aug 2013 18:56:40 +0200 Message-Id: <1376672203-31191-4-git-send-email-afaerber@suse.de> In-Reply-To: <1376672203-31191-1-git-send-email-afaerber@suse.de> References: <1376672203-31191-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 3/6] qom: Introduce instance_post_init hook List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Eduardo Habkost , =?UTF-8?q?Andreas=20F=C3=A4rber?= From: Eduardo Habkost 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 Signed-off-by: Andreas F=C3=A4rber --- 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..9b69065 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 respon= sible * 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 ca= lled. * An object should only free the members that are unique to its type = in this @@ -433,6 +435,7 @@ struct TypeInfo =20 size_t instance_size; void (*instance_init)(Object *obj); + void (*instance_post_init)(Object *obj); void (*instance_finalize)(Object *obj); =20 bool abstract; diff --git a/qom/object.c b/qom/object.c index b2479d1..74fd241 100644 --- a/qom/object.c +++ b/qom/object.c @@ -51,6 +51,7 @@ struct TypeImpl void *class_data; =20 void (*instance_init)(Object *obj); + void (*instance_post_init)(Object *obj); void (*instance_finalize)(Object *obj); =20 bool abstract; @@ -111,6 +112,7 @@ static TypeImpl *type_register_internal(const TypeInf= o *info) ti->class_data =3D info->class_data; =20 ti->instance_init =3D info->instance_init; + ti->instance_post_init =3D info->instance_post_init; ti->instance_finalize =3D info->instance_finalize; =20 ti->abstract =3D info->abstract; @@ -298,6 +300,17 @@ static void object_init_with_type(Object *obj, TypeI= mpl *ti) } } =20 +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 =3D 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); } =20 void object_initialize(void *data, const char *typename) --=20 1.8.1.4