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 {
25 public:
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::LoggableComponentBase::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,
44 std::string_view dependency) const;
45
46 /// @returns all the components that `component_name` depends on directly or
47 /// transitively.
48 ///
49 /// Component with name `component_name` should be loaded.
50 /// Components construction should finish before any call to this function
51 /// is made. The result should now outlive the all the components
52 /// destruction.
55
56 private:
57 const impl::ComponentContextImpl& impl_;
58};
59
60} // namespace components
61
62USERVER_NAMESPACE_END