1 //
2 // Copyright 2021 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/server_config_selector/server_config_selector.h"
20
21 #include "src/core/lib/channel/channel_args.h"
22
23 namespace grpc_core {
24 namespace {
25
ServerConfigSelectorProviderArgCopy(void * p)26 void* ServerConfigSelectorProviderArgCopy(void* p) {
27 ServerConfigSelectorProvider* arg =
28 static_cast<ServerConfigSelectorProvider*>(p);
29 return arg->Ref().release();
30 }
31
ServerConfigSelectorProviderArgDestroy(void * p)32 void ServerConfigSelectorProviderArgDestroy(void* p) {
33 ServerConfigSelectorProvider* arg =
34 static_cast<ServerConfigSelectorProvider*>(p);
35 arg->Unref();
36 }
37
ServerConfigSelectorProviderArgCmp(void * p,void * q)38 int ServerConfigSelectorProviderArgCmp(void* p, void* q) {
39 return QsortCompare(p, q);
40 }
41
42 const grpc_arg_pointer_vtable kChannelArgVtable = {
43 ServerConfigSelectorProviderArgCopy, ServerConfigSelectorProviderArgDestroy,
44 ServerConfigSelectorProviderArgCmp};
45
46 const char* kServerConfigSelectorProviderChannelArgName =
47 "grpc.internal.server_config_selector_provider";
48
49 } // namespace
50
MakeChannelArg() const51 grpc_arg ServerConfigSelectorProvider::MakeChannelArg() const {
52 return grpc_channel_arg_pointer_create(
53 const_cast<char*>(kServerConfigSelectorProviderChannelArgName),
54 const_cast<ServerConfigSelectorProvider*>(this), &kChannelArgVtable);
55 }
56
57 RefCountedPtr<ServerConfigSelectorProvider>
GetFromChannelArgs(const grpc_channel_args & args)58 ServerConfigSelectorProvider::GetFromChannelArgs(
59 const grpc_channel_args& args) {
60 ServerConfigSelectorProvider* config_selector_provider =
61 grpc_channel_args_find_pointer<ServerConfigSelectorProvider>(
62 &args, kServerConfigSelectorProviderChannelArgName);
63 return config_selector_provider != nullptr ? config_selector_provider->Ref()
64 : nullptr;
65 }
66
67 } // namespace grpc_core
68