libcamera supports several environment variables that can override configuration options. This requires components that use such overrides to call the special envOption() and envListOption() functions, spreading knowledge of the overrides through the code base. This will hinder future enhancements to the global configuration, such as implementing per-camera options that will override pipeline handler-level options. To prepare for that, move handling of the environment variables to the GlobalConfiguration class. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Isaac Scott <isaac.scott@ideasonboard.com> Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
55 lines
1.0 KiB
C++
55 lines
1.0 KiB
C++
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
|
/*
|
|
* Copyright (C) 2024-2025 Red Hat, inc.
|
|
*
|
|
* Global configuration handling
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <filesystem>
|
|
#include <initializer_list>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <string_view>
|
|
|
|
#include <libcamera/base/utils.h>
|
|
|
|
#include "libcamera/internal/value_node.h"
|
|
|
|
namespace libcamera {
|
|
|
|
class GlobalConfiguration
|
|
{
|
|
public:
|
|
GlobalConfiguration();
|
|
|
|
unsigned int version() const;
|
|
const ValueNode &configuration() const;
|
|
|
|
template<typename T>
|
|
std::optional<T> option(
|
|
const std::initializer_list<std::string_view> confPath) const
|
|
{
|
|
const ValueNode *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;
|
|
|
|
private:
|
|
void load();
|
|
bool loadFile(const std::filesystem::path &fileName);
|
|
|
|
std::unique_ptr<ValueNode> configuration_ =
|
|
std::make_unique<ValueNode>();
|
|
};
|
|
|
|
} /* namespace libcamera */
|