[v12,06/12] config: Look up pipelines match list in configuration file
diff mbox series

Message ID 20250702131032.47654-7-mzamazal@redhat.com
State New
Headers show
Series
  • Add global configuration file
Related show

Commit Message

Milan Zamazal July 2, 2025, 1:10 p.m. UTC
Let's add a configuration file item for the pipelines match list.

The configuration snippet:

  configuration:
    pipelines_match_list: rkisp1,simple

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
---
 include/libcamera/internal/global_configuration.h |  3 ++-
 src/libcamera/camera_manager.cpp                  | 10 ++++++----
 src/libcamera/global_configuration.cpp            |  6 ++++--
 3 files changed, 12 insertions(+), 7 deletions(-)

Patch
diff mbox series

diff --git a/include/libcamera/internal/global_configuration.h b/include/libcamera/internal/global_configuration.h
index b9f6d134a..d1751ee7c 100644
--- a/include/libcamera/internal/global_configuration.h
+++ b/include/libcamera/internal/global_configuration.h
@@ -48,7 +48,8 @@  public:
 		const std::initializer_list<std::string_view> confPath) const;
 	std::optional<std::vector<std::string>> envListOption(
 		const char *const envVariable,
-		const std::initializer_list<std::string_view> confPath) const;
+		const std::initializer_list<std::string_view> confPath,
+		const std::string delimiter = ":") const;
 
 private:
 	bool loadFile(const std::filesystem::path &fileName);
diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp
index c47fd3677..8123ae9e3 100644
--- a/src/libcamera/camera_manager.cpp
+++ b/src/libcamera/camera_manager.cpp
@@ -111,14 +111,16 @@  void CameraManager::Private::createPipelineHandlers()
 	 * file and only fallback on environment variable or all handlers, if
 	 * there is no configuration file.
 	 */
-	const char *pipesList =
-		utils::secure_getenv("LIBCAMERA_PIPELINES_MATCH_LIST");
-	if (pipesList) {
+	const auto pipesList =
+		configuration().envListOption("LIBCAMERA_PIPELINES_MATCH_LIST",
+					      { "pipelines_match_list" },
+					      ",");
+	if (pipesList.has_value()) {
 		/*
 		 * When a list of preferred pipelines is defined, iterate
 		 * through the ordered list to match the enumerated devices.
 		 */
-		for (const auto &pipeName : utils::split(pipesList, ",")) {
+		for (const auto &pipeName : pipesList.value()) {
 			const PipelineHandlerFactoryBase *factory;
 			factory = PipelineHandlerFactoryBase::getFactoryByName(pipeName);
 			if (!factory)
diff --git a/src/libcamera/global_configuration.cpp b/src/libcamera/global_configuration.cpp
index cb01eff22..2ac6191dc 100644
--- a/src/libcamera/global_configuration.cpp
+++ b/src/libcamera/global_configuration.cpp
@@ -176,6 +176,7 @@  std::optional<std::string> GlobalConfiguration::envOption(
  * \brief Return values of the configuration option from a file or environment
  * \param[in] envVariable Environment variable to get the value from
  * \param[in] confPath The same as in GlobalConfiguration::option
+ * \param[in] delimiter Items separator in the environment variable
  *
  * This helper looks first at the given environment variable and if it is
  * defined (even if it is empty) then it splits its value by semicolons and
@@ -192,11 +193,12 @@  std::optional<std::string> GlobalConfiguration::envOption(
  */
 std::optional<std::vector<std::string>> GlobalConfiguration::envListOption(
 	const char *const envVariable,
-	const std::initializer_list<std::string_view> confPath) const
+	const std::initializer_list<std::string_view> confPath,
+	const std::string delimiter) const
 {
 	const char *envValue = utils::secure_getenv(envVariable);
 	if (envValue) {
-		auto items = utils::split(envValue, ":");
+		auto items = utils::split(envValue, delimiter);
 		return std::vector<std::string>(items.begin(), items.end());
 	}
 	return listOption(confPath);