Patch Detail
Show a patch.
GET /api/patches/2054/?format=api
{ "id": 2054, "url": "https://patchwork.libcamera.org/api/patches/2054/?format=api", "web_url": "https://patchwork.libcamera.org/patch/2054/", "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": "<20190928152238.23752-13-laurent.pinchart@ideasonboard.com>", "date": "2019-09-28T15:22:38", "name": "[libcamera-devel,12/12] libcamera: controls: Use ControlValidator to validate ControlList", "commit_ref": null, "pull_url": null, "state": "superseded", "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/2054/mbox/", "series": [ { "id": 511, "url": "https://patchwork.libcamera.org/api/series/511/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=511", "date": "2019-09-28T15:22:26", "name": "Improve the application-facing controls API", "version": 1, "mbox": "https://patchwork.libcamera.org/series/511/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/2054/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/2054/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 681936191B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 28 Sep 2019 17:23:02 +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 9330D729\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 28 Sep 2019 17:23:01 +0200 (CEST)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1569684182;\n\tbh=YEcJBzSAceW2ItSZj3clgO9qB+QO8KyrwqUtu2oXlKQ=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=dY6bUBHNVRqgPO+OUuT1FbDOc702q1oxrBEIN7arE/qoSsMb9GTGueRN2B+KEOXDz\n\tYZlgEv7kYVPs5awSNRbN9CKIwfcJiM/a02+Aaztai7QtQljMRDfwloamNt/2F5cwn+\n\tp3+V7SOdvFYOx6DMfsZnMb1RozeTUB6ebwnAKvb8=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Sat, 28 Sep 2019 18:22:38 +0300", "Message-Id": "<20190928152238.23752-13-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.21.0", "In-Reply-To": "<20190928152238.23752-1-laurent.pinchart@ideasonboard.com>", "References": "<20190928152238.23752-1-laurent.pinchart@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH 12/12] 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": "Sat, 28 Sep 2019 15:23:03 -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 51abb4ea7f6f..f9124ca65e19 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@@ -492,12 +487,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", "12/12" ] }