From patchwork Fri Aug 26 15:44:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 17208 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 BE7FFC0DA4 for ; Fri, 26 Aug 2022 15:44:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 36DD661FCA; Fri, 26 Aug 2022 17:44:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1661528676; bh=IxFSiWGSzsiGxLtILB+AtR6jLdWwt4vkvdZm+aOgHII=; 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=I2//k/zkwdlsA4Nnunofnu3cpIsQEXgSRpnoIF/io684Ev3vAZ5xVlutDvmLR5Imr Cqhph3YWRfJFt6/OnvWKjzHOePGXeyiTRfS6KFvdrrAjnu8V62QGHR84fPomIVYMHa PkmJYeB/yioCOXO15DSV4TEjlQ6/m5hpU+WiMpYojScIoH5Kfz6HWs8c1ObFojn9Oz HSbGEI/No1kgERRKbkGBVbxwoHaZ1sZdXD5MxAvCHgpR9GPuAc5UnLd8S8AhQaEYsX TC4OWJW+xFqEFVtwID7air08I4Ns8Vuoj8GXZ9RHnjIsWqKmb7JJ6fLSLeiVVIyM7F ZdUvkXhn/SJsQ== 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 90E7E61FBB for ; Fri, 26 Aug 2022 17:44:32 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="fzNRvpXs"; 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 850B62B3; Fri, 26 Aug 2022 17:44:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1661528672; bh=IxFSiWGSzsiGxLtILB+AtR6jLdWwt4vkvdZm+aOgHII=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fzNRvpXsxb064MJP/fzOzxZvz4FIkO+yqbR/QDC09IW02XrPXl6t050ED8lsNFQ0F 1TOnWs50SARLBYlnZhH35uR/oE3xjnKBaIlRxN/H1YfASlXRAJ06YTvX/x3NxE62EC 3DtU1AIiLjIeLzVP6IfxKeafj7LzdIAj+YGDl79g= To: libcamera-devel@lists.libcamera.org Date: Fri, 26 Aug 2022 10:44:14 -0500 Message-Id: <20220826154419.4099372-3-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220826154419.4099372-1-paul.elder@ideasonboard.com> References: <20220826154419.4099372-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 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 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 -%}