From patchwork Sat Dec 22 23:00:33 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: 80 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 D693960B31 for ; Sun, 23 Dec 2018 00:02:22 +0100 (CET) X-Halon-ID: 936ed3d0-063d-11e9-9adf-005056917a89 Authorized-sender: niklas@soderlund.pp.se Received: from wyvern.dyn.berto.se (unknown [217.31.177.236]) by bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA id 936ed3d0-063d-11e9-9adf-005056917a89; Sun, 23 Dec 2018 00:01:56 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Sun, 23 Dec 2018 00:00:33 +0100 Message-Id: <20181222230041.29999-5-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20181222230041.29999-1-niklas.soderlund@ragnatech.se> References: <20181222230041.29999-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 04/12] libcamera: deviceenumerator: 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, 22 Dec 2018 23:02:23 -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 --- src/libcamera/deviceenumerator.cpp | 54 ++++++++++++++++++++++++ src/libcamera/include/deviceenumerator.h | 17 ++++++++ 2 files changed, 71 insertions(+) diff --git a/src/libcamera/deviceenumerator.cpp b/src/libcamera/deviceenumerator.cpp index 7c44a65b45472ef3..17b6874d229c791c 100644 --- a/src/libcamera/deviceenumerator.cpp +++ b/src/libcamera/deviceenumerator.cpp @@ -75,4 +75,58 @@ bool DeviceInfo::lookup(const std::string &name, std::string &devnode) const return true; } +/* ----------------------------------------------------------------------------- + * DeviceMatch + */ + +DeviceMatch::DeviceMatch(const std::string &driver) + : driver_(driver) +{ +} + +void DeviceMatch::add(const std::string &entity) +{ + entities_.push_back(std::string(entity)); +} + +bool DeviceMatch::match(const DeviceInfo *info) const +{ + std::vector entities; + + if (!matchInfo(info->info())) + return false; + + if (!matchEntities(info->entities())) + return false; + + return true; +} + +bool DeviceMatch::matchInfo(const struct media_device_info &info) const +{ + /* TODO: Add more optinal matching pairs from struct media_device_info */ + /* TODO: Allow for empty driver in DeviceMatch */ + return driver_ == info.driver; +} + +bool DeviceMatch::matchEntities(const std::vector &entities) const +{ + for (const std::string &name : entities_) { + bool found = false; + + for (const std::string &entity : entities) { + + if (name == entity) { + found = true; + break; + } + } + + if (!found) + return false; + } + + return true; +} + } /* namespace libcamera */ diff --git a/src/libcamera/include/deviceenumerator.h b/src/libcamera/include/deviceenumerator.h index 0136ed6ea23bf65e..fb412b8840cb2ffe 100644 --- a/src/libcamera/include/deviceenumerator.h +++ b/src/libcamera/include/deviceenumerator.h @@ -39,6 +39,23 @@ 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_; + + bool matchInfo(const struct media_device_info &info) const; + bool matchEntities(const std::vector &entities) const; +}; + } /* namespace libcamera */ #endif /* __LIBCAMERA_DEVICEENUMERATE_H__ */