Craig Tiller | 178edfa | 2016-02-17 20:54:46 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 9b52412 | 2016-02-18 08:23:08 -0800 | [diff] [blame] | 3 | * Copyright 2016, Google Inc. |
Craig Tiller | 178edfa | 2016-02-17 20:54:46 -0800 | [diff] [blame] | 4 | * All rights reserved. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions are |
| 8 | * met: |
| 9 | * |
| 10 | * * Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * * Redistributions in binary form must reproduce the above |
| 13 | * copyright notice, this list of conditions and the following disclaimer |
| 14 | * in the documentation and/or other materials provided with the |
| 15 | * distribution. |
| 16 | * * Neither the name of Google Inc. nor the names of its |
| 17 | * contributors may be used to endorse or promote products derived from |
| 18 | * this software without specific prior written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | * |
| 32 | */ |
| 33 | |
Craig Tiller | 9a4dddd | 2016-03-25 17:08:13 -0700 | [diff] [blame] | 34 | #ifndef GRPC_CORE_LIB_SURFACE_CHANNEL_INIT_H |
| 35 | #define GRPC_CORE_LIB_SURFACE_CHANNEL_INIT_H |
Craig Tiller | 178edfa | 2016-02-17 20:54:46 -0800 | [diff] [blame] | 36 | |
Craig Tiller | 9533d04 | 2016-03-25 17:11:06 -0700 | [diff] [blame] | 37 | #include "src/core/lib/channel/channel_stack_builder.h" |
| 38 | #include "src/core/lib/surface/channel_stack_type.h" |
| 39 | #include "src/core/lib/transport/transport.h" |
Craig Tiller | 178edfa | 2016-02-17 20:54:46 -0800 | [diff] [blame] | 40 | |
Craig Tiller | b88e962 | 2016-02-22 21:34:41 -0800 | [diff] [blame] | 41 | /// This module provides a way for plugins (and the grpc core library itself) |
| 42 | /// to register mutators for channel stacks. |
| 43 | /// It also provides a universal entry path to run those mutators to build |
| 44 | /// a channel stack for various subsystems. |
Craig Tiller | 178edfa | 2016-02-17 20:54:46 -0800 | [diff] [blame] | 45 | |
Craig Tiller | b88e962 | 2016-02-22 21:34:41 -0800 | [diff] [blame] | 46 | /// One stage of mutation: call functions against \a builder to influence the |
| 47 | /// finally constructed channel stack |
Craig Tiller | 178edfa | 2016-02-17 20:54:46 -0800 | [diff] [blame] | 48 | typedef bool (*grpc_channel_init_stage)(grpc_channel_stack_builder *builder, |
| 49 | void *arg); |
| 50 | |
Craig Tiller | b88e962 | 2016-02-22 21:34:41 -0800 | [diff] [blame] | 51 | /// Global initialization of the system |
Craig Tiller | 178edfa | 2016-02-17 20:54:46 -0800 | [diff] [blame] | 52 | void grpc_channel_init_init(void); |
| 53 | |
Craig Tiller | b88e962 | 2016-02-22 21:34:41 -0800 | [diff] [blame] | 54 | /// Register one stage of mutators. |
| 55 | /// Stages are run in priority order (lowest to highest), and then in |
| 56 | /// registration order (in the case of a tie). |
| 57 | /// Stages are registered against one of the pre-determined channel stack |
| 58 | /// types. |
Craig Tiller | 178edfa | 2016-02-17 20:54:46 -0800 | [diff] [blame] | 59 | void grpc_channel_init_register_stage(grpc_channel_stack_type type, |
| 60 | int priority, |
Craig Tiller | b88e962 | 2016-02-22 21:34:41 -0800 | [diff] [blame] | 61 | grpc_channel_init_stage stage_fn, |
Craig Tiller | 178edfa | 2016-02-17 20:54:46 -0800 | [diff] [blame] | 62 | void *stage_arg); |
| 63 | |
Craig Tiller | b88e962 | 2016-02-22 21:34:41 -0800 | [diff] [blame] | 64 | /// Finalize registration. No more calls to grpc_channel_init_register_stage are |
| 65 | /// allowed. |
Craig Tiller | 178edfa | 2016-02-17 20:54:46 -0800 | [diff] [blame] | 66 | void grpc_channel_init_finalize(void); |
Craig Tiller | b88e962 | 2016-02-22 21:34:41 -0800 | [diff] [blame] | 67 | /// Shutdown the channel init system |
Craig Tiller | 178edfa | 2016-02-17 20:54:46 -0800 | [diff] [blame] | 68 | void grpc_channel_init_shutdown(void); |
| 69 | |
Craig Tiller | b88e962 | 2016-02-22 21:34:41 -0800 | [diff] [blame] | 70 | /// Construct a channel stack of some sort: see channel_stack.h for details |
| 71 | /// \a type is the type of channel stack to create |
| 72 | /// \a prefix_bytes is the number of bytes before the channel stack to allocate |
| 73 | /// \a args are configuration arguments for the channel stack |
| 74 | /// \a initial_refs is the initial refcount to give the channel stack |
| 75 | /// \a destroy and \a destroy_arg specify how to destroy the channel stack |
| 76 | /// if destroy_arg is NULL, the returned value from this function will be |
| 77 | /// substituted |
| 78 | /// \a optional_transport is either NULL or a constructed transport object |
| 79 | /// Returns a pointer to the base of the memory allocated (the actual channel |
| 80 | /// stack object will be prefix_bytes past that pointer) |
Craig Tiller | 178edfa | 2016-02-17 20:54:46 -0800 | [diff] [blame] | 81 | void *grpc_channel_init_create_stack( |
| 82 | grpc_exec_ctx *exec_ctx, grpc_channel_stack_type type, size_t prefix_bytes, |
| 83 | const grpc_channel_args *args, int initial_refs, grpc_iomgr_cb_func destroy, |
| 84 | void *destroy_arg, grpc_transport *optional_transport); |
| 85 | |
Craig Tiller | 9a4dddd | 2016-03-25 17:08:13 -0700 | [diff] [blame] | 86 | #endif /* GRPC_CORE_LIB_SURFACE_CHANNEL_INIT_H */ |