GRPC Core  18.0.0
service_config_call_data.h
Go to the documentation of this file.
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_EXT_FILTERS_CLIENT_CHANNEL_SERVICE_CONFIG_CALL_DATA_H
18 #define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_SERVICE_CONFIG_CALL_DATA_H
19 
21 
22 #include <map>
23 
24 #include "absl/strings/string_view.h"
25 
30 
31 namespace grpc_core {
32 
38  public:
41  const ServiceConfigParser::ParsedConfigVector* method_configs,
42  std::map<const char*, absl::string_view> call_attributes,
43  grpc_call_context_element* call_context)
44  : service_config_(std::move(service_config)),
45  method_configs_(method_configs),
46  call_attributes_(std::move(call_attributes)) {
47  call_context[GRPC_CONTEXT_SERVICE_CONFIG_CALL_DATA].value = this;
48  call_context[GRPC_CONTEXT_SERVICE_CONFIG_CALL_DATA].destroy = Destroy;
49  }
50 
53  const ServiceConfigParser::ParsedConfigVector* method_configs,
54  grpc_call_context_element* call_context)
55  : ServiceConfigCallData(std::move(service_config), method_configs, {},
56  call_context) {}
57 
58  ServiceConfig* service_config() { return service_config_.get(); }
59 
61  return method_configs_ != nullptr ? (*method_configs_)[index].get()
62  : nullptr;
63  }
64 
66  return service_config_->GetGlobalParsedConfig(index);
67  }
68 
69  const std::map<const char*, absl::string_view>& call_attributes() const {
70  return call_attributes_;
71  }
72 
73  private:
74  static void Destroy(void* ptr) {
75  ServiceConfigCallData* self = static_cast<ServiceConfigCallData*>(ptr);
76  self->~ServiceConfigCallData();
77  }
78 
79  RefCountedPtr<ServiceConfig> service_config_;
80  const ServiceConfigParser::ParsedConfigVector* method_configs_ = nullptr;
81  std::map<const char*, absl::string_view> call_attributes_;
82 };
83 
84 } // namespace grpc_core
85 
86 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_SERVICE_CONFIG_CALL_DATA_H */
Definition: ref_counted_ptr.h:35
When a service config is applied to a call in the client_channel_filter, we create an instance of thi...
Definition: service_config_call_data.h:37
ServiceConfigParser::ParsedConfig * GetMethodParsedConfig(size_t index) const
Definition: service_config_call_data.h:60
ServiceConfigParser::ParsedConfig * GetGlobalParsedConfig(size_t index) const
Definition: service_config_call_data.h:65
const std::map< const char *, absl::string_view > & call_attributes() const
Definition: service_config_call_data.h:69
ServiceConfig * service_config()
Definition: service_config_call_data.h:58
ServiceConfigCallData(RefCountedPtr< ServiceConfig > service_config, const ServiceConfigParser::ParsedConfigVector *method_configs, grpc_call_context_element *call_context)
Definition: service_config_call_data.h:51
ServiceConfigCallData(RefCountedPtr< ServiceConfig > service_config, const ServiceConfigParser::ParsedConfigVector *method_configs, std::map< const char *, absl::string_view > call_attributes, grpc_call_context_element *call_context)
Definition: service_config_call_data.h:39
Definition: service_config.h:64
This is the base class that all service config parsers MUST use to store parsed service config data.
Definition: service_config_parser.h:39
absl::InlinedVector< std::unique_ptr< ParsedConfig >, kNumPreallocatedParsers > ParsedConfigVector
Definition: service_config_parser.h:71
@ GRPC_CONTEXT_SERVICE_CONFIG_CALL_DATA
Holds a pointer to ServiceConfigCallData associated with this call.
Definition: context.h:39
Round Robin Policy.
Definition: backend_metric.cc:26
Definition: context.h:44
void(* destroy)(void *)
Definition: context.h:46
void * value
Definition: context.h:45