1 //
2 // Copyright 2020 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 #include <grpc/support/port_platform.h>
18 
19 #include "src/core/ext/filters/client_channel/config_selector.h"
20 #include "src/core/lib/channel/channel_args.h"
21 
22 namespace grpc_core {
23 
24 namespace {
25 
ConfigSelectorArgCopy(void * p)26 void* ConfigSelectorArgCopy(void* p) {
27   ConfigSelector* config_selector = static_cast<ConfigSelector*>(p);
28   config_selector->Ref().release();
29   return p;
30 }
31 
ConfigSelectorArgDestroy(void * p)32 void ConfigSelectorArgDestroy(void* p) {
33   ConfigSelector* config_selector = static_cast<ConfigSelector*>(p);
34   config_selector->Unref();
35 }
36 
ConfigSelectorArgCmp(void * p,void * q)37 int ConfigSelectorArgCmp(void* p, void* q) { return GPR_ICMP(p, q); }
38 
39 const grpc_arg_pointer_vtable kChannelArgVtable = {
40     ConfigSelectorArgCopy, ConfigSelectorArgDestroy, ConfigSelectorArgCmp};
41 
42 }  // namespace
43 
MakeChannelArg() const44 grpc_arg ConfigSelector::MakeChannelArg() const {
45   return grpc_channel_arg_pointer_create(
46       const_cast<char*>(GRPC_ARG_CONFIG_SELECTOR),
47       const_cast<ConfigSelector*>(this), &kChannelArgVtable);
48 }
49 
GetFromChannelArgs(const grpc_channel_args & args)50 RefCountedPtr<ConfigSelector> ConfigSelector::GetFromChannelArgs(
51     const grpc_channel_args& args) {
52   ConfigSelector* config_selector =
53       grpc_channel_args_find_pointer<ConfigSelector>(&args,
54                                                      GRPC_ARG_CONFIG_SELECTOR);
55   return config_selector != nullptr ? config_selector->Ref() : nullptr;
56 }
57 
58 }  // namespace grpc_core
59