[libcamera-devel,v2,07/12] libcamera: device_enumerator: add factory for DeviceEnumerators

Message ID 20181229032855.26249-8-niklas.soderlund@ragnatech.se
State Accepted
Headers show
Series
  • Add basic camera enumeration
Related show

Commit Message

Niklas Söderlund Dec. 29, 2018, 3:28 a.m. UTC
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 <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 src/libcamera/device_enumerator.cpp       | 19 +++++++++++++++++++
 src/libcamera/include/device_enumerator.h |  2 ++
 2 files changed, 21 insertions(+)

Comments

Jacopo Mondi Dec. 30, 2018, 10:17 a.m. UTC | #1
Hi Niklas,

On Sat, Dec 29, 2018 at 04:28:50AM +0100, Niklas Söderlund wrote:
> 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.
>

Reviewed-by; Jacopo Mondi <jacopo@jmondi.org>

Thanks
   j

> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  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;
> --
> 2.20.1
>
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

Patch

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;