3 * Copyright 2015 gRPC authors.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <grpc/support/port_platform.h>
25 #include <grpc/support/alloc.h>
27 #include "src/core/ext/filters/client_channel/client_channel.h"
28 #include "src/core/ext/filters/client_channel/client_channel_channelz.h"
29 #include "src/core/ext/filters/client_channel/global_subchannel_pool.h"
30 #include "src/core/ext/filters/client_channel/http_connect_handshaker.h"
31 #include "src/core/ext/filters/client_channel/http_proxy.h"
32 #include "src/core/ext/filters/client_channel/lb_policy_registry.h"
33 #include "src/core/ext/filters/client_channel/proxy_mapper_registry.h"
34 #include "src/core/ext/filters/client_channel/resolver_registry.h"
35 #include "src/core/ext/filters/client_channel/resolver_result_parsing.h"
36 #include "src/core/ext/filters/client_channel/retry_throttle.h"
37 #include "src/core/lib/surface/channel_init.h"
39 static bool append_filter(grpc_channel_stack_builder* builder, void* arg) {
40 const grpc_channel_args* args =
41 grpc_channel_stack_builder_get_channel_arguments(builder);
42 grpc_arg args_to_add[] = {
43 grpc_core::channelz::ClientChannelNode::CreateChannelArg()};
44 grpc_channel_args* new_args = grpc_channel_args_copy_and_add(
45 args, args_to_add, GPR_ARRAY_SIZE(args_to_add));
46 grpc_channel_stack_builder_set_channel_arguments(builder, new_args);
47 grpc_channel_args_destroy(new_args);
48 return grpc_channel_stack_builder_append_filter(
49 builder, static_cast<const grpc_channel_filter*>(arg), nullptr, nullptr);
52 void grpc_client_channel_init(void) {
53 grpc_core::ServiceConfig::Init();
54 grpc_core::internal::ClientChannelServiceConfigParser::Register();
55 grpc_core::LoadBalancingPolicyRegistry::Builder::InitRegistry();
56 grpc_core::ResolverRegistry::Builder::InitRegistry();
57 grpc_core::internal::ServerRetryThrottleMap::Init();
58 grpc_proxy_mapper_registry_init();
59 grpc_register_http_proxy_mapper();
60 grpc_core::GlobalSubchannelPool::Init();
61 grpc_channel_init_register_stage(
62 GRPC_CLIENT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, append_filter,
63 (void*)&grpc_client_channel_filter);
64 grpc_http_connect_register_handshaker_factory();
67 void grpc_client_channel_shutdown(void) {
68 grpc_core::GlobalSubchannelPool::Shutdown();
69 grpc_channel_init_shutdown();
70 grpc_proxy_mapper_registry_shutdown();
71 grpc_core::internal::ServerRetryThrottleMap::Shutdown();
72 grpc_core::ResolverRegistry::Builder::ShutdownRegistry();
73 grpc_core::LoadBalancingPolicyRegistry::Builder::ShutdownRegistry();
74 grpc_core::ServiceConfig::Shutdown();