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