From patchwork Tue Apr 7 15:34:17 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 26472 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id E2190C3323 for ; Tue, 7 Apr 2026 15:35:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 644F862E3A; Tue, 7 Apr 2026 17:35:19 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="MrbxktGT"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D95E762E12 for ; Tue, 7 Apr 2026 17:35:12 +0200 (CEST) Received: from killaraus.ideasonboard.com (2001-14ba-703d-e500--2a1.rev.dnainternet.fi [IPv6:2001:14ba:703d:e500::2a1]) by perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 42893DA4 for ; Tue, 7 Apr 2026 17:33:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1775576025; bh=lXFT8sbMKANHO79mqPYgg46EfdY7jAa3FvD524sI4Qo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=MrbxktGTHMLKjqVN6w03anK4GRkdpxeTzKlzksfHY2uAKN8xrakLbrgNnHhLPLWCa PzKwTUClaxcwL0lQhN+CJVuGQmpFsi+mckQf8ALxygJ/PjpBA2BaN32kGVcJJquaDL IEP1tKAjTUuLgWVaMsUaeARxowatSSxTNsx2iRlo= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Subject: [PATCH v2 32/42] libcamera: global_configuration: Reorder functions Date: Tue, 7 Apr 2026 18:34:17 +0300 Message-ID: <20260407153427.1825999-33-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260407153427.1825999-1-laurent.pinchart@ideasonboard.com> References: <20260407153427.1825999-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Member functions should be implemented in the .cpp file in the same order as in the class definition, within each access group. Move them to the right location. While at it, move load() before loadFile() in the class definition to match execution order, making the code easier to read. Signed-off-by: Laurent Pinchart Reviewed-by: Barnabás Pőcze --- .../libcamera/internal/global_configuration.h | 2 +- src/libcamera/global_configuration.cpp | 144 +++++++++--------- 2 files changed, 73 insertions(+), 73 deletions(-) diff --git a/include/libcamera/internal/global_configuration.h b/include/libcamera/internal/global_configuration.h index 7ae923977aa6..84bdf90244d9 100644 --- a/include/libcamera/internal/global_configuration.h +++ b/include/libcamera/internal/global_configuration.h @@ -52,8 +52,8 @@ public: const std::string delimiter = ":") const; private: - bool loadFile(const std::filesystem::path &fileName); void load(); + bool loadFile(const std::filesystem::path &fileName); std::unique_ptr yamlConfiguration_ = std::make_unique(); diff --git a/src/libcamera/global_configuration.cpp b/src/libcamera/global_configuration.cpp index c4999d32d7c7..c853a028c91d 100644 --- a/src/libcamera/global_configuration.cpp +++ b/src/libcamera/global_configuration.cpp @@ -53,6 +53,48 @@ LOG_DEFINE_CATEGORY(Configuration) * options, or configuration() to access the whole configuration. */ +/** + * \typedef GlobalConfiguration::Configuration + * \brief Type representing global libcamera configuration + * + * All code outside GlobalConfiguration must use this type declaration and not + * the underlying type. + */ + +/** + * \brief Initialize the global configuration + */ +GlobalConfiguration::GlobalConfiguration() +{ + load(); +} + +void GlobalConfiguration::load() +{ + std::filesystem::path userConfigurationDirectory; + const char *xdgConfigHome = utils::secure_getenv("XDG_CONFIG_HOME"); + if (xdgConfigHome) { + userConfigurationDirectory = xdgConfigHome; + } else { + const char *home = utils::secure_getenv("HOME"); + if (home) + userConfigurationDirectory = + std::filesystem::path(home) / ".config"; + } + + if (!userConfigurationDirectory.empty()) { + std::filesystem::path user_configuration_file = + userConfigurationDirectory / "libcamera" / "configuration.yaml"; + if (loadFile(user_configuration_file)) + return; + } + + for (const auto &path : globalConfigurationFiles) { + if (loadFile(path)) + return; + } +} + bool GlobalConfiguration::loadFile(const std::filesystem::path &fileName) { File file(fileName); @@ -85,47 +127,39 @@ bool GlobalConfiguration::loadFile(const std::filesystem::path &fileName) return true; } -void GlobalConfiguration::load() -{ - std::filesystem::path userConfigurationDirectory; - const char *xdgConfigHome = utils::secure_getenv("XDG_CONFIG_HOME"); - if (xdgConfigHome) { - userConfigurationDirectory = xdgConfigHome; - } else { - const char *home = utils::secure_getenv("HOME"); - if (home) - userConfigurationDirectory = - std::filesystem::path(home) / ".config"; - } - - if (!userConfigurationDirectory.empty()) { - std::filesystem::path user_configuration_file = - userConfigurationDirectory / "libcamera" / "configuration.yaml"; - if (loadFile(user_configuration_file)) - return; - } - - for (const auto &path : globalConfigurationFiles) { - if (loadFile(path)) - return; - } -} - /** - * \brief Initialize the global configuration - */ -GlobalConfiguration::GlobalConfiguration() -{ - load(); -} - -/** - * \typedef GlobalConfiguration::Configuration - * \brief Type representing global libcamera configuration + * \brief Retrieve the configuration version * - * All code outside GlobalConfiguration must use this type declaration and not - * the underlying type. + * The version is declared in the configuration file in the top-level `%version` + * element, alongside `%configuration`. This has currently no real use but may be + * needed in future if configuration incompatibilities occur. + * + * \return Configuration version as declared in the configuration file or 0 if + * no global configuration is available */ +unsigned int GlobalConfiguration::version() const +{ + return (*yamlConfiguration_)["version"].get().value_or(0); +} + +/** + * \brief Retrieve the libcamera global configuration + * + * This returns the whole configuration stored in the top-level section + * `%configuration` of the YAML configuration file. + * + * The requested part of the configuration can be accessed using \a ValueNode + * methods. + * + * \note \a ValueNode type itself shouldn't be used in type declarations to + * avoid trouble if we decide to change the underlying data objects in future. + * + * \return The whole configuration section + */ +GlobalConfiguration::Configuration GlobalConfiguration::configuration() const +{ + return (*yamlConfiguration_)["configuration"]; +} /** * \fn std::optional GlobalConfiguration::option(const std::initializer_list &confPath) const @@ -216,38 +250,4 @@ std::optional> GlobalConfiguration::envListOption( return listOption(confPath); } -/** - * \brief Retrieve the configuration version - * - * The version is declared in the configuration file in the top-level `%version` - * element, alongside `%configuration`. This has currently no real use but may be - * needed in future if configuration incompatibilities occur. - * - * \return Configuration version as declared in the configuration file or 0 if - * no global configuration is available - */ -unsigned int GlobalConfiguration::version() const -{ - return (*yamlConfiguration_)["version"].get().value_or(0); -} - -/** - * \brief Retrieve the libcamera global configuration - * - * This returns the whole configuration stored in the top-level section - * `%configuration` of the YAML configuration file. - * - * The requested part of the configuration can be accessed using \a ValueNode - * methods. - * - * \note \a ValueNode type itself shouldn't be used in type declarations to - * avoid trouble if we decide to change the underlying data objects in future. - * - * \return The whole configuration section - */ -GlobalConfiguration::Configuration GlobalConfiguration::configuration() const -{ - return (*yamlConfiguration_)["configuration"]; -} - } /* namespace libcamera */