From patchwork Wed Aug 28 01:17:03 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: 1871 Return-Path: Received: from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net [195.74.38.229]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8A15D60C18 for ; Wed, 28 Aug 2019 03:17:44 +0200 (CEST) X-Halon-ID: 99af6639-c931-11e9-bdc3-005056917a89 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [95.195.154.80]) by bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA id 99af6639-c931-11e9-bdc3-005056917a89; Wed, 28 Aug 2019 03:17:28 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Wed, 28 Aug 2019 03:17:03 +0200 Message-Id: <20190828011710.32128-7-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.22.1 In-Reply-To: <20190828011710.32128-1-niklas.soderlund@ragnatech.se> References: <20190828011710.32128-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 06/13] libcamera: controls: Allow read only access to control values 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, 28 Aug 2019 01:17:44 -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 | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 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 54efef1bb337e945..424fe515fa69f8d8 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -517,6 +517,40 @@ ControlValue &ControlList::operator[](ControlId id) return controls_[&iter->second]; } +/** + * \brief Access a control specified by \a id + * \param[in] id The control ID + * + * This method returns a reference to the control identified by \a id, if it + * exsists or an empty control if it does not. + * + * The behaviour is undefined if the control \a id is not supported by the + * camera that the ControlList refers to. + * + * \return A 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 iter = controls.find(id); + if (iter == controls.end()) { + LOG(Controls, Error) + << "Camera " << camera_->name() + << " does not support control " << id; + return empty; + } + + const auto it = controls_.find(&iter->second); + if (it == controls_.end()) { + LOG(Controls, Error) << "list does not have control " << id; + return empty; + } + + return it->second; +} + /** * \fn ControlList::operator[](const ControlInfo *info) * \brief Access or insert the control specified by \a info