Home | History | Annotate | Download | only in surface
      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 void grpc_channel_init_register_stage(grpc_channel_stack_type type,
     49                                       int priority,
     50                                       grpc_channel_init_stage stage_fn,
     51                                       void* stage_arg);
     52 
     53 /// Finalize registration. No more calls to grpc_channel_init_register_stage are
     54 /// allowed.
     55 void grpc_channel_init_finalize(void);
     56 /// Shutdown the channel init system
     57 void grpc_channel_init_shutdown(void);
     58 
     59 /// Construct a channel stack of some sort: see channel_stack.h for details
     60 /// \a type is the type of channel stack to create
     61 /// \a prefix_bytes is the number of bytes before the channel stack to allocate
     62 /// \a args are configuration arguments for the channel stack
     63 /// \a initial_refs is the initial refcount to give the channel stack
     64 /// \a destroy and \a destroy_arg specify how to destroy the channel stack
     65 ///    if destroy_arg is NULL, the returned value from this function will be
     66 ///    substituted
     67 /// \a optional_transport is either NULL or a constructed transport object
     68 /// Returns a pointer to the base of the memory allocated (the actual channel
     69 /// stack object will be prefix_bytes past that pointer)
     70 bool grpc_channel_init_create_stack(grpc_channel_stack_builder* builder,
     71                                     grpc_channel_stack_type type);
     72 
     73 #endif /* GRPC_CORE_LIB_SURFACE_CHANNEL_INIT_H */
     74