libcamera: include/libcamera/internal/global_configuration.h Source File

libcamera v0.7.0 Supporting cameras in Linux since 2019

Loading...
Searching...
No Matches
global_configuration.h
1/* SPDX-License-Identifier: LGPL-2.1-or-later */
2/*
3 * Copyright (C) 2024-2025 Red Hat, inc.
4 *
5 * Global configuration handling
6 */
7
8#pragma once
9
10#include <filesystem>
11#include <optional>
12#include <string>
13#include <string_view>
14
15#include <libcamera/base/utils.h>
16
17#include "libcamera/internal/yaml_parser.h"
18
19namespace libcamera {
20
21 class GlobalConfiguration
22{
23public:
24 using Configuration = const YamlObject &;
25
26 GlobalConfiguration();
27
28 unsigned int version() const;
29 Configuration configuration() const;
30
31 template<typename T>
32 std::optional<T> option(
33 const std::initializer_list<std::string_view> confPath) const
34 {
35 const YamlObject *c = &configuration();
36 for (auto part : confPath) {
37 c = &(*c)[part];
38 if (!*c)
39 return {};
40 }
41 return c->get<T>();
42 }
43
44 std::optional<std::vector<std::string>> listOption(
45 const std::initializer_list<std::string_view> confPath) const;
46 std::optional<std::string> envOption(
47 const char *const envVariable,
48 const std::initializer_list<std::string_view> confPath) const;
49 std::optional<std::vector<std::string>> envListOption(
50 const char *const envVariable,
51 const std::initializer_list<std::string_view> confPath,
52 const std::string delimiter = ":") const;
53
54private:
55 bool loadFile(const std::filesystem::path &fileName);
56 void load();
57
58 std::unique_ptr<YamlObject> yamlConfiguration_ =
59 std::make_unique<YamlObject>();
60};
61
62} /* 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.