From patchwork Sat Dec 29 03:28:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 99 Return-Path: Received: from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net [195.74.38.229]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1204560B36 for ; Sat, 29 Dec 2018 04:29:54 +0100 (CET) X-Halon-ID: fa85b787-0b19-11e9-911a-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id fa85b787-0b19-11e9-911a-0050569116f7; Sat, 29 Dec 2018 04:29:41 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Sat, 29 Dec 2018 04:28:47 +0100 Message-Id: <20181229032855.26249-5-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20181229032855.26249-1-niklas.soderlund@ragnatech.se> References: <20181229032855.26249-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 04/12] libcamera: device_enumerator: add DeviceMatch class X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 29 Dec 2018 03:29:54 -0000 Provide a DeviceMatch class which represents all properties of a media device a pipeline hander can specify when searching for a device to use in its pipeline. Signed-off-by: Niklas Söderlund Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- * Changes since v1 - Remove unneeded std::string(entity) in DeviceMatch::add(). - Inline matchInfo() and matchEntities() into the only caller, DeviceMatch::match. --- src/libcamera/device_enumerator.cpp | 36 +++++++++++++++++++++++ src/libcamera/include/device_enumerator.h | 14 +++++++++ 2 files changed, 50 insertions(+) diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp index 83dcda9403526010..61b32bb921581f49 100644 --- a/src/libcamera/device_enumerator.cpp +++ b/src/libcamera/device_enumerator.cpp @@ -75,4 +75,40 @@ int DeviceInfo::lookup(const std::string &name, std::string &devnode) const return 0; } +/* ----------------------------------------------------------------------------- + * DeviceMatch + */ + +DeviceMatch::DeviceMatch(const std::string &driver) + : driver_(driver) +{ +} + +void DeviceMatch::add(const std::string &entity) +{ + entities_.push_back(entity); +} + +bool DeviceMatch::match(const DeviceInfo *info) const +{ + if (driver_ != info->info().driver) + return false; + + for (const std::string &name : entities_) { + bool found = false; + + for (const std::string &entity : info->entities()) { + if (name == entity) { + found = true; + break; + } + } + + if (!found) + return false; + } + + return true; +} + } /* namespace libcamera */ diff --git a/src/libcamera/include/device_enumerator.h b/src/libcamera/include/device_enumerator.h index ac40bafc5169c7c7..ed1e986ff45f95f5 100644 --- a/src/libcamera/include/device_enumerator.h +++ b/src/libcamera/include/device_enumerator.h @@ -39,6 +39,20 @@ private: std::map entities_; }; +class DeviceMatch +{ +public: + DeviceMatch(const std::string &driver); + + void add(const std::string &entity); + + bool match(const DeviceInfo *info) const; + +private: + std::string driver_; + std::vector entities_; +}; + } /* namespace libcamera */ #endif /* __LIBCAMERA_DEVICE_ENUMERATOR_H__ */