• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  * Copyright 2016 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 #ifndef GRPC_CORE_LIB_SURFACE_CHANNEL_INIT_H
20 #define GRPC_CORE_LIB_SURFACE_CHANNEL_INIT_H
21 
22 #include <grpc/support/port_platform.h>
23 
24 #include "src/core/lib/channel/channel_stack_builder.h"
25 #include "src/core/lib/surface/channel_stack_type.h"
26 #include "src/core/lib/transport/transport.h"
27 
28 #define GRPC_CHANNEL_INIT_BUILTIN_PRIORITY 10000
29 
30 /// This module provides a way for plugins (and the grpc core library itself)
31 /// to register mutators for channel stacks.
32 /// It also provides a universal entry path to run those mutators to build
33 /// a channel stack for various subsystems.
34 
35 /// One stage of mutation: call functions against \a builder to influence the
36 /// finally constructed channel stack
37 typedef bool (*grpc_channel_init_stage)(grpc_channel_stack_builder* builder,
38                                         void* arg);
39 
40 /// Global initialization of the system
41 void grpc_channel_init_init(void);
42 
43 /// Register one stage of mutators.
44 /// Stages are run in priority order (lowest to highest), and then in
45 /// registration order (in the case of a tie).
46 /// Stages are registered against one of the pre-determined channel stack
47 /// types.
48 /// If the channel stack type is GRPC_CLIENT_SUBCHANNEL, the caller should
49 /// ensure that subchannels with different filter lists will always have
50 /// different channel args. This requires setting a channel arg in case the
51 /// registration function relies on some condition other than channel args to
52 /// decide whether to add a filter or not.
53 void grpc_channel_init_register_stage(grpc_channel_stack_type type,
54                                       int priority,
55                                       grpc_channel_init_stage stage_fn,
56                                       void* stage_arg);
57 
58 /// Finalize registration. No more calls to grpc_channel_init_register_stage are
59 /// allowed.
60 void grpc_channel_init_finalize(void);
61 /// Shutdown the channel init system
62 void grpc_channel_init_shutdown(void);
63 
64 /// Construct a channel stack of some sort: see channel_stack.h for details
65 /// \a type is the type of channel stack to create
66 /// \a prefix_bytes is the number of bytes before the channel stack to allocate
67 /// \a args are configuration arguments for the channel stack
68 /// \a initial_refs is the initial refcount to give the channel stack
69 /// \a destroy and \a destroy_arg specify how to destroy the channel stack
70 ///    if destroy_arg is NULL, the returned value from this function will be
71 ///    substituted
72 /// \a optional_transport is either NULL or a constructed transport object
73 /// Returns a pointer to the base of the memory allocated (the actual channel
74 /// stack object will be prefix_bytes past that pointer)
75 bool grpc_channel_init_create_stack(grpc_channel_stack_builder* builder,
76                                     grpc_channel_stack_type type);
77 
78 #endif /* GRPC_CORE_LIB_SURFACE_CHANNEL_INIT_H */
79