1 /*
2 *
3 * Copyright 2015 gRPC authors.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18
19 #include <grpc/support/port_platform.h>
20
21 #include "src/core/ext/filters/client_channel/client_channel_factory.h"
22 #include "src/core/lib/channel/channel_args.h"
23
24 // Channel arg key for client channel factory.
25 #define GRPC_ARG_CLIENT_CHANNEL_FACTORY "grpc.client_channel_factory"
26
27 namespace grpc_core {
28
29 namespace {
30
factory_arg_copy(void * f)31 void* factory_arg_copy(void* f) { return f; }
factory_arg_destroy(void *)32 void factory_arg_destroy(void* /*f*/) {}
factory_arg_cmp(void * factory1,void * factory2)33 int factory_arg_cmp(void* factory1, void* factory2) {
34 return GPR_ICMP(factory1, factory2);
35 }
36 const grpc_arg_pointer_vtable factory_arg_vtable = {
37 factory_arg_copy, factory_arg_destroy, factory_arg_cmp};
38
39 } // namespace
40
CreateChannelArg(ClientChannelFactory * factory)41 grpc_arg ClientChannelFactory::CreateChannelArg(ClientChannelFactory* factory) {
42 return grpc_channel_arg_pointer_create(
43 const_cast<char*>(GRPC_ARG_CLIENT_CHANNEL_FACTORY), factory,
44 &factory_arg_vtable);
45 }
46
GetFromChannelArgs(const grpc_channel_args * args)47 ClientChannelFactory* ClientChannelFactory::GetFromChannelArgs(
48 const grpc_channel_args* args) {
49 const grpc_arg* arg =
50 grpc_channel_args_find(args, GRPC_ARG_CLIENT_CHANNEL_FACTORY);
51 if (arg == nullptr || arg->type != GRPC_ARG_POINTER) return nullptr;
52 return static_cast<ClientChannelFactory*>(arg->value.pointer.p);
53 }
54
55 } // namespace grpc_core
56