[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH for-3.2 v3 11/14] qom: teach interfaces to implement post-init
The following patches are going to implement post_init callbacks for settings properties. The interface post_init are called before the instance post_init, so the default interface behaviour can be overriden if necessary. Signed-off-by: Marc-André Lureau <marcandre.lureau@xxxxxxxxxx> --- qom/object.c | 8 +++++++- tests/check-qom-interface.c | 23 +++++++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/qom/object.c b/qom/object.c index b1a7f70550..980eeb8283 100644 --- a/qom/object.c +++ b/qom/object.c @@ -290,7 +290,6 @@ static void type_initialize(TypeImpl *ti) assert(ti->instance_size == 0); assert(ti->abstract); assert(!ti->instance_init); - assert(!ti->instance_post_init); assert(!ti->instance_finalize); assert(!ti->num_interfaces); } @@ -363,6 +362,13 @@ static void object_init_with_type(Object *obj, TypeImpl *ti) static void object_post_init_with_type(Object *obj, TypeImpl *ti) { + GSList *e; + + for (e = ti->class->interfaces; e; e = e->next) { + TypeImpl *itype = OBJECT_CLASS(e->data)->type; + object_post_init_with_type(obj, itype); + } + if (ti->instance_post_init) { ti->instance_post_init(obj); } diff --git a/tests/check-qom-interface.c b/tests/check-qom-interface.c index 2177f0dce5..cd2dd6dcee 100644 --- a/tests/check-qom-interface.c +++ b/tests/check-qom-interface.c @@ -31,9 +31,27 @@ typedef struct TestIfClass { uint32_t test; } TestIfClass; +typedef struct DirectImpl { + Object parent_obj; + + bool if_post_init; +} DirectImpl; + +#define TYPE_DIRECT_IMPL "direct-impl" +#define DIRECT_IMPL(obj) \ + OBJECT_CHECK(DirectImpl, (obj), TYPE_DIRECT_IMPL) + +static void test_if_post_init(Object *obj) +{ + DirectImpl *d = DIRECT_IMPL(obj); + + d->if_post_init = true; +} + static const TypeInfo test_if_info = { .name = TYPE_TEST_IF, .parent = TYPE_INTERFACE, + .instance_post_init = test_if_post_init, .class_size = sizeof(TestIfClass), }; @@ -47,11 +65,10 @@ static void test_class_init(ObjectClass *oc, void *data) tc->test = PATTERN; } -#define TYPE_DIRECT_IMPL "direct-impl" - static const TypeInfo direct_impl_info = { .name = TYPE_DIRECT_IMPL, .parent = TYPE_OBJECT, + .instance_size = sizeof(DirectImpl), .class_init = test_class_init, .interfaces = (InterfaceInfo[]) { { TYPE_TEST_IF }, @@ -70,10 +87,12 @@ static void test_interface_impl(const char *type) { Object *obj = object_new(type); TestIf *iobj = TEST_IF(obj); + DirectImpl *d = DIRECT_IMPL(obj); TestIfClass *ioc = TEST_IF_GET_CLASS(iobj); g_assert(iobj); g_assert(ioc->test == PATTERN); + g_assert(d->if_post_init == true); object_unref(obj); } -- 2.19.1.708.g4ede3d42df _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |