userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
service_component_base.hpp
Go to the documentation of this file.
1
#pragma once
2
5
6
#include <atomic>
7
8
#include <
userver/components/component_base.hpp
>
9
#include <
userver/engine/task/task_processor_fwd.hpp
>
10
#include <
userver/middlewares/runner.hpp
>
11
#include <
userver/yaml_config/fwd.hpp
>
12
13
#include <
userver/ugrpc/server/middlewares/fwd.hpp
>
14
#include <
userver/ugrpc/server/service_base.hpp
>
15
16
USERVER_NAMESPACE_BEGIN
17
18
namespace
ugrpc::server
{
19
20
class
ServerComponent
;
21
class
GenericServiceBase
;
22
class
MiddlewareBase
;
23
struct
ServiceInfo
;
24
25
namespace
impl {
26
28
using
MiddlewareRunnerComponentBase = USERVER_NAMESPACE::middlewares::RunnerComponentBase<MiddlewareBase, ServiceInfo>;
29
30
}
// namespace impl
31
44
class
ServiceComponentBase :
public
impl::MiddlewareRunnerComponentBase {
45
public
:
46
ServiceComponentBase(
const
components::ComponentConfig
& config,
const
components::ComponentContext
& context);
47
48
~ServiceComponentBase()
override
;
49
50
static
yaml_config::Schema
GetStaticConfigSchema
();
51
52
protected
:
55
void
RegisterService
(
ServiceBase
& service);
56
58
void
RegisterService
(
GenericServiceBase
& service);
59
60
private
:
61
ServerComponent
& server_;
62
ServiceConfig
config_;
63
std::string component_name_;
64
std::atomic<bool> registered_{
false
};
65
};
66
67
namespace
impl {
68
69
template
<
typename
ServiceInterface>
70
// NOLINTNEXTLINE(fuchsia-multiple-inheritance)
71
class
ServiceComponentBase :
public
server::ServiceComponentBase
,
public
ServiceInterface {
72
static_assert
(std::is_base_of_v<ServiceBase, ServiceInterface> || std::is_base_of_v<GenericServiceBase, ServiceInterface>);
73
74
public
:
75
ServiceComponentBase(
const
components::ComponentConfig
& config,
const
components::ComponentContext
& context)
76
:
server
::ServiceComponentBase(config, context),
77
ServiceInterface()
78
{
79
// At this point the derived class that implements ServiceInterface is not
80
// constructed yet. We rely on the implementation detail that the methods of
81
// ServiceInterface are never called right after RegisterService. Unless
82
// Server starts during the construction of this component (which is an
83
// error anyway), we should be fine.
84
RegisterService(*
this
);
85
}
86
87
private
:
88
using
server::ServiceComponentBase::RegisterService
;
89
};
90
91
}
// namespace impl
92
93
}
// namespace ugrpc::server
94
95
USERVER_NAMESPACE_END
userver
ugrpc
server
service_component_base.hpp
Generated on
for userver by
Doxygen
1.17.0