From patchwork Sat Dec 29 03:28:50 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: 102 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 1ECDB60B31 for ; Sat, 29 Dec 2018 04:29:56 +0100 (CET) X-Halon-ID: fbb49f4a-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 fbb49f4a-0b19-11e9-911a-0050569116f7; Sat, 29 Dec 2018 04:29:43 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Sat, 29 Dec 2018 04:28:50 +0100 Message-Id: <20181229032855.26249-8-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 07/12] libcamera: device_enumerator: 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, 29 Dec 2018 03:29:56 -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/device_enumerator.cpp | 19 +++++++++++++++++++ src/libcamera/include/device_enumerator.h | 2 ++ 2 files changed, 21 insertions(+) diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp index 3cafd0d3703dac99..26a3e68fcf39e43a 100644 --- a/src/libcamera/device_enumerator.cpp +++ b/src/libcamera/device_enumerator.cpp @@ -121,6 +121,25 @@ bool DeviceMatch::match(const DeviceInfo *info) 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 nullptr; +} + DeviceEnumerator::~DeviceEnumerator() { for (DeviceInfo *dev : devices_) { diff --git a/src/libcamera/include/device_enumerator.h b/src/libcamera/include/device_enumerator.h index 5348e6cf583dbd15..24bca0e3fc32c377 100644 --- a/src/libcamera/include/device_enumerator.h +++ b/src/libcamera/include/device_enumerator.h @@ -56,6 +56,8 @@ private: class DeviceEnumerator { public: + static DeviceEnumerator *create(); + virtual ~DeviceEnumerator(); virtual int init() = 0;