userver: userver/components/impl/component_base.hpp Source File
Loading...
Searching...
No Matches
component_base.hpp
1#pragma once
2
3USERVER_NAMESPACE_BEGIN
4
5namespace yaml_config {
6
7struct Schema;
8
9} // namespace yaml_config
10
11namespace components {
12
13/// State of the component
14enum class ComponentHealth {
15 /// component is alive and fine
16 kOk,
17 /// component in fallback state, but the service keeps working
19 /// component is sick, service can not work without it
20 kFatal,
21};
22
23/// Whether the static config for the component must always be present, or can
24/// be missing
25enum class ConfigFileMode {
26 /// component must be setup in config
28 /// component must be not setup in config
30};
31
32namespace impl {
33
34/// Don't use it for application components, use LoggableComponentBase instead
35class ComponentBase {
36 public:
37 ComponentBase() = default;
38
39 ComponentBase(ComponentBase&&) = delete;
40
41 ComponentBase(const ComponentBase&) = delete;
42
43 virtual ~ComponentBase();
44
45 virtual ComponentHealth GetComponentHealth() const {
47 }
48
49 virtual void OnLoadingCancelled() {}
50
51 virtual void OnAllComponentsLoaded() {}
52
53 virtual void OnAllComponentsAreStopping() {}
54
55 static yaml_config::Schema GetStaticConfigSchema();
56};
57
58} // namespace impl
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