userver: userver/components/raw_component_base.hpp Source File
Loading...
Searching...
No Matches
raw_component_base.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/components/raw_component_base.hpp
4/// @brief @copybrief components::RawComponentBase
5
6#include <type_traits>
7#include <userver/utils/void_t.hpp>
8
9USERVER_NAMESPACE_BEGIN
10
11namespace yaml_config {
12
13struct Schema;
14
15} // namespace yaml_config
16
17namespace components {
18
19/// State of the component
20enum class ComponentHealth {
21 /// component is alive and fine
22 kOk,
23 /// component in fallback state, but the service keeps working
25 /// component is sick, service can not work without it
26 kFatal,
27};
28
29/// Whether the static config for the component must always be present, or can
30/// be missing
31enum class ConfigFileMode {
32 /// component must be setup in config
34 /// component must be not setup in config
36};
37
38/// @brief The base class for all components. Don't use it for application
39/// components, use ComponentBase instead.
40///
41/// Only inherited directly by some of the built-in userver components.
43public:
44 RawComponentBase() = default;
45
46 RawComponentBase(RawComponentBase&&) = delete;
47
48 RawComponentBase(const RawComponentBase&) = delete;
49
50 virtual ~RawComponentBase();
51
52 virtual ComponentHealth GetComponentHealth() const { return ComponentHealth::kOk; }
53
54 virtual void OnLoadingCancelled() {}
55
56 virtual void OnAllComponentsLoaded() {}
57
58 virtual void OnAllComponentsAreStopping() {}
59
60 static yaml_config::Schema GetStaticConfigSchema();
61};
62
63/// Specialize it for typename Component to validate static config against
64/// schema from Component::GetStaticConfigSchema
65///
66/// @see @ref static-configs-validation "Static configs validation"
67template <typename Component>
68inline constexpr bool kHasValidate = false;
69
70/// Specialize it for typename Component to skip validation of static config against
71/// schema from Component::GetStaticConfigSchema
72///
73/// @see @ref static-configs-validation "Static configs validation"
74template <typename Component>
75inline constexpr bool kForceNoValidation = false;
76
77namespace impl {
78
79template <typename Component, typename = void>
80inline constexpr auto kDefaultConfigFileMode = ConfigFileMode::kRequired;
81
82template <typename Component>
83inline constexpr auto
84 kDefaultConfigFileMode<Component, utils::void_t<decltype(Component::kConfigFileMode)>> = Component::kConfigFileMode;
85} // namespace impl
86
87/// Specialize this to customize the loading of component settings
88///
89/// @see @ref select-config-file-mode "Setup config file mode"
90template <typename Component>
92
93} // namespace components
94
95USERVER_NAMESPACE_END