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