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

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

Commit Message

Milan Zamazal July 29, 2025, 7:31 a.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(-)

Comments

Paul Elder Sept. 9, 2025, 8:52 a.m. UTC | #1
Quoting Milan Zamazal (2025-07-29 16:31:54)
> 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(-)
> 
> diff --git a/include/libcamera/internal/global_configuration.h b/include/libcamera/internal/global_configuration.h
> index 3b500ee29..8d09517ed 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;

Same comment as 5/12; imo this (and the cpp below) should be added in 3/12,
then this patch will just be plubimg CameraManager.

>  
>  private:
>         bool loadFile(const std::filesystem::path &fileName);
> diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp
> index 64df62444..c203b08f7 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" },
> +                                             ",");

It's really neat that it becomes so clean to do this.


Paul

> +       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 1371392c5..b9531fdfb 100644
> --- a/src/libcamera/global_configuration.cpp
> +++ b/src/libcamera/global_configuration.cpp
> @@ -174,6 +174,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
> @@ -190,11 +191,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);
> -- 
> 2.50.1
>

Patch
diff mbox series

diff --git a/include/libcamera/internal/global_configuration.h b/include/libcamera/internal/global_configuration.h
index 3b500ee29..8d09517ed 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 64df62444..c203b08f7 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 1371392c5..b9531fdfb 100644
--- a/src/libcamera/global_configuration.cpp
+++ b/src/libcamera/global_configuration.cpp
@@ -174,6 +174,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
@@ -190,11 +191,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);