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/fixed_array.hpp>
15#include <userver/utils/statistics/fwd.hpp>
16
17#include <userver/ugrpc/impl/static_metadata.hpp>
18#include <userver/ugrpc/impl/statistics_storage.hpp>
19#include <userver/ugrpc/server/impl/queue_holder.hpp>
20#include <userver/ugrpc/server/middlewares/fwd.hpp>
21
22USERVER_NAMESPACE_BEGIN
23
24namespace ugrpc::server::impl {
25
26/// Config for a `ServiceWorker`, provided by `ugrpc::server::Server`
27struct ServiceSettings final {
28 QueueHolder& queue;
29 engine::TaskProcessor& task_processor;
30 ugrpc::impl::StatisticsStorage& statistics_storage;
31 Middlewares middlewares;
32 logging::LoggerPtr access_tskv_logger;
33 const dynamic_config::Source config_source;
34};
35
36/// @brief Listens to requests for a gRPC service, forwarding them to a
37/// user-provided service implementation. ServiceWorker instances are
38/// created and owned by `Server`; services, on the other hand, are created
39/// and owned by the user.
40/// @note Must be destroyed after the corresponding `CompletionQueue`
41class ServiceWorker {
42 public:
43 ServiceWorker& operator=(ServiceWorker&&) = delete;
44 virtual ~ServiceWorker();
45
46 /// Get the grpcpp service for registration in the `ServerBuilder`
47 virtual grpc::Service& GetService() = 0;
48
49 /// Get the static per-gRPC-service metadata provided by codegen
50 virtual const ugrpc::impl::StaticServiceMetadata& GetMetadata() const = 0;
51
52 /// Start serving requests. Should be called after the grpcpp server starts.
53 virtual void Start() = 0;
54};
55
56} // namespace ugrpc::server::impl
57
58USERVER_NAMESPACE_END