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