Built motion from commit 44377920.|2.6.11
[motion2.git] / legacy-libs / grpc / deps / grpc / src / core / ext / filters / client_channel / resolver_result_parsing.h
1 /*
2  *
3  * Copyright 2018 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18
19 #ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_RESULT_PARSING_H
20 #define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_RESULT_PARSING_H
21
22 #include <grpc/support/port_platform.h>
23
24 #include "src/core/ext/filters/client_channel/lb_policy.h"
25 #include "src/core/ext/filters/client_channel/lb_policy_factory.h"
26 #include "src/core/ext/filters/client_channel/resolver.h"
27 #include "src/core/ext/filters/client_channel/retry_throttle.h"
28 #include "src/core/ext/filters/client_channel/service_config.h"
29 #include "src/core/lib/channel/status_util.h"
30 #include "src/core/lib/gprpp/optional.h"
31 #include "src/core/lib/gprpp/ref_counted.h"
32 #include "src/core/lib/gprpp/ref_counted_ptr.h"
33 #include "src/core/lib/iomgr/exec_ctx.h"  // for grpc_millis
34 #include "src/core/lib/json/json.h"
35 #include "src/core/lib/slice/slice_hash_table.h"
36
37 namespace grpc_core {
38 namespace internal {
39
40 class ClientChannelGlobalParsedConfig : public ServiceConfig::ParsedConfig {
41  public:
42   struct RetryThrottling {
43     intptr_t max_milli_tokens = 0;
44     intptr_t milli_token_ratio = 0;
45   };
46
47   ClientChannelGlobalParsedConfig(
48       RefCountedPtr<LoadBalancingPolicy::Config> parsed_lb_config,
49       UniquePtr<char> parsed_deprecated_lb_policy,
50       const Optional<RetryThrottling>& retry_throttling,
51       const char* health_check_service_name)
52       : parsed_lb_config_(std::move(parsed_lb_config)),
53         parsed_deprecated_lb_policy_(std::move(parsed_deprecated_lb_policy)),
54         retry_throttling_(retry_throttling),
55         health_check_service_name_(health_check_service_name) {}
56
57   Optional<RetryThrottling> retry_throttling() const {
58     return retry_throttling_;
59   }
60
61   RefCountedPtr<LoadBalancingPolicy::Config> parsed_lb_config() const {
62     return parsed_lb_config_;
63   }
64
65   const char* parsed_deprecated_lb_policy() const {
66     return parsed_deprecated_lb_policy_.get();
67   }
68
69   const char* health_check_service_name() const {
70     return health_check_service_name_;
71   }
72
73  private:
74   RefCountedPtr<LoadBalancingPolicy::Config> parsed_lb_config_;
75   UniquePtr<char> parsed_deprecated_lb_policy_;
76   Optional<RetryThrottling> retry_throttling_;
77   const char* health_check_service_name_;
78 };
79
80 class ClientChannelMethodParsedConfig : public ServiceConfig::ParsedConfig {
81  public:
82   struct RetryPolicy {
83     int max_attempts = 0;
84     grpc_millis initial_backoff = 0;
85     grpc_millis max_backoff = 0;
86     float backoff_multiplier = 0;
87     StatusCodeSet retryable_status_codes;
88   };
89
90   ClientChannelMethodParsedConfig(grpc_millis timeout,
91                                   const Optional<bool>& wait_for_ready,
92                                   UniquePtr<RetryPolicy> retry_policy)
93       : timeout_(timeout),
94         wait_for_ready_(wait_for_ready),
95         retry_policy_(std::move(retry_policy)) {}
96
97   grpc_millis timeout() const { return timeout_; }
98
99   Optional<bool> wait_for_ready() const { return wait_for_ready_; }
100
101   const RetryPolicy* retry_policy() const { return retry_policy_.get(); }
102
103  private:
104   grpc_millis timeout_ = 0;
105   Optional<bool> wait_for_ready_;
106   UniquePtr<RetryPolicy> retry_policy_;
107 };
108
109 class ClientChannelServiceConfigParser : public ServiceConfig::Parser {
110  public:
111   UniquePtr<ServiceConfig::ParsedConfig> ParseGlobalParams(
112       const grpc_json* json, grpc_error** error) override;
113
114   UniquePtr<ServiceConfig::ParsedConfig> ParsePerMethodParams(
115       const grpc_json* json, grpc_error** error) override;
116
117   static size_t ParserIndex();
118   static void Register();
119 };
120
121 }  // namespace internal
122 }  // namespace grpc_core
123
124 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_RESULT_PARSING_H */