summaryrefslogtreecommitdiff
path: root/src/libcamera
diff options
context:
space:
mode:
authorNiklas Söderlund <niklas.soderlund@ragnatech.se>2018-12-21 15:54:23 +0100
committerNiklas Söderlund <niklas.soderlund@ragnatech.se>2018-12-31 00:58:11 +0100
commitc0d39bab5bf3be585a7860d51429913187d05f04 (patch)
treeaa005684a6daa356e680d9f5a009bae293b1ff58 /src/libcamera
parent0eab433d057ba5ed0feffe89c9f5b67f3557fb41 (diff)
libcamera: device_enumerator: add DeviceMatch class
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: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/libcamera')
-rw-r--r--src/libcamera/device_enumerator.cpp36
-rw-r--r--src/libcamera/include/device_enumerator.h14
2 files changed, 50 insertions, 0 deletions
diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp
index 83dcda94..61b32bb9 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 ac40bafc..ed1e986f 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__ */