userver: userver/ugrpc/client/impl/call_params.hpp Source File
Loading...
Searching...
No Matches
call_params.hpp
1#pragma once
2
3#include <string_view>
4
5#include <grpcpp/client_context.h>
6#include <grpcpp/completion_queue.h>
7
8#include <userver/dynamic_config/snapshot.hpp>
9
10#include <userver/ugrpc/client/impl/client_data.hpp>
11#include <userver/ugrpc/client/middlewares/fwd.hpp>
12#include <userver/ugrpc/client/qos.hpp>
13#include <userver/ugrpc/impl/statistics.hpp>
14
15USERVER_NAMESPACE_BEGIN
16
17namespace ugrpc::client::impl {
18
19struct CallParams {
20 std::string_view client_name;
21 grpc::CompletionQueue& queue;
22 dynamic_config::Snapshot config;
23 std::string_view call_name;
24 std::unique_ptr<grpc::ClientContext> context;
25 ugrpc::impl::MethodStatistics& statistics;
26 const Middlewares& mws;
27};
28
29CallParams DoCreateCallParams(const ClientData&, std::size_t method_id,
30 std::unique_ptr<grpc::ClientContext>);
31
32template <typename ClientQosConfig>
33CallParams CreateCallParams(const ClientData& client_data,
34 std::size_t method_id,
35 std::unique_ptr<grpc::ClientContext> client_context,
36 const ClientQosConfig& client_qos,
37 const ugrpc::client::Qos& qos) {
38 const auto& metadata = client_data.GetMetadata();
39 const auto& full_name = metadata.method_full_names[method_id];
40 const auto& method_name =
41 full_name.substr(metadata.service_full_name.size() + 1);
42
43 const auto& config = client_data.GetConfigSnapshot();
44
45 // User qos goes first
46 ApplyQos(*client_context, qos, client_data.GetTestsuiteControl());
47
48 // If user qos was empty update timeout from config
49 ApplyQos(*client_context, config[client_qos][method_name],
50 client_data.GetTestsuiteControl());
51
52 return DoCreateCallParams(client_data, method_id, std::move(client_context));
53}
54
55} // namespace ugrpc::client::impl
56
57USERVER_NAMESPACE_END