From patchwork Mon Oct 7 22:46:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2137 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 951E36197A for ; Tue, 8 Oct 2019 00:46:59 +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 CEE59B2D for ; Tue, 8 Oct 2019 00:46:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1570488419; bh=bLkfjQh9qvSAmLcrRWH0Cq5MipYCnwfXqr0Dg5tI6cU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=IGQZIKopdc7LmCLazWjeZ2fpVuip6VGAZjsnpzb37jcxbdo2k9Ho2l+OxkAyyGDQv eftHuP/xgoweq/EGh6ud2jSTgBrJeVjGd/DDARGT4OX+0X01dRszqpjUIEvuL5HEhT IPBGiUKY+O8By9qdTMguJzrZINHJ981fvQMELCho= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 8 Oct 2019 01:46:42 +0300 Message-Id: <20191007224642.6597-10-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 9/9] libcamera: v4l2_controls: Add control validator 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:47:00 -0000 Add a ControlValidator specialisation that validates controls based on a V4L2 device. Signed-off-by: Laurent Pinchart --- src/libcamera/include/v4l2_controls.h | 14 ++++++++++++ src/libcamera/v4l2_controls.cpp | 33 +++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/src/libcamera/include/v4l2_controls.h b/src/libcamera/include/v4l2_controls.h index 133ab9ec208b..5fd92e3ac4e5 100644 --- a/src/libcamera/include/v4l2_controls.h +++ b/src/libcamera/include/v4l2_controls.h @@ -17,6 +17,8 @@ #include +#include "control_validator.h" + namespace libcamera { class V4L2ControlId : public ControlId @@ -57,6 +59,18 @@ private: const V4L2ControlInfoMap &controls_; }; +class V4L2ControlValidator final : public ControlValidator +{ +public: + V4L2ControlValidator(V4L2Device *device); + + const std::string &name() const override; + bool validate(const ControlId &id) const override; + +private: + V4L2Device *dev_; +}; + } /* namespace libcamera */ #endif /* __LIBCAMERA_V4L2_CONTROLS_H__ */ diff --git a/src/libcamera/v4l2_controls.cpp b/src/libcamera/v4l2_controls.cpp index d3f94709e821..498567ee0bf0 100644 --- a/src/libcamera/v4l2_controls.cpp +++ b/src/libcamera/v4l2_controls.cpp @@ -239,4 +239,37 @@ void V4L2ControlList::set(unsigned int id, const ControlValue &value) ControlList::set(ctrl->second.id(), value); } +/** + * \class V4L2ControlValidator + * \brief A control validator for V4L2Devoe instances + * + * This ControlValidator specialisation validates that controls exist in the + * V4L2Device associated with the validator. + */ + +/** + * \brief Construst a V4L2ControlValidator for the V4L2 \a device + * \param[in] device The V4L2 device + */ +V4L2ControlValidator::V4L2ControlValidator(V4L2Device *device) + : dev_(device) +{ +} + +const std::string &V4L2ControlValidator::name() const +{ + return dev_->deviceNode(); +} + +/** + * \brief Validate a control + * \param[in] id The control ID + * \return True if the control is valid, false otherwise + */ +bool V4L2ControlValidator::validate(const ControlId &id) const +{ + const V4L2ControlInfoMap &controls = dev_->controls(); + return controls.find(id.id()) != controls.end(); +} + } /* namespace libcamera */