Loading...
Searching...
No Matches
global_configuration.h
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2024-2025 Red Hat, inc.
*
* Global configuration handling
*/
#pragma once
#include <filesystem>
#include <optional>
#include <string>
#include <string_view>
#include <libcamera/base/utils.h>
#include "libcamera/internal/yaml_parser.h"
namespace libcamera {
class GlobalConfiguration
{
public:
using Configuration = const YamlObject &;
GlobalConfiguration();
unsigned int version() const;
Configuration configuration() const;
template<typename T>
std::optional<T> option(
const std::initializer_list<std::string_view> confPath) const
{
const YamlObject *c = &configuration();
for (auto part : confPath) {
c = &(*c)[part];
if (!*c)
return {};
}
return c->get<T>();
}
std::optional<std::vector<std::string>> listOption(
const std::initializer_list<std::string_view> confPath) const;
std::optional<std::string> envOption(
const char *const envVariable,
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 std::string delimiter = ":") const;
private:
bool loadFile(const std::filesystem::path &fileName);
void load();
std::unique_ptr<YamlObject> yamlConfiguration_ =
std::make_unique<YamlObject>();
};
} /* namespace libcamera */
libcamera::GlobalConfiguration::Configuration
const YamlObject & Configuration
Type representing global libcamera configuration.
Definition global_configuration.h:24
libcamera::GlobalConfiguration::envListOption
std::optional< std::vector< std::string > > envListOption(const char *const envVariable, const std::initializer_list< std::string_view > confPath, const std::string delimiter=":") const
Retrieve the value of the configuration option from a file or environment.
Definition global_configuration.cpp:206
libcamera::GlobalConfiguration::GlobalConfiguration
GlobalConfiguration()
Initialize the global configuration.
Definition global_configuration.cpp:117
libcamera::GlobalConfiguration::version
unsigned int version() const
Retrieve the configuration version.
Definition global_configuration.cpp:229
libcamera::GlobalConfiguration::listOption
std::optional< std::vector< std::string > > listOption(const std::initializer_list< std::string_view > confPath) const
Retrieve the value of configuration option confPath.
Definition global_configuration.cpp:146
libcamera::GlobalConfiguration::option
std::optional< T > option(const std::initializer_list< std::string_view > confPath) const
Retrieve the value of configuration option confPath.
Definition global_configuration.h:32
libcamera::GlobalConfiguration::configuration
Configuration configuration() const
Retrieve the libcamera global configuration.
Definition global_configuration.cpp:248
libcamera::GlobalConfiguration::envOption
std::optional< std::string > envOption(const char *const envVariable, const std::initializer_list< std::string_view > confPath) const
Retrieve the value of environment variable with a fallback on the configuration file.
Definition global_configuration.cpp:177
libcamera::YamlObject
A class representing the tree structure of the YAML content.
Definition yaml_parser.h:28
libcamera::YamlObject::get
std::optional< T > get() const
Parse the YamlObject as a T value.
Definition yaml_parser.h:175
libcamera
Top-level libcamera namespace.
Definition backtrace.h:17
utils.h
Miscellaneous utility functions.
yaml_parser.h
A YAML parser helper.