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

libcamera v0.7.1 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 <initializer_list>
12#include <optional>
13#include <string>
14#include <string_view>
15
16#include <libcamera/base/utils.h>
17
18#include "libcamera/internal/value_node.h"
19
20namespace libcamera {
21
22 class GlobalConfiguration
23{
24public:
25 GlobalConfiguration();
26
27 unsigned int version() const;
28 const ValueNode &configuration() const;
29
30 template<typename T>
31 std::optional<T> option(
32 const std::initializer_list<std::string_view> confPath) const
33 {
34 const ValueNode *c = &configuration();
35 for (auto part : confPath) {
36 c = &(*c)[part];
37 if (!*c)
38 return {};
39 }
40 return c->get<T>();
41 }
42
43 std::optional<std::vector<std::string>> listOption(
44 const std::initializer_list<std::string_view> confPath) const;
45
46private:
47 void load();
48 bool loadFile(const std::filesystem::path &fileName);
49
50 std::unique_ptr<ValueNode> configuration_ =
51 std::make_unique<ValueNode>();
52};
53
54} /* namespace libcamera */
libcamera::GlobalConfiguration::GlobalConfiguration
GlobalConfiguration()
Initialize the global configuration.
Definition global_configuration.cpp:155
libcamera::GlobalConfiguration::configuration
const ValueNode & configuration() const
Retrieve the libcamera global configuration.
Definition global_configuration.cpp:268
libcamera::GlobalConfiguration::version
unsigned int version() const
Retrieve the configuration version.
Definition global_configuration.cpp:252
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:289
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:31
libcamera::ValueNode
A class representing a tree structure of values.
Definition value_node.h:27
libcamera::ValueNode::get
std::optional< T > get() const
Parse the ValueNode as a T value.
Definition value_node.h:211
libcamera
Top-level libcamera namespace.
Definition backtrace.h:17
utils.h
Miscellaneous utility functions.
value_node.h
Data structure to manage tree of values.