[{"id":24451,"web_url":"https://patchwork.libcamera.org/comment/24451/","msgid":"<YvGykD/8a4Dz3ZuO@pendragon.ideasonboard.com>","date":"2022-08-09T01:04:16","subject":"Re: [libcamera-devel] [PATCH 2/9] utils: ipc: Add support for enums\n\tin function parameters","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Paul,\n\nThank you for the patch.\n\nOn Wed, Aug 03, 2022 at 08:21:43PM +0900, Paul Elder via libcamera-devel wrote:\n> There is already support for enums as struct members, but there was no\n> support for enums in function parameters. Add it.\n> \n> This does not add support for returning enums as direct return values.\n> \n> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n> ---\n>  .../libcamera_templates/proxy_functions.tmpl        | 13 +++++++++++--\n>  1 file changed, 11 insertions(+), 2 deletions(-)\n> \n> diff --git a/utils/ipc/generators/libcamera_templates/proxy_functions.tmpl b/utils/ipc/generators/libcamera_templates/proxy_functions.tmpl\n> index bac826a7..dc35620f 100644\n> --- a/utils/ipc/generators/libcamera_templates/proxy_functions.tmpl\n> +++ b/utils/ipc/generators/libcamera_templates/proxy_functions.tmpl\n> @@ -59,7 +59,11 @@\n>  {%- else %}\n>  \tstd::tie({{param.mojom_name}}Buf, std::ignore) =\n>  {%- endif %}\n> +{%- if param|is_enum %}\n> +\t\tIPADataSerializer<uint32_t>::serialize(static_cast<uint32_t>({{param.mojom_name}})\n\nC++ has a concept of underlying type for enumerations (see\nhttps://en.cppreference.com/w/cpp/language/enum and\nhttps://en.cppreference.com/w/cpp/types/underlying_type). We could use\nthat to serialize to an integer type suitable for the enum, but I think\nthat's overkill. However, it would be good to make sure we don't\nsilently truncate the value here. A\n\nstatic_assert(sizeof({{param|name_full}}) <= 4);\n\nwould work. It can be placed in either the serialization or\ndeserializatin code, once should be enough. With that,\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> +{%- else %}\n>  \t\tIPADataSerializer<{{param|name}}>::serialize({{param.mojom_name}}\n> +{% endif -%}\n>  {{- \", &controlSerializer_\" if param|needs_control_serializer -}}\n>  );\n>  {%- endfor %}\n> @@ -97,7 +101,12 @@\n>   # This code is meant to be used by macro deserialize_call.\n>   #}\n>  {%- macro deserialize_param(param, pointer, loop, buf, fds, iter, data_size) -%}\n> -{{\"*\" if pointer}}{{param.mojom_name}} = IPADataSerializer<{{param|name}}>::deserialize(\n> +{{\"*\" if pointer}}{{param.mojom_name}} =\n> +{%- if param|is_enum %}\n> +static_cast<{{param|name_full}}>(IPADataSerializer<uint32_t>::deserialize(\n> +{%- else %}\n> +IPADataSerializer<{{param|name}}>::deserialize(\n> +{%- endif %}\n>  \t{{buf}}{{- \".cbegin()\" if not iter}} + {{param.mojom_name}}Start,\n>  {%- if loop.last and not iter %}\n>  \t{{buf}}.cend()\n> @@ -121,7 +130,7 @@\n>  {%- if param|needs_control_serializer %}\n>  \t&controlSerializer_\n>  {%- endif -%}\n> -);\n> +){{\")\" if param|is_enum}};\n>  {%- endmacro -%}\n>  \n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 307B5BE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  9 Aug 2022 01:04:30 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 999546332B;\n\tTue,  9 Aug 2022 03:04:29 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 51F326330E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  9 Aug 2022 03:04:28 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B8574481;\n\tTue,  9 Aug 2022 03:04:27 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1660007069;\n\tbh=oSK9fnrcPHePRHrA9FuccNBQEOEKHy/9lghRYz7T2IA=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=soTyUzQui7K2SL29pF3l1eP5NIxhXE2nn4qjSI3nreJUIXrrk1Ins86tZv0xZQVI8\n\t3kUP92RDVrxkWVqF/K+1F6aqn653Qy9E3sogoHoOW9Z5Ktm55aWVRwe2fRZ9/zjdkE\n\toJryPE8J6XjNx98ZI9QtMZ5fvC5UaJbVnF1IBTeNyOELJ2Oz6PYwVEIkLBLTWPuitk\n\t03/zhe3ipuQwzhYTEPWRQ40ZbriWXzWT58xn4MAPoGO6veZn2aDEVLZGrWu+TrTzPo\n\tLqok9qaHTzXQ4YFXW6mw5EzHUsmFMPzIIm+me8WDJcm1i/3vyp9qk0WtO3H82iOaZU\n\tM5XwsqtuhqJaA==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1660007067;\n\tbh=oSK9fnrcPHePRHrA9FuccNBQEOEKHy/9lghRYz7T2IA=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=XoaFEeRQUVNENb2+Hx7GRCjQsojZLlEHGLeX7aIAJSIbFhNmgpxtLb0opyGOaVmJB\n\taSXKHJQF5dDmXD3kolo+HZ6bZ3Tw8sS94v7f1MWSU4wPIc0OgJmQHA2zJlpPvp88UA\n\ticfwAI2TmsZOHZlhJ4ZPQ8qZZ7AIylJWaHy0nLiI="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"XoaFEeRQ\"; dkim-atps=neutral","Date":"Tue, 9 Aug 2022 04:04:16 +0300","To":"Paul Elder <paul.elder@ideasonboard.com>","Message-ID":"<YvGykD/8a4Dz3ZuO@pendragon.ideasonboard.com>","References":"<20220803112150.3040287-1-paul.elder@ideasonboard.com>\n\t<20220803112150.3040287-3-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20220803112150.3040287-3-paul.elder@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH 2/9] utils: ipc: Add support for enums\n\tin function parameters","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]