libcamera: global_configuration: Reorder functions

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 <laurent.pinchart@ideasonboard.com>
Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
Reviewed-by: Isaac Scott <isaac.scott@ideasonboard.com>
This commit is contained in:
Laurent Pinchart
2025-10-14 23:33:02 +03:00
parent 1c3e1baa6e
commit e2aea3f4e1
2 changed files with 73 additions and 73 deletions

View File

@@ -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<ValueNode> yamlConfiguration_ =
std::make_unique<ValueNode>();

View File

@@ -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<unsigned int>().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<T> GlobalConfiguration::option(const std::initializer_list<std::string_view> &confPath) const
@@ -216,38 +250,4 @@ std::optional<std::vector<std::string>> 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<unsigned int>().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 */