userver: userver/ugrpc/server/call_context.hpp Source File
Loading...
Searching...
No Matches
call_context.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include <grpcpp/server_context.h>
7
11
13#include <userver/utils/impl/internal_tag_fwd.hpp>
14
15namespace google::protobuf {
16class Arena;
17}
18
19USERVER_NAMESPACE_BEGIN
20
21namespace ugrpc::server {
22
23namespace impl {
24struct CallState;
25} // namespace impl
26
27class CallContextBase {
28public:
30 // For internal use only.
31 CallContextBase(utils::impl::InternalTag, impl::CallState& state);
33
34 CallContextBase(CallContextBase&&) = delete;
35 CallContextBase& operator=(CallContextBase&&) = delete;
36
38 grpc::ServerContextBase& GetServerContext();
39
41 const grpc::ServerContextBase& GetServerContext() const;
42
44 std::string_view GetCallName() const;
45
47 std::string_view GetServiceName() const;
48
50 std::string_view GetMethodName() const;
51
54
60
65 std::shared_ptr<google::protobuf::Arena> GetArenaSharedPtr() const noexcept;
66
90
91protected:
93 // For internal use only.
94 const impl::CallState& GetCallState(utils::impl::InternalTag) const { return state_; }
95
96 // For internal use only.
97 impl::CallState& GetCallState(utils::impl::InternalTag) { return state_; }
98
99 // Prevent destruction via pointer to base.
100 ~CallContextBase() = default;
102
103private:
104 impl::CallState& state_;
105};
106
108class CallContext final : public CallContextBase {
109public:
111 using CallContextBase::CallContextBase;
113};
114
116class GenericCallContext final : public CallContextBase {
117public:
119 using CallContextBase::CallContextBase;
121
123 void SetMetricsCallName(std::string_view call_name);
124};
125
126} // namespace ugrpc::server
127
128USERVER_NAMESPACE_END