[v4,2/3] libcamera: pipeline: Add a get factory by name helper
diff mbox series

Message ID 20240503144919.2371357-3-julien.vuillaumier@nxp.com
State Accepted
Commit 353ccef1437df142059da12dd154e426ce5464ee
Headers show
Series
  • Add environment variable to order pipelines match
Related show

Commit Message

Julien Vuillaumier May 3, 2024, 2:49 p.m. UTC
Add a static helper to the PipelineHandlerFactoryBase class to
allow retrieving a pipeline by name.

Signed-off-by: Julien Vuillaumier <julien.vuillaumier@nxp.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
 include/libcamera/internal/pipeline_handler.h |  1 +
 src/libcamera/pipeline_handler.cpp            | 22 +++++++++++++++++++
 2 files changed, 23 insertions(+)

Patch
diff mbox series

diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h
index cc70f69c..67d5164f 100644
--- a/include/libcamera/internal/pipeline_handler.h
+++ b/include/libcamera/internal/pipeline_handler.h
@@ -114,6 +114,7 @@  public:
 	const std::string &name() const { return name_; }
 
 	static std::vector<PipelineHandlerFactoryBase *> &factories();
+	static const PipelineHandlerFactoryBase *getFactoryByName(const std::string &name);
 
 private:
 	static void registerType(PipelineHandlerFactoryBase *factory);
diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp
index 0c913e50..de5097e1 100644
--- a/src/libcamera/pipeline_handler.cpp
+++ b/src/libcamera/pipeline_handler.cpp
@@ -794,6 +794,28 @@  std::vector<PipelineHandlerFactoryBase *> &PipelineHandlerFactoryBase::factories
 	return factories;
 }
 
+/**
+ * \brief Return the factory for the pipeline handler with name \a name
+ * \param[in] name The pipeline handler name
+ * \return The factory of the pipeline with name \a name, or nullptr if not found
+ */
+const PipelineHandlerFactoryBase *PipelineHandlerFactoryBase::getFactoryByName(const std::string &name)
+{
+	const std::vector<PipelineHandlerFactoryBase *> &factories =
+		PipelineHandlerFactoryBase::factories();
+
+	auto iter = std::find_if(factories.begin(),
+				 factories.end(),
+				 [&name](const PipelineHandlerFactoryBase *f) {
+					 return f->name() == name;
+				 });
+
+	if (iter != factories.end())
+		return *iter;
+
+	return nullptr;
+}
+
 /**
  * \class PipelineHandlerFactory
  * \brief Registration of PipelineHandler classes and creation of instances