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
21 kFallback,
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
30 kRequired,
31 /// component must be not setup in config
32 kNotRequired
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.
39class RawComponentBase {
40public:
41 RawComponentBase() = default;
42
43 RawComponentBase(RawComponentBase&&) = delete;
44
45 RawComponentBase(const RawComponentBase&) = delete;
46
47 virtual ~RawComponentBase();
48
49 virtual ComponentHealth GetComponentHealth() const { return ComponentHealth::kOk; }
50
51 virtual void OnLoadingCancelled() {}
52
53 virtual void OnAllComponentsLoaded() {}
54
55 virtual void OnAllComponentsAreStopping() {}
56
57 static yaml_config::Schema GetStaticConfigSchema();
58};
59
60/// Specialize it for typename Component to validate static config against
61/// schema from Component::GetStaticConfigSchema
62///
63/// @see @ref static-configs-validation "Static configs validation"
64template <typename Component>
65inline constexpr bool kHasValidate = false;
66
67/// Specialize this to customize the loading of component settings
68///
69/// @see @ref select-config-file-mode "Setup config file mode"
70template <typename Component>
71inline constexpr auto kConfigFileMode = ConfigFileMode::kRequired;
72
73} // namespace components
74
75USERVER_NAMESPACE_END