[libcamera-devel,v2,04/12] libcamera: device_enumerator: add DeviceMatch class

Message ID 20181229032855.26249-5-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 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 <niklas.soderlund@ragnatech.se>
---
* 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(+)

Comments

Jacopo Mondi Dec. 30, 2018, 10:04 a.m. UTC | #1
Hi Niklas,
On Sat, Dec 29, 2018 at 04:28:47AM +0100, Niklas Söderlund wrote:
> 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.
>

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

> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>

Thanks
  j

> ---
> * 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<std::string, std::string> 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<std::string> entities_;
> +};
> +
>  } /* namespace libcamera */
>
>  #endif	/* __LIBCAMERA_DEVICE_ENUMERATOR_H__ */
> --
> 2.20.1
>
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel
Laurent Pinchart Dec. 30, 2018, 8:11 p.m. UTC | #2
Hi Niklas,

Thank you for the patch.

On Saturday, 29 December 2018 05:28:47 EET Niklas Söderlund wrote:
> 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 <niklas.soderlund@ragnatech.se>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
> * 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<std::string, std::string> 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<std::string> entities_;
> +};
> +
>  } /* namespace libcamera */
> 
>  #endif	/* __LIBCAMERA_DEVICE_ENUMERATOR_H__ */

Patch

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<std::string, std::string> 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<std::string> entities_;
+};
+
 } /* namespace libcamera */
 
 #endif	/* __LIBCAMERA_DEVICE_ENUMERATOR_H__ */