8bd41f2c7220183eb5452f53959ac0f7d95c1397
[platform/upstream/grpc.git] / src / core / ext / filters / client_channel / client_channel_plugin.cc
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 <limits.h>
22 #include <stdbool.h>
23 #include <string.h>
24
25 #include <grpc/support/alloc.h>
26
27 #include "src/core/ext/filters/client_channel/backup_poller.h"
28 #include "src/core/ext/filters/client_channel/client_channel.h"
29 #include "src/core/ext/filters/client_channel/client_channel_channelz.h"
30 #include "src/core/ext/filters/client_channel/global_subchannel_pool.h"
31 #include "src/core/ext/filters/client_channel/http_connect_handshaker.h"
32 #include "src/core/ext/filters/client_channel/http_proxy.h"
33 #include "src/core/ext/filters/client_channel/lb_policy_registry.h"
34 #include "src/core/ext/filters/client_channel/proxy_mapper_registry.h"
35 #include "src/core/ext/filters/client_channel/resolver_registry.h"
36 #include "src/core/ext/filters/client_channel/resolver_result_parsing.h"
37 #include "src/core/ext/filters/client_channel/retry_service_config.h"
38 #include "src/core/ext/filters/client_channel/retry_throttle.h"
39 #include "src/core/ext/filters/client_channel/service_config_parser.h"
40 #include "src/core/lib/surface/channel_init.h"
41
42 static bool append_filter(grpc_channel_stack_builder* builder, void* arg) {
43   return grpc_channel_stack_builder_append_filter(
44       builder, static_cast<const grpc_channel_filter*>(arg), nullptr, nullptr);
45 }
46
47 void grpc_client_channel_init(void) {
48   grpc_core::ServiceConfigParser::Init();
49   grpc_core::internal::ClientChannelServiceConfigParser::Register();
50   grpc_core::internal::RetryServiceConfigParser::Register();
51   grpc_core::LoadBalancingPolicyRegistry::Builder::InitRegistry();
52   grpc_core::ResolverRegistry::Builder::InitRegistry();
53   grpc_core::internal::ServerRetryThrottleMap::Init();
54   grpc_core::ProxyMapperRegistry::Init();
55   grpc_core::RegisterHttpProxyMapper();
56   grpc_core::GlobalSubchannelPool::Init();
57   grpc_channel_init_register_stage(
58       GRPC_CLIENT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, append_filter,
59       const_cast<grpc_channel_filter*>(
60           &grpc_core::ClientChannel::kFilterVtable));
61   grpc_client_channel_global_init_backup_polling();
62 }
63
64 void grpc_client_channel_shutdown(void) {
65   grpc_core::GlobalSubchannelPool::Shutdown();
66   grpc_channel_init_shutdown();
67   grpc_core::ProxyMapperRegistry::Shutdown();
68   grpc_core::internal::ServerRetryThrottleMap::Shutdown();
69   grpc_core::ResolverRegistry::Builder::ShutdownRegistry();
70   grpc_core::LoadBalancingPolicyRegistry::Builder::ShutdownRegistry();
71   grpc_core::ServiceConfigParser::Shutdown();
72 }
73
74 namespace grpc_core {
75
76 void BuildClientChannelConfiguration(CoreConfiguration::Builder* builder) {
77   RegisterHttpConnectHandshaker(builder);
78 }
79
80 }  // namespace grpc_core