[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 5/6] qom: introduce post_init() function
From: |
Eduardo Habkost |
Subject: |
[Qemu-devel] [PATCH 5/6] qom: introduce post_init() function |
Date: |
Wed, 3 Oct 2012 14:48:37 -0300 |
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 <address@hidden>
---
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)
--
1.7.11.4
- [Qemu-devel] [PATCH 0/6] qdev: handle global properties after all instance_init calls, Eduardo Habkost, 2012/10/03
- [Qemu-devel] [PATCH 5/6] qom: introduce post_init() function,
Eduardo Habkost <=
- [Qemu-devel] [PATCH 2/6] qapi-types.h doesn't really need to include qemu-common.h, Eduardo Habkost, 2012/10/03
- [Qemu-devel] [PATCH 6/6] qdev: set globals on post_init() function, Eduardo Habkost, 2012/10/03
- [Qemu-devel] [PATCH 4/6] tests: unit tests for qdev global-properties handling, Eduardo Habkost, 2012/10/03
- [Qemu-devel] [PATCH 3/6] qdev: separate core from the code used only by qemu-system-*, Eduardo Habkost, 2012/10/03
- [Qemu-devel] [PATCH 1/6] qdev: split up header so it can be used in cpu.h, Eduardo Habkost, 2012/10/03