[libcamera-devel,RESEND,v2,4/4] libcamera: media device: Add 'match()' method

Message ID 20181228075743.28637-5-jacopo@jmondi.org
State Rejected
Headers show
Series
  • Add MediaDevice and associated MediaObject
Related show

Commit Message

Jacopo Mondi Dec. 28, 2018, 7:57 a.m. UTC
Add 'match()' method to the MediaDevice class. The method allows
matching the media device against a MediaDeviceDesc.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
---
 src/libcamera/include/media_device.h |  2 ++
 src/libcamera/media_device.cpp       | 19 +++++++++++++++++++
 2 files changed, 21 insertions(+)

--
2.20.1

Patch

diff --git a/src/libcamera/include/media_device.h b/src/libcamera/include/media_device.h
index e1b26e2..9f6d091 100644
--- a/src/libcamera/include/media_device.h
+++ b/src/libcamera/include/media_device.h
@@ -75,6 +75,8 @@  public:
 	int enumerate(std::map<std::string, std::string> &entitiesMap);
 	void dumpGraph(std::ostream &os);

+	bool match(MediaDeviceDesc &desc);
+
 	int resetLinks();
 	int link(const std::string &source, unsigned int sourceIdx,
 		 const std::string &sink, unsigned int sinkIdx,
diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp
index b98d62f..a961506 100644
--- a/src/libcamera/media_device.cpp
+++ b/src/libcamera/media_device.cpp
@@ -453,6 +453,25 @@  int MediaDevice::setupLink(const MediaPad *source, const MediaPad *sink,
 	return 0;
 }

+/**
+ * \brief Match the media device represented by this object against
+ *	  a media device description \a desc
+ * \param desc The media device description to math this MediaDevice against
+ */
+bool MediaDevice::match(MediaDeviceDesc &desc)
+{
+	/* TODO: add more fields to MediaDeviceDesc and match them
+	 * against media_device_info fields if required */
+	if (name_ != desc.driver())
+		return false;
+
+	for (std::string &e : desc.entities())
+		if (!getEntityByName(e))
+			return false;
+
+	return true;
+}
+
 /**
  * \fn MediaDevice::resetLinks()
  * \brief Reset all links on the media graph