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
6USERVER_NAMESPACE_BEGIN
7
8namespace yaml_config {
9
10struct Schema;
11
12} // namespace yaml_config
13
14namespace components {
15
16/// State of the component
17enum class ComponentHealth {
18 /// component is alive and fine
19 kOk,
20 /// component in fallback state, but the service keeps working
22 /// component is sick, service can not work without it
23 kFatal,
24};
25
26/// Whether the static config for the component must always be present, or can
27/// be missing
28enum class ConfigFileMode {
29 /// component must be setup in config
31 /// component must be not setup in config
33};
34
35/// @brief The base class for all components. Don't use it for application
36/// components, use ComponentBase instead.
37///
38/// Only inherited directly by some of the built-in userver components.
40 public:
41 RawComponentBase() = default;
42
43 RawComponentBase(RawComponentBase&&) = delete;
44
45 RawComponentBase(const RawComponentBase&) = delete;
46
47 virtual ~RawComponentBase();
48
49 virtual ComponentHealth GetComponentHealth() const {
51 }
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 this to customize the loading of component settings
70///
71/// @see @ref select-config-file-mode "Setup config file mode"
72template <typename Component>
73inline constexpr auto kConfigFileMode = ConfigFileMode::kRequired;
74
75} // namespace components
76
77USERVER_NAMESPACE_END