userver: userver/ugrpc/server/impl/service_worker.hpp Source File
⚠️ This is the documentation for an old userver version. Click here to switch to the latest version.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
service_worker.hpp
1#pragma once
2
3#include <cstddef>
4#include <memory>
5#include <string_view>
6#include <vector>
7
8#include <grpcpp/completion_queue.h>
9#include <grpcpp/impl/service_type.h>
10
11#include <userver/dynamic_config/source.hpp>
12#include <userver/engine/task/task_processor_fwd.hpp>
13#include <userver/logging/null_logger.hpp>
14#include <userver/utils/statistics/fwd.hpp>
15
16#include <userver/ugrpc/impl/static_metadata.hpp>
17#include <userver/ugrpc/impl/statistics_storage.hpp>
18#include <userver/ugrpc/server/middlewares/fwd.hpp>
19
20USERVER_NAMESPACE_BEGIN
21
22namespace ugrpc::server::impl {
23
24/// Config for a `ServiceWorker`, provided by `ugrpc::server::Server`
25struct ServiceSettings final {
26 grpc::ServerCompletionQueue& queue;
27 engine::TaskProcessor& task_processor;
28 ugrpc::impl::StatisticsStorage& statistics_storage;
29 Middlewares middlewares;
30 logging::LoggerPtr access_tskv_logger;
31 const dynamic_config::Source config_source;
32};
33
34/// @brief Listens to requests for a gRPC service, forwarding them to a
35/// user-provided service implementation. ServiceWorker instances are
36/// created and owned by `Server`; services, on the other hand, are created
37/// and owned by the user.
38/// @note Must be destroyed after the corresponding `CompletionQueue`
39class ServiceWorker {
40 public:
41 ServiceWorker& operator=(ServiceWorker&&) = delete;
42 virtual ~ServiceWorker();
43
44 /// Get the grpcpp service for registration in the `ServerBuilder`
45 virtual grpc::Service& GetService() = 0;
46
47 /// Get the static per-gRPC-service metadata provided by codegen
48 virtual const ugrpc::impl::StaticServiceMetadata& GetMetadata() const = 0;
49
50 /// Start serving requests. Should be called after the grpcpp server starts.
51 virtual void Start() = 0;
52};
53
54} // namespace ugrpc::server::impl
55
56USERVER_NAMESPACE_END