From patchwork Mon Aug 29 23:30:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 17242 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 AF95BC3272 for ; Mon, 29 Aug 2022 23:30:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0118A61FCB; Tue, 30 Aug 2022 01:30:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1661815833; bh=MYU606i8EwFZCs3I/T0Dfsm3IbmzvjzvJaVt6A0S0P4=; 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=GC+XO9PdyCaXUpdL9dM09A9fK1RA4dmuuzsTCqhdI3XgRI1Dq1F456IymZNB35Ptt qiHW6J3kglIQawpDfyJ8SWbqY7wXzjdRPUotOsmieS0wFCaqbG7p9SgjTMplQaC8Hs NaL+I+HC4ZPraT0+3QSGo1mmjZujO9hfGqc83s2iR2Kc3xTdAZH2IHrGvX8ngc78OV kPkIuWKjxLkh2KfB3o46SUTDKBdwRUNONZhf+QtHD6pu6IM3M+++dX11WZZHqgzVOE 8PYW6EogQVtuvx93v6L9un4MJpVHDdVgyYXNXUZ0fq3YDuqOni17m/qauY2EL6FV6e onbbBi1y8wg3A== 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 61C7B61FBE for ; Tue, 30 Aug 2022 01:30:29 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="beUjBhYk"; dkim-atps=neutral Received: from pyrite.mediacom.info (unknown [IPv6:2604:2d80:ad8a:9000:1bf9:855b:22de:3645]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 14870481; Tue, 30 Aug 2022 01:30:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1661815828; bh=MYU606i8EwFZCs3I/T0Dfsm3IbmzvjzvJaVt6A0S0P4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=beUjBhYkt8zz7IlJrhQQXrFLSAJ07rINRbEX2HQGHEacnnNfkwScm2B0kYvTFDfzy 02Urmlk4j4TLqBcytdz80x4yUTK8EE/cfnbMeu36woTCddP4L/zoYtdrnGRdgTr61/ gal0nGqFL0wCkzfNeA0RXrn2DVAv8Cpv30eYDd8g= To: libcamera-devel@lists.libcamera.org Date: Mon, 29 Aug 2022 18:30:12 -0500 Message-Id: <20220829233017.2699444-3-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220829233017.2699444-1-paul.elder@ideasonboard.com> References: <20220829233017.2699444-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 2/7] 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 --- 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 -%}