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