From nobody Sat Apr 5 02:15:17 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1739565120; cv=none; d=zohomail.com; s=zohoarc; b=KjPFM9WmYaAI49I8bVmOkHVso3ukUzgpfAq8gbBbBIFpNrboANhewdQ9J8cUjWQ1KlIvEc8yKpoejv/TsfNMkLzY9pt3MF2qtQN5FPMu9SYzK8oEHdlOP8KyRpsxFTbO44jbpC99OPy0pHi8comCwokTVROSzLuLsaLICr1S+dg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1739565120; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=S7J/rt19u5i7ccmeMEi0N5tDk0udDVxbxjxL2xbH3Lg=; b=i+amZYgrTiHjh96pL2n96ghtdFlxIUD4K9YyNVVyPdqSCbBd+o+hOTa8Gq5t2Mweb5/xyoNq16CX+hGqjUU15pCOaBL7cMizk2YAIuYQsdr0ymTEsqDX5OIWd0sITCq0q0lRdv4o8VbvKiQRid6ypWRFvcjjzwZDW1AdMlbcOUY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1739565120555680.2264591206678; Fri, 14 Feb 2025 12:32:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tj2LX-0004w4-3p; Fri, 14 Feb 2025 15:31:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tj2KN-00048g-Bd for qemu-devel@nongnu.org; Fri, 14 Feb 2025 15:30:23 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tj2KL-00021Q-M3 for qemu-devel@nongnu.org; Fri, 14 Feb 2025 15:30:23 -0500 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-547-Gbdm0egUOEmEN3C0IURRuQ-1; Fri, 14 Feb 2025 15:30:19 -0500 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 84EAF19373DC for ; Fri, 14 Feb 2025 20:30:18 +0000 (UTC) Received: from tapioca.redhat.com (unknown [10.44.32.23]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0DA561800940; Fri, 14 Feb 2025 20:30:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1739565021; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=S7J/rt19u5i7ccmeMEi0N5tDk0udDVxbxjxL2xbH3Lg=; b=Uz3WJI5AG7qhqSxMD9TDHH1kwtHBdt7Sbxmif1atok+NnG1P8Cz4+rtC712WA9D5pUX1oN 0vnxMe+UEBeVR/WM0EIvk2kaB3w7afxLa79nTOi97LHBQvl1xoqaFwCHhjzVi6wDxL3fZO XL0JvhXjU5TkU3N8AcK0gejx24+c1K4= X-MC-Unique: Gbdm0egUOEmEN3C0IURRuQ-1 X-Mimecast-MFC-AGG-ID: Gbdm0egUOEmEN3C0IURRuQ_1739565018 From: Victor Toso To: qemu-devel@nongnu.org Cc: Markus Armbruster , John Snow , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Andrea Bolognani Subject: [PATCH v4 08/11] qapi: golang: Generate Event interface Date: Fri, 14 Feb 2025 21:29:41 +0100 Message-ID: <20250214202944.69897-9-victortoso@redhat.com> In-Reply-To: <20250214202944.69897-1-victortoso@redhat.com> References: <20250214202944.69897-1-victortoso@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=victortoso@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -37 X-Spam_score: -3.8 X-Spam_bar: --- X-Spam_report: (-3.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.732, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1739565122281019100 Content-Type: text/plain; charset="utf-8" The Event interface is an abstraction that can be used by client and server to the manager the Event types albeit with a different implementation for sending and receiving. The implementation of client/server is not part of this series. Signed-off-by: Victor Toso --- scripts/qapi/golang/golang.py | 38 ++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/scripts/qapi/golang/golang.py b/scripts/qapi/golang/golang.py index 63d55ca950..b9a2c47137 100644 --- a/scripts/qapi/golang/golang.py +++ b/scripts/qapi/golang/golang.py @@ -229,6 +229,12 @@ }} """ =20 +TEMPLATE_EVENT =3D """ +type Event interface {{ +{methods} +}} +""" + =20 # Takes the documentation object of a specific type and returns # that type's documentation and its member's docs. @@ -1003,13 +1009,16 @@ def generate_template_alternate( return "\n" + content =20 =20 -def generate_template_event(events: dict[str, Tuple[str, str]]) -> str: +def generate_template_event(events: dict[str, Tuple[str, str]]) -> (str, s= tr): content =3D "" + methods =3D "" for name in sorted(events): type_name, gocode =3D events[name] + methods +=3D f"\t{type_name}({type_name}, time.Time) error\n" content +=3D gocode =20 - return content + iface =3D string_to_code(TEMPLATE_EVENT.format(methods=3Dmethods[:-1])) + return content, iface =20 =20 def generate_content_from_dict(data: dict[str, str]) -> str: @@ -1065,6 +1074,9 @@ def __init__(self, _: str): "struct": ["encoding/json"], "union": ["encoding/json", "errors", "fmt"], } + interfaces =3D { + "event": ["time"], + } =20 self.schema: QAPISchema self.events: dict[str, Tuple[str, str]] =3D {} @@ -1080,6 +1092,9 @@ def __init__(self, _: str): self.types =3D dict.fromkeys(types, "") self.types_import =3D types =20 + self.interfaces =3D dict.fromkeys(interfaces, "") + self.interface_imports =3D interfaces + def visit_begin(self, schema: QAPISchema) -> None: self.schema =3D schema =20 @@ -1100,6 +1115,12 @@ def visit_begin(self, schema: QAPISchema) -> None: continue self.docmap[doc.symbol] =3D doc =20 + for qapitype, imports in self.interface_imports.items(): + self.interfaces[qapitype] =3D TEMPLATE_GENERATED_HEADER[1:].fo= rmat( + package_name=3Dself.golang_package_name + ) + self.interfaces[qapitype] +=3D generate_template_imports(impor= ts) + for qapitype, imports in self.types_import.items(): self.types[qapitype] =3D TEMPLATE_GENERATED_HEADER[1:].format( package_name=3Dself.golang_package_name @@ -1114,7 +1135,10 @@ def visit_end(self) -> None: self.types["alternate"] +=3D generate_content_from_dict(self.alter= nates) self.types["struct"] +=3D generate_content_from_dict(self.structs) self.types["union"] +=3D generate_content_from_dict(self.unions) - self.types["event"] +=3D generate_template_event(self.events) + + evtype, eviface =3D generate_template_event(self.events) + self.types["event"] +=3D evtype + self.interfaces["event"] +=3D eviface =20 def visit_object_type( self, @@ -1318,3 +1342,11 @@ def write(self, outdir: str) -> None: =20 with open(pathname, "w", encoding=3D"utf8") as outfile: outfile.write(content) + + # Interfaces to be generated + for qapitype, content in self.interfaces.items(): + gofile =3D f"gen_iface_{qapitype}.go" + pathname =3D os.path.join(targetpath, gofile) + + with open(pathname, "w", encoding=3D"utf8") as outfile: + outfile.write(content) --=20 2.48.1