From patchwork Wed Sep 18 10:31:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 1982 Return-Path: Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CC7E460C1A; Wed, 18 Sep 2019 12:30:03 +0200 (CEST) X-Originating-IP: 2.224.242.101 Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 4DF691BF208; Wed, 18 Sep 2019 10:30:02 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org, To:libcamera-devel@lists.libcamera.org Date: Wed, 18 Sep 2019 12:31:32 +0200 Message-Id: <20190918103133.14296-5-jacopo@jmondi.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190918103133.14296-1-jacopo@jmondi.org> References: <20190918103133.14296-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 4/5] libcamera: controls: De-couple Controls from Camera X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Sep 2019 10:30:04 -0000 ControlList requires a Camera class instance at construction time, preventing it from being re-constructed from serialized binary data. De-couple ControlList from Camera by internally storing a reference to the Camera's ControlInfoList. Signed-off-by: Jacopo Mondi --- include/libcamera/controls.h | 4 +-- src/libcamera/controls.cpp | 54 +++++++++++++++++----------------- src/libcamera/request.cpp | 4 +-- test/controls/control_list.cpp | 4 +-- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index e46cd8a78679..d3065c0f3f16 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -48,7 +48,7 @@ private: using ControlListMap = std::unordered_map; public: - ControlList(Camera *camera); + ControlList(const ControlInfoMap &infoMap); using iterator = ControlListMap::iterator; using const_iterator = ControlListMap::const_iterator; @@ -70,7 +70,7 @@ public: void update(const ControlList &list); private: - Camera *camera_; + const ControlInfoMap &infoMap_; ControlListMap controls_; }; diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index 2d8adde5688e..184d544c05bc 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -175,10 +175,10 @@ std::string ControlInfo::toString() const /** * \brief Construct a ControlList with a reference to the Camera it applies on - * \param[in] camera The camera + * \param[in] infoMap The ControlInfoMap of the camera the control list refers to */ -ControlList::ControlList(Camera *camera) - : camera_(camera) +ControlList::ControlList(const ControlInfoMap &infoMap) + : infoMap_(infoMap) { } @@ -229,17 +229,14 @@ ControlList::ControlList(Camera *camera) */ bool ControlList::contains(ControlId id) const { - const ControlInfoMap &controls = camera_->controls(); - const auto iter = controls.find(id); - if (iter == controls.end()) { - LOG(Controls, Error) - << "Camera " << camera_->name() - << " does not support control " << id; + const auto info = infoMap_.find(id); + if (info == infoMap_.end()) { + LOG(Controls, Error) << "Control " << id << " not supported"; return false; } - return controls_.find(&iter->second) != controls_.end(); + return controls_.find(&info->second) != controls_.end(); } /** @@ -283,18 +280,15 @@ bool ControlList::contains(const ControlInfo *info) const */ DataValue &ControlList::operator[](ControlId id) { - const ControlInfoMap &controls = camera_->controls(); - const auto iter = controls.find(id); - if (iter == controls.end()) { - LOG(Controls, Error) - << "Camera " << camera_->name() - << " does not support control " << id; + const auto info = infoMap_.find(id); + if (info == infoMap_.end()) { + LOG(Controls, Error) << "Control " << id << " not supported"; static DataValue empty; return empty; } - return controls_[&iter->second]; + return controls_[&info->second]; } /** @@ -322,18 +316,24 @@ DataValue &ControlList::operator[](ControlId id) */ void ControlList::update(const ControlList &other) { - if (other.camera_ != camera_) { - LOG(Controls, Error) - << "Can't update ControlList from a different camera"; - return; + /* + * Make sure if all controls in other's list are supported by this + * Camera. This is guaranteed to be true if the two lists refer to + * the same Camera. + */ + for (auto &control : other) { + ControlId id = control.first->id(); + + if (infoMap_.find(id) == infoMap_.end()) { + LOG(Controls, Error) + << "Failed to update control list with control: " + << id; + return; + } } - for (auto it : other) { - const ControlInfo *info = it.first; - const DataValue &value = it.second; - - controls_[info] = value; - } + for (auto &control : other) + controls_[control.first] = control.second; } } /* namespace libcamera */ diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp index ee2158fc7a9c..2b3e1870094e 100644 --- a/src/libcamera/request.cpp +++ b/src/libcamera/request.cpp @@ -55,8 +55,8 @@ LOG_DEFINE_CATEGORY(Request) * */ Request::Request(Camera *camera, uint64_t cookie) - : camera_(camera), controls_(camera), cookie_(cookie), - status_(RequestPending), cancelled_(false) + : camera_(camera), controls_(camera->controls()), + cookie_(cookie), status_(RequestPending), cancelled_(false) { } diff --git a/test/controls/control_list.cpp b/test/controls/control_list.cpp index f1d79ff8fcfd..3c6eb40c091b 100644 --- a/test/controls/control_list.cpp +++ b/test/controls/control_list.cpp @@ -39,7 +39,7 @@ protected: int run() { - ControlList list(camera_.get()); + ControlList list(camera_->controls()); /* Test that the list is initially empty. */ if (!list.empty()) { @@ -155,7 +155,7 @@ protected: * the old list. Verify that the new list is empty and that the * new list contains the expected items and values. */ - ControlList newList(camera_.get()); + ControlList newList(camera_->controls()); newList[Brightness] = 128; newList[Saturation] = 255;