1 // 2 // Copyright 2016 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_SERVICE_CONFIG_SERVICE_CONFIG_H 18 #define GRPC_SRC_CORE_SERVICE_CONFIG_SERVICE_CONFIG_H 19 20 #include <grpc/slice.h> 21 #include <grpc/support/port_platform.h> 22 #include <stddef.h> 23 24 #include "absl/strings/string_view.h" 25 #include "src/core/service_config/service_config_parser.h" 26 #include "src/core/util/ref_counted.h" 27 #include "src/core/util/useful.h" 28 29 // The main purpose of the code here is to parse the service config in 30 // JSON form, which will look like this: 31 // 32 // { 33 // "loadBalancingPolicy": "string", // optional 34 // "methodConfig": [ // array of one or more method_config objects 35 // { 36 // "name": [ // array of one or more name objects 37 // { 38 // "service": "string", // required 39 // "method": "string", // optional 40 // } 41 // ], 42 // // remaining fields are optional. 43 // // see https://developers.google.com/protocol-buffers/docs/proto3#json 44 // // for format details. 45 // "waitForReady": bool, 46 // "timeout": "duration_string", 47 // "maxRequestMessageBytes": "int64_string", 48 // "maxResponseMessageBytes": "int64_string", 49 // } 50 // ] 51 // } 52 53 #define GRPC_ARG_SERVICE_CONFIG_OBJ "grpc.internal.service_config_obj" 54 55 namespace grpc_core { 56 57 // TODO(roth): Consider stripping this down further to the completely minimal 58 // interface required to be exposed as part of the resolver API. 59 class ServiceConfig : public RefCounted<ServiceConfig> { 60 public: ChannelArgName()61 static absl::string_view ChannelArgName() { 62 return GRPC_ARG_SERVICE_CONFIG_OBJ; 63 } ChannelArgsCompare(const ServiceConfig * a,const ServiceConfig * b)64 static int ChannelArgsCompare(const ServiceConfig* a, 65 const ServiceConfig* b) { 66 return QsortCompare(a, b); 67 } 68 69 virtual absl::string_view json_string() const = 0; 70 71 /// Retrieves the global parsed config at index \a index. The 72 /// lifetime of the returned object is tied to the lifetime of the 73 /// ServiceConfig object. 74 virtual ServiceConfigParser::ParsedConfig* GetGlobalParsedConfig( 75 size_t index) = 0; 76 77 /// Retrieves the vector of parsed configs for the method identified 78 /// by \a path. The lifetime of the returned vector and contained objects 79 /// is tied to the lifetime of the ServiceConfig object. 80 virtual const ServiceConfigParser::ParsedConfigVector* 81 GetMethodParsedConfigVector(const grpc_slice& path) const = 0; 82 }; 83 84 } // namespace grpc_core 85 86 #endif // GRPC_SRC_CORE_SERVICE_CONFIG_SERVICE_CONFIG_H 87