Show a patch.

GET /api/1.1/patches/21229/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 21229,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/21229/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/21229/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20240911093600.671979-2-paul.elder@ideasonboard.com>",
    "date": "2024-09-11T09:35:58",
    "name": "[v3,1/3] libcamera: controls: Add enum names and values map to ControlId",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "4280235d5165b5e908d447a3be34834c9972b45d",
    "submitter": {
        "id": 17,
        "url": "https://patchwork.libcamera.org/api/1.1/people/17/?format=api",
        "name": "Paul Elder",
        "email": "paul.elder@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/21229/mbox/",
    "series": [
        {
            "id": 4579,
            "url": "https://patchwork.libcamera.org/api/1.1/series/4579/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4579",
            "date": "2024-09-11T09:35:57",
            "name": "libcamera: controls: Add enum information to ControlId",
            "version": 3,
            "mbox": "https://patchwork.libcamera.org/series/4579/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/21229/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/21229/checks/",
    "tags": {},
    "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 AF879C324C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 11 Sep 2024 09:36:23 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 87CC363502;\n\tWed, 11 Sep 2024 11:36:21 +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 F329C634F8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 11 Sep 2024 11:36:17 +0200 (CEST)",
            "from pyrite.hamster-moth.ts.net\n\t(213-229-8-243.static.upcbusiness.at [213.229.8.243])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 368035B3;\n\tWed, 11 Sep 2024 11:35:00 +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=\"NNS1I/OO\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1726047300;\n\tbh=Merarit6R7O+1+scQXD8fxtOfsoykGcNhExOBQXwP+c=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=NNS1I/OOjB7Rqa0HPx5ea6itvd/EC6jWqNW2yF2Vvi4GnQHONEI57R0XcyI7KdRFA\n\tulDhfnVoYQYwh5q0+DZsLB8lUVbTiuVuVMwx6HclLp4WDO3DkDgUQy0AHIQPbXrVCD\n\tR5kb/qKZvNo2sx6jg+aXn7E8pYj4qxTOJmxCvvHM=",
        "From": "Paul Elder <paul.elder@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Paul Elder <paul.elder@ideasonboard.com>, stefan.klug@ideasonboard.com, \n\tUmang Jain <umang.jain@ideasonboard.com>",
        "Subject": "[PATCH v3 1/3] libcamera: controls: Add enum names and values map to\n\tControlId",
        "Date": "Wed, 11 Sep 2024 11:35:58 +0200",
        "Message-Id": "<20240911093600.671979-2-paul.elder@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.39.2",
        "In-Reply-To": "<20240911093600.671979-1-paul.elder@ideasonboard.com>",
        "References": "<20240911093600.671979-1-paul.elder@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "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>"
    },
    "content": "Add to ControlId information about the names and values of enum, in the\nevent that the ControlId is an enum type. This allows applications to\nquery the ControlId for the names of the enum values, so that they can\nbe displayed on a UI, for example. Without this, it was necessary to use\nmacros of NameOfControlNameValueMap, which is difficult to use and is\nvery inflexible.\n\nThe main map is name -> value, as this was necessary for mapping names\nfrom tuning files to enum values. We reuse this generated code to\nreduce complexity, and generate a reverse map from it.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\nReviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n\n---\nChanges in v3:\n- s/nameValueMap/enumStrMap/\n- s/enumName/enumToString/\n\nNo change in v2\n---\n include/libcamera/controls.h     | 15 +++++++++------\n src/libcamera/control_ids.cpp.in |  4 +++-\n src/libcamera/controls.cpp       | 29 +++++++++++++++++++++++++++++\n 3 files changed, 41 insertions(+), 7 deletions(-)",
    "diff": "diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h\nindex 7c2bb2872..8959dfcc2 100644\n--- a/include/libcamera/controls.h\n+++ b/include/libcamera/controls.h\n@@ -8,6 +8,7 @@\n #pragma once\n \n #include <assert.h>\n+#include <map>\n #include <optional>\n #include <set>\n #include <stdint.h>\n@@ -213,14 +214,14 @@ private:\n class ControlId\n {\n public:\n-\tControlId(unsigned int id, const std::string &name, ControlType type)\n-\t\t: id_(id), name_(name), type_(type)\n-\t{\n-\t}\n+\tControlId(unsigned int id, const std::string &name, ControlType type,\n+\t\t  const std::map<std::string, int32_t> &enumStrMap = {});\n \n \tunsigned int id() const { return id_; }\n \tconst std::string &name() const { return name_; }\n \tControlType type() const { return type_; }\n+\tconst std::map<std::string, int32_t> &enumStrMap() const { return enumStrMap_; }\n+\tconst std::string enumToString(int32_t value) const;\n \n private:\n \tLIBCAMERA_DISABLE_COPY_AND_MOVE(ControlId)\n@@ -228,6 +229,8 @@ private:\n \tunsigned int id_;\n \tstd::string name_;\n \tControlType type_;\n+\tstd::map<std::string, int32_t> enumStrMap_;\n+\tstd::map<int32_t, std::string> reverseMap_;\n };\n \n static inline bool operator==(unsigned int lhs, const ControlId &rhs)\n@@ -256,8 +259,8 @@ class Control : public ControlId\n public:\n \tusing type = T;\n \n-\tControl(unsigned int id, const char *name)\n-\t\t: ControlId(id, name, details::control_type<std::remove_cv_t<T>>::value)\n+\tControl(unsigned int id, const char *name, const std::map<std::string, int32_t> &enumStrMap = {})\n+\t\t: ControlId(id, name, details::control_type<std::remove_cv_t<T>>::value, enumStrMap)\n \t{\n \t}\n \ndiff --git a/src/libcamera/control_ids.cpp.in b/src/libcamera/control_ids.cpp.in\nindex 05c8fb385..3a2049311 100644\n--- a/src/libcamera/control_ids.cpp.in\n+++ b/src/libcamera/control_ids.cpp.in\n@@ -89,8 +89,10 @@ extern const std::map<std::string, {{ctrl.type}}> {{ctrl.name}}NameValueMap = {\n \t{ \"{{enum.name}}\", {{enum.name}} },\n {%- endfor %}\n };\n-{% endif -%}\n+extern const Control<{{ctrl.type}}> {{ctrl.name}}({{ctrl.name|snake_case|upper}}, \"{{ctrl.name}}\", {{ctrl.name}}NameValueMap);\n+{% else -%}\n extern const Control<{{ctrl.type}}> {{ctrl.name}}({{ctrl.name|snake_case|upper}}, \"{{ctrl.name}}\");\n+{% endif -%}\n {%- endfor %}\n \n {% if vendor != 'libcamera' %}\ndiff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp\nindex dba744042..0f83139fb 100644\n--- a/src/libcamera/controls.cpp\n+++ b/src/libcamera/controls.cpp\n@@ -7,6 +7,8 @@\n \n #include <libcamera/controls.h>\n \n+#include <algorithm>\n+#include <map>\n #include <sstream>\n #include <string.h>\n #include <string>\n@@ -389,7 +391,15 @@ void ControlValue::reserve(ControlType type, bool isArray, std::size_t numElemen\n  * \\param[in] id The control numerical ID\n  * \\param[in] name The control name\n  * \\param[in] type The control data type\n+ * \\param[in] enumStrMap The map from enum names to values (optional)\n  */\n+ControlId::ControlId(unsigned int id, const std::string &name, ControlType type,\n+\t\t     const std::map<std::string, int32_t> &enumStrMap)\n+\t: id_(id), name_(name), type_(type), enumStrMap_(enumStrMap)\n+{\n+\tfor (const auto &pair : enumStrMap_)\n+\t\treverseMap_[pair.second] = pair.first;\n+}\n \n /**\n  * \\fn unsigned int ControlId::id() const\n@@ -409,6 +419,24 @@ void ControlValue::reserve(ControlType type, bool isArray, std::size_t numElemen\n  * \\return The control data type\n  */\n \n+/**\n+ * \\brief Retrieve the name of an enum value\n+ * \\return The name of the enum value\n+ */\n+const std::string ControlId::enumToString(int32_t value) const\n+{\n+\tif (reverseMap_.find(value) != reverseMap_.end())\n+\t\treturn reverseMap_.at(value);\n+\n+\treturn \"UNKNOWN\";\n+}\n+\n+/**\n+ * \\fn std::map<std::string, int32_t> ControlId::enumStrMap() const\n+ * \\brief Retrieve the map from enum names to enum values (if applicable)\n+ * \\return The map from enum names to enum values\n+ */\n+\n /**\n  * \\fn bool operator==(unsigned int lhs, const ControlId &rhs)\n  * \\brief Compare a ControlId with a control numerical ID\n@@ -459,6 +487,7 @@ void ControlValue::reserve(ControlType type, bool isArray, std::size_t numElemen\n  * \\brief Construct a Control instance\n  * \\param[in] id The control numerical ID\n  * \\param[in] name The control name\n+ * \\param[in] enumStrMap The map from enum names to values (optional)\n  *\n  * The control data type is automatically deduced from the template type T.\n  */\n",
    "prefixes": [
        "v3",
        "1/3"
    ]
}