From patchwork Tue Sep 24 17:24:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 2008 Return-Path: Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4A9BE62379 for ; Tue, 24 Sep 2019 19:23:34 +0200 (CEST) X-Originating-IP: 213.45.248.89 Received: from uno.homenet.telecomitalia.it (host89-248-dynamic.45-213-r.retail.telecomitalia.it [213.45.248.89]) (Authenticated sender: jacopo@jmondi.org) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id D546960006 for ; Tue, 24 Sep 2019 17:23:33 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 24 Sep 2019 19:24:51 +0200 Message-Id: <20190924172503.30864-10-jacopo@jmondi.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190924172503.30864-1-jacopo@jmondi.org> References: <20190924172503.30864-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 09/21] libcamera: v4l2_controls: Make V4L2ControlInfoMap 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: Tue, 24 Sep 2019 17:23:34 -0000 Make V4L2ControlInfoMap a class to be able to serialize its content. Signed-off-by: Jacopo Mondi --- src/libcamera/include/v4l2_controls.h | 25 ++++++++- src/libcamera/v4l2_controls.cpp | 79 ++++++++++++++++++++++++++- src/libcamera/v4l2_device.cpp | 3 +- 3 files changed, 103 insertions(+), 4 deletions(-) diff --git a/src/libcamera/include/v4l2_controls.h b/src/libcamera/include/v4l2_controls.h index 739f9f131923..5b583b9dfda6 100644 --- a/src/libcamera/include/v4l2_controls.h +++ b/src/libcamera/include/v4l2_controls.h @@ -24,6 +24,8 @@ namespace libcamera { class V4L2ControlInfo : public DataInfo { public: + V4L2ControlInfo(unsigned int id, const DataValue &min = 0, + const DataValue &max = 0); V4L2ControlInfo(const struct v4l2_query_ext_ctrl &ctrl); unsigned int id() const { return id_; } @@ -31,7 +33,28 @@ private: unsigned int id_; }; -using V4L2ControlInfoMap = std::map; +class V4L2ControlInfoMap +{ +private: + using InfoMap = std::map; + +public: + using iterator = InfoMap::iterator; + using const_iterator = InfoMap::const_iterator; + + iterator begin() { return map_.begin(); } + iterator end() { return map_.end(); } + const_iterator begin() const { return map_.begin(); } + const_iterator end() const { return map_.end(); } + + iterator find(unsigned int id) { return map_.find(id); } + const_iterator find(unsigned int id) const { return map_.find(id); } + + void emplace(unsigned int id, const struct v4l2_query_ext_ctrl &ctrl); + +private: + InfoMap map_; +}; class V4L2Control : public DataValue { diff --git a/src/libcamera/v4l2_controls.cpp b/src/libcamera/v4l2_controls.cpp index b386d313bc4a..c046f88bc7d3 100644 --- a/src/libcamera/v4l2_controls.cpp +++ b/src/libcamera/v4l2_controls.cpp @@ -68,6 +68,18 @@ namespace libcamera { * the first time the control information is accessed. */ +/** + * \brief Contruct a V4L2ControlInfo from with a min and max values + * \param[in] id The v4l2 control id + * \param[in] min The v4l2 control minimum value + * \param[in] max The v4l2 control maximum value + */ +V4L2ControlInfo::V4L2ControlInfo(unsigned int id, const DataValue &min, + const DataValue &max) + : DataInfo(min, max), id_(id) +{ +} + /** * \brief Construct a V4L2ControlInfo from a struct v4l2_query_ext_ctrl * \param ctrl The struct v4l2_query_ext_ctrl as returned by the kernel @@ -86,10 +98,75 @@ V4L2ControlInfo::V4L2ControlInfo(const struct v4l2_query_ext_ctrl &ctrl) */ /** - * \typedef V4L2ControlInfoMap + * \class V4L2ControlInfoMap * \brief A map of control ID to V4L2ControlInfo */ +/** + * \typedef V4L2ControlInfoMap::iterator + * \brief Iterator for the controls contained within the list + */ + +/** + * \typedef V4L2ControlInfoMap::const_iterator + * \brief Const iterator for the controls contained within the list + */ + +/** + * \fn iterator V4L2ControlInfoMap::begin() + * \brief Retrieve an iterator to the first control in the list + * \return An iterator to the first Control in the list + */ + +/** + * \fn const_iterator V4L2ControlInfoMap::begin() const + * \brief Retrieve a const_iterator to the first control in the list + * \return A const_iterator to the first Control in the list + */ + +/** + * \fn iterator V4L2ControlInfoMap::end() + * \brief Retrieve an iterator pointing to the past-the-end control in the list + * \return An iterator to the element following the last control in the list + */ + +/** + * \fn const_iterator V4L2ControlInfoMap::end() const + * \brief Retrieve a const iterator pointing to the past-the-end control in the + * list + * \return A const iterator to the element following the last control in the + * list + */ + +/** + * \fn iterator V4L2ControlInfoMap::find(unsigned int id) + * \brief Find V4L2ControlInfo with \a id + * \param id The control identifier + * \return An interator to the V4L2ControlInfo with key \a id or the + * past-the-end iterator if no element with key \a id exists + */ + +/** + * \fn const_iterator V4L2ControlInfoMap::find(unsigned int id) const + * \brief Find V4L2ControlInfo with \a id + * \param id The control identifier + * \return A const interator to the V4L2ControlInfo with key \a id or the + * past-the-end iterator if no element with key \a id exists + */ + +/** + * \brief Insert a new element in the map constructed in-place + * \param[in] id The control identifier + * \param[in] ctrl The v4l2_query_ext_ctrl containing info on the control + */ +void V4L2ControlInfoMap::emplace(unsigned int id, + const struct v4l2_query_ext_ctrl &ctrl) +{ + map_.emplace(std::piecewise_construct, + std::forward_as_tuple(id), + std::forward_as_tuple(ctrl)); +} + /** * \class V4L2Control * \brief A V4L2 control value diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index e1a715edec13..f89f4cd6c505 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -364,8 +364,7 @@ void V4L2Device::listControls() continue; } - V4L2ControlInfo info(ctrl); - controls_.emplace(ctrl.id, info); + controls_.emplace(ctrl.id, ctrl); } }