• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2018 gRPC authors.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_RESULT_PARSING_H
18 #define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_RESULT_PARSING_H
19 
20 #include <grpc/support/port_platform.h>
21 
22 #include "absl/types/optional.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/service_config.h"
28 #include "src/core/lib/channel/status_util.h"
29 #include "src/core/lib/gprpp/ref_counted.h"
30 #include "src/core/lib/gprpp/ref_counted_ptr.h"
31 #include "src/core/lib/iomgr/exec_ctx.h"  // for grpc_millis
32 #include "src/core/lib/json/json.h"
33 
34 namespace grpc_core {
35 namespace internal {
36 
37 class ClientChannelGlobalParsedConfig
38     : public ServiceConfigParser::ParsedConfig {
39  public:
ClientChannelGlobalParsedConfig(RefCountedPtr<LoadBalancingPolicy::Config> parsed_lb_config,std::string parsed_deprecated_lb_policy,absl::optional<std::string> health_check_service_name)40   ClientChannelGlobalParsedConfig(
41       RefCountedPtr<LoadBalancingPolicy::Config> parsed_lb_config,
42       std::string parsed_deprecated_lb_policy,
43       absl::optional<std::string> health_check_service_name)
44       : parsed_lb_config_(std::move(parsed_lb_config)),
45         parsed_deprecated_lb_policy_(std::move(parsed_deprecated_lb_policy)),
46         health_check_service_name_(std::move(health_check_service_name)) {}
47 
parsed_lb_config()48   RefCountedPtr<LoadBalancingPolicy::Config> parsed_lb_config() const {
49     return parsed_lb_config_;
50   }
51 
parsed_deprecated_lb_policy()52   const std::string& parsed_deprecated_lb_policy() const {
53     return parsed_deprecated_lb_policy_;
54   }
55 
health_check_service_name()56   const absl::optional<std::string>& health_check_service_name() const {
57     return health_check_service_name_;
58   }
59 
60  private:
61   RefCountedPtr<LoadBalancingPolicy::Config> parsed_lb_config_;
62   std::string parsed_deprecated_lb_policy_;
63   absl::optional<std::string> health_check_service_name_;
64 };
65 
66 class ClientChannelMethodParsedConfig
67     : public ServiceConfigParser::ParsedConfig {
68  public:
ClientChannelMethodParsedConfig(grpc_millis timeout,const absl::optional<bool> & wait_for_ready)69   ClientChannelMethodParsedConfig(grpc_millis timeout,
70                                   const absl::optional<bool>& wait_for_ready)
71       : timeout_(timeout), wait_for_ready_(wait_for_ready) {}
72 
timeout()73   grpc_millis timeout() const { return timeout_; }
74 
wait_for_ready()75   absl::optional<bool> wait_for_ready() const { return wait_for_ready_; }
76 
77  private:
78   grpc_millis timeout_ = 0;
79   absl::optional<bool> wait_for_ready_;
80 };
81 
82 class ClientChannelServiceConfigParser : public ServiceConfigParser::Parser {
83  public:
84   std::unique_ptr<ServiceConfigParser::ParsedConfig> ParseGlobalParams(
85       const grpc_channel_args* /*args*/, const Json& json,
86       grpc_error_handle* error) override;
87 
88   std::unique_ptr<ServiceConfigParser::ParsedConfig> ParsePerMethodParams(
89       const grpc_channel_args* /*args*/, const Json& json,
90       grpc_error_handle* error) override;
91 
92   static size_t ParserIndex();
93   static void Register();
94 };
95 
96 }  // namespace internal
97 }  // namespace grpc_core
98 
99 #endif  // GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_RESULT_PARSING_H
100