From patchwork Sat Apr 25 23:16:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3544 X-Patchwork-Delegate: laurent.pinchart@ideasonboard.com Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CEDDB603FD for ; Sun, 26 Apr 2020 01:16:41 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="qZ7xzRTw"; dkim-atps=neutral Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 3DFB84F7; Sun, 26 Apr 2020 01:16:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1587856601; bh=UkjB9ANiqnfRJ3FzWVHqjroZgqqC4m7kiUIXDtrFLfs=; h=From:To:Cc:Subject:Date:From; b=qZ7xzRTw7dujmrPfznPDw8WiZ8/A2AGkhC/Jeq81G+Z0pVO8+f9YDc8qwqNiIbadH l3+bfG6Kh7hdY3a2UBUe4cmXtW28PF7ddhO0O/q4WTBDhhWyXus1mDhCIqQE0UNw5w 1zJSXOQfI8TtyohO0c6fzCG10oOepsyIPHsUnYm0= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sun, 26 Apr 2020 02:16:22 +0300 Message-Id: <20200425231623.6505-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.25.3 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/2] libcamera: controls: Return ControlValue reference from ControlList::set() 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: Sat, 25 Apr 2020 23:16:42 -0000 It is useful for the caller of ControlList::set() to get a reference to the ControlValue that stores the control in the control list, in order to then modify that value directly. This allows creating an entry in the ControlList and then reserving memory for the control when getting V4L2 controls from a device. This is already possible by calling the get() function right after set(), but results in two lookups. Extend the id-based set() function to return the reference to the inserted ControlValue to avoid the second lookup. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- include/libcamera/controls.h | 2 +- src/libcamera/controls.cpp | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index 80944efc133a..5a5cfc3e52ca 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -394,7 +394,7 @@ public: } const ControlValue &get(unsigned int id) const; - void set(unsigned int id, const ControlValue &value); + ControlValue &set(unsigned int id, const ControlValue &value); const ControlInfoMap *infoMap() const { return infoMap_; } diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index 08df7f29e938..12822e87a4d7 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -930,14 +930,17 @@ const ControlValue &ControlList::get(unsigned int id) const * * The behaviour is undefined if the control \a id is not supported by the * object that the list refers to. + * + * \return A reference to the ControlValue stored in the control list */ -void ControlList::set(unsigned int id, const ControlValue &value) +ControlValue &ControlList::set(unsigned int id, const ControlValue &value) { ControlValue *val = find(id); if (!val) - return; + return *val; *val = value; + return *val; } /**