Debian Codegraph @

src/core/lib/service_config/service_config_call_data.h

raw
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_CORE_LIB_SERVICE_CONFIG_SERVICE_CONFIG_CALL_DATA_H
18 #define GRPC_CORE_LIB_SERVICE_CONFIG_SERVICE_CONFIG_CALL_DATA_H
19
20 #include <grpc/support/port_platform.h>
21
22 #include <stddef.h>
23
24 #include <map>
25 #include <memory>
26 #include <utility>
27
28 #include "absl/strings/string_view.h"
29
30 #include "src/core/lib/gprpp/ref_counted_ptr.h"
31 #include "src/core/lib/gprpp/unique_type_name.h"
32 #include "src/core/lib/service_config/service_config.h"
33 #include "src/core/lib/service_config/service_config_parser.h"
34
35 namespace grpc_core {
36
37 /// Stores the service config data associated with an individual call.
38 /// A pointer to this object is stored in the call_context
39 /// GRPC_CONTEXT_SERVICE_CONFIG_CALL_DATA element, so that filters can
40 /// easily access method and global parameters for the call.
41 class ServiceConfigCallData {
42 public:
43 using CallAttributes = std::map<UniqueTypeName, absl::string_view>;
44
45 ServiceConfigCallData() : method_configs_(nullptr) {}
46
47 ServiceConfigCallData(
48 RefCountedPtr<ServiceConfig> service_config,
49 const ServiceConfigParser::ParsedConfigVector* method_configs,
50 CallAttributes call_attributes)
51 : service_config_(std::move(service_config)),
52 method_configs_(method_configs),
53 call_attributes_(std::move(call_attributes)) {}
54
55 ServiceConfig* service_config() { return service_config_.get(); }
56
57 ServiceConfigParser::ParsedConfig* GetMethodParsedConfig(size_t index) const {
58 return method_configs_ != nullptr ? (*method_configs_)[index].get()
59 : nullptr;
60 }
61
62 ServiceConfigParser::ParsedConfig* GetGlobalParsedConfig(size_t index) const {
63 return service_config_->GetGlobalParsedConfig(index);
64 }
65
66 const CallAttributes& call_attributes() const { return call_attributes_; }
67
68 private:
69 RefCountedPtr<ServiceConfig> service_config_;
70 const ServiceConfigParser::ParsedConfigVector* method_configs_;
71 CallAttributes call_attributes_;
72 };
73
74 } // namespace grpc_core
75
76 #endif /* GRPC_CORE_LIB_SERVICE_CONFIG_SERVICE_CONFIG_CALL_DATA_H */