From patchwork Mon Oct 7 22:46:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2130 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B764560E1F for ; Tue, 8 Oct 2019 00:46:52 +0200 (CEST) Received: from pendragon.ideasonboard.com (modemcable118.64-20-96.mc.videotron.ca [96.20.64.118]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D8A8AB2D for ; Tue, 8 Oct 2019 00:46:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1570488412; bh=l7hpykS7uvEgF6n4GRYEzSmexVZKkNXXwkjQMQ9sanY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=fqx2TNzQJwROO85aGJHCNvRVDfGp2CDQR46+9xDDgbTQbtNS/Amv7goupFnUe/ftU IogNbMg4bVIKk4xL4XBnMey4TLa0DausB70sYEUfyWJgcOf8AGpnP/73+ANosTfqx5 FUwo1oJ5k3xMxGmCJQXRXlojKLDp/VX1mZ+NzMaU= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 8 Oct 2019 01:46:35 +0300 Message-Id: <20191007224642.6597-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191007224642.6597-1-laurent.pinchart@ideasonboard.com> References: <20191007224642.6597-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/9] libcamera: controls: Support getting and setting controls by ControlId 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: Mon, 07 Oct 2019 22:46:53 -0000 The ControlList class has template get() and set() methods to get and set control values. The methods require a reference to a Control instance, which is only available when calling them with a hardcoded control. In order to support serialisation and deserialisation of ControlList, we need a way to get and set control values based on a ControlId. Add new get() and set() overload methods to do so. Signed-off-by: Laurent Pinchart --- include/libcamera/controls.h | 3 +++ src/libcamera/controls.cpp | 46 ++++++++++++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index 90426753f40f..49ff1a6f747f 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -156,6 +156,9 @@ public: val->set(value); } + const ControlValue &get(const ControlId &id) const; + void set(const ControlId &id, const ControlValue &value); + private: const ControlValue *find(const ControlId &id) const; ControlValue *find(const ControlId &id); diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index f3260edce0bc..f862a09adef9 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -445,7 +445,7 @@ bool ControlList::contains(const ControlId &id) const */ /** - * \fn template const T &ControlList::get() const + * \fn template const T &ControlList::get(const Control &ctrl) const * \brief Get the value of a control * \param[in] ctrl The control * @@ -460,7 +460,7 @@ bool ControlList::contains(const ControlId &id) const */ /** - * \fn template void ControlList::set() + * \fn template void ControlList::set(const Control< T > &ctrl, const T &value) * \brief Set the control value to \a value * \param[in] ctrl The control * \param[in] value The control value @@ -473,6 +473,48 @@ bool ControlList::contains(const ControlId &id) const * camera that the list refers to. */ +/** + * \brief Get the value of control \a id + * \param[in] id The control ID + * + * The behaviour is undefined if the control \a id is not present in the list. + * Use ControlList::contains() to test for the presence of a control in the + * list before retrieving its value. + * + * \return The control value + */ +const ControlValue &ControlList::get(const ControlId &id) const +{ + const ControlValue *val = find(id); + if (!val) { + static ControlValue zero; + return zero; + } + + return *val; +} + +/** + * \brief Set the value of control \a id to \a value + * \param[in] id The control ID + * \param[in] value The control value + * + * This method sets the value of a control in the control list. If the control + * is already present in the list, its value is updated, otherwise it is added + * to the list. + * + * The behaviour is undefined if the control \a ctrl is not supported by the + * camera that the list refers to. + */ +void ControlList::set(const ControlId &id, const ControlValue &value) +{ + ControlValue *val = find(id); + if (!val) + return; + + *val = value; +} + const ControlValue *ControlList::find(const ControlId &id) const { const auto iter = controls_.find(&id);