Show a patch.

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

{
    "id": 2476,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/2476/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/2476/",
    "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": "<20191230155725.28691-1-jacopo@jmondi.org>",
    "date": "2019-12-30T15:57:25",
    "name": "[libcamera-devel] libcamera: controls: Use template in the id-based interface",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "2521abccce44d16c76f81d2d97da636413cbd61e",
    "submitter": {
        "id": 3,
        "url": "https://patchwork.libcamera.org/api/1.1/people/3/?format=api",
        "name": "Jacopo Mondi",
        "email": "jacopo@jmondi.org"
    },
    "delegate": {
        "id": 15,
        "url": "https://patchwork.libcamera.org/api/1.1/users/15/?format=api",
        "username": "jmondi",
        "first_name": "Jacopo",
        "last_name": "Mondi",
        "email": "jacopo@jmondi.org"
    },
    "mbox": "https://patchwork.libcamera.org/patch/2476/mbox/",
    "series": [
        {
            "id": 594,
            "url": "https://patchwork.libcamera.org/api/1.1/series/594/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=594",
            "date": "2019-12-30T15:57:25",
            "name": "[libcamera-devel] libcamera: controls: Use template in the id-based interface",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/594/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/2476/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/2476/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<jacopo@jmondi.org>",
        "Received": [
            "from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net\n\t[217.70.183.198])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2A4296046B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 30 Dec 2019 16:55:10 +0100 (CET)",
            "from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay6-d.mail.gandi.net (Postfix) with ESMTPSA id AB457C000E;\n\tMon, 30 Dec 2019 15:55:09 +0000 (UTC)"
        ],
        "X-Originating-IP": "2.224.242.101",
        "From": "Jacopo Mondi <jacopo@jmondi.org>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Mon, 30 Dec 2019 16:57:25 +0100",
        "Message-Id": "<20191230155725.28691-1-jacopo@jmondi.org>",
        "X-Mailer": "git-send-email 2.24.0",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH] libcamera: controls: Use template in the\n\tid-based interface",
        "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>",
        "X-List-Received-Date": "Mon, 30 Dec 2019 15:55:10 -0000"
    },
    "content": "The ControlList Control<> and id based interfaces to set or get controls\ndiffer in the way they return or receive values. The Control<> based\ninterface allows the usage of raw values, while the id-based interface\nalways goes through ControlValue, resulting in one additional function\ncall in the caller when accessing controls by numerical id.\n\nAlign the two implementations by providing access to raw values for the\nid-based interface.\n\n-       controls.get(V4L2_CID_CONTRAST).get<int32_t>()\n+\tcontrols.get<int32_t>(V4L2_CID_CONTRAST)\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n include/libcamera/controls.h       | 23 ++++++++++++++++++-\n src/libcamera/controls.cpp         | 37 +++++++++++++++++-------------\n test/ipa/ipa_wrappers_test.cpp     |  6 ++---\n test/v4l2_videodevice/controls.cpp | 12 +++++-----\n 4 files changed, 52 insertions(+), 26 deletions(-)",
    "diff": "diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h\nindex b1b73367e874..0b55359890e6 100644\n--- a/include/libcamera/controls.h\n+++ b/include/libcamera/controls.h\n@@ -220,6 +220,18 @@ public:\n \t\treturn val->get<T>();\n \t}\n \n+\ttemplate<typename T>\n+\tconst T &get(unsigned int id) const\n+\t{\n+\t\tconst ControlValue *val = find(id);\n+\t\tif (!val) {\n+\t\t\tstatic T t(0);\n+\t\t\treturn t;\n+\t\t}\n+\n+\t\treturn val->get<T>();\n+\t}\n+\n \ttemplate<typename T>\n \tvoid set(const Control<T> &ctrl, const T &value)\n \t{\n@@ -230,7 +242,16 @@ public:\n \t\tval->set<T>(value);\n \t}\n \n-\tconst ControlValue &get(unsigned int id) const;\n+\ttemplate<typename T>\n+\tvoid set(unsigned int id, const T &value)\n+\t{\n+\t\tControlValue *val = find(id);\n+\t\tif (!val)\n+\t\t\treturn;\n+\n+\t\tval->set<T>(value);\n+\t}\n+\n \tvoid set(unsigned int id, const ControlValue &value);\n \n \tconst ControlInfoMap *infoMap() const { return infoMap_; }\ndiff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp\nindex 7d8a0e97ee3a..78729d55ee29 100644\n--- a/src/libcamera/controls.cpp\n+++ b/src/libcamera/controls.cpp\n@@ -726,6 +726,18 @@ bool ControlList::contains(unsigned int id) const\n  * \\return The control value\n  */\n \n+/**\n+ * \\fn template<typename T> const T &ControlList::get(unsigned int id) const\n+ * \\brief Get the value of control \\a id\n+ * \\param[in] id The control numerical ID\n+ *\n+ * The behaviour is undefined if the control \\a id is not present in the list.\n+ * Use ControlList::contains() to test for the presence of a control in the\n+ * list before retrieving its value.\n+ *\n+ * \\return The control value\n+ */\n+\n /**\n  * \\fn template<typename T> void ControlList::set(const Control<T> &ctrl, const T &value)\n  * \\brief Set the control \\a ctrl value to \\a value\n@@ -741,25 +753,18 @@ bool ControlList::contains(unsigned int id) const\n  */\n \n /**\n- * \\brief Get the value of control \\a id\n- * \\param[in] id The control numerical ID\n+ * \\fn template<typename T> void ControlList::set(unsigned int id, const T &value)\n+ * \\brief Set the value of control \\a id to \\a value\n+ * \\param[in] id The control ID\n+ * \\param[in] value The control value\n  *\n- * The behaviour is undefined if the control \\a id is not present in the list.\n- * Use ControlList::contains() to test for the presence of a control in the\n- * list before retrieving its value.\n+ * This method sets the value of a control in the control list. If the control\n+ * is already present in the list, its value is updated, otherwise it is added\n+ * to the list.\n  *\n- * \\return The control value\n+ * The behaviour is undefined if the control \\a id is not supported by the\n+ * object that the list refers to.\n  */\n-const ControlValue &ControlList::get(unsigned int id) const\n-{\n-\tstatic ControlValue zero;\n-\n-\tconst ControlValue *val = find(id);\n-\tif (!val)\n-\t\treturn zero;\n-\n-\treturn *val;\n-}\n \n /**\n  * \\brief Set the value of control \\a id to \\a value\ndiff --git a/test/ipa/ipa_wrappers_test.cpp b/test/ipa/ipa_wrappers_test.cpp\nindex a1e34ad52317..11fea2ccc506 100644\n--- a/test/ipa/ipa_wrappers_test.cpp\n+++ b/test/ipa/ipa_wrappers_test.cpp\n@@ -181,9 +181,9 @@ public:\n \t\t}\n \n \t\tconst ControlList &controls = data.controls[0];\n-\t\tif (controls.get(V4L2_CID_BRIGHTNESS).get<int32_t>() != 10 ||\n-\t\t    controls.get(V4L2_CID_CONTRAST).get<int32_t>() != 20 ||\n-\t\t    controls.get(V4L2_CID_SATURATION).get<int32_t>() != 30) {\n+\t\tif (controls.get<int32_t>(V4L2_CID_BRIGHTNESS) != 10 ||\n+\t\t    controls.get<int32_t>(V4L2_CID_CONTRAST) != 20 ||\n+\t\t    controls.get<int32_t>(V4L2_CID_SATURATION) != 30) {\n \t\t\tcerr << \"processEvent(): Invalid controls\" << endl;\n \t\t\treturn report(Op_processEvent, TestFail);\n \t\t}\ndiff --git a/test/v4l2_videodevice/controls.cpp b/test/v4l2_videodevice/controls.cpp\nindex 42c653d4435a..e6ab1b4c11bc 100644\n--- a/test/v4l2_videodevice/controls.cpp\n+++ b/test/v4l2_videodevice/controls.cpp\n@@ -57,9 +57,9 @@ protected:\n \t\t\treturn TestFail;\n \t\t}\n \n-\t\tif (ctrls.get(V4L2_CID_BRIGHTNESS).get<int32_t>() == -1 ||\n-\t\t    ctrls.get(V4L2_CID_CONTRAST).get<int32_t>() == -1 ||\n-\t\t    ctrls.get(V4L2_CID_SATURATION).get<int32_t>() == -1) {\n+\t\tif (ctrls.get<int32_t>(V4L2_CID_BRIGHTNESS) == -1 ||\n+\t\t    ctrls.get<int32_t>(V4L2_CID_CONTRAST) == -1 ||\n+\t\t    ctrls.get<int32_t>(V4L2_CID_SATURATION) == -1) {\n \t\t\tcerr << \"Incorrect value for retrieved controls\" << endl;\n \t\t\treturn TestFail;\n \t\t}\n@@ -86,9 +86,9 @@ protected:\n \t\t\treturn TestFail;\n \t\t}\n \n-\t\tif (ctrls.get(V4L2_CID_BRIGHTNESS) != brightness.min() ||\n-\t\t    ctrls.get(V4L2_CID_CONTRAST) != contrast.max() ||\n-\t\t    ctrls.get(V4L2_CID_SATURATION) != saturation.min().get<int32_t>() + 1) {\n+\t\tif (ctrls.get<int32_t>(V4L2_CID_BRIGHTNESS) != brightness.min().get<int32_t>() ||\n+\t\t    ctrls.get<int32_t>(V4L2_CID_CONTRAST) != contrast.max().get<int32_t>() ||\n+\t\t    ctrls.get<int32_t>(V4L2_CID_SATURATION) != saturation.min().get<int32_t>() + 1) {\n \t\t\tcerr << \"Controls not updated when set\" << endl;\n \t\t\treturn TestFail;\n \t\t}\n",
    "prefixes": [
        "libcamera-devel"
    ]
}