From nobody Mon Feb 9 03:14:01 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1555344172; cv=none; d=zoho.com; s=zohoarc; b=WaC9/89ek15tdkS+faPPljTRoRFKFOYgdNMIIGC/yPRhhu5wz1joRQmTUjkU2stptIc6bBB12RZ2VGB7F6JIqvu8gGuDrDo5ds7Ngr4uZj7BcjNcxdNxxXgfWhrVDuKr5cddCrHwrnox9EDTYCZ/PVqlVKjy4NIHSM1pQMwVrHY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555344172; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=i+IXQ5HVkwOkjITRS3mzcYykUWOicclDinWMc1Nnz+M=; b=eYrcGe6NYSVBU6fWWP7A86TOqPtl7upnIzPqHFSc2HMWIM4JPasBWxzQsN7dT3t/Y72hf0UQ0HTGCcl4JPUqLhpeqI2CVb6YTxS/TN0KrbTcid/03xuCVwPfhjM4sfC2lrs3Ze5XoLybjDavLQ6sbGegPetGvW51+U0xvbaDncQ= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1555344172844436.628302947359; Mon, 15 Apr 2019 09:02:52 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2B235307EA82; Mon, 15 Apr 2019 16:02:51 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 020CD5C22D; Mon, 15 Apr 2019 16:02:51 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B3E473FA4B; Mon, 15 Apr 2019 16:02:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x3FG2STd003367 for ; Mon, 15 Apr 2019 12:02:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4A77A1001947; Mon, 15 Apr 2019 16:02:28 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id C6FE110A33C1 for ; Mon, 15 Apr 2019 16:02:27 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Mon, 15 Apr 2019 18:02:06 +0200 Message-Id: <1b5f005c3d6747cad52212a549d737cf3fb50f57.1555344008.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 13/21] qemu: qapi: Use declarative approach for meta-type parsers in virQEMUQAPISchemaTraverse X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Mon, 15 Apr 2019 16:02:51 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Introduce an array of callbacks for given 'meta-type' of the QAPI schema structure rather than using code to select it. This will simplify extension for the other meta-types which are not handled yet. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_qapi.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/qemu/qemu_qapi.c b/src/qemu/qemu_qapi.c index a03aab7f9b..9a5becb26f 100644 --- a/src/qemu/qemu_qapi.c +++ b/src/qemu/qemu_qapi.c @@ -164,12 +164,30 @@ virQEMUQAPISchemaTraverseCommand(virJSONValuePtr cur, } +typedef int (*virQEMUQAPISchemaTraverseFunc)(virJSONValuePtr cur, + struct virQEMUQAPISchemaTrave= rseContext *ctxt); + +struct virQEMUQAPISchemaTraverseMetaType { + const char *metatype; + virQEMUQAPISchemaTraverseFunc func; +}; + + +static const struct virQEMUQAPISchemaTraverseMetaType traverseMetaType[] = =3D { + { "object", virQEMUQAPISchemaTraverseObject }, + { "array", virQEMUQAPISchemaTraverseArray }, + { "command", virQEMUQAPISchemaTraverseCommand }, + { "event", virQEMUQAPISchemaTraverseCommand }, +}; + + static int virQEMUQAPISchemaTraverse(const char *baseName, struct virQEMUQAPISchemaTraverseContext *ctxt) { virJSONValuePtr cur; const char *metatype; + size_t i; if (!(cur =3D virHashLookup(ctxt->schema, baseName))) return 0; @@ -182,16 +200,9 @@ virQEMUQAPISchemaTraverse(const char *baseName, if (!(metatype =3D virJSONValueObjectGetString(cur, "meta-type"))) return 0; - if (STREQ(metatype, "array")) { - return virQEMUQAPISchemaTraverseArray(cur, ctxt); - } else if (STREQ(metatype, "object")) { - return virQEMUQAPISchemaTraverseObject(cur, ctxt); - } else if (STREQ(metatype, "command") || - STREQ(metatype, "event")) { - return virQEMUQAPISchemaTraverseCommand(cur, ctxt); - } else { - /* alternates, basic types and enums can't be entered */ - return 0; + for (i =3D 0; i < ARRAY_CARDINALITY(traverseMetaType); i++) { + if (STREQ(metatype, traverseMetaType[i].metatype)) + return traverseMetaType[i].func(cur, ctxt); } return 0; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list