From patchwork Wed Nov 7 12:36:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 994235 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42qmRQ59gxz9sDL for ; Wed, 7 Nov 2018 23:48:02 +1100 (AEDT) Received: from localhost ([::1]:47684 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKNFX-00007M-Js for incoming@patchwork.ozlabs.org; Wed, 07 Nov 2018 07:47:59 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37890) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKN7D-00088m-6Z for qemu-devel@nongnu.org; Wed, 07 Nov 2018 07:39:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gKN74-0007Nz-2y for qemu-devel@nongnu.org; Wed, 07 Nov 2018 07:39:19 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39370) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gKN6x-000713-4i; Wed, 07 Nov 2018 07:39:08 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 775F930B7DE6; Wed, 7 Nov 2018 12:38:40 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 245F126328; Wed, 7 Nov 2018 12:38:32 +0000 (UTC) From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= To: qemu-devel@nongnu.org Date: Wed, 7 Nov 2018 16:36:49 +0400 Message-Id: <20181107123652.23417-12-marcandre.lureau@redhat.com> In-Reply-To: <20181107123652.23417-1-marcandre.lureau@redhat.com> References: <20181107123652.23417-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 07 Nov 2018 12:38:40 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-3.2 v3 11/14] qom: teach interfaces to implement post-init X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Stefano Stabellini , xen-devel@lists.xenproject.org, Corey Minyard , Amit Shah , =?utf-8?q?Herv=C3=A9_Poussineau?= , "Michael S. Tsirkin" , Mark Cave-Ayland , dgilbert@redhat.com, Eduardo Habkost , =?utf-8?q?Marc-Andr=C3=A9_Lure?= =?utf-8?q?au?= , qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Igor Mammedov , Anthony Perard , Paolo Bonzini , Stefan Berger , =?utf-8?q?Andreas_F=C3=A4rber?= , Artyom Tarasenko , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- 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); }