userver: userver/components/state.hpp Source File
Loading...
Searching...
No Matches
state.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/components/state.hpp
4/// @brief @copybrief components::State
5
6#include <string>
7#include <string_view>
8#include <unordered_set>
9
10USERVER_NAMESPACE_BEGIN
11
12namespace components {
13
14class ComponentContext;
15
16namespace impl {
17class ComponentContextImpl;
18}
19
20/// State of components that is usable after the components constructor and
21/// until all the components were not destroyed.
22///
23/// @see components::ComponentContext
24class State final {
25public:
26 explicit State(const ComponentContext& cc) noexcept;
27
28 /// @returns true if one of the components is in fatal state and can not
29 /// work. A component is in fatal state if the
30 /// components::ComponentHealth::kFatal value is returned from the overridden
31 /// components::ComponentBase::GetComponentHealth().
33
34 /// @returns true if component with name `component_name` depends
35 /// (directly or transitively) on a component with name `dependency`.
36 ///
37 /// Component with name `component_name` should be loaded.
38 /// Components construction should finish before any call to this function
39 /// is made.
40 ///
41 /// Note that GetAllDependencies usually is more effective, if you are
42 /// planning multiple calls for the same component name.
43 bool HasDependencyOn(std::string_view component_name, std::string_view dependency) const;
44
45 /// @returns all the components that `component_name` depends on directly or
46 /// transitively.
47 ///
48 /// Component with name `component_name` should be loaded.
49 /// Components construction should finish before any call to this function
50 /// is made. The result should now outlive the all the components
51 /// destruction.
53
54private:
55 const impl::ComponentContextImpl& impl_;
56};
57
58} // namespace components
59
60USERVER_NAMESPACE_END