userver: userver/ugrpc/server/service_component_base.hpp Source File
Loading...
Searching...
No Matches
service_component_base.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include <atomic>
7
12
15
16USERVER_NAMESPACE_BEGIN
17
18namespace ugrpc::server {
19
20class ServerComponent;
22class MiddlewareBase;
23struct ServiceInfo;
24
25namespace impl {
26
28using MiddlewareRunnerComponentBase = USERVER_NAMESPACE::middlewares::RunnerComponentBase<MiddlewareBase, ServiceInfo>;
29
30} // namespace impl
31
44class ServiceComponentBase : public impl::MiddlewareRunnerComponentBase {
45public:
46 ServiceComponentBase(const components::ComponentConfig& config, const components::ComponentContext& context);
47
48 ~ServiceComponentBase() override;
49
51
52protected:
56
59
60private:
61 ServerComponent& server_;
62 ServiceConfig config_;
63 std::string component_name_;
64 std::atomic<bool> registered_{false};
65};
66
67namespace impl {
68
69template <typename ServiceInterface>
70// NOLINTNEXTLINE(fuchsia-multiple-inheritance)
71class ServiceComponentBase : public server::ServiceComponentBase, public ServiceInterface {
72 static_assert(std::is_base_of_v<ServiceBase, ServiceInterface> || std::is_base_of_v<GenericServiceBase, ServiceInterface>);
73
74public:
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
87private:
89};
90
91} // namespace impl
92
93} // namespace ugrpc::server
94
95USERVER_NAMESPACE_END