Patch Detail
Show a patch.
GET /api/patches/2068/?format=api
{ "id": 2068, "url": "https://patchwork.libcamera.org/api/patches/2068/?format=api", "web_url": "https://patchwork.libcamera.org/patch/2068/", "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": "<20190929190254.18920-14-laurent.pinchart@ideasonboard.com>", "date": "2019-09-29T19:02:54", "name": "[libcamera-devel,v2,13/13] libcamera: controls: Use ControlValidator to validate ControlList", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "a4a62a24858d6270bb460a473b8bbe420316428e", "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/2068/mbox/", "series": [ { "id": 512, "url": "https://patchwork.libcamera.org/api/series/512/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=512", "date": "2019-09-29T19:02:41", "name": "Improve the application-facing controls API", "version": 2, "mbox": "https://patchwork.libcamera.org/series/512/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/2068/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/2068/checks/", "tags": {}, "headers": { "Return-Path": "<laurent.pinchart@ideasonboard.com>", "Received": [ "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B033C61964\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 29 Sep 2019 21:03:15 +0200 (CEST)", "from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 49A55813\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 29 Sep 2019 21:03:15 +0200 (CEST)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1569783795;\n\tbh=ZrkAjAayFSXg8FArGn7fWuf5BhX8/3kODKypo7oG+bQ=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=D216+Wy2orli0UwsaevH/0BPyQUlsd1K8Myb6Swau3rk6hzCxd6suDFuxjxwOmZe1\n\t/xFH3Rr8XqF9XJuF+i/mCWOS1rS46EHjhse8Di8USsTOPO0tCjJ4zHvfVjCHTdreb0\n\terJXPc8UEtdYlZayRLyGnVHd9Rqy++8z+Gd+WgtY=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Sun, 29 Sep 2019 22:02:54 +0300", "Message-Id": "<20190929190254.18920-14-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.21.0", "In-Reply-To": "<20190929190254.18920-1-laurent.pinchart@ideasonboard.com>", "References": "<20190929190254.18920-1-laurent.pinchart@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v2 13/13] libcamera: controls: Use\n\tControlValidator to validate ControlList", "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": "Sun, 29 Sep 2019 19:03:16 -0000" }, "content": "Replace the manual validation of controls against a Camera with usage of\nthe new ControlValidator interface.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n include/libcamera/controls.h | 6 +++---\n include/libcamera/request.h | 7 ++++---\n src/libcamera/controls.cpp | 27 ++++++++++-----------------\n src/libcamera/request.cpp | 14 ++++++++++++--\n test/controls/control_list.cpp | 15 ++++++++++++++-\n 5 files changed, 43 insertions(+), 26 deletions(-)", "diff": "diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h\nindex d3eea643c0ec..90426753f40f 100644\n--- a/include/libcamera/controls.h\n+++ b/include/libcamera/controls.h\n@@ -13,7 +13,7 @@\n \n namespace libcamera {\n \n-class Camera;\n+class ControlValidator;\n \n enum ControlType {\n \tControlTypeNone,\n@@ -119,7 +119,7 @@ private:\n \tusing ControlListMap = std::unordered_map<const ControlId *, ControlValue>;\n \n public:\n-\tControlList(Camera *camera);\n+\tControlList(ControlValidator *validator);\n \n \tusing iterator = ControlListMap::iterator;\n \tusing const_iterator = ControlListMap::const_iterator;\n@@ -160,7 +160,7 @@ private:\n \tconst ControlValue *find(const ControlId &id) const;\n \tControlValue *find(const ControlId &id);\n \n-\tCamera *camera_;\n+\tControlValidator *validator_;\n \tControlListMap controls_;\n };\n \ndiff --git a/include/libcamera/request.h b/include/libcamera/request.h\nindex 9edf1cedc054..e3db5243aaf3 100644\n--- a/include/libcamera/request.h\n+++ b/include/libcamera/request.h\n@@ -19,9 +19,9 @@ namespace libcamera {\n \n class Buffer;\n class Camera;\n+class CameraControlValidator;\n class Stream;\n \n-\n class Request\n {\n public:\n@@ -36,7 +36,7 @@ public:\n \tRequest &operator=(const Request &) = delete;\n \t~Request();\n \n-\tControlList &controls() { return controls_; }\n+\tControlList &controls() { return *controls_; }\n \tconst std::map<Stream *, Buffer *> &buffers() const { return bufferMap_; }\n \tint addBuffer(std::unique_ptr<Buffer> buffer);\n \tBuffer *findBuffer(Stream *stream) const;\n@@ -56,7 +56,8 @@ private:\n \tbool completeBuffer(Buffer *buffer);\n \n \tCamera *camera_;\n-\tControlList controls_;\n+\tCameraControlValidator *validator_;\n+\tControlList *controls_;\n \tstd::map<Stream *, Buffer *> bufferMap_;\n \tstd::unordered_set<Buffer *> pending_;\n \ndiff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp\nindex a7e9d069b31a..f3260edce0bc 100644\n--- a/src/libcamera/controls.cpp\n+++ b/src/libcamera/controls.cpp\n@@ -10,8 +10,7 @@\n #include <sstream>\n #include <string>\n \n-#include <libcamera/camera.h>\n-\n+#include \"control_validator.h\"\n #include \"log.h\"\n #include \"utils.h\"\n \n@@ -365,20 +364,16 @@ std::string ControlRange::toString() const\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+ * A ControlList wraps a map of ControlId to ControlValue and optionally\n+ * validates controls against a ControlValidator.\n */\n \n /**\n- * \\brief Construct a ControlList with a reference to the Camera it applies on\n- * \\param[in] camera The camera\n+ * \\brief Construct a ControlList with an optional control validator\n+ * \\param[in] validator The validator (may be null)\n */\n-ControlList::ControlList(Camera *camera)\n-\t: camera_(camera)\n+ControlList::ControlList(ControlValidator *validator)\n+\t: validator_(validator)\n {\n }\n \n@@ -493,12 +488,10 @@ const ControlValue *ControlList::find(const ControlId &id) const\n \n ControlValue *ControlList::find(const ControlId &id)\n {\n-\tconst ControlInfoMap &controls = camera_->controls();\n-\tconst auto iter = controls.find(&id);\n-\tif (iter == controls.end()) {\n+\tif (validator_ && !validator_->validate(id)) {\n \t\tLOG(Controls, Error)\n-\t\t\t<< \"Camera \" << camera_->name()\n-\t\t\t<< \" does not support control \" << id.name();\n+\t\t\t<< \"Control \" << id.name()\n+\t\t\t<< \" is not valid for \" << validator_->name();\n \t\treturn nullptr;\n \t}\n \ndiff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp\nindex ee2158fc7a9c..19f6d0b9a0ae 100644\n--- a/src/libcamera/request.cpp\n+++ b/src/libcamera/request.cpp\n@@ -13,6 +13,7 @@\n #include <libcamera/camera.h>\n #include <libcamera/stream.h>\n \n+#include \"camera_controls.h\"\n #include \"log.h\"\n \n /**\n@@ -55,9 +56,15 @@ LOG_DEFINE_CATEGORY(Request)\n *\n */\n Request::Request(Camera *camera, uint64_t cookie)\n-\t: camera_(camera), controls_(camera), cookie_(cookie),\n-\t status_(RequestPending), cancelled_(false)\n+\t: camera_(camera), cookie_(cookie), status_(RequestPending),\n+\t cancelled_(false)\n {\n+\t/**\n+\t * \\todo Should the Camera expose a validator instance, to avoid\n+\t * creating a new instance for each request?\n+\t */\n+\tvalidator_ = new CameraControlValidator(camera);\n+\tcontrols_ = new ControlList(validator_);\n }\n \n Request::~Request()\n@@ -66,6 +73,9 @@ Request::~Request()\n \t\tBuffer *buffer = it.second;\n \t\tdelete buffer;\n \t}\n+\n+\tdelete controls_;\n+\tdelete validator_;\n }\n \n /**\ndiff --git a/test/controls/control_list.cpp b/test/controls/control_list.cpp\nindex 8469ecf09439..1bcfecc467b5 100644\n--- a/test/controls/control_list.cpp\n+++ b/test/controls/control_list.cpp\n@@ -12,6 +12,7 @@\n #include <libcamera/control_ids.h>\n #include <libcamera/controls.h>\n \n+#include \"camera_controls.h\"\n #include \"test.h\"\n \n using namespace std;\n@@ -40,7 +41,8 @@ protected:\n \n \tint run()\n \t{\n-\t\tControlList list(camera_.get());\n+\t\tCameraControlValidator validator(camera_.get());\n+\t\tControlList list(&validator);\n \n \t\t/* Test that the list is initially empty. */\n \t\tif (!list.empty()) {\n@@ -141,6 +143,17 @@ protected:\n \t\t\treturn TestFail;\n \t\t}\n \n+\t\t/*\n+\t\t * Attempt to set an invalid control and verify that the\n+\t\t * operation failed.\n+\t\t */\n+\t\tlist.set(controls::AwbEnable, true);\n+\n+\t\tif (list.contains(controls::AwbEnable)) {\n+\t\t\tcout << \"List shouldn't contain AwbEnable control\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n \t\treturn TestPass;\n \t}\n \n", "prefixes": [ "libcamera-devel", "v2", "13/13" ] }