From patchwork Sat Dec 22 23:00:36 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: 83 Return-Path: Received: from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net [195.74.38.228]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 19A0A60B31 for ; Sun, 23 Dec 2018 00:02:28 +0100 (CET) X-Halon-ID: 96ba8d9d-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 96ba8d9d-063d-11e9-9adf-005056917a89; Sun, 23 Dec 2018 00:02:01 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Sun, 23 Dec 2018 00:00:36 +0100 Message-Id: <20181222230041.29999-8-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 07/12] libcamera: deviceenumerator: add factory for DeviceEnumerators 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:28 -0000 Provide a factory for DeviceEnumerator objects. Depending on which libraries are available there will be different ways to enumerate information in the system. This factory hides this from the rest of the library. Currently udev enumeration is the only supported implementation, a sysfs implementation is another method that surely will be added in the future. Signed-off-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- src/libcamera/deviceenumerator.cpp | 17 +++++++++++++++++ src/libcamera/include/deviceenumerator.h | 2 ++ 2 files changed, 19 insertions(+) diff --git a/src/libcamera/deviceenumerator.cpp b/src/libcamera/deviceenumerator.cpp index f4c40bf0376ab453..6d675fc78af8e586 100644 --- a/src/libcamera/deviceenumerator.cpp +++ b/src/libcamera/deviceenumerator.cpp @@ -138,6 +138,23 @@ bool DeviceMatch::matchEntities(const std::vector &entities) const * Enumerator Base */ +DeviceEnumerator *DeviceEnumerator::create() +{ + DeviceEnumerator *enumerator; + + /* TODO: add compile time checks to only try udev enumerator if libudev is available */ + enumerator = new DeviceEnumeratorUdev(); + if (!enumerator->init()) + return enumerator; + + /* NOTE: Either udev is not available or initialization of it + * failed, use/fallback on sysfs enumerator */ + + /* TODO: add a sysfs based enumerator */ + + return NULL; +} + DeviceEnumerator::~DeviceEnumerator() { for (DeviceInfo *dev : devices_) { diff --git a/src/libcamera/include/deviceenumerator.h b/src/libcamera/include/deviceenumerator.h index 2c7ff3f336ba127d..6aa6e59d4a8a9729 100644 --- a/src/libcamera/include/deviceenumerator.h +++ b/src/libcamera/include/deviceenumerator.h @@ -59,6 +59,8 @@ private: class DeviceEnumerator { public: + static DeviceEnumerator *create(); + virtual ~DeviceEnumerator(); virtual int init() = 0;