userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
server.hpp
Go to the documentation of this file.
1
#pragma once
2
5
6
#include <functional>
7
#include <memory>
8
#include <unordered_map>
9
10
#include <grpcpp/completion_queue.h>
11
#include <grpcpp/server_builder.h>
12
13
#include <
userver/dynamic_config/source.hpp
>
14
#include <
userver/engine/task/task_processor_fwd.hpp
>
15
#include <
userver/logging/level.hpp
>
16
#include <
userver/server/congestion_control/sensor.hpp
>
17
#include <
userver/utils/function_ref.hpp
>
18
#include <userver/utils/impl/internal_tag_fwd.hpp>
19
#include <
userver/utils/resource_scopes_fwd.hpp
>
20
#include <
userver/utils/statistics/fwd.hpp
>
21
#include <
userver/yaml_config/fwd.hpp
>
22
23
#include <userver/ugrpc/impl/statistics.hpp>
24
#include <
userver/ugrpc/server/middlewares/fwd.hpp
>
25
#include <
userver/ugrpc/server/service_base.hpp
>
26
27
USERVER_NAMESPACE_BEGIN
28
29
namespace
ugrpc::impl {
30
class
CompletionQueuePoolBase;
31
}
// namespace ugrpc::impl
32
33
namespace
ugrpc::server
{
34
35
class
GenericServiceBase
;
36
37
struct
TlsConfig
{
38
// Certificate Authority, for client auth
39
std::optional<std::string> ca;
40
41
// Server certificate private key
42
std::optional<std::string> key;
43
44
// Server certificate
45
std::optional<std::string> cert;
46
};
47
49
struct
EventEngineConfig
final {
57
bool
enabled
{
false
};
58
63
engine::TaskProcessor*
task_processor
{
nullptr
};
64
};
65
67
struct
ServerConfig
final {
71
std::optional<int>
port
{0};
72
75
std::optional<std::string>
unix_socket_path
{std::nullopt};
76
78
bool
use_callback_api
{
false
};
79
82
std::size_t
completion_queue_num
{2};
83
86
std::unordered_map<std::string, std::string>
channel_args
{};
87
90
logging::Level
native_log_level
{
logging::Level::kError
};
91
93
bool
enable_channelz
{
false
};
94
96
TlsConfig
tls
{};
97
99
bool
otel_trace_sampling_enabled
{
false
};
100
102
EventEngineConfig
event_engine
{};
103
};
104
109
class
Server
final :
public
USERVER_NAMESPACE::server::congestion_control::RequestsSource {
110
public
:
111
using
SetupHook = utils::function_ref<void(grpc::ServerBuilder&)>;
112
117
explicit
Server
(
118
utils::ResourceScopeStorage
& scope_storage,
119
ServerConfig
&& config,
120
utils::statistics::Storage
& statistics_storage
121
);
122
123
Server
(
Server
&&) =
delete
;
124
Server
& operator=(
Server
&&) =
delete
;
125
~Server
()
override
;
126
130
void
AddService
(
ServiceBase
& service,
ServiceConfig
&& config);
131
133
void
AddService
(
GenericServiceBase
& service,
ServiceConfig
&& config);
134
136
std::vector<std::string_view>
GetServiceNames
()
const
;
137
140
void
WithServerBuilder
(SetupHook setup);
141
144
void
Start
();
145
148
int
GetPort
() const noexcept;
149
153
void
Stop
() noexcept;
154
159
void
StopServing
(
std
::optional<
engine
::Deadline> serving_shutdown_deadline =
std
::nullopt) noexcept;
160
162
// For internal use only.
163
std
::uint64_t GetTotalRequests() const override;
164
165
// For internal use only.
166
ugrpc
::impl::CompletionQueuePoolBase* GetCompletionQueues(
utils
::impl::InternalTag);
168
169
private:
170
class Impl;
171
std
::unique_ptr<Impl> impl_;
172
};
173
174
}
// namespace ugrpc::server
175
176
USERVER_NAMESPACE_END
userver
ugrpc
server
server.hpp
Generated on
for userver by
Doxygen
1.17.0