Patch Detail
Show a patch.
GET /api/1.1/patches/21217/?format=api
{ "id": 21217, "url": "https://patchwork.libcamera.org/api/1.1/patches/21217/?format=api", "web_url": "https://patchwork.libcamera.org/patch/21217/", "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": "<20240910180729.2096985-2-paul.elder@ideasonboard.com>", "date": "2024-09-10T18:07:28", "name": "[1/2] libcamera: controls: Add enum names and values map to ControlId", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "6907add4184ef7fa5e9b91d3a4e95a9ff4501639", "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/21217/mbox/", "series": [ { "id": 4575, "url": "https://patchwork.libcamera.org/api/1.1/series/4575/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4575", "date": "2024-09-10T18:07:27", "name": "libcamera: controls: Add enum information to", "version": 1, "mbox": "https://patchwork.libcamera.org/series/4575/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/21217/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/21217/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 6277CC324C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 10 Sep 2024 18:07:50 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0F5A4634FC;\n\tTue, 10 Sep 2024 20:07:47 +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 2C526634F5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 10 Sep 2024 20:07:43 +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 EE0E118E5;\n\tTue, 10 Sep 2024 20:06:25 +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=\"RYNtL4Tf\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1725991586;\n\tbh=hWzvMQlYrOCQ70RdHH4U8zW9lFbfvRGA5TSw6I59YqA=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=RYNtL4TfPjUyWW0oicZPOGGRZHnHiT3brEAilv9nMd56Cg8c52V+qP+CWsDVDCP1z\n\tZlrls12CPqq6lWMeHLQre7v/BW20scvsQMWauo1IVoRZ46eyAS2RraZimmkolJvC9Y\n\tfrm1Jv2/9u9vtgdX14TkCMMFhIKq7oj7i+PnDyCk=", "From": "Paul Elder <paul.elder@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Paul Elder <paul.elder@ideasonboard.com>,\n\tstefan.klug@ideasonboard.com", "Subject": "[PATCH 1/2] libcamera: controls: Add enum names and values map to\n\tControlId", "Date": "Tue, 10 Sep 2024 20:07:28 +0200", "Message-Id": "<20240910180729.2096985-2-paul.elder@ideasonboard.com>", "X-Mailer": "git-send-email 2.39.2", "In-Reply-To": "<20240910180729.2096985-1-paul.elder@ideasonboard.com>", "References": "<20240910180729.2096985-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>\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..407a12256 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> &nameValueMap = {});\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> &nameValueMap() const { return nameValueMap_; }\n+\tconst std::string enumName(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> nameValueMap_;\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> &nameValueMap = {})\n+\t\t: ControlId(id, name, details::control_type<std::remove_cv_t<T>>::value, nameValueMap)\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..1c7e7fde1 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] nameValueMap 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> &nameValueMap)\n+\t: id_(id), name_(name), type_(type), nameValueMap_(nameValueMap)\n+{\n+\tfor (const auto &pair : nameValueMap_)\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::enumName(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::nameValueMap() 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] nameValueMap 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": [ "1/2" ] }