diff mbox series

[for-3.2,v3,11/14] qom: teach interfaces to implement post-init

Message ID 20181107123652.23417-12-marcandre.lureau@redhat.com
State New
Headers show
Series Generalize machine compatibility properties | expand

Commit Message

Marc-André Lureau Nov. 7, 2018, 12:36 p.m. UTC
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@redhat.com>
---
 qom/object.c                |  8 +++++++-
 tests/check-qom-interface.c | 23 +++++++++++++++++++++--
 2 files changed, 28 insertions(+), 3 deletions(-)

Comments

Igor Mammedov Nov. 26, 2018, 1:46 p.m. UTC | #1
On Wed,  7 Nov 2018 16:36:49 +0400
Marc-André Lureau <marcandre.lureau@redhat.com> wrote:

> 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.


CCing ARM guys who touched arm_cpu_post_init() in the past,
pls provide feedback if suggested below approach is acceptable.


> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  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);
> +    }
isn't arm_cpu_post_init() issue[1] still valid here?
1) http://patchwork.ozlabs.org/patch/969002/

probably cleanest/easiest way is to get rid of arm_cpu_post_init()
by calling it from leaf classes and then drop device_post_init()
along with switching to interface approach.

CCing guys who touched arm_cpu_post_init() in the past

>      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);
>  }
>
diff mbox series

Patch

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);
 }