Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 6169d5f | 2016-03-31 07:46:18 -0700 | [diff] [blame] | 3 | * Copyright 2015, Google Inc. |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -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_CHANNEL_CHANNEL_STACK_H |
| 35 | #define GRPC_CORE_LIB_CHANNEL_CHANNEL_STACK_H |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 36 | |
Mark D. Roth | aa1cd14 | 2016-12-12 10:24:59 -0800 | [diff] [blame^] | 37 | ////////////////////////////////////////////////////////////////////////////// |
| 38 | // IMPORTANT NOTE: |
| 39 | // |
| 40 | // When you update this API, please make the corresponding changes to |
| 41 | // the C++ API in src/cpp/common/channel_filter.{h,cc} |
| 42 | ////////////////////////////////////////////////////////////////////////////// |
| 43 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 44 | /* A channel filter defines how operations on a channel are implemented. |
| 45 | Channel filters are chained together to create full channels, and if those |
| 46 | chains are linear, then channel stacks provide a mechanism to minimize |
| 47 | allocations for that chain. |
| 48 | Call stacks are created by channel stacks and represent the per-call data |
| 49 | for that stack. */ |
| 50 | |
| 51 | #include <stddef.h> |
| 52 | |
| 53 | #include <grpc/grpc.h> |
| 54 | #include <grpc/support/log.h> |
David Garcia Quintas | 9ef0e1c | 2016-04-14 12:44:30 -0700 | [diff] [blame] | 55 | #include <grpc/support/time.h> |
| 56 | |
Craig Tiller | 9533d04 | 2016-03-25 17:11:06 -0700 | [diff] [blame] | 57 | #include "src/core/lib/debug/trace.h" |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 58 | #include "src/core/lib/iomgr/polling_entity.h" |
Craig Tiller | 9533d04 | 2016-03-25 17:11:06 -0700 | [diff] [blame] | 59 | #include "src/core/lib/transport/transport.h" |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 60 | |
Mark D. Roth | c459ecf | 2016-06-16 09:17:49 -0700 | [diff] [blame] | 61 | #ifdef __cplusplus |
| 62 | extern "C" { |
| 63 | #endif |
| 64 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 65 | typedef struct grpc_channel_element grpc_channel_element; |
| 66 | typedef struct grpc_call_element grpc_call_element; |
| 67 | |
Craig Tiller | 906e3bc | 2015-11-24 07:31:31 -0800 | [diff] [blame] | 68 | typedef struct grpc_channel_stack grpc_channel_stack; |
| 69 | typedef struct grpc_call_stack grpc_call_stack; |
| 70 | |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 71 | typedef struct { |
Craig Tiller | 906e3bc | 2015-11-24 07:31:31 -0800 | [diff] [blame] | 72 | grpc_channel_stack *channel_stack; |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 73 | const grpc_channel_args *channel_args; |
Craig Tiller | 9d69e80 | 2016-06-06 11:37:50 -0700 | [diff] [blame] | 74 | /** Transport, iff it is known */ |
| 75 | grpc_transport *optional_transport; |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 76 | int is_first; |
| 77 | int is_last; |
| 78 | } grpc_channel_element_args; |
| 79 | |
| 80 | typedef struct { |
Craig Tiller | 906e3bc | 2015-11-24 07:31:31 -0800 | [diff] [blame] | 81 | grpc_call_stack *call_stack; |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 82 | const void *server_transport_data; |
| 83 | grpc_call_context_element *context; |
Mark D. Roth | aa850a7 | 2016-09-26 13:38:02 -0700 | [diff] [blame] | 84 | grpc_mdstr *path; |
Mark D. Roth | ff08f33 | 2016-10-14 13:01:01 -0700 | [diff] [blame] | 85 | gpr_timespec start_time; |
Mark D. Roth | f28763c | 2016-09-14 15:18:40 -0700 | [diff] [blame] | 86 | gpr_timespec deadline; |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 87 | } grpc_call_element_args; |
| 88 | |
David Garcia Quintas | 9ef0e1c | 2016-04-14 12:44:30 -0700 | [diff] [blame] | 89 | typedef struct { |
David Garcia Quintas | c9bb983 | 2016-04-14 12:52:31 -0700 | [diff] [blame] | 90 | grpc_transport_stream_stats transport_stream_stats; |
| 91 | gpr_timespec latency; /* From call creating to enqueing of received status */ |
David Garcia Quintas | 9ef0e1c | 2016-04-14 12:44:30 -0700 | [diff] [blame] | 92 | } grpc_call_stats; |
| 93 | |
David Garcia Quintas | 6eee24c | 2016-07-11 22:56:50 -0700 | [diff] [blame] | 94 | /** Information about the call upon completion. */ |
David Garcia Quintas | 01c4d99 | 2016-07-07 20:11:27 -0700 | [diff] [blame] | 95 | typedef struct { |
| 96 | grpc_call_stats stats; |
| 97 | grpc_status_code final_status; |
| 98 | } grpc_call_final_info; |
| 99 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 100 | /* Channel filters specify: |
| 101 | 1. the amount of memory needed in the channel & call (via the sizeof_XXX |
| 102 | members) |
| 103 | 2. functions to initialize and destroy channel & call data |
| 104 | (init_XXX, destroy_XXX) |
| 105 | 3. functions to implement call operations and channel operations (call_op, |
| 106 | channel_op) |
| 107 | 4. a name, which is useful when debugging |
| 108 | |
| 109 | Members are laid out in approximate frequency of use order. */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 110 | typedef struct { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 111 | /* Called to eg. send/receive data on a call. |
| 112 | See grpc_call_next_op on how to call the next element in the stack */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 113 | void (*start_transport_stream_op)(grpc_exec_ctx *exec_ctx, |
| 114 | grpc_call_element *elem, |
| 115 | grpc_transport_stream_op *op); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 116 | /* Called to handle channel level operations - e.g. new calls, or transport |
| 117 | closure. |
| 118 | See grpc_channel_next_op on how to call the next element in the stack */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 119 | void (*start_transport_op)(grpc_exec_ctx *exec_ctx, |
| 120 | grpc_channel_element *elem, grpc_transport_op *op); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 121 | |
| 122 | /* sizeof(per call data) */ |
| 123 | size_t sizeof_call_data; |
| 124 | /* Initialize per call data. |
| 125 | elem is initialized at the start of the call, and elem->call_data is what |
| 126 | needs initializing. |
| 127 | The filter does not need to do any chaining. |
| 128 | server_transport_data is an opaque pointer. If it is NULL, this call is |
| 129 | on a client; if it is non-NULL, then it points to memory owned by the |
| 130 | transport and is on the server. Most filters want to ignore this |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 131 | argument. */ |
Mark D. Roth | 76d2442 | 2016-06-23 13:22:10 -0700 | [diff] [blame] | 132 | grpc_error *(*init_call_elem)(grpc_exec_ctx *exec_ctx, |
Mark D. Roth | 0badbe8 | 2016-06-23 10:15:12 -0700 | [diff] [blame] | 133 | grpc_call_element *elem, |
| 134 | grpc_call_element_args *args); |
David Garcia Quintas | 4afce7e | 2016-04-18 16:25:17 -0700 | [diff] [blame] | 135 | void (*set_pollset_or_pollset_set)(grpc_exec_ctx *exec_ctx, |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 136 | grpc_call_element *elem, |
| 137 | grpc_polling_entity *pollent); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 138 | /* Destroy per call data. |
Craig Tiller | 2c8063c | 2016-03-22 22:12:15 -0700 | [diff] [blame] | 139 | The filter does not need to do any chaining. |
| 140 | The bottom filter of a stack will be passed a non-NULL pointer to |
| 141 | \a and_free_memory that should be passed to gpr_free when destruction |
David Garcia Quintas | 6eee24c | 2016-07-11 22:56:50 -0700 | [diff] [blame] | 142 | is complete. \a final_info contains data about the completed call, mainly |
David Garcia Quintas | 01c4d99 | 2016-07-07 20:11:27 -0700 | [diff] [blame] | 143 | for reporting purposes. */ |
Craig Tiller | 2c8063c | 2016-03-22 22:12:15 -0700 | [diff] [blame] | 144 | void (*destroy_call_elem)(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, |
David Garcia Quintas | 5dde14c | 2016-07-28 17:29:27 -0700 | [diff] [blame] | 145 | const grpc_call_final_info *final_info, |
Craig Tiller | 2c8063c | 2016-03-22 22:12:15 -0700 | [diff] [blame] | 146 | void *and_free_memory); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 147 | |
| 148 | /* sizeof(per channel data) */ |
| 149 | size_t sizeof_channel_data; |
| 150 | /* Initialize per-channel data. |
David Garcia Quintas | 01c4d99 | 2016-07-07 20:11:27 -0700 | [diff] [blame] | 151 | elem is initialized at the creating of the channel, and elem->channel_data |
| 152 | is what needs initializing. |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 153 | is_first, is_last designate this elements position in the stack, and are |
| 154 | useful for asserting correct configuration by upper layer code. |
| 155 | The filter does not need to do any chaining */ |
Mark D. Roth | 5e2566e | 2016-11-18 10:53:13 -0800 | [diff] [blame] | 156 | grpc_error *(*init_channel_elem)(grpc_exec_ctx *exec_ctx, |
| 157 | grpc_channel_element *elem, |
| 158 | grpc_channel_element_args *args); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 159 | /* Destroy per channel data. |
| 160 | The filter does not need to do any chaining */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 161 | void (*destroy_channel_elem)(grpc_exec_ctx *exec_ctx, |
| 162 | grpc_channel_element *elem); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 163 | |
Craig Tiller | 1b22b9d | 2015-07-20 13:42:22 -0700 | [diff] [blame] | 164 | /* Implement grpc_call_get_peer() */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 165 | char *(*get_peer)(grpc_exec_ctx *exec_ctx, grpc_call_element *elem); |
Craig Tiller | 1b22b9d | 2015-07-20 13:42:22 -0700 | [diff] [blame] | 166 | |
Mark D. Roth | b2d2488 | 2016-10-27 15:44:07 -0700 | [diff] [blame] | 167 | /* Implement grpc_channel_get_info() */ |
| 168 | void (*get_channel_info)(grpc_exec_ctx *exec_ctx, grpc_channel_element *elem, |
Mark D. Roth | f79ce7d | 2016-11-04 08:43:36 -0700 | [diff] [blame] | 169 | const grpc_channel_info *channel_info); |
Mark D. Roth | b2d2488 | 2016-10-27 15:44:07 -0700 | [diff] [blame] | 170 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 171 | /* The name of this filter */ |
| 172 | const char *name; |
| 173 | } grpc_channel_filter; |
| 174 | |
| 175 | /* A channel_element tracks its filter and the filter requested memory within |
| 176 | a channel allocation */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 177 | struct grpc_channel_element { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 178 | const grpc_channel_filter *filter; |
| 179 | void *channel_data; |
| 180 | }; |
| 181 | |
| 182 | /* A call_element tracks its filter, the filter requested memory within |
| 183 | a channel allocation, and the filter requested memory within a call |
| 184 | allocation */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 185 | struct grpc_call_element { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 186 | const grpc_channel_filter *filter; |
| 187 | void *channel_data; |
| 188 | void *call_data; |
| 189 | }; |
| 190 | |
| 191 | /* A channel stack tracks a set of related filters for one channel, and |
| 192 | guarantees they live within a single malloc() allocation */ |
Craig Tiller | 906e3bc | 2015-11-24 07:31:31 -0800 | [diff] [blame] | 193 | struct grpc_channel_stack { |
| 194 | grpc_stream_refcount refcount; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 195 | size_t count; |
| 196 | /* Memory required for a call stack (computed at channel stack |
| 197 | initialization) */ |
| 198 | size_t call_stack_size; |
Craig Tiller | 906e3bc | 2015-11-24 07:31:31 -0800 | [diff] [blame] | 199 | }; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 200 | |
| 201 | /* A call stack tracks a set of related filters for one call, and guarantees |
| 202 | they live within a single malloc() allocation */ |
Craig Tiller | 906e3bc | 2015-11-24 07:31:31 -0800 | [diff] [blame] | 203 | struct grpc_call_stack { |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 204 | /* shared refcount for this channel stack. |
| 205 | MUST be the first element: the underlying code calls destroy |
| 206 | with the address of the refcount, but higher layers prefer to think |
| 207 | about the address of the call stack itself. */ |
| 208 | grpc_stream_refcount refcount; |
| 209 | size_t count; |
Craig Tiller | 906e3bc | 2015-11-24 07:31:31 -0800 | [diff] [blame] | 210 | }; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 211 | |
| 212 | /* Get a channel element given a channel stack and its index */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 213 | grpc_channel_element *grpc_channel_stack_element(grpc_channel_stack *stack, |
| 214 | size_t i); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 215 | /* Get the last channel element in a channel stack */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 216 | grpc_channel_element *grpc_channel_stack_last_element( |
| 217 | grpc_channel_stack *stack); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 218 | /* Get a call stack element given a call stack and an index */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 219 | grpc_call_element *grpc_call_stack_element(grpc_call_stack *stack, size_t i); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 220 | |
| 221 | /* Determine memory required for a channel stack containing a set of filters */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 222 | size_t grpc_channel_stack_size(const grpc_channel_filter **filters, |
| 223 | size_t filter_count); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 224 | /* Initialize a channel stack given some filters */ |
Mark D. Roth | c108788 | 2016-11-18 10:54:45 -0800 | [diff] [blame] | 225 | grpc_error *grpc_channel_stack_init( |
Mark D. Roth | 5e2566e | 2016-11-18 10:53:13 -0800 | [diff] [blame] | 226 | grpc_exec_ctx *exec_ctx, int initial_refs, grpc_iomgr_cb_func destroy, |
Mark D. Roth | c108788 | 2016-11-18 10:54:45 -0800 | [diff] [blame] | 227 | void *destroy_arg, const grpc_channel_filter **filters, size_t filter_count, |
| 228 | const grpc_channel_args *args, grpc_transport *optional_transport, |
| 229 | const char *name, grpc_channel_stack *stack); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 230 | /* Destroy a channel stack */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 231 | void grpc_channel_stack_destroy(grpc_exec_ctx *exec_ctx, |
| 232 | grpc_channel_stack *stack); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 233 | |
| 234 | /* Initialize a call stack given a channel stack. transport_server_data is |
| 235 | expected to be NULL on a client, or an opaque transport owned pointer on the |
| 236 | server. */ |
Mark D. Roth | f28763c | 2016-09-14 15:18:40 -0700 | [diff] [blame] | 237 | grpc_error *grpc_call_stack_init( |
| 238 | grpc_exec_ctx *exec_ctx, grpc_channel_stack *channel_stack, |
| 239 | int initial_refs, grpc_iomgr_cb_func destroy, void *destroy_arg, |
| 240 | grpc_call_context_element *context, const void *transport_server_data, |
Mark D. Roth | 3d88341 | 2016-11-07 13:42:54 -0800 | [diff] [blame] | 241 | grpc_mdstr *path, gpr_timespec start_time, gpr_timespec deadline, |
| 242 | grpc_call_stack *call_stack); |
David Garcia Quintas | 4afce7e | 2016-04-18 16:25:17 -0700 | [diff] [blame] | 243 | /* Set a pollset or a pollset_set for a call stack: must occur before the first |
| 244 | * op is started */ |
David Garcia Quintas | f72eb97 | 2016-05-03 18:28:09 -0700 | [diff] [blame] | 245 | void grpc_call_stack_set_pollset_or_pollset_set(grpc_exec_ctx *exec_ctx, |
| 246 | grpc_call_stack *call_stack, |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 247 | grpc_polling_entity *pollent); |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 248 | |
| 249 | #ifdef GRPC_STREAM_REFCOUNT_DEBUG |
Craig Tiller | 906e3bc | 2015-11-24 07:31:31 -0800 | [diff] [blame] | 250 | #define GRPC_CALL_STACK_REF(call_stack, reason) \ |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 251 | grpc_stream_ref(&(call_stack)->refcount, reason) |
Craig Tiller | 906e3bc | 2015-11-24 07:31:31 -0800 | [diff] [blame] | 252 | #define GRPC_CALL_STACK_UNREF(exec_ctx, call_stack, reason) \ |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 253 | grpc_stream_unref(exec_ctx, &(call_stack)->refcount, reason) |
Craig Tiller | 906e3bc | 2015-11-24 07:31:31 -0800 | [diff] [blame] | 254 | #define GRPC_CHANNEL_STACK_REF(channel_stack, reason) \ |
| 255 | grpc_stream_ref(&(channel_stack)->refcount, reason) |
| 256 | #define GRPC_CHANNEL_STACK_UNREF(exec_ctx, channel_stack, reason) \ |
| 257 | grpc_stream_unref(exec_ctx, &(channel_stack)->refcount, reason) |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 258 | #else |
Craig Tiller | 7b43561 | 2015-11-24 08:15:05 -0800 | [diff] [blame] | 259 | #define GRPC_CALL_STACK_REF(call_stack, reason) \ |
| 260 | grpc_stream_ref(&(call_stack)->refcount) |
Craig Tiller | 906e3bc | 2015-11-24 07:31:31 -0800 | [diff] [blame] | 261 | #define GRPC_CALL_STACK_UNREF(exec_ctx, call_stack, reason) \ |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 262 | grpc_stream_unref(exec_ctx, &(call_stack)->refcount) |
Craig Tiller | 7b43561 | 2015-11-24 08:15:05 -0800 | [diff] [blame] | 263 | #define GRPC_CHANNEL_STACK_REF(channel_stack, reason) \ |
| 264 | grpc_stream_ref(&(channel_stack)->refcount) |
Craig Tiller | 906e3bc | 2015-11-24 07:31:31 -0800 | [diff] [blame] | 265 | #define GRPC_CHANNEL_STACK_UNREF(exec_ctx, channel_stack, reason) \ |
| 266 | grpc_stream_unref(exec_ctx, &(channel_stack)->refcount) |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 267 | #endif |
| 268 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 269 | /* Destroy a call stack */ |
Craig Tiller | 2c8063c | 2016-03-22 22:12:15 -0700 | [diff] [blame] | 270 | void grpc_call_stack_destroy(grpc_exec_ctx *exec_ctx, grpc_call_stack *stack, |
David Garcia Quintas | 01c4d99 | 2016-07-07 20:11:27 -0700 | [diff] [blame] | 271 | const grpc_call_final_info *final_info, |
Craig Tiller | 2c8063c | 2016-03-22 22:12:15 -0700 | [diff] [blame] | 272 | void *and_free_memory); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 273 | |
David Garcia Quintas | f72eb97 | 2016-05-03 18:28:09 -0700 | [diff] [blame] | 274 | /* Ignore set pollset{_set} - used by filters if they don't care about pollsets |
| 275 | * at all. Does nothing. */ |
David Garcia Quintas | 2a50dfe | 2016-05-31 15:09:12 -0700 | [diff] [blame] | 276 | void grpc_call_stack_ignore_set_pollset_or_pollset_set( |
| 277 | grpc_exec_ctx *exec_ctx, grpc_call_element *elem, |
| 278 | grpc_polling_entity *pollent); |
Craig Tiller | 83f88d9 | 2015-04-21 16:02:05 -0700 | [diff] [blame] | 279 | /* Call the next operation in a call stack */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 280 | void grpc_call_next_op(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, |
| 281 | grpc_transport_stream_op *op); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 282 | /* Call the next operation (depending on call directionality) in a channel |
| 283 | stack */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 284 | void grpc_channel_next_op(grpc_exec_ctx *exec_ctx, grpc_channel_element *elem, |
| 285 | grpc_transport_op *op); |
Craig Tiller | 1b22b9d | 2015-07-20 13:42:22 -0700 | [diff] [blame] | 286 | /* Pass through a request to get_peer to the next child element */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 287 | char *grpc_call_next_get_peer(grpc_exec_ctx *exec_ctx, grpc_call_element *elem); |
Mark D. Roth | b2d2488 | 2016-10-27 15:44:07 -0700 | [diff] [blame] | 288 | /* Pass through a request to get_channel_info() to the next child element */ |
| 289 | void grpc_channel_next_get_info(grpc_exec_ctx *exec_ctx, |
| 290 | grpc_channel_element *elem, |
Mark D. Roth | f79ce7d | 2016-11-04 08:43:36 -0700 | [diff] [blame] | 291 | const grpc_channel_info *channel_info); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 292 | |
| 293 | /* Given the top element of a channel stack, get the channel stack itself */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 294 | grpc_channel_stack *grpc_channel_stack_from_top_element( |
| 295 | grpc_channel_element *elem); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 296 | /* Given the top element of a call stack, get the call stack itself */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 297 | grpc_call_stack *grpc_call_stack_from_top_element(grpc_call_element *elem); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 298 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 299 | void grpc_call_log_op(char *file, int line, gpr_log_severity severity, |
| 300 | grpc_call_element *elem, grpc_transport_stream_op *op); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 301 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 302 | void grpc_call_element_send_cancel(grpc_exec_ctx *exec_ctx, |
| 303 | grpc_call_element *cur_elem); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 304 | |
Yuchen Zeng | ec066b3 | 2016-06-13 18:10:23 -0700 | [diff] [blame] | 305 | void grpc_call_element_send_cancel_with_message(grpc_exec_ctx *exec_ctx, |
| 306 | grpc_call_element *cur_elem, |
| 307 | grpc_status_code status, |
Craig Tiller | d41a4a7 | 2016-10-26 16:16:06 -0700 | [diff] [blame] | 308 | grpc_slice *optional_message); |
Yuchen Zeng | ec066b3 | 2016-06-13 18:10:23 -0700 | [diff] [blame] | 309 | |
Mark D. Roth | 75d7478 | 2016-09-09 07:46:01 -0700 | [diff] [blame] | 310 | void grpc_call_element_send_close_with_message(grpc_exec_ctx *exec_ctx, |
| 311 | grpc_call_element *cur_elem, |
| 312 | grpc_status_code status, |
Craig Tiller | d41a4a7 | 2016-10-26 16:16:06 -0700 | [diff] [blame] | 313 | grpc_slice *optional_message); |
Mark D. Roth | 75d7478 | 2016-09-09 07:46:01 -0700 | [diff] [blame] | 314 | |
Craig Tiller | faa8480 | 2015-03-01 21:56:38 -0800 | [diff] [blame] | 315 | extern int grpc_trace_channel; |
| 316 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 317 | #define GRPC_CALL_LOG_OP(sev, elem, op) \ |
Craig Tiller | faa8480 | 2015-03-01 21:56:38 -0800 | [diff] [blame] | 318 | if (grpc_trace_channel) grpc_call_log_op(sev, elem, op) |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 319 | |
Mark D. Roth | c459ecf | 2016-06-16 09:17:49 -0700 | [diff] [blame] | 320 | #ifdef __cplusplus |
| 321 | } |
| 322 | #endif |
| 323 | |
Craig Tiller | 9a4dddd | 2016-03-25 17:08:13 -0700 | [diff] [blame] | 324 | #endif /* GRPC_CORE_LIB_CHANNEL_CHANNEL_STACK_H */ |