Show a patch.

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

{
    "id": 1373,
    "url": "https://patchwork.libcamera.org/api/patches/1373/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/1373/",
    "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": "<20190606205654.9311-2-kieran.bingham@ideasonboard.com>",
    "date": "2019-06-06T20:56:50",
    "name": "[libcamera-devel,RFC,1/5] libcamera: Add control handling",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "f4ff7958a8c20042602da29296c968adf36f1c1b",
    "submitter": {
        "id": 4,
        "url": "https://patchwork.libcamera.org/api/people/4/?format=api",
        "name": "Kieran Bingham",
        "email": "kieran.bingham@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/1373/mbox/",
    "series": [
        {
            "id": 340,
            "url": "https://patchwork.libcamera.org/api/series/340/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=340",
            "date": "2019-06-06T20:56:49",
            "name": "Libcamera Controls",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/340/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/1373/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/1373/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<kieran.bingham@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 4AC9F64092\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  6 Jun 2019 22:56:58 +0200 (CEST)",
            "from localhost.localdomain\n\t(cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id C47BB549;\n\tThu,  6 Jun 2019 22:56:57 +0200 (CEST)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1559854617;\n\tbh=6I1PCG8fdueE3foNeBpttwGWSJJaHxOnK9M2uP+NVxw=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=QhAffW+1GRlGVN8ElvtMM4BBLMDzRb/lIjUSucl6IzNrqu5l3duks1Ut9/PazAe6y\n\t+o7LGkfwhMvD8OTGOI22D7/KKVdoyfo392GzITnWUB7+3IxbmxXJLaiJxVdcJNc/i/\n\tlMOZNWyWDiw7pt1VIm7vAuGDkALGoIMZT5knOTtI=",
        "From": "Kieran Bingham <kieran.bingham@ideasonboard.com>",
        "To": "LibCamera Devel <libcamera-devel@lists.libcamera.org>",
        "Date": "Thu,  6 Jun 2019 21:56:50 +0100",
        "Message-Id": "<20190606205654.9311-2-kieran.bingham@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.20.1",
        "In-Reply-To": "<20190606205654.9311-1-kieran.bingham@ideasonboard.com>",
        "References": "<20190606205654.9311-1-kieran.bingham@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [RFC PATCH 1/5] libcamera: Add control handling",
        "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": "Thu, 06 Jun 2019 20:56:58 -0000"
    },
    "content": "---\n include/libcamera/controls.h  | 106 ++++++++++++\n include/libcamera/meson.build |   1 +\n src/libcamera/controls.cpp    | 310 ++++++++++++++++++++++++++++++++++\n src/libcamera/meson.build     |   1 +\n 4 files changed, 418 insertions(+)\n create mode 100644 include/libcamera/controls.h\n create mode 100644 src/libcamera/controls.cpp",
    "diff": "diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h\nnew file mode 100644\nindex 000000000000..0b751aa7a9d2\n--- /dev/null\n+++ b/include/libcamera/controls.h\n@@ -0,0 +1,106 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * controls.h - Control handling\n+ */\n+#ifndef __LIBCAMERA_CONTROLS_H__\n+#define __LIBCAMERA_CONTROLS_H__\n+\n+#include <map>\n+#include <set>\n+\n+namespace libcamera {\n+\n+enum ControlId : uint32_t {\n+\t/* IPA Controls */\n+\tIpaAwbEnable,\n+\n+\t/* Manual Controls */\n+\tManualBrightness,\n+\tManualExposure,\n+\tManualGain,\n+};\n+\n+enum ControlType : uint32_t {\n+\tControlBool,\n+\tControlInteger,\n+\tControlString,\n+};\n+\n+enum ControlAction : uint8_t {\n+\tControlWrite = 1,\n+\tControlRead = 2,\n+\tControlWriteRead = 3,\n+};\n+\n+class ControlValue\n+{\n+public:\n+\tControlValue(enum ControlType type);\n+\tControlValue(bool value);\n+\tControlValue(int value);\n+\tControlValue(const char *value);\n+\tControlValue(const std::string &value);\n+\n+\tControlType type() const { return type_; };\n+\n+\tbool isRead() const { return action_ == ControlRead ||\n+\t\t\t\t     action_ == ControlWriteRead; };\n+\tbool isWrite() const { return action_ == ControlWrite ||\n+\t\t\t\t      action_ == ControlWriteRead; };\n+\n+\tvoid set(bool value);\n+\tvoid set(int value);\n+\tvoid set(unsigned int value);\n+\n+\tvoid set(const char *value);\n+\tvoid set(const std::string &value);\n+\n+\tbool getBool() const;\n+\tint getInt() const;\n+\tstd::string getString() const;\n+\n+\tstd::string toString() const;\n+\n+private:\n+\tControlType type_;\n+\tControlAction action_;\n+\n+\tunion {\n+\t\tbool bool_;\n+\t\tint integer_;\n+\t};\n+\tstd::string string_;\n+};\n+\n+std::ostream &operator<<(std::ostream &stream, const ControlValue &value);\n+\n+class Control\n+{\n+public:\n+\t/* Create a Read control */\n+\tControl(ControlId id);\n+\n+\t/* Create a Write control */\n+\tControl(ControlId id, bool value);\n+\tControl(ControlId id, int value);\n+\n+\tControlId id() const { return id_; };\n+\tControlValue &value() { return value_; };\n+\n+\tstd::string toString() const;\n+\n+\t/* Overloaded for std::set usage */\n+\tbool operator<(const Control &rhs) const { return id_ < rhs.id_; };\n+\n+private:\n+\tControlId id_;\n+\tControlValue value_;\n+};\n+\n+std::ostream &operator<<(std::ostream &stream, const Control &control);\n+\n+} /* namespace libcamera */\n+\n+#endif /* __LIBCAMERA_CONTROLS_H__ */\ndiff --git a/include/libcamera/meson.build b/include/libcamera/meson.build\nindex 1fcf6b509a1e..6a69db60b3c9 100644\n--- a/include/libcamera/meson.build\n+++ b/include/libcamera/meson.build\n@@ -1,5 +1,6 @@\n libcamera_api = files([\n     'buffer.h',\n+    'controls.h',\n     'camera.h',\n     'camera_manager.h',\n     'event_dispatcher.h',\ndiff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp\nnew file mode 100644\nindex 000000000000..bef0ddcc89a3\n--- /dev/null\n+++ b/src/libcamera/controls.cpp\n@@ -0,0 +1,310 @@\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 <map>\n+#include <string>\n+\n+#include <libcamera/controls.h>\n+\n+#include \"log.h\"\n+\n+/**\n+ * \\file controls.h\n+ * \\brief Describes all controls supported by a camera\n+ */\n+\n+namespace libcamera {\n+\n+LOG_DEFINE_CATEGORY(ControlId)\n+\n+/**\n+ * \\enum Controls\n+ * Control Identifiers\n+ * \\var IpaAwbEnable\n+ * bool: Enables or disables the AWB\n+ * \\var ManualExposure\n+ * Manually control the exposure time in milli-seconds\n+ * \\var ManualGain\n+ * Controls the value of the manual gain setting\n+ */\n+\n+/**\n+ * \\enum ControlType\n+ * Determines the type of value represented by a \\a ControlValue\n+ * \\var ControlBool\n+ * Identifies controls storing a boolean value\n+ * \\var ControlInteger\n+ * Identifies controls storing an integer value\n+ * \\var ControlString\n+ * Identifies controls storing a string value.\n+ */\n+\n+/**\n+ * \\enum ControlAction\n+ * Declare the intent of the ControlValue.\n+ * \\var ControlNoop\n+ * The ControlValue has not been given an action to perform. It can exist as\n+ * part of the request, but will not be acted upon by the device.\n+ * \\var ControlWrite\n+ * The ControlValue is to be given and set at the camera\n+ * \\var ControlRead\n+ * The ControlValue is to be read from the camera\n+ * \\var ControlWriteRead\n+ * The ControlValue should be written to the camera and read before request\n+ * completion\n+ */\n+\n+/*\n+ * Two sets of tables are generated for the control definitions.\n+ *\n+ * An enum to declare the ID (in controls.h), and a type to establish its\n+ * representation.\n+ *\n+ * Todo: Automate the generation of both tables from a single input table.\n+ */\n+struct ControlIdentifier {\n+\tControlId id;\n+\tconst char *name;\n+\tControlType type;\n+} static const ControlTypes[] = {\n+#define CONTROL_TYPE(_id, _type) { _id, #_id, _type }\n+\n+\tCONTROL_TYPE(IpaAwbEnable,\t\tControlBool),\n+\tCONTROL_TYPE(ManualBrightness,\t\tControlInteger),\n+\tCONTROL_TYPE(ManualExposure,\t\tControlInteger),\n+\tCONTROL_TYPE(ManualGain,\t\tControlInteger),\n+\n+#undef CONTROL_TYPE\n+};\n+\n+static struct ControlIdentifier FindControlType(ControlId id)\n+{\n+\tfor (auto ident : ControlTypes) {\n+\t\tif (ident.id == id)\n+\t\t\treturn ident;\n+\t}\n+\n+\tLOG(ControlId, Fatal) << \"Failed to find a ControlType.\";\n+\n+\t/* Unreachable. */\n+\treturn {};\n+}\n+\n+static ControlType GetControlType(ControlId id)\n+{\n+\treturn FindControlType(id).type;\n+}\n+\n+static std::string ControlIDName(ControlId id)\n+{\n+\treturn FindControlType(id).name;\n+}\n+\n+/**\n+ * \\brief Construct a ControlValue of a given type without initialising a value\n+ * \\param[in] type The type of ControlValue to be read\n+ */\n+ControlValue::ControlValue(ControlType type)\n+\t: type_(type), action_(ControlRead)\n+{\n+}\n+\n+/**\n+ * \\brief Construct a Boolean Control Value\n+ * \\param[in] value Boolean value to store\n+ */\n+ControlValue::ControlValue(bool value)\n+\t: type_(ControlBool), action_(ControlWrite), bool_(value)\n+{\n+}\n+\n+/**\n+ * \\brief Construct an integer Control Value\n+ * \\param[in] value Integer value to store\n+ */\n+ControlValue::ControlValue(int value)\n+\t: type_(ControlInteger), action_(ControlWrite), integer_(value)\n+{\n+}\n+\n+/**\n+ * \\brief Construct a string Control Value\n+ * \\param[in] value String representation to store\n+ */\n+ControlValue::ControlValue(const char *value)\n+\t: type_(ControlString), action_(ControlWrite), string_(value)\n+{\n+}\n+\n+/**\n+ * \\brief Construct a string Control Value\n+ * \\param[in] value String representation to store\n+ */\n+ControlValue::ControlValue(const std::string &value)\n+\t: type_(ControlString), action_(ControlWrite), string_(value)\n+{\n+}\n+\n+/**\n+ * \\brief Set the Control value with a boolean\n+ * \\param[in] value Boolean value to store\n+ */\n+void ControlValue::set(bool value)\n+{\n+\tASSERT(type_ == ControlBool);\n+\n+\tbool_ = value;\n+}\n+\n+/**\n+ * \\brief Set the Control value with an integer\n+ * \\param[in] value Integer value to store\n+ */\n+void ControlValue::set(int value)\n+{\n+\tASSERT(type_ == ControlInteger);\n+\n+\tinteger_ = value;\n+}\n+\n+/**\n+ * \\brief Set the Control value with a string representation\n+ * \\param[in] value String value to store\n+ */\n+void ControlValue::set(const char *value)\n+{\n+\tASSERT(type_ == ControlString);\n+\n+\tstring_ = value;\n+}\n+\n+/**\n+ * \\brief Set the Control value with a string representation\n+ * \\param[in] value String value to store\n+ */\n+void ControlValue::set(const std::string &value)\n+{\n+\tASSERT(type_ == ControlString);\n+\n+\tstring_ = value;\n+}\n+\n+/**\n+ * \\brief Get the Control value.\n+ *\n+ * The ControlValue type must be Boolean.\n+ */\n+bool ControlValue::getBool() const\n+{\n+\tASSERT(type_ == ControlBool);\n+\n+\treturn bool_;\n+}\n+\n+/**\n+ * \\brief Get the Control value.\n+ *\n+ * The ControlValue type must be Integer.\n+ */\n+int ControlValue::getInt() const\n+{\n+\tASSERT(type_ == ControlInteger);\n+\n+\treturn integer_;\n+}\n+\n+/**\n+ * \\brief Get the Control value.\n+ *\n+ * The ControlValue type must be String.\n+ */\n+std::string ControlValue::getString() const\n+{\n+\tASSERT(type_ == ControlString);\n+\n+\treturn string_;\n+}\n+\n+/**\n+ * \\brief Prepare a string representation of the ControlValue\n+ */\n+std::string ControlValue::toString() const\n+{\n+\tswitch (type_) {\n+\tcase ControlBool:\n+\t\treturn bool_ ? \"True\" : \"False\";\n+\tcase ControlInteger:\n+\t\treturn std::to_string(integer_);\n+\tcase ControlString:\n+\t\treturn string_;\n+\t}\n+\n+\t/* Unreachable */\n+\treturn \"<ControlType Error>\";\n+}\n+\n+std::ostream &operator<<(std::ostream &stream, const ControlValue &value)\n+{\n+\treturn stream << value.toString();\n+}\n+\n+\n+/**\n+ * \\brief Create a new empty control\n+ * \\param[in] id ID of the new control\n+ *\n+ * The control is constructed, and the type determined by the \\a ControlId.\n+ */\n+Control::Control(ControlId id)\n+\t: id_(id), value_(GetControlType(id))\n+{\n+}\n+\n+/**\n+ * \\brief Create a new control\n+ * \\param[in] id ID of the new control\n+ * \\param[in] value Boolean value to apply to the new control\n+ *\n+ * The control is constructed, and the type determined by the \\a ControlId.\n+ */\n+Control::Control(ControlId id, bool value)\n+\t: id_(id), value_(value)\n+{\n+\tASSERT(GetControlType(id) == ControlBool);\n+}\n+\n+/**\n+ * \\brief Create a new control\n+ * \\param[in] id ID of the new control\n+ * \\param[in] value Integer value to apply to the new control\n+ *\n+ * The control is constructed, and the type determined by the \\a ControlId.\n+ */\n+Control::Control(ControlId id, int value)\n+\t: id_(id), value_(value)\n+{\n+\tASSERT(GetControlType(id) == ControlInteger);\n+}\n+\n+/**\n+ * \\brief Prepare a string representation of the Control\n+ */\n+std::string Control::toString() const\n+{\n+\tstd::stringstream ss;\n+\n+\tss << \"Control: \" << ControlIDName(id_) << \" : \" << value_;\n+\n+\treturn ss.str();\n+}\n+\n+std::ostream &operator<<(std::ostream &stream, const Control &control)\n+{\n+\treturn stream << control.toString();\n+}\n+\n+} /* namespace libcamera */\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex fa1fbcb5faf5..7c67fdf3691a 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",
    "prefixes": [
        "libcamera-devel",
        "RFC",
        "1/5"
    ]
}