From patchwork Tue Oct 11 10:58:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 17580 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 347E8C0DA4 for ; Tue, 11 Oct 2022 10:59:18 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D75A462D79; Tue, 11 Oct 2022 12:59:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1665485957; bh=KizrgP6O/mGAbSVLFZLKJWcEI65LDo/w8QgFS5JqgOw=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=QVhEtJKIK9MeNiXieZpi600wtyJlw/Kqw17C5WOqvqepUldMUEobofCs1OLZIg1qF w/89MVAWwV+PeYk5hhLFmQjCTMyYSZRp6fu0Niqc2excklKyP2Y/vN1GCXwr9EcYuf G/8E/s6bEkykjlFjdnw95B9Yd1IZ62XJE1tbuLLDp0L+c7pTPF9kp7ihw8EdIPvpHy Sa/SMUuZVBApQf0NRT3V6ZUhVDtbxR6wS2Z8hi8fTYvfl+iGHQjj+cHjcjeRUeUUP8 q1sC2Bg+YIKqA8Gwa7RVQZZZ6S5OEhLlLyfFwZ92HSnQoFgr/M/99jpMEL9QQPparL uxSq99p83m6dw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E739062D4E for ; Tue, 11 Oct 2022 12:59:16 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="H0VsiKH9"; dkim-atps=neutral Received: from pyrite.rasen.tech (h175-177-042-159.catv02.itscom.jp [175.177.42.159]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2D2E5143F; Tue, 11 Oct 2022 12:59:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1665485956; bh=KizrgP6O/mGAbSVLFZLKJWcEI65LDo/w8QgFS5JqgOw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H0VsiKH9Bi8DqzlvRi50nEvldd9LQvjuLWO/l7J/iEyR0f18T0FDrLfwZllNyRFji qyBu+jQMghrOKU0a8+7GJyQZ+i7Ta5Y3pCWsZ3hO+fl9Oes8OiSskRXUskIPL1jNuF bNklv0+HIMG8mslJjalqz65FzY8SI5zU4qpN/BuE= To: libcamera-devel@lists.libcamera.org Date: Tue, 11 Oct 2022 19:58:52 +0900 Message-Id: <20221011105859.457567-3-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221011105859.457567-1-paul.elder@ideasonboard.com> References: <20221011105859.457567-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 2/9] utils: ipc: Add support for enums in function parameters X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Paul Elder via libcamera-devel From: Paul Elder Reply-To: Paul Elder Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" There is already support for enums as struct members, but there was no support for enums in function parameters. Add it. This does not add support for returning enums as direct return values. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- No change in v5 No change in v4 No change in v3 Changes in v2: - add static assertion to confirm that the enum type fits in int32_t --- .../libcamera_templates/proxy_functions.tmpl | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/utils/ipc/generators/libcamera_templates/proxy_functions.tmpl b/utils/ipc/generators/libcamera_templates/proxy_functions.tmpl index bac826a7..cbcfb64a 100644 --- a/utils/ipc/generators/libcamera_templates/proxy_functions.tmpl +++ b/utils/ipc/generators/libcamera_templates/proxy_functions.tmpl @@ -52,6 +52,9 @@ #} {%- macro serialize_call(params, buf, fds) %} {%- for param in params %} +{%- if param|is_enum %} + static_assert(sizeof({{param|name_full}}) <= 4); +{%- endif %} std::vector {{param.mojom_name}}Buf; {%- if param|has_fd %} std::vector {{param.mojom_name}}Fds; @@ -59,7 +62,11 @@ {%- else %} std::tie({{param.mojom_name}}Buf, std::ignore) = {%- endif %} +{%- if param|is_enum %} + IPADataSerializer::serialize(static_cast({{param.mojom_name}}) +{%- else %} IPADataSerializer<{{param|name}}>::serialize({{param.mojom_name}} +{% endif -%} {{- ", &controlSerializer_" if param|needs_control_serializer -}} ); {%- endfor %} @@ -97,7 +104,12 @@ # This code is meant to be used by macro deserialize_call. #} {%- macro deserialize_param(param, pointer, loop, buf, fds, iter, data_size) -%} -{{"*" if pointer}}{{param.mojom_name}} = IPADataSerializer<{{param|name}}>::deserialize( +{{"*" if pointer}}{{param.mojom_name}} = +{%- if param|is_enum %} +static_cast<{{param|name_full}}>(IPADataSerializer::deserialize( +{%- else %} +IPADataSerializer<{{param|name}}>::deserialize( +{%- endif %} {{buf}}{{- ".cbegin()" if not iter}} + {{param.mojom_name}}Start, {%- if loop.last and not iter %} {{buf}}.cend() @@ -121,7 +133,7 @@ {%- if param|needs_control_serializer %} &controlSerializer_ {%- endif -%} -); +){{")" if param|is_enum}}; {%- endmacro -%}