Home | History | Annotate | Download | only in client_channel
      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/client_channel.h"
     28 #include "src/core/ext/filters/client_channel/client_channel_channelz.h"
     29 #include "src/core/ext/filters/client_channel/http_connect_handshaker.h"
     30 #include "src/core/ext/filters/client_channel/http_proxy.h"
     31 #include "src/core/ext/filters/client_channel/lb_policy_registry.h"
     32 #include "src/core/ext/filters/client_channel/proxy_mapper_registry.h"
     33 #include "src/core/ext/filters/client_channel/resolver_registry.h"
     34 #include "src/core/ext/filters/client_channel/retry_throttle.h"
     35 #include "src/core/ext/filters/client_channel/subchannel_index.h"
     36 #include "src/core/lib/surface/channel_init.h"
     37 
     38 static bool append_filter(grpc_channel_stack_builder* builder, void* arg) {
     39   const grpc_channel_args* args =
     40       grpc_channel_stack_builder_get_channel_arguments(builder);
     41   grpc_arg args_to_add[] = {
     42       grpc_core::channelz::ClientChannelNode::CreateChannelArg()};
     43   grpc_channel_args* new_args = grpc_channel_args_copy_and_add(
     44       args, args_to_add, GPR_ARRAY_SIZE(args_to_add));
     45   grpc_channel_stack_builder_set_channel_arguments(builder, new_args);
     46   grpc_channel_args_destroy(new_args);
     47   return grpc_channel_stack_builder_append_filter(
     48       builder, static_cast<const grpc_channel_filter*>(arg), nullptr, nullptr);
     49 }
     50 
     51 void grpc_client_channel_init(void) {
     52   grpc_core::LoadBalancingPolicyRegistry::Builder::InitRegistry();
     53   grpc_core::ResolverRegistry::Builder::InitRegistry();
     54   grpc_core::internal::ServerRetryThrottleMap::Init();
     55   grpc_proxy_mapper_registry_init();
     56   grpc_register_http_proxy_mapper();
     57   grpc_subchannel_index_init();
     58   grpc_channel_init_register_stage(
     59       GRPC_CLIENT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, append_filter,
     60       (void*)&grpc_client_channel_filter);
     61   grpc_http_connect_register_handshaker_factory();
     62 }
     63 
     64 void grpc_client_channel_shutdown(void) {
     65   grpc_subchannel_index_shutdown();
     66   grpc_channel_init_shutdown();
     67   grpc_proxy_mapper_registry_shutdown();
     68   grpc_core::internal::ServerRetryThrottleMap::Shutdown();
     69   grpc_core::ResolverRegistry::Builder::ShutdownRegistry();
     70   grpc_core::LoadBalancingPolicyRegistry::Builder::ShutdownRegistry();
     71 }
     72