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_SRC_CORE_CLIENT_CHANNEL_CLIENT_CHANNEL_SERVICE_CONFIG_H 18 #define GRPC_SRC_CORE_CLIENT_CHANNEL_CLIENT_CHANNEL_SERVICE_CONFIG_H 19 20 #include <grpc/support/port_platform.h> 21 #include <stddef.h> 22 23 #include <memory> 24 #include <string> 25 26 #include "absl/strings/string_view.h" 27 #include "absl/types/optional.h" 28 #include "src/core/config/core_configuration.h" 29 #include "src/core/lib/channel/channel_args.h" 30 #include "src/core/load_balancing/lb_policy.h" 31 #include "src/core/service_config/service_config_parser.h" 32 #include "src/core/util/json/json.h" 33 #include "src/core/util/json/json_args.h" 34 #include "src/core/util/json/json_object_loader.h" 35 #include "src/core/util/ref_counted_ptr.h" 36 #include "src/core/util/time.h" 37 #include "src/core/util/validation_errors.h" 38 39 namespace grpc_core { 40 namespace internal { 41 42 class ClientChannelGlobalParsedConfig final 43 : public ServiceConfigParser::ParsedConfig { 44 public: parsed_lb_config()45 RefCountedPtr<LoadBalancingPolicy::Config> parsed_lb_config() const { 46 return parsed_lb_config_; 47 } 48 parsed_deprecated_lb_policy()49 const std::string& parsed_deprecated_lb_policy() const { 50 return parsed_deprecated_lb_policy_; 51 } 52 health_check_service_name()53 const absl::optional<std::string>& health_check_service_name() const { 54 return health_check_config_.service_name; 55 } 56 57 static const JsonLoaderInterface* JsonLoader(const JsonArgs&); 58 void JsonPostLoad(const Json& json, const JsonArgs&, 59 ValidationErrors* errors); 60 61 private: 62 struct HealthCheckConfig { 63 absl::optional<std::string> service_name; 64 65 static const JsonLoaderInterface* JsonLoader(const JsonArgs&); 66 }; 67 68 RefCountedPtr<LoadBalancingPolicy::Config> parsed_lb_config_; 69 std::string parsed_deprecated_lb_policy_; 70 HealthCheckConfig health_check_config_; 71 }; 72 73 class ClientChannelMethodParsedConfig final 74 : public ServiceConfigParser::ParsedConfig { 75 public: timeout()76 Duration timeout() const { return timeout_; } 77 wait_for_ready()78 absl::optional<bool> wait_for_ready() const { return wait_for_ready_; } 79 80 static const JsonLoaderInterface* JsonLoader(const JsonArgs&); 81 82 private: 83 Duration timeout_; 84 absl::optional<bool> wait_for_ready_; 85 }; 86 87 class ClientChannelServiceConfigParser final 88 : public ServiceConfigParser::Parser { 89 public: name()90 absl::string_view name() const override { return parser_name(); } 91 92 std::unique_ptr<ServiceConfigParser::ParsedConfig> ParseGlobalParams( 93 const ChannelArgs& /*args*/, const Json& json, 94 ValidationErrors* errors) override; 95 96 std::unique_ptr<ServiceConfigParser::ParsedConfig> ParsePerMethodParams( 97 const ChannelArgs& /*args*/, const Json& json, 98 ValidationErrors* errors) override; 99 100 static size_t ParserIndex(); 101 static void Register(CoreConfiguration::Builder* builder); 102 103 private: parser_name()104 static absl::string_view parser_name() { return "client_channel"; } 105 }; 106 107 } // namespace internal 108 } // namespace grpc_core 109 110 #endif // GRPC_SRC_CORE_CLIENT_CHANNEL_CLIENT_CHANNEL_SERVICE_CONFIG_H 111