• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
grpc_client_channel_factory_ref(grpc_client_channel_factory * factory)24 void grpc_client_channel_factory_ref(grpc_client_channel_factory* factory) {
25   factory->vtable->ref(factory);
26 }
27 
grpc_client_channel_factory_unref(grpc_client_channel_factory * factory)28 void grpc_client_channel_factory_unref(grpc_client_channel_factory* factory) {
29   factory->vtable->unref(factory);
30 }
31 
grpc_client_channel_factory_create_subchannel(grpc_client_channel_factory * factory,const grpc_subchannel_args * args)32 grpc_subchannel* grpc_client_channel_factory_create_subchannel(
33     grpc_client_channel_factory* factory, const grpc_subchannel_args* args) {
34   return factory->vtable->create_subchannel(factory, args);
35 }
36 
grpc_client_channel_factory_create_channel(grpc_client_channel_factory * factory,const char * target,grpc_client_channel_type type,const grpc_channel_args * args)37 grpc_channel* grpc_client_channel_factory_create_channel(
38     grpc_client_channel_factory* factory, const char* target,
39     grpc_client_channel_type type, const grpc_channel_args* args) {
40   return factory->vtable->create_client_channel(factory, target, type, args);
41 }
42 
factory_arg_copy(void * factory)43 static void* factory_arg_copy(void* factory) {
44   grpc_client_channel_factory_ref(
45       static_cast<grpc_client_channel_factory*>(factory));
46   return factory;
47 }
48 
factory_arg_destroy(void * factory)49 static void factory_arg_destroy(void* factory) {
50   grpc_client_channel_factory_unref(
51       static_cast<grpc_client_channel_factory*>(factory));
52 }
53 
factory_arg_cmp(void * factory1,void * factory2)54 static int factory_arg_cmp(void* factory1, void* factory2) {
55   if (factory1 < factory2) return -1;
56   if (factory1 > factory2) return 1;
57   return 0;
58 }
59 
60 static const grpc_arg_pointer_vtable factory_arg_vtable = {
61     factory_arg_copy, factory_arg_destroy, factory_arg_cmp};
62 
grpc_client_channel_factory_create_channel_arg(grpc_client_channel_factory * factory)63 grpc_arg grpc_client_channel_factory_create_channel_arg(
64     grpc_client_channel_factory* factory) {
65   return grpc_channel_arg_pointer_create((char*)GRPC_ARG_CLIENT_CHANNEL_FACTORY,
66                                          factory, &factory_arg_vtable);
67 }
68