[{"id":29052,"web_url":"https://patchwork.libcamera.org/comment/29052/","msgid":"<20240325160142.dthdvcociz5zlnvq@jasper>","date":"2024-03-25T16:01:42","subject":"Re: [PATCH 02/10] libcamera: controls: Generate enum value-name maps","submitter":{"id":184,"url":"https://patchwork.libcamera.org/api/people/184/","name":"Stefan Klug","email":"stefan.klug@ideasonboard.com"},"content":"Hi Daniel,\n\nthank you for the patch.\n\nOn Fri, Mar 22, 2024 at 01:14:43PM +0000, Daniel Scally wrote:\n> Generate maps associating control enumerated control values with a\n> string representing that value to provide a central reference for\n> them across all pipeline handlers.\n\nI think\ns/control enumerated control/enumerated control/ \n\nOtherwise, it looks good to me.\n\nReviewed-by: Stefan Klug <stefan.klug@ideasonboard.com> \n\nCheers,\nStefan\n\n> \n> Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>\n> ---\n>  include/libcamera/control_ids.h.in  |  2 ++\n>  include/libcamera/property_ids.h.in |  2 ++\n>  utils/gen-controls.py               | 19 +++++++++++++++++++\n>  3 files changed, 23 insertions(+)\n> \n> diff --git a/include/libcamera/control_ids.h.in b/include/libcamera/control_ids.h.in\n> index d53b1cf7..58dd48e1 100644\n> --- a/include/libcamera/control_ids.h.in\n> +++ b/include/libcamera/control_ids.h.in\n> @@ -10,7 +10,9 @@\n>  #pragma once\n>  \n>  #include <array>\n> +#include <map>\n>  #include <stdint.h>\n> +#include <string>\n>  \n>  #include <libcamera/controls.h>\n>  \n> diff --git a/include/libcamera/property_ids.h.in b/include/libcamera/property_ids.h.in\n> index 43372c71..f51ba028 100644\n> --- a/include/libcamera/property_ids.h.in\n> +++ b/include/libcamera/property_ids.h.in\n> @@ -9,7 +9,9 @@\n>  \n>  #pragma once\n>  \n> +#include <map>\n>  #include <stdint.h>\n> +#include <string>\n>  \n>  #include <libcamera/controls.h>\n>  \n> diff --git a/utils/gen-controls.py b/utils/gen-controls.py\n> index 6cd5e362..4fe1e705 100755\n> --- a/utils/gen-controls.py\n> +++ b/utils/gen-controls.py\n> @@ -140,6 +140,12 @@ ${description}\n>   */''')\n>      enum_values_start = string.Template('''extern const std::array<const ControlValue, ${size}> ${name}Values = {''')\n>      enum_values_values = string.Template('''\\tstatic_cast<int32_t>(${name}),''')\n> +    name_value_map_doc = string.Template('''/**\n> + * \\\\var ${name}NameValueMap\n> + * \\\\brief Map of all $name supported value names (in std::string format) to value\n> + */''')\n> +    name_value_map_start = string.Template('''extern const std::map<std::string, ${type}> ${name}NameValueMap = {''')\n> +    name_value_values = string.Template('''\\t{ \"${name}\", ${name} },''')\n>  \n>      ctrls_doc = {}\n>      ctrls_def = {}\n> @@ -183,6 +189,7 @@ ${description}\n>  \n>              values_info = {\n>                  'name': info['name'],\n> +                'type': ctrl.type,\n>                  'size': num_entries,\n>              }\n>              target_doc.append(enum_values_doc.substitute(values_info))\n> @@ -194,6 +201,15 @@ ${description}\n>                  target_def.append(enum_values_values.substitute(value_info))\n>              target_def.append(\"};\")\n>  \n> +            target_doc.append(name_value_map_doc.substitute(values_info))\n> +            target_def.append(name_value_map_start.substitute(values_info))\n> +            for enum in ctrl.enum_values:\n> +                value_info = {\n> +                    'name': enum.name\n> +                }\n> +                target_def.append(name_value_values.substitute(value_info))\n> +            target_def.append(\"};\")\n> +\n>          target_doc.append(doc_template.substitute(info))\n>          target_def.append(def_template.substitute(info))\n>  \n> @@ -231,6 +247,7 @@ def generate_h(controls, mode, ranges):\n>      enum_template_start = string.Template('''enum ${name}Enum {''')\n>      enum_value_template = string.Template('''\\t${name} = ${value},''')\n>      enum_values_template = string.Template('''extern const std::array<const ControlValue, ${size}> ${name}Values;''')\n> +    name_value_map_template = string.Template('''extern const std::map<std::string, ${type}> ${name}NameValueMap;''')\n>      template = string.Template('''extern const Control<${type}> ${name};''')\n>  \n>      ctrls = {}\n> @@ -273,9 +290,11 @@ def generate_h(controls, mode, ranges):\n>  \n>              values_info = {\n>                  'name': info['name'],\n> +                'type': ctrl.type,\n>                  'size': num_entries,\n>              }\n>              target_ctrls.append(enum_values_template.substitute(values_info))\n> +            target_ctrls.append(name_value_map_template.substitute(values_info))\n>  \n>          target_ctrls.append(template.substitute(info))\n>          id_value[vendor] += 1\n> -- \n> 2.34.1\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 2FE73C0DA4\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 25 Mar 2024 16:01:48 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 511C7632EA;\n\tMon, 25 Mar 2024 17:01:47 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id EAF0763036\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 25 Mar 2024 17:01:45 +0100 (CET)","from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:585a:15d7:7ede:ea8c])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id C3F897E4;\n\tMon, 25 Mar 2024 17:01:14 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"eyiQXrCj\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1711382474;\n\tbh=AX3TrYgavoW/GctbC7xVXnX0/HFxB5h2TSBTLZW5w+M=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=eyiQXrCjm0Yfose6yTMZp6bAz7uyxNd1vLFffOtOjMG/rT/Lt07MYxWQmQf7gMnsh\n\teQGpJA+faBXx9jDsU7HKIlLRRUiIxm3jdQOBaSP7dqIITWGG1kGXgfbRlJhgfHdxen\n\tVMyQTciv4neIbl06CK2YSLmX2WCi8bLkhWajacus=","Date":"Mon, 25 Mar 2024 17:01:42 +0100","From":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"Daniel Scally <dan.scally@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH 02/10] libcamera: controls: Generate enum value-name maps","Message-ID":"<20240325160142.dthdvcociz5zlnvq@jasper>","References":"<20240322131451.3092931-1-dan.scally@ideasonboard.com>\n\t<20240322131451.3092931-3-dan.scally@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20240322131451.3092931-3-dan.scally@ideasonboard.com>","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":29053,"web_url":"https://patchwork.libcamera.org/comment/29053/","msgid":"<2p3j6y2zqcqn4usv5bkby3o5r6myrdbjxhydo65ti2zfh4zjjf@7mp7zh7zc2ao>","date":"2024-03-25T16:01:55","subject":"Re: [PATCH 02/10] libcamera: controls: Generate enum value-name maps","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"content":"Hi Dan\n\nOn Fri, Mar 22, 2024 at 01:14:43PM +0000, Daniel Scally wrote:\n> Generate maps associating control enumerated control values with a\ns/control enumerated control values/enumerated control values/ ?\n\n> string representing that value to provide a central reference for\n> them across all pipeline handlers.\n\nAs noticed by Kieran, it would be nice to expand a bit on what this\nwould be used for\n\n>\n> Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>\n> ---\n>  include/libcamera/control_ids.h.in  |  2 ++\n>  include/libcamera/property_ids.h.in |  2 ++\n>  utils/gen-controls.py               | 19 +++++++++++++++++++\n>  3 files changed, 23 insertions(+)\n\nI like this\n\nThe only alternative proposal would be to unify the ControlValue and\nthe name string into a struct and enumerate them in a single array\nto make sure they stay in sync.\n\nBut since this is auto-generated and adjusting all users of the *Values\narray is probably a big job, I'm not sure it's even worth considering the\nalternative proposal.\n\nWhat you have here is more than fine!\n\nReviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n\n>\n> diff --git a/include/libcamera/control_ids.h.in b/include/libcamera/control_ids.h.in\n> index d53b1cf7..58dd48e1 100644\n> --- a/include/libcamera/control_ids.h.in\n> +++ b/include/libcamera/control_ids.h.in\n> @@ -10,7 +10,9 @@\n>  #pragma once\n>\n>  #include <array>\n> +#include <map>\n>  #include <stdint.h>\n> +#include <string>\n>\n>  #include <libcamera/controls.h>\n>\n> diff --git a/include/libcamera/property_ids.h.in b/include/libcamera/property_ids.h.in\n> index 43372c71..f51ba028 100644\n> --- a/include/libcamera/property_ids.h.in\n> +++ b/include/libcamera/property_ids.h.in\n> @@ -9,7 +9,9 @@\n>\n>  #pragma once\n>\n> +#include <map>\n>  #include <stdint.h>\n> +#include <string>\n>\n>  #include <libcamera/controls.h>\n>\n> diff --git a/utils/gen-controls.py b/utils/gen-controls.py\n> index 6cd5e362..4fe1e705 100755\n> --- a/utils/gen-controls.py\n> +++ b/utils/gen-controls.py\n> @@ -140,6 +140,12 @@ ${description}\n>   */''')\n>      enum_values_start = string.Template('''extern const std::array<const ControlValue, ${size}> ${name}Values = {''')\n>      enum_values_values = string.Template('''\\tstatic_cast<int32_t>(${name}),''')\n> +    name_value_map_doc = string.Template('''/**\n> + * \\\\var ${name}NameValueMap\n> + * \\\\brief Map of all $name supported value names (in std::string format) to value\n> + */''')\n> +    name_value_map_start = string.Template('''extern const std::map<std::string, ${type}> ${name}NameValueMap = {''')\n> +    name_value_values = string.Template('''\\t{ \"${name}\", ${name} },''')\n>\n>      ctrls_doc = {}\n>      ctrls_def = {}\n> @@ -183,6 +189,7 @@ ${description}\n>\n>              values_info = {\n>                  'name': info['name'],\n> +                'type': ctrl.type,\n>                  'size': num_entries,\n>              }\n>              target_doc.append(enum_values_doc.substitute(values_info))\n> @@ -194,6 +201,15 @@ ${description}\n>                  target_def.append(enum_values_values.substitute(value_info))\n>              target_def.append(\"};\")\n>\n> +            target_doc.append(name_value_map_doc.substitute(values_info))\n> +            target_def.append(name_value_map_start.substitute(values_info))\n> +            for enum in ctrl.enum_values:\n> +                value_info = {\n> +                    'name': enum.name\n> +                }\n> +                target_def.append(name_value_values.substitute(value_info))\n> +            target_def.append(\"};\")\n> +\n>          target_doc.append(doc_template.substitute(info))\n>          target_def.append(def_template.substitute(info))\n>\n> @@ -231,6 +247,7 @@ def generate_h(controls, mode, ranges):\n>      enum_template_start = string.Template('''enum ${name}Enum {''')\n>      enum_value_template = string.Template('''\\t${name} = ${value},''')\n>      enum_values_template = string.Template('''extern const std::array<const ControlValue, ${size}> ${name}Values;''')\n> +    name_value_map_template = string.Template('''extern const std::map<std::string, ${type}> ${name}NameValueMap;''')\n>      template = string.Template('''extern const Control<${type}> ${name};''')\n>\n>      ctrls = {}\n> @@ -273,9 +290,11 @@ def generate_h(controls, mode, ranges):\n>\n>              values_info = {\n>                  'name': info['name'],\n> +                'type': ctrl.type,\n>                  'size': num_entries,\n>              }\n>              target_ctrls.append(enum_values_template.substitute(values_info))\n> +            target_ctrls.append(name_value_map_template.substitute(values_info))\n>\n>          target_ctrls.append(template.substitute(info))\n>          id_value[vendor] += 1\n> --\n> 2.34.1\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 33C57C0DA4\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 25 Mar 2024 16:02:00 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id DB0A96331B;\n\tMon, 25 Mar 2024 17:01:59 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D6ED06303D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 25 Mar 2024 17:01:58 +0100 (CET)","from ideasonboard.com (93-61-96-190.ip145.fastwebnet.it\n\t[93.61.96.190])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id D72F07E4;\n\tMon, 25 Mar 2024 17:01:27 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"nPHpSrvm\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1711382488;\n\tbh=8hYg6gdTJeSjplwcQv4BQcgt8hdMrvdtgKWw8YI73no=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=nPHpSrvmfsIp62jPegi14jNV0jcjttmU0ekJpNUoEw/X/UwhstJMKPnxB4s3evyls\n\tsxD1sn6Yj0HLYhCL1B65UQtOAE0SyRDaurqLPKP4Jym7YZaoOvMRKwEGI/26pOEFos\n\tuxGmAcmpCLE/d8rEyHj7djLjF3xVPO4CntapeMVo=","Date":"Mon, 25 Mar 2024 17:01:55 +0100","From":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","To":"Daniel Scally <dan.scally@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH 02/10] libcamera: controls: Generate enum value-name maps","Message-ID":"<2p3j6y2zqcqn4usv5bkby3o5r6myrdbjxhydo65ti2zfh4zjjf@7mp7zh7zc2ao>","References":"<20240322131451.3092931-1-dan.scally@ideasonboard.com>\n\t<20240322131451.3092931-3-dan.scally@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20240322131451.3092931-3-dan.scally@ideasonboard.com>","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":29163,"web_url":"https://patchwork.libcamera.org/comment/29163/","msgid":"<20240405213942.GI12507@pendragon.ideasonboard.com>","date":"2024-04-05T21:39:42","subject":"Re: [PATCH 02/10] libcamera: controls: Generate enum value-name maps","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Mon, Mar 25, 2024 at 05:01:55PM +0100, Jacopo Mondi wrote:\n> Hi Dan\n> \n> On Fri, Mar 22, 2024 at 01:14:43PM +0000, Daniel Scally wrote:\n> > Generate maps associating control enumerated control values with a\n> s/control enumerated control values/enumerated control values/ ?\n> \n> > string representing that value to provide a central reference for\n> > them across all pipeline handlers.\n> \n> As noticed by Kieran, it would be nice to expand a bit on what this\n> would be used for\n\nI was going to mention the same :-) A good commit message needs to\ninclude *why* a change is needed and desirable. Describing what it does\nis secondary to the reason.\n\n> > Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>\n> > ---\n> >  include/libcamera/control_ids.h.in  |  2 ++\n> >  include/libcamera/property_ids.h.in |  2 ++\n> >  utils/gen-controls.py               | 19 +++++++++++++++++++\n> >  3 files changed, 23 insertions(+)\n> \n> I like this\n> \n> The only alternative proposal would be to unify the ControlValue and\n> the name string into a struct and enumerate them in a single array\n> to make sure they stay in sync.\n> \n> But since this is auto-generated and adjusting all users of the *Values\n> array is probably a big job, I'm not sure it's even worth considering the\n> alternative proposal.\n> \n> What you have here is more than fine!\n> \n> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> \n> > diff --git a/include/libcamera/control_ids.h.in b/include/libcamera/control_ids.h.in\n> > index d53b1cf7..58dd48e1 100644\n> > --- a/include/libcamera/control_ids.h.in\n> > +++ b/include/libcamera/control_ids.h.in\n> > @@ -10,7 +10,9 @@\n> >  #pragma once\n> >\n> >  #include <array>\n> > +#include <map>\n> >  #include <stdint.h>\n> > +#include <string>\n> >\n> >  #include <libcamera/controls.h>\n> >\n> > diff --git a/include/libcamera/property_ids.h.in b/include/libcamera/property_ids.h.in\n> > index 43372c71..f51ba028 100644\n> > --- a/include/libcamera/property_ids.h.in\n> > +++ b/include/libcamera/property_ids.h.in\n> > @@ -9,7 +9,9 @@\n> >\n> >  #pragma once\n> >\n> > +#include <map>\n> >  #include <stdint.h>\n> > +#include <string>\n> >\n> >  #include <libcamera/controls.h>\n> >\n> > diff --git a/utils/gen-controls.py b/utils/gen-controls.py\n> > index 6cd5e362..4fe1e705 100755\n> > --- a/utils/gen-controls.py\n> > +++ b/utils/gen-controls.py\n> > @@ -140,6 +140,12 @@ ${description}\n> >   */''')\n> >      enum_values_start = string.Template('''extern const std::array<const ControlValue, ${size}> ${name}Values = {''')\n> >      enum_values_values = string.Template('''\\tstatic_cast<int32_t>(${name}),''')\n> > +    name_value_map_doc = string.Template('''/**\n> > + * \\\\var ${name}NameValueMap\n> > + * \\\\brief Map of all $name supported value names (in std::string format) to value\n> > + */''')\n> > +    name_value_map_start = string.Template('''extern const std::map<std::string, ${type}> ${name}NameValueMap = {''')\n> > +    name_value_values = string.Template('''\\t{ \"${name}\", ${name} },''')\n\nWe should really switch to jinja templates, this is harder to read (no a\nprerequisite for this series).\n\n> >\n> >      ctrls_doc = {}\n> >      ctrls_def = {}\n> > @@ -183,6 +189,7 @@ ${description}\n> >\n> >              values_info = {\n> >                  'name': info['name'],\n> > +                'type': ctrl.type,\n> >                  'size': num_entries,\n> >              }\n> >              target_doc.append(enum_values_doc.substitute(values_info))\n> > @@ -194,6 +201,15 @@ ${description}\n> >                  target_def.append(enum_values_values.substitute(value_info))\n> >              target_def.append(\"};\")\n> >\n> > +            target_doc.append(name_value_map_doc.substitute(values_info))\n> > +            target_def.append(name_value_map_start.substitute(values_info))\n> > +            for enum in ctrl.enum_values:\n> > +                value_info = {\n> > +                    'name': enum.name\n> > +                }\n> > +                target_def.append(name_value_values.substitute(value_info))\n> > +            target_def.append(\"};\")\n> > +\n> >          target_doc.append(doc_template.substitute(info))\n> >          target_def.append(def_template.substitute(info))\n> >\n> > @@ -231,6 +247,7 @@ def generate_h(controls, mode, ranges):\n> >      enum_template_start = string.Template('''enum ${name}Enum {''')\n> >      enum_value_template = string.Template('''\\t${name} = ${value},''')\n> >      enum_values_template = string.Template('''extern const std::array<const ControlValue, ${size}> ${name}Values;''')\n> > +    name_value_map_template = string.Template('''extern const std::map<std::string, ${type}> ${name}NameValueMap;''')\n> >      template = string.Template('''extern const Control<${type}> ${name};''')\n> >\n> >      ctrls = {}\n> > @@ -273,9 +290,11 @@ def generate_h(controls, mode, ranges):\n> >\n> >              values_info = {\n> >                  'name': info['name'],\n> > +                'type': ctrl.type,\n> >                  'size': num_entries,\n> >              }\n> >              target_ctrls.append(enum_values_template.substitute(values_info))\n> > +            target_ctrls.append(name_value_map_template.substitute(values_info))\n> >\n> >          target_ctrls.append(template.substitute(info))\n> >          id_value[vendor] += 1","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 A5AB9BD16B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  5 Apr 2024 21:39:55 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D7B5761C29;\n\tFri,  5 Apr 2024 23:39:54 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9EAD461C29\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  5 Apr 2024 23:39:53 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 8FE14ACB;\n\tFri,  5 Apr 2024 23:39:14 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"trFAwQzn\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1712353154;\n\tbh=QqlETNNVN7hPDff+bPai5q9PanbMymDMVwzQEqImxMc=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=trFAwQznXQdgh7Md3jjPju6NFFS6nJVTN81mO3j+7LM8673AD2GYzDeIwHVz46Sv3\n\t0Pf07EHJOy0o2B4SsHiAnKDusB+u767hdN8zJwOAPlz16UhPvnSg48NaEC3ZWFF8LJ\n\tCr+dUg9f6PcbbyN2TsGq6QHYwLsD+ss1k/Gmvruw=","Date":"Sat, 6 Apr 2024 00:39:42 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Cc":"Daniel Scally <dan.scally@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH 02/10] libcamera: controls: Generate enum value-name maps","Message-ID":"<20240405213942.GI12507@pendragon.ideasonboard.com>","References":"<20240322131451.3092931-1-dan.scally@ideasonboard.com>\n\t<20240322131451.3092931-3-dan.scally@ideasonboard.com>\n\t<2p3j6y2zqcqn4usv5bkby3o5r6myrdbjxhydo65ti2zfh4zjjf@7mp7zh7zc2ao>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<2p3j6y2zqcqn4usv5bkby3o5r6myrdbjxhydo65ti2zfh4zjjf@7mp7zh7zc2ao>","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":29175,"web_url":"https://patchwork.libcamera.org/comment/29175/","msgid":"<ZhOXQbFchA3I2d7a@pyrite.rasen.tech>","date":"2024-04-08T07:05:37","subject":"Re: [PATCH 02/10] libcamera: controls: Generate enum value-name maps","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"content":"Hi Dan,\n\nOn Fri, Mar 22, 2024 at 01:14:43PM +0000, Daniel Scally wrote:\n> Generate maps associating control enumerated control values with a\n> string representing that value to provide a central reference for\n> them across all pipeline handlers.\n> \n> Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>\n\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n> ---\n>  include/libcamera/control_ids.h.in  |  2 ++\n>  include/libcamera/property_ids.h.in |  2 ++\n>  utils/gen-controls.py               | 19 +++++++++++++++++++\n>  3 files changed, 23 insertions(+)\n> \n> diff --git a/include/libcamera/control_ids.h.in b/include/libcamera/control_ids.h.in\n> index d53b1cf7..58dd48e1 100644\n> --- a/include/libcamera/control_ids.h.in\n> +++ b/include/libcamera/control_ids.h.in\n> @@ -10,7 +10,9 @@\n>  #pragma once\n>  \n>  #include <array>\n> +#include <map>\n>  #include <stdint.h>\n> +#include <string>\n>  \n>  #include <libcamera/controls.h>\n>  \n> diff --git a/include/libcamera/property_ids.h.in b/include/libcamera/property_ids.h.in\n> index 43372c71..f51ba028 100644\n> --- a/include/libcamera/property_ids.h.in\n> +++ b/include/libcamera/property_ids.h.in\n> @@ -9,7 +9,9 @@\n>  \n>  #pragma once\n>  \n> +#include <map>\n>  #include <stdint.h>\n> +#include <string>\n>  \n>  #include <libcamera/controls.h>\n>  \n> diff --git a/utils/gen-controls.py b/utils/gen-controls.py\n> index 6cd5e362..4fe1e705 100755\n> --- a/utils/gen-controls.py\n> +++ b/utils/gen-controls.py\n> @@ -140,6 +140,12 @@ ${description}\n>   */''')\n>      enum_values_start = string.Template('''extern const std::array<const ControlValue, ${size}> ${name}Values = {''')\n>      enum_values_values = string.Template('''\\tstatic_cast<int32_t>(${name}),''')\n> +    name_value_map_doc = string.Template('''/**\n> + * \\\\var ${name}NameValueMap\n> + * \\\\brief Map of all $name supported value names (in std::string format) to value\n> + */''')\n> +    name_value_map_start = string.Template('''extern const std::map<std::string, ${type}> ${name}NameValueMap = {''')\n> +    name_value_values = string.Template('''\\t{ \"${name}\", ${name} },''')\n>  \n>      ctrls_doc = {}\n>      ctrls_def = {}\n> @@ -183,6 +189,7 @@ ${description}\n>  \n>              values_info = {\n>                  'name': info['name'],\n> +                'type': ctrl.type,\n>                  'size': num_entries,\n>              }\n>              target_doc.append(enum_values_doc.substitute(values_info))\n> @@ -194,6 +201,15 @@ ${description}\n>                  target_def.append(enum_values_values.substitute(value_info))\n>              target_def.append(\"};\")\n>  \n> +            target_doc.append(name_value_map_doc.substitute(values_info))\n> +            target_def.append(name_value_map_start.substitute(values_info))\n> +            for enum in ctrl.enum_values:\n> +                value_info = {\n> +                    'name': enum.name\n> +                }\n> +                target_def.append(name_value_values.substitute(value_info))\n> +            target_def.append(\"};\")\n> +\n>          target_doc.append(doc_template.substitute(info))\n>          target_def.append(def_template.substitute(info))\n>  \n> @@ -231,6 +247,7 @@ def generate_h(controls, mode, ranges):\n>      enum_template_start = string.Template('''enum ${name}Enum {''')\n>      enum_value_template = string.Template('''\\t${name} = ${value},''')\n>      enum_values_template = string.Template('''extern const std::array<const ControlValue, ${size}> ${name}Values;''')\n> +    name_value_map_template = string.Template('''extern const std::map<std::string, ${type}> ${name}NameValueMap;''')\n>      template = string.Template('''extern const Control<${type}> ${name};''')\n>  \n>      ctrls = {}\n> @@ -273,9 +290,11 @@ def generate_h(controls, mode, ranges):\n>  \n>              values_info = {\n>                  'name': info['name'],\n> +                'type': ctrl.type,\n>                  'size': num_entries,\n>              }\n>              target_ctrls.append(enum_values_template.substitute(values_info))\n> +            target_ctrls.append(name_value_map_template.substitute(values_info))\n>  \n>          target_ctrls.append(template.substitute(info))\n>          id_value[vendor] += 1\n> -- \n> 2.34.1\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 AADF0C0DA4\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  8 Apr 2024 07:05:47 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5927E63354;\n\tMon,  8 Apr 2024 09:05:47 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B47B76333B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  8 Apr 2024 09:05:45 +0200 (CEST)","from pyrite.rasen.tech (h175-177-049-156.catv02.itscom.jp\n\t[175.177.49.156])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 2473B231;\n\tMon,  8 Apr 2024 09:05:03 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"lSwi2YCi\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1712559905;\n\tbh=PI6TzVgHa2Dok3fb+lK3rci7F9t+BQZldRP3QeZ8kSo=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=lSwi2YCi6HdtA4X39upHdylsK8qzCZQp5d8rVIWlel0ub7Q4+FQq2WC8OMZw5gf57\n\t7Bz8A6YPawtmYDDaVUnrFHpHXR+fnVhXilnQwjBocsml8StcxWHzuDFdPW/Ta66bOU\n\tGQ1tueulGkrn7aFLUC8qMYUD5CzIO6hTcdwHEZLI=","Date":"Mon, 8 Apr 2024 16:05:37 +0900","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"Daniel Scally <dan.scally@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH 02/10] libcamera: controls: Generate enum value-name maps","Message-ID":"<ZhOXQbFchA3I2d7a@pyrite.rasen.tech>","References":"<20240322131451.3092931-1-dan.scally@ideasonboard.com>\n\t<20240322131451.3092931-3-dan.scally@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20240322131451.3092931-3-dan.scally@ideasonboard.com>","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]