From patchwork Sat Oct 12 18:44:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2173 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AAD5D61998 for ; Sat, 12 Oct 2019 20:44:22 +0200 (CEST) Received: from pendragon.bb.dnainternet.fi (dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 42CA733A for ; Sat, 12 Oct 2019 20:44:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1570905862; bh=G6sXZFVt53xbTzzhk7rk5JduO2MXjDbfRqpb6Tkj+RU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=t8RX2KaFQwanihACJLHsHhCX45d+0UrGYPR6uxAFGywdVqOAwPrHSLeznJWg/Ekas vC2HD9wyBg39Ya1FxmLMIhSXLspiYCz59Mbv1T0r753fZaDNFou2S7nUsAzro/u37L PvUB+CogZ20tb/I10eYYazwlmc5oBrCDTKwzTO2c= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 12 Oct 2019 21:44:05 +0300 Message-Id: <20191012184407.31684-13-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191012184407.31684-1-laurent.pinchart@ideasonboard.com> References: <20191012184407.31684-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 12/14] libcamera: v4l2_controls: Turn V4L2ControlInfoMap into a class 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, 12 Oct 2019 18:44:23 -0000 In preparation for extending V4L2ControlInfoMap with control idmap support, turn it into a real class. Make it inherit from std::map<> instead of wrapping it to keep the API simple. V4L2ControlInfoMap is meant to be constructed with a set of control info, and never modified afterwards. To ensure this, inherit from std::map<> with private access specifier, and explicitly expose the std::map<> methods that do not allow insertion or removal of elements. A custom move assignment operator is implemented to allow efficient construction of the V4L2ControlInfoMap. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Niklas Söderlund --- src/libcamera/include/v4l2_controls.h | 16 +++++++++++++++- src/libcamera/v4l2_controls.cpp | 17 ++++++++++++++++- src/libcamera/v4l2_device.cpp | 9 ++++++--- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/libcamera/include/v4l2_controls.h b/src/libcamera/include/v4l2_controls.h index 949ca21cb863..8990e755a385 100644 --- a/src/libcamera/include/v4l2_controls.h +++ b/src/libcamera/include/v4l2_controls.h @@ -43,7 +43,21 @@ private: ControlRange range_; }; -using V4L2ControlInfoMap = std::map; +class V4L2ControlInfoMap : private std::map +{ +public: + V4L2ControlInfoMap &operator=(std::map &&info); + + using std::map::begin; + using std::map::cbegin; + using std::map::end; + using std::map::cend; + using std::map::at; + using std::map::empty; + using std::map::size; + using std::map::count; + using std::map::find; +}; class V4L2Control { diff --git a/src/libcamera/v4l2_controls.cpp b/src/libcamera/v4l2_controls.cpp index 3f5f3ff10880..438e8d8bdb99 100644 --- a/src/libcamera/v4l2_controls.cpp +++ b/src/libcamera/v4l2_controls.cpp @@ -156,10 +156,25 @@ V4L2ControlInfo::V4L2ControlInfo(const struct v4l2_query_ext_ctrl &ctrl) */ /** - * \typedef V4L2ControlInfoMap + * \class V4L2ControlInfoMap * \brief A map of control ID to V4L2ControlInfo */ +/** + * \brief Move assignment operator from plain map + * + * Populate the map by replacing its contents with those of \a info using move + * semantics. This is the only supported + * + * \return *this + */ +V4L2ControlInfoMap &V4L2ControlInfoMap::operator=(std::map &&info) +{ + std::map::operator=(std::move(info)); + + return *this; +} + /** * \class V4L2Control * \brief A V4L2 control value diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 8c5998435020..1f755f0f3ef6 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -340,6 +340,7 @@ int V4L2Device::ioctl(unsigned long request, void *argp) */ void V4L2Device::listControls() { + std::map ctrls; struct v4l2_query_ext_ctrl ctrl = {}; /* \todo Add support for menu and compound controls. */ @@ -368,10 +369,12 @@ void V4L2Device::listControls() continue; } - controls_.emplace(std::piecewise_construct, - std::forward_as_tuple(ctrl.id), - std::forward_as_tuple(ctrl)); + ctrls.emplace(std::piecewise_construct, + std::forward_as_tuple(ctrl.id), + std::forward_as_tuple(ctrl)); } + + controls_ = std::move(ctrls); } /*