Craig Tiller | 178edfa | 2016-02-17 20:54:46 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * |
| 3 | * Copyright 2015, Google Inc. |
| 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 | |
| 34 | #ifndef GRPC_INTERNAL_CORE_CHANNEL_CHANNEL_BUILDER_H |
| 35 | #define GRPC_INTERNAL_CORE_CHANNEL_CHANNEL_BUILDER_H |
| 36 | |
| 37 | #include <stdbool.h> |
| 38 | |
| 39 | #include "src/core/channel/channel_args.h" |
| 40 | #include "src/core/channel/channel_stack.h" |
| 41 | |
| 42 | // grpc_channel_stack_builder offers a programmatic interface to selected |
| 43 | // and order channel filters |
| 44 | typedef struct grpc_channel_stack_builder grpc_channel_stack_builder; |
| 45 | typedef struct grpc_channel_stack_builder_iterator |
| 46 | grpc_channel_stack_builder_iterator; |
| 47 | |
| 48 | // Create a new channel stack builder |
| 49 | grpc_channel_stack_builder *grpc_channel_stack_builder_create(void); |
| 50 | |
| 51 | // Assign a name to the channel stack: string must be statically allocated |
| 52 | void grpc_channel_stack_builder_set_name(grpc_channel_stack_builder *builder, |
| 53 | const char *name); |
| 54 | |
| 55 | // Attach a transport to the builder (does not take ownership) |
| 56 | void grpc_channel_stack_builder_set_transport( |
| 57 | grpc_channel_stack_builder *builder, grpc_transport *transport); |
| 58 | |
| 59 | // Fetch attached transport |
| 60 | grpc_transport *grpc_channel_stack_builder_get_transport( |
| 61 | grpc_channel_stack_builder *builder); |
| 62 | |
| 63 | // Set channel arguments: they must continue to exist until after |
| 64 | // grpc_channel_stack_builder_finish returns |
| 65 | void grpc_channel_stack_builder_set_channel_arguments( |
| 66 | grpc_channel_stack_builder *builder, const grpc_channel_args *args); |
| 67 | |
| 68 | // Return a borrowed pointer to the channel arguments |
| 69 | const grpc_channel_args *grpc_channel_stack_builder_get_channel_arguments( |
| 70 | grpc_channel_stack_builder *builder); |
| 71 | |
| 72 | // Begin iterating over already defined filters in the builder |
| 73 | grpc_channel_stack_builder_iterator * |
| 74 | grpc_channel_stack_builder_create_iterator_at_first( |
| 75 | grpc_channel_stack_builder *builder); |
| 76 | grpc_channel_stack_builder_iterator * |
| 77 | grpc_channel_stack_builder_create_iterator_at_last( |
| 78 | grpc_channel_stack_builder *builder); |
| 79 | |
| 80 | // Is an iterator at the first element? |
| 81 | bool grpc_channel_stack_builder_iterator_is_first( |
| 82 | grpc_channel_stack_builder_iterator *iterator); |
| 83 | |
| 84 | // Is an iterator at the end? |
| 85 | bool grpc_channel_stack_builder_iterator_is_end( |
| 86 | grpc_channel_stack_builder_iterator *iterator); |
| 87 | |
| 88 | // Move an iterator to the next item |
| 89 | bool grpc_channel_stack_builder_move_next( |
| 90 | grpc_channel_stack_builder_iterator *iterator); |
| 91 | |
| 92 | bool grpc_channel_stack_builder_move_prev( |
| 93 | grpc_channel_stack_builder_iterator *iterator); |
| 94 | |
| 95 | typedef void (*grpc_post_filter_create_init_func)( |
| 96 | grpc_channel_stack *channel_stack, grpc_channel_element *elem, void *arg); |
| 97 | |
| 98 | // Add a filter to the stack, after the given iterator |
| 99 | bool grpc_channel_stack_builder_add_filter_after( |
| 100 | grpc_channel_stack_builder_iterator *iterator, |
| 101 | const grpc_channel_filter *filter, |
| 102 | grpc_post_filter_create_init_func post_init_func, |
| 103 | void *user_data) GRPC_MUST_USE_RESULT; |
| 104 | |
| 105 | // Add a filter to the stack, before the given iterator |
| 106 | bool grpc_channel_stack_builder_add_filter_before( |
| 107 | grpc_channel_stack_builder_iterator *iterator, |
| 108 | const grpc_channel_filter *filter, |
| 109 | grpc_post_filter_create_init_func post_init_func, |
| 110 | void *user_data) GRPC_MUST_USE_RESULT; |
| 111 | |
| 112 | // Add a filter to the beginning of the filter list |
| 113 | bool grpc_channel_stack_builder_prepend_filter( |
| 114 | grpc_channel_stack_builder *builder, const grpc_channel_filter *filter, |
| 115 | grpc_post_filter_create_init_func post_init_func, |
| 116 | void *user_data) GRPC_MUST_USE_RESULT; |
| 117 | |
| 118 | // Add a filter to the end of the filter list |
| 119 | bool grpc_channel_stack_builder_append_filter( |
| 120 | grpc_channel_stack_builder *builder, const grpc_channel_filter *filter, |
| 121 | grpc_post_filter_create_init_func post_init_func, |
| 122 | void *user_data) GRPC_MUST_USE_RESULT; |
| 123 | |
| 124 | // Terminate iteration |
| 125 | void grpc_channel_stack_builder_iterator_destroy( |
| 126 | grpc_channel_stack_builder_iterator *iterator); |
| 127 | |
| 128 | // Destroy the builder, return the freshly minted channel stack |
| 129 | void *grpc_channel_stack_builder_finish(grpc_exec_ctx *exec_ctx, |
| 130 | grpc_channel_stack_builder *builder, |
| 131 | size_t prefix_bytes, int initial_refs, |
| 132 | grpc_iomgr_cb_func destroy, |
| 133 | void *destroy_arg); |
| 134 | |
| 135 | // Destroy the builder without creating a channel stack |
| 136 | void grpc_channel_stack_builder_destroy(grpc_channel_stack_builder *builder); |
| 137 | |
| 138 | #endif |