userver
C++ Async Framework
Toggle main menu visibility
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
8
USERVER_NAMESPACE_BEGIN
9
10
namespace
yaml_config {
11
12
struct
Schema;
13
14
}
// namespace yaml_config
15
16
namespace
engine {
17
18
class
Deadline;
19
20
}
// namespace engine
21
22
namespace
components
{
23
24
/// State of the component
25
enum
class
ComponentHealth
{
26
/// component is alive and fine
27
kOk
,
28
/// component in fallback state, but the service keeps working
29
kFallback
,
30
/// component is sick, service can not work without it
31
kFatal
,
32
};
33
34
/// Whether the static config for the component must always be present, or can
35
/// be missing
36
enum
class
ConfigFileMode
{
37
/// component must be setup in config
38
kRequired
,
39
/// component must be not setup in config
40
kNotRequired
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.
47
class
RawComponentBase
{
48
public
:
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"
74
template
<
typename
Component
>
75
inline
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"
81
template
<
typename
Component
>
82
inline
constexpr
bool
kForceNoValidation
=
false
;
83
84
namespace
impl {
85
86
template
<
typename
Component>
87
inline
constexpr
auto
kDefaultConfigFileMode = ConfigFileMode::kRequired;
88
89
template
<
typename
Component>
90
requires
requires
{ Component::kConfigFileMode; }
91
inline
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"
97
template
<
typename
Component
>
98
inline
constexpr
auto
kConfigFileMode
=
impl
::
kDefaultConfigFileMode
<
Component
>;
99
100
}
// namespace components
101
102
USERVER_NAMESPACE_END
userver
components
raw_component_base.hpp
Generated on
for userver by
Doxygen
1.17.0