From patchwork Fri Sep 27 02:44:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 2027 Return-Path: Received: from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net [195.74.38.228]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EE73F61917 for ; Fri, 27 Sep 2019 04:45:26 +0200 (CEST) X-Halon-ID: cc9cfc69-e0d0-11e9-bdc3-005056917a89 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [84.172.88.101]) by bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA id cc9cfc69-e0d0-11e9-bdc3-005056917a89; Fri, 27 Sep 2019 04:45:00 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Fri, 27 Sep 2019 04:44:07 +0200 Message-Id: <20190927024417.725906-4-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190927024417.725906-1-niklas.soderlund@ragnatech.se> References: <20190927024417.725906-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 03/13] libcamera: controls: Allow read only access to control values X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Sep 2019 02:45:27 -0000 Allow the control values in a ControlList to be examined from a const environment. Signed-off-by: Niklas Söderlund --- include/libcamera/controls.h | 1 + src/libcamera/controls.cpp | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index fbb3a62274c64259..eee5ef87b8fd2633 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -124,6 +124,7 @@ public: void clear() { controls_.clear(); } ControlValue &operator[](ControlId id); + const ControlValue &operator[](ControlId id) const; ControlValue &operator[](const ControlInfo *info) { return controls_[info]; } void update(const ControlList &list); diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index 44cb09d9102d93f6..6271a0bd7518dda5 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -523,6 +523,41 @@ ControlValue &ControlList::operator[](ControlId id) return controls_[&iter->second]; } +/** + * \brief Access the control specified by \a id + * \param[in] id The control ID + * + * This method returns a const reference to the control identified by \a id. If + * no such controls is present in the list, a const reference to an empty + * control value is returned. + * + * The behaviour is undefined if the control \a id is not supported by the + * camera that the ControlList refers to. + * + * \return A const reference to the value of the control identified by \a id + */ +const ControlValue &ControlList::operator[](ControlId id) const +{ + const ControlInfoMap &controls = camera_->controls(); + static ControlValue empty; + + const auto camctrl = controls.find(id); + if (camctrl == controls.end()) { + LOG(Controls, Error) + << "Camera " << camera_->name() + << " does not support control " << id; + return empty; + } + + const auto ctrl = controls_.find(&camctrl->second); + if (ctrl == controls_.end()) { + LOG(Controls, Error) << "list does not have control " << id; + return empty; + } + + return ctrl->second; +} + /** * \fn ControlList::operator[](const ControlInfo *info) * \brief Access or insert the control specified by \a info