Patch Detail
Show a patch.
GET /api/patches/1562/?format=api
{ "id": 1562, "url": "https://patchwork.libcamera.org/api/patches/1562/?format=api", "web_url": "https://patchwork.libcamera.org/patch/1562/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/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": "<20190701201504.28487-4-laurent.pinchart@ideasonboard.com>", "date": "2019-07-01T20:14:54", "name": "[libcamera-devel,v4,03/13] libcamera: controls: Introduce control-related data types", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "4c33c7ae21c8c3cfe0422af1ea2072d6581d5805", "submitter": { "id": 2, "url": "https://patchwork.libcamera.org/api/people/2/?format=api", "name": "Laurent Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/1562/mbox/", "series": [ { "id": 386, "url": "https://patchwork.libcamera.org/api/series/386/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=386", "date": "2019-07-01T20:14:51", "name": "libcamera Controls", "version": 4, "mbox": "https://patchwork.libcamera.org/series/386/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/1562/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/1562/checks/", "tags": {}, "headers": { "Return-Path": "<laurent.pinchart@ideasonboard.com>", "Received": [ "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 59E436157D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 1 Jul 2019 22:15:29 +0200 (CEST)", "from pendragon.bb.dnainternet.fi\n\t(dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 050F2524\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 1 Jul 2019 22:15:28 +0200 (CEST)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1562012129;\n\tbh=fePYzODQtkZ+kFnmU1Nd6sET7nbOKwIFlU1YHIYKYAs=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=XfcC+EZPFUdA8QuFwY2G7dyAN/Np2d8XPK8LYe50Rpf2znz+7AO6w7Cufmuyui7b1\n\tCyU9HcFWFfPIY16ugcCVsEz71M6ebdrj+Jppl9Bven76pSbPxnLaf4lI8GcPqZOJuW\n\t77z837CHuj4Yc3zmf7KP6tTFnnrhoju2K3yAJCdE=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Mon, 1 Jul 2019 23:14:54 +0300", "Message-Id": "<20190701201504.28487-4-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.21.0", "In-Reply-To": "<20190701201504.28487-1-laurent.pinchart@ideasonboard.com>", "References": "<20190701201504.28487-1-laurent.pinchart@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v4 03/13] libcamera: controls: Introduce\n\tcontrol-related data types", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.23", "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>", "X-List-Received-Date": "Mon, 01 Jul 2019 20:15:29 -0000" }, "content": "From: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\nAdd a set of data types to support controls:\n\n- ControlValue stores a control type and value in a generic way\n- ControlId enumerates all the control identifiers\n- ControlIdentifier declares the types of a control and map their names\n- ControlInfo stores runtime information for controls\n- ControlList contains a set of control info and value pairs\n\nThe control definitions map is generated from the controls documentation\nto ensure that the two will always be synchronised.\n\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\nChanges since v3:\n\n- Typo fixes\n- Optimized the contains() implementation\n- Various documentation updates\n\nChanges since v2:\n\n- Squashed \"Provide ControlValue class\"\n- Renamed Value to ControlValue\n- Removed operator<<()\n- Added control table generation\n- Moved control definitions to control_definitions.h\n- Renamed ControlTypes to controlTypes and make it const\n- Moved the initial controls list to a separate patch\n- Renamed control_definitions.h to control_ids.h and\n control_definitions.cpp to control_types.cpp to match the contained\n enum and variable name respectively\n- Indexed ControlList by ControlInfo pointer instead of value\n- Replaced ControlInfoHash with std::hash specialisation\n- Added automatic conversion between 32- and 64-bit integer values\n\nThe automatic conversion between integer types was prompted by an\nassertion failure due to the use of getInt() on the min() and max()\nvalue of an Integer control. The min and max ControlValue instances are\ncreate as Integer64, due to the V4L2ControlInfo class returning the\nrange as int64_t. This may need to be reworked.\n---\n Documentation/Doxyfile.in | 3 +-\n include/libcamera/control_ids.h | 35 +++\n include/libcamera/controls.h | 134 ++++++++++\n include/libcamera/meson.build | 2 +\n src/libcamera/controls.cpp | 451 ++++++++++++++++++++++++++++++++\n src/libcamera/gen-controls.awk | 106 ++++++++\n src/libcamera/meson.build | 11 +\n 7 files changed, 741 insertions(+), 1 deletion(-)\n create mode 100644 include/libcamera/control_ids.h\n create mode 100644 include/libcamera/controls.h\n create mode 100644 src/libcamera/controls.cpp\n create mode 100755 src/libcamera/gen-controls.awk", "diff": "diff --git a/Documentation/Doxyfile.in b/Documentation/Doxyfile.in\nindex c58631200dd5..9ca32241b895 100644\n--- a/Documentation/Doxyfile.in\n+++ b/Documentation/Doxyfile.in\n@@ -868,7 +868,8 @@ EXCLUDE_SYMBOLS = libcamera::SignalBase \\\n libcamera::SlotArgs \\\n libcamera::SlotBase \\\n libcamera::SlotMember \\\n- libcamera::SlotStatic\n+ libcamera::SlotStatic \\\n+ std::*\n \n # The EXAMPLE_PATH tag can be used to specify one or more files or directories\n # that contain example code fragments that are included (see the \\include\ndiff --git a/include/libcamera/control_ids.h b/include/libcamera/control_ids.h\nnew file mode 100644\nindex 000000000000..d0e700da9844\n--- /dev/null\n+++ b/include/libcamera/control_ids.h\n@@ -0,0 +1,35 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * control_ids.h : Control ID list\n+ */\n+\n+#ifndef __LIBCAMERA_CONTROL_IDS_H__\n+#define __LIBCAMERA_CONTROL_IDS_H__\n+\n+#include <functional>\n+\n+namespace libcamera {\n+\n+enum ControlId {\n+};\n+\n+} /* namespace libcamera */\n+\n+namespace std {\n+\n+template<>\n+struct hash<libcamera::ControlId> {\n+\tusing argument_type = libcamera::ControlId;\n+\tusing result_type = std::size_t;\n+\n+\tresult_type operator()(const argument_type &key) const noexcept\n+\t{\n+\t\treturn std::hash<std::underlying_type<argument_type>::type>()(key);\n+\t}\n+};\n+\n+} /* namespace std */\n+\n+#endif // __LIBCAMERA_CONTROL_IDS_H__\ndiff --git a/include/libcamera/controls.h b/include/libcamera/controls.h\nnew file mode 100644\nindex 000000000000..2206155909ca\n--- /dev/null\n+++ b/include/libcamera/controls.h\n@@ -0,0 +1,134 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * controls.h - Control handling\n+ */\n+\n+#ifndef __LIBCAMERA_CONTROLS_H__\n+#define __LIBCAMERA_CONTROLS_H__\n+\n+#include <stdint.h>\n+#include <string>\n+#include <unordered_map>\n+\n+#include <libcamera/control_ids.h>\n+\n+namespace libcamera {\n+\n+class Camera;\n+\n+enum ControlValueType {\n+\tControlValueNone,\n+\tControlValueBool,\n+\tControlValueInteger,\n+\tControlValueInteger64,\n+};\n+\n+class ControlValue\n+{\n+public:\n+\tControlValue();\n+\tControlValue(bool value);\n+\tControlValue(int value);\n+\tControlValue(int64_t value);\n+\n+\tControlValueType type() const { return type_; };\n+\tbool isNone() const { return type_ == ControlValueNone; };\n+\n+\tvoid set(bool value);\n+\tvoid set(int value);\n+\tvoid set(int64_t value);\n+\n+\tbool getBool() const;\n+\tint getInt() const;\n+\tint64_t getInt64() const;\n+\n+\tstd::string toString() const;\n+\n+private:\n+\tControlValueType type_;\n+\n+\tunion {\n+\t\tbool bool_;\n+\t\tint integer_;\n+\t\tint64_t integer64_;\n+\t};\n+};\n+\n+struct ControlIdentifier {\n+\tControlId id;\n+\tconst char *name;\n+\tControlValueType type;\n+};\n+\n+class ControlInfo\n+{\n+public:\n+\texplicit ControlInfo(ControlId id, const ControlValue &min = 0,\n+\t\t\t const ControlValue &max = 0);\n+\n+\tControlId id() const { return ident_->id; }\n+\tconst char *name() const { return ident_->name; }\n+\tControlValueType type() const { return ident_->type; }\n+\n+\tconst ControlValue &min() const { return min_; }\n+\tconst ControlValue &max() const { return max_; }\n+\n+\tstd::string toString() const;\n+\n+private:\n+\tconst struct ControlIdentifier *ident_;\n+\tControlValue min_;\n+\tControlValue max_;\n+};\n+\n+bool operator==(const ControlInfo &lhs, const ControlInfo &rhs);\n+bool operator==(const ControlId &lhs, const ControlInfo &rhs);\n+bool operator==(const ControlInfo &lhs, const ControlId &rhs);\n+static inline bool operator!=(const ControlInfo &lhs, const ControlInfo &rhs)\n+{\n+\treturn !(lhs == rhs);\n+}\n+static inline bool operator!=(const ControlId &lhs, const ControlInfo &rhs)\n+{\n+\treturn !(lhs == rhs);\n+}\n+static inline bool operator!=(const ControlInfo &lhs, const ControlId &rhs)\n+{\n+\treturn !(lhs == rhs);\n+}\n+\n+class ControlList\n+{\n+private:\n+\tusing ControlListMap = std::unordered_map<const ControlInfo *, ControlValue>;\n+\n+public:\n+\tControlList(Camera *camera);\n+\n+\tusing iterator = ControlListMap::iterator;\n+\tusing const_iterator = ControlListMap::const_iterator;\n+\n+\titerator begin() { return controls_.begin(); }\n+\titerator end() { return controls_.end(); }\n+\tconst_iterator begin() const { return controls_.begin(); }\n+\tconst_iterator end() const { return controls_.end(); }\n+\n+\tbool contains(const ControlInfo *info) const;\n+\tbool empty() const { return controls_.empty(); }\n+\tstd::size_t size() const { return controls_.size(); }\n+\tvoid clear() { controls_.clear(); }\n+\n+\tControlValue &operator[](const ControlInfo *info) { return controls_[info]; }\n+\n+\tvoid update(const ControlList &list);\n+\n+private:\n+\tCamera *camera_;\n+\tControlListMap controls_;\n+};\n+\n+} /* namespace libcamera */\n+\n+#endif /* __LIBCAMERA_CONTROLS_H__ */\ndiff --git a/include/libcamera/meson.build b/include/libcamera/meson.build\nindex 15484724df01..3067120a1598 100644\n--- a/include/libcamera/meson.build\n+++ b/include/libcamera/meson.build\n@@ -2,6 +2,8 @@ libcamera_api = files([\n 'buffer.h',\n 'camera.h',\n 'camera_manager.h',\n+ 'control_ids.h',\n+ 'controls.h',\n 'event_dispatcher.h',\n 'event_notifier.h',\n 'geometry.h',\ndiff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp\nnew file mode 100644\nindex 000000000000..7fac1169cbfd\n--- /dev/null\n+++ b/src/libcamera/controls.cpp\n@@ -0,0 +1,451 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * controls.cpp - Control handling\n+ */\n+\n+#include <libcamera/controls.h>\n+\n+#include <sstream>\n+#include <string>\n+\n+#include \"log.h\"\n+#include \"utils.h\"\n+\n+/**\n+ * \\file controls.h\n+ * \\brief Describes control framework and controls supported by a camera\n+ */\n+\n+namespace libcamera {\n+\n+LOG_DEFINE_CATEGORY(Controls)\n+\n+/**\n+ * \\enum ControlValueType\n+ * \\brief Define the data type of value represented by a ControlValue\n+ * \\var ControlValueNone\n+ * Identifies an unset control value\n+ * \\var ControlValueBool\n+ * Identifies controls storing a boolean value\n+ * \\var ControlValueInteger\n+ * Identifies controls storing an integer value\n+ * \\var ControlValueInteger64\n+ * Identifies controls storing a 64-bit integer value\n+ */\n+\n+/**\n+ * \\class ControlValue\n+ * \\brief Abstract type representing the value of a control\n+ */\n+\n+/**\n+ * \\brief Construct an empty ControlValue.\n+ */\n+ControlValue::ControlValue()\n+\t: type_(ControlValueNone)\n+{\n+}\n+\n+/**\n+ * \\brief Construct a Boolean ControlValue\n+ * \\param[in] value Boolean value to store\n+ */\n+ControlValue::ControlValue(bool value)\n+\t: type_(ControlValueBool), bool_(value)\n+{\n+}\n+\n+/**\n+ * \\brief Construct an integer ControlValue\n+ * \\param[in] value Integer value to store\n+ */\n+ControlValue::ControlValue(int value)\n+\t: type_(ControlValueInteger), integer_(value)\n+{\n+}\n+\n+/**\n+ * \\brief Construct a 64 bit integer ControlValue\n+ * \\param[in] value Integer value to store\n+ */\n+ControlValue::ControlValue(int64_t value)\n+\t: type_(ControlValueInteger64), integer64_(value)\n+{\n+}\n+\n+/**\n+ * \\fn ControlValue::type()\n+ * \\brief Retrieve the data type of the value\n+ * \\return The value data type\n+ */\n+\n+/**\n+ * \\fn ControlValue::isNone()\n+ * \\brief Determine if the value is not initialised\n+ * \\return True if the value type is ControlValueNone, false otherwise\n+ */\n+\n+/**\n+ * \\brief Set the value with a boolean\n+ * \\param[in] value Boolean value to store\n+ */\n+void ControlValue::set(bool value)\n+{\n+\ttype_ = ControlValueBool;\n+\tbool_ = value;\n+}\n+\n+/**\n+ * \\brief Set the value with an integer\n+ * \\param[in] value Integer value to store\n+ */\n+void ControlValue::set(int value)\n+{\n+\ttype_ = ControlValueInteger;\n+\tinteger_ = value;\n+}\n+\n+/**\n+ * \\brief Set the value with a 64 bit integer\n+ * \\param[in] value 64 bit integer value to store\n+ */\n+void ControlValue::set(int64_t value)\n+{\n+\ttype_ = ControlValueInteger64;\n+\tinteger64_ = value;\n+}\n+\n+/**\n+ * \\brief Get the boolean value\n+ *\n+ * The value type must be Boolean.\n+ *\n+ * \\return The boolean value\n+ */\n+bool ControlValue::getBool() const\n+{\n+\tASSERT(type_ == ControlValueBool);\n+\n+\treturn bool_;\n+}\n+\n+/**\n+ * \\brief Get the integer value\n+ *\n+ * The value type must be Integer or Integer64.\n+ *\n+ * \\return The integer value\n+ */\n+int ControlValue::getInt() const\n+{\n+\tASSERT(type_ == ControlValueInteger || type_ == ControlValueInteger64);\n+\n+\treturn integer_;\n+}\n+\n+/**\n+ * \\brief Get the 64-bit integer value\n+ *\n+ * The value type must be Integer or Integer64.\n+ *\n+ * \\return The 64-bit integer value\n+ */\n+int64_t ControlValue::getInt64() const\n+{\n+\tASSERT(type_ == ControlValueInteger || type_ == ControlValueInteger64);\n+\n+\treturn integer64_;\n+}\n+\n+/**\n+ * \\brief Assemble and return a string describing the value\n+ * \\return A string describing the ControlValue\n+ */\n+std::string ControlValue::toString() const\n+{\n+\tswitch (type_) {\n+\tcase ControlValueNone:\n+\t\treturn \"<None>\";\n+\tcase ControlValueBool:\n+\t\treturn bool_ ? \"True\" : \"False\";\n+\tcase ControlValueInteger:\n+\t\treturn std::to_string(integer_);\n+\tcase ControlValueInteger64:\n+\t\treturn std::to_string(integer64_);\n+\t}\n+\n+\treturn \"<ValueType Error>\";\n+}\n+\n+/**\n+ * \\enum ControlId\n+ * \\brief Numerical control ID\n+ */\n+\n+/**\n+ * \\struct ControlIdentifier\n+ * \\brief Describe a ControlId with control specific constant meta-data\n+ *\n+ * Defines a Control with a unique ID, a name, and a type.\n+ * This structure is used as static part of the auto-generated control\n+ * definitions, which are generated from the ControlId documentation.\n+ *\n+ * \\var ControlIdentifier::id\n+ * The unique ID for a control\n+ * \\var ControlIdentifier::name\n+ * The string representation of the control\n+ * \\var ControlIdentifier::type\n+ * The ValueType required to represent the control value\n+ */\n+\n+/*\n+ * The controlTypes are automatically generated to produce a control_types.cpp\n+ * output. This file is not for public use, and so no suitable header exists\n+ * for this sole usage of the controlTypes reference. As such the extern is\n+ * only defined here for use during the ControlInfo constructor and should not\n+ * be referenced directly elsewhere.\n+ */\n+extern const std::unordered_map<ControlId, ControlIdentifier> controlTypes;\n+\n+/**\n+ * \\class ControlInfo\n+ * \\brief Describe the information and capabilities of a Control\n+ *\n+ * The ControlInfo represents control specific meta-data which is constant on a\n+ * per camera basis. ControlInfo classes are constructed by pipeline handlers\n+ * to expose the controls they support and the metadata needed to utilise those\n+ * controls.\n+ */\n+\n+/**\n+ * \\brief Construct a ControlInfo with minimum and maximum range parameters\n+ * \\param[in] id The control ID\n+ * \\param[in] min The control minimum value\n+ * \\param[in] max The control maximum value\n+ */\n+ControlInfo::ControlInfo(ControlId id, const ControlValue &min,\n+\t\t\t const ControlValue &max)\n+\t: min_(min), max_(max)\n+{\n+\tauto iter = controlTypes.find(id);\n+\tif (iter == controlTypes.end()) {\n+\t\tLOG(Controls, Fatal) << \"Attempt to create invalid ControlInfo\";\n+\t\treturn;\n+\t}\n+\n+\tident_ = &iter->second;\n+}\n+\n+/**\n+ * \\fn ControlInfo::id()\n+ * \\brief Retrieve the control ID\n+ * \\return The control ID\n+ */\n+\n+/**\n+ * \\fn ControlInfo::name()\n+ * \\brief Retrieve the control name string\n+ * \\return The control name string\n+ */\n+\n+/**\n+ * \\fn ControlInfo::type()\n+ * \\brief Retrieve the control data type\n+ * \\return The control data type\n+ */\n+\n+/**\n+ * \\fn ControlInfo::min()\n+ * \\brief Retrieve the minimum value of the control\n+ * \\return A ControlValue with the minimum value for the control\n+ */\n+\n+/**\n+ * \\fn ControlInfo::max()\n+ * \\brief Retrieve the maximum value of the control\n+ * \\return A ControlValue with the maximum value for the control\n+ */\n+\n+/**\n+ * \\brief Provide a string representation of the ControlInfo\n+ */\n+std::string ControlInfo::toString() const\n+{\n+\tstd::stringstream ss;\n+\n+\tss << name() << \"[\" << min_.toString() << \"..\" << max_.toString() << \"]\";\n+\n+\treturn ss.str();\n+}\n+\n+/**\n+ * \\brief Compare control information for equality\n+ * \\param[in] lhs Left-hand side control information\n+ * \\param[in] rhs Right-hand side control information\n+ *\n+ * Control information is compared based on the ID only, as a camera may not\n+ * have two separate controls with the same ID.\n+ *\n+ * \\return True if \\a lhs and \\a rhs are equal, false otherwise\n+ */\n+bool operator==(const ControlInfo &lhs, const ControlInfo &rhs)\n+{\n+\treturn lhs.id() == rhs.id();\n+}\n+\n+/**\n+ * \\brief Compare control ID and information for equality\n+ * \\param[in] lhs Left-hand side control identifier\n+ * \\param[in] rhs Right-hand side control information\n+ *\n+ * Control information is compared based on the ID only, as a camera may not\n+ * have two separate controls with the same ID.\n+ *\n+ * \\return True if \\a lhs and \\a rhs are equal, false otherwise\n+ */\n+bool operator==(const ControlId &lhs, const ControlInfo &rhs)\n+{\n+\treturn lhs == rhs.id();\n+}\n+\n+/**\n+ * \\brief Compare control information and ID for equality\n+ * \\param[in] lhs Left-hand side control information\n+ * \\param[in] rhs Right-hand side control identifier\n+ *\n+ * Control information is compared based on the ID only, as a camera may not\n+ * have two separate controls with the same ID.\n+ *\n+ * \\return True if \\a lhs and \\a rhs are equal, false otherwise\n+ */\n+bool operator==(const ControlInfo &lhs, const ControlId &rhs)\n+{\n+\treturn lhs.id() == rhs;\n+}\n+\n+/**\n+ * \\class ControlList\n+ * \\brief Associate a list of ControlId with their values for a camera\n+ *\n+ * A ControlList wraps a map of ControlId to ControlValue and provide\n+ * additional validation against the control information exposed by a Camera.\n+ *\n+ * A list is only valid for as long as the camera it refers to is valid. After\n+ * that calling any method of the ControlList class other than its destructor\n+ * will cause undefined behaviour.\n+ */\n+\n+/**\n+ * \\brief Construct a ControlList with a reference to the Camera it applies on\n+ * \\param[in] camera The camera\n+ */\n+ControlList::ControlList(Camera *camera)\n+\t: camera_(camera)\n+{\n+}\n+\n+/**\n+ * \\typedef ControlList::iterator\n+ * \\brief Iterator for the controls contained within the list\n+ */\n+\n+/**\n+ * \\typedef ControlList::const_iterator\n+ * \\brief Const iterator for the controls contained within the list\n+ */\n+\n+/**\n+ * \\fn iterator ControlList::begin()\n+ * \\brief Retrieve an iterator to the first Control in the list\n+ * \\return An iterator to the first Control in the list\n+ */\n+\n+/**\n+ * \\fn const_iterator ControlList::begin() const\n+ * \\brief Retrieve a const_iterator to the first Control in the list\n+ * \\return A const_iterator to the first Control in the list\n+ */\n+\n+/**\n+ * \\fn iterator ControlList::end()\n+ * \\brief Retrieve an iterator pointing to the past-the-end control in the list\n+ * \\return An iterator to the element following the last control in the list\n+ */\n+\n+/**\n+ * \\fn const_iterator ControlList::end() const\n+ * \\brief Retrieve a const iterator pointing to the past-the-end control in the\n+ * list\n+ * \\return A const iterator to the element following the last control in the\n+ * list\n+ */\n+\n+/**\n+ * \\brief Check if the list contains a control with the specified \\a info\n+ * \\param[in] info The control info\n+ * \\return True if the list contains a matching control, false otherwise\n+ */\n+bool ControlList::contains(const ControlInfo *info) const\n+{\n+\treturn controls_.find(info) != controls_.end();\n+}\n+\n+/**\n+ * \\fn ControlList::empty()\n+ * \\brief Identify if the list is empty\n+ * \\return True if the list does not contain any control, false otherwise\n+ */\n+\n+/**\n+ * \\fn ControlList::size()\n+ * \\brief Retrieve the number of controls in the list\n+ * \\return The number of Control entries stored in the list\n+ */\n+\n+/**\n+ * \\fn ControlList::clear()\n+ * \\brief Removes all controls from the list\n+ */\n+\n+/**\n+ * \\fn ControlList::operator[](const ControlInfo *info)\n+ * \\brief Access or insert the control specified by \\a info\n+ * \\param[in] info The control info\n+ *\n+ * This method returns a reference to the control identified by \\a info,\n+ * inserting it in the list if the info is not already present.\n+ *\n+ * \\return A reference to the value of the control identified by \\a info\n+ */\n+\n+/**\n+ * \\brief Update the list with a union of itself and \\a other\n+ * \\param other The other list\n+ *\n+ * Update the control list to include all values from the \\a other list.\n+ * Elements in the list whose control IDs are contained in \\a other are updated\n+ * with the value from \\a other. Elements in the \\a other list that have no\n+ * corresponding element in the list are added to the list with their value.\n+ *\n+ * The behaviour is undefined if the two lists refer to different Camera\n+ * instances.\n+ */\n+void ControlList::update(const ControlList &other)\n+{\n+\tif (other.camera_ != camera_) {\n+\t\tLOG(Controls, Error)\n+\t\t\t<< \"Can't update ControlList from a different camera\";\n+\t\treturn;\n+\t}\n+\n+\tfor (auto it : other) {\n+\t\tconst ControlInfo *info = it.first;\n+\t\tconst ControlValue &value = it.second;\n+\n+\t\tcontrols_[info] = value;\n+\t}\n+}\n+\n+} /* namespace libcamera */\ndiff --git a/src/libcamera/gen-controls.awk b/src/libcamera/gen-controls.awk\nnew file mode 100755\nindex 000000000000..f3d068123012\n--- /dev/null\n+++ b/src/libcamera/gen-controls.awk\n@@ -0,0 +1,106 @@\n+#!/usr/bin/awk -f\n+\n+# SPDX-License-Identifier: LGPL-2.1-or-later\n+\n+# Controls are documented using Doxygen in the main controls.cpp source.\n+#\n+# Generate control tables directly from the documentation, creating enumerations\n+# to support the IDs and static type information regarding each control.\n+\n+BEGIN {\n+\tid=0\n+\tinput=ARGV[1]\n+\tmode=ARGV[2]\n+\toutput=ARGV[3]\n+}\n+\n+# Detect Doxygen style comment blocks and ignore other lines\n+/^\\/\\*\\*$/ { in_doxygen=1; first_line=1; next }\n+// { if (!in_doxygen) next }\n+\n+# Entry point for the Control Documentation\n+/ * \\\\enum ControlId$/ { in_controls=1; first_line=0; next }\n+// { if (!in_controls) next }\n+\n+# Extract control information\n+/ \\* \\\\var/ { names[++id]=$3; first_line=0; next }\n+/ \\* ControlType:/ { types[id] = $3 }\n+\n+# End of comment blocks\n+/^ \\*\\// { in_doxygen=0 }\n+\n+# Identify the end of controls\n+/^ \\* \\\\/ { if (first_line) exit }\n+// { first_line=0 }\n+\n+################################\n+# Support output file generation\n+\n+function basename(file) {\n+\tsub(\".*/\", \"\", file)\n+\treturn file\n+}\n+\n+function Header(file, description) {\n+\tprint \"/* SPDX-License-Identifier: LGPL-2.1-or-later */\" > file\n+\tprint \"/*\" > file\n+\tprint \" * Copyright (C) 2019, Google Inc.\" > file\n+\tprint \" *\" > file\n+\tprint \" * \" basename(file) \" - \" description > file\n+\tprint \" *\" > file\n+\tprint \" * This file is auto-generated. Do not edit.\" > file\n+\tprint \" */\" > file\n+\tprint \"\" > file\n+}\n+\n+function EnterNameSpace(file) {\n+\tprint \"namespace libcamera {\" > file\n+\tprint \"\" > file\n+}\n+\n+function ExitNameSpace(file) {\n+\tprint \"\" > file\n+\tprint \"} /* namespace libcamera */\" > file\n+}\n+\n+function GenerateHeader(file) {\n+\tHeader(file, \"Control ID list\")\n+\n+\tprint \"#ifndef __LIBCAMERA_CONTROL_IDS_H__\" > file\n+\tprint \"#define __LIBCAMERA_CONTROL_IDS_H__\" > file\n+\tprint \"\" > file\n+\n+\tEnterNameSpace(file)\n+\tprint \"enum ControlId {\" > file\n+\tfor (i=1; i <= id; ++i) {\n+\t\tprintf \"\\t%s,\\n\", names[i] > file\n+\t}\n+\tprint \"};\" > file\n+\tExitNameSpace(file)\n+\n+\tprint \"\" > file\n+\tprint \"#endif // __LIBCAMERA_CONTROL_IDS_H__\" > file\n+}\n+\n+function GenerateTable(file) {\n+\tHeader(file, \"Control types\")\n+\tprint \"#include <libcamera/controls.h>\" > file\n+\tprint \"\" > file\n+\n+\tEnterNameSpace(file)\n+\n+\tprint \"extern const std::unordered_map<ControlId, ControlIdentifier>\" > file\n+\tprint \"controlTypes {\" > file\n+\tfor (i=1; i <= id; ++i) {\n+\t\tprintf \"\\t{ %s, { %s, \\\"%s\\\", ControlValue%s } },\\n\", names[i], names[i], names[i], types[i] > file\n+\t}\n+\tprint \"};\" > file\n+\tExitNameSpace(file)\n+}\n+\n+END {\n+\tif (mode == \"--header\")\n+\t\tGenerateHeader(output)\n+\telse\n+\t\tGenerateTable(output)\n+}\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex 985aa7e8ab0e..b1ee92735e41 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -3,6 +3,7 @@ libcamera_sources = files([\n 'camera.cpp',\n 'camera_manager.cpp',\n 'camera_sensor.cpp',\n+ 'controls.cpp',\n 'device_enumerator.cpp',\n 'device_enumerator_sysfs.cpp',\n 'event_dispatcher.cpp',\n@@ -66,6 +67,16 @@ if libudev.found()\n ])\n endif\n \n+gen_controls = files('gen-controls.awk')\n+\n+control_types_cpp = custom_target('control_types_cpp',\n+ input : files('controls.cpp'),\n+ output : 'control_types.cpp',\n+ depend_files : gen_controls,\n+ command : [gen_controls, '@INPUT@', '--code', '@OUTPUT@'])\n+\n+libcamera_sources += control_types_cpp\n+\n libcamera_deps = [\n cc.find_library('dl'),\n libudev,\n", "prefixes": [ "libcamera-devel", "v4", "03/13" ] }