OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * |
| 3 * Copyright 2015-2016, 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_CLIENT_CONFIG_SUBCHANNEL_H |
| 35 #define GRPC_INTERNAL_CORE_CLIENT_CONFIG_SUBCHANNEL_H |
| 36 |
| 37 #include "src/core/channel/channel_stack.h" |
| 38 #include "src/core/client_config/connector.h" |
| 39 #include "src/core/transport/connectivity_state.h" |
| 40 |
| 41 /** A (sub-)channel that knows how to connect to exactly one target |
| 42 address. Provides a target for load balancing. */ |
| 43 typedef struct grpc_subchannel grpc_subchannel; |
| 44 typedef struct grpc_connected_subchannel grpc_connected_subchannel; |
| 45 typedef struct grpc_subchannel_call grpc_subchannel_call; |
| 46 typedef struct grpc_subchannel_args grpc_subchannel_args; |
| 47 |
| 48 #ifdef GRPC_STREAM_REFCOUNT_DEBUG |
| 49 #define GRPC_SUBCHANNEL_REF(p, r) \ |
| 50 grpc_subchannel_ref((p), __FILE__, __LINE__, (r)) |
| 51 #define GRPC_SUBCHANNEL_REF_FROM_WEAK_REF(p, r) \ |
| 52 grpc_subchannel_ref_from_weak_ref((p), __FILE__, __LINE__, (r)) |
| 53 #define GRPC_SUBCHANNEL_UNREF(cl, p, r) \ |
| 54 grpc_subchannel_unref((cl), (p), __FILE__, __LINE__, (r)) |
| 55 #define GRPC_SUBCHANNEL_WEAK_REF(p, r) \ |
| 56 grpc_subchannel_weak_ref((p), __FILE__, __LINE__, (r)) |
| 57 #define GRPC_SUBCHANNEL_WEAK_UNREF(cl, p, r) \ |
| 58 grpc_subchannel_weak_unref((cl), (p), __FILE__, __LINE__, (r)) |
| 59 #define GRPC_CONNECTED_SUBCHANNEL_REF(p, r) \ |
| 60 grpc_connected_subchannel_ref((p), __FILE__, __LINE__, (r)) |
| 61 #define GRPC_CONNECTED_SUBCHANNEL_UNREF(cl, p, r) \ |
| 62 grpc_connected_subchannel_unref((cl), (p), __FILE__, __LINE__, (r)) |
| 63 #define GRPC_SUBCHANNEL_CALL_REF(p, r) \ |
| 64 grpc_subchannel_call_ref((p), __FILE__, __LINE__, (r)) |
| 65 #define GRPC_SUBCHANNEL_CALL_UNREF(cl, p, r) \ |
| 66 grpc_subchannel_call_unref((cl), (p), __FILE__, __LINE__, (r)) |
| 67 #define GRPC_SUBCHANNEL_REF_EXTRA_ARGS \ |
| 68 , const char *file, int line, const char *reason |
| 69 #else |
| 70 #define GRPC_SUBCHANNEL_REF(p, r) grpc_subchannel_ref((p)) |
| 71 #define GRPC_SUBCHANNEL_REF_FROM_WEAK_REF(p, r) \ |
| 72 grpc_subchannel_ref_from_weak_ref((p)) |
| 73 #define GRPC_SUBCHANNEL_UNREF(cl, p, r) grpc_subchannel_unref((cl), (p)) |
| 74 #define GRPC_SUBCHANNEL_WEAK_REF(p, r) grpc_subchannel_weak_ref((p)) |
| 75 #define GRPC_SUBCHANNEL_WEAK_UNREF(cl, p, r) \ |
| 76 grpc_subchannel_weak_unref((cl), (p)) |
| 77 #define GRPC_CONNECTED_SUBCHANNEL_REF(p, r) grpc_connected_subchannel_ref((p)) |
| 78 #define GRPC_CONNECTED_SUBCHANNEL_UNREF(cl, p, r) \ |
| 79 grpc_connected_subchannel_unref((cl), (p)) |
| 80 #define GRPC_SUBCHANNEL_CALL_REF(p, r) grpc_subchannel_call_ref((p)) |
| 81 #define GRPC_SUBCHANNEL_CALL_UNREF(cl, p, r) \ |
| 82 grpc_subchannel_call_unref((cl), (p)) |
| 83 #define GRPC_SUBCHANNEL_REF_EXTRA_ARGS |
| 84 #endif |
| 85 |
| 86 grpc_subchannel *grpc_subchannel_ref(grpc_subchannel *channel |
| 87 GRPC_SUBCHANNEL_REF_EXTRA_ARGS); |
| 88 grpc_subchannel *grpc_subchannel_ref_from_weak_ref( |
| 89 grpc_subchannel *channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS); |
| 90 void grpc_subchannel_unref(grpc_exec_ctx *exec_ctx, |
| 91 grpc_subchannel *channel |
| 92 GRPC_SUBCHANNEL_REF_EXTRA_ARGS); |
| 93 grpc_subchannel *grpc_subchannel_weak_ref(grpc_subchannel *channel |
| 94 GRPC_SUBCHANNEL_REF_EXTRA_ARGS); |
| 95 void grpc_subchannel_weak_unref(grpc_exec_ctx *exec_ctx, |
| 96 grpc_subchannel *channel |
| 97 GRPC_SUBCHANNEL_REF_EXTRA_ARGS); |
| 98 void grpc_connected_subchannel_ref(grpc_connected_subchannel *channel |
| 99 GRPC_SUBCHANNEL_REF_EXTRA_ARGS); |
| 100 void grpc_connected_subchannel_unref(grpc_exec_ctx *exec_ctx, |
| 101 grpc_connected_subchannel *channel |
| 102 GRPC_SUBCHANNEL_REF_EXTRA_ARGS); |
| 103 void grpc_subchannel_call_ref(grpc_subchannel_call *call |
| 104 GRPC_SUBCHANNEL_REF_EXTRA_ARGS); |
| 105 void grpc_subchannel_call_unref(grpc_exec_ctx *exec_ctx, |
| 106 grpc_subchannel_call *call |
| 107 GRPC_SUBCHANNEL_REF_EXTRA_ARGS); |
| 108 |
| 109 /** construct a subchannel call */ |
| 110 grpc_subchannel_call *grpc_connected_subchannel_create_call( |
| 111 grpc_exec_ctx *exec_ctx, grpc_connected_subchannel *connected_subchannel, |
| 112 grpc_pollset *pollset); |
| 113 |
| 114 /** process a transport level op */ |
| 115 void grpc_connected_subchannel_process_transport_op( |
| 116 grpc_exec_ctx *exec_ctx, grpc_connected_subchannel *subchannel, |
| 117 grpc_transport_op *op); |
| 118 |
| 119 /** poll the current connectivity state of a channel */ |
| 120 grpc_connectivity_state grpc_subchannel_check_connectivity( |
| 121 grpc_subchannel *channel); |
| 122 |
| 123 /** call notify when the connectivity state of a channel changes from *state. |
| 124 Updates *state with the new state of the channel */ |
| 125 void grpc_subchannel_notify_on_state_change( |
| 126 grpc_exec_ctx *exec_ctx, grpc_subchannel *channel, |
| 127 grpc_pollset_set *interested_parties, grpc_connectivity_state *state, |
| 128 grpc_closure *notify); |
| 129 void grpc_connected_subchannel_notify_on_state_change( |
| 130 grpc_exec_ctx *exec_ctx, grpc_connected_subchannel *channel, |
| 131 grpc_pollset_set *interested_parties, grpc_connectivity_state *state, |
| 132 grpc_closure *notify); |
| 133 void grpc_connected_subchannel_ping(grpc_exec_ctx *exec_ctx, |
| 134 grpc_connected_subchannel *channel, |
| 135 grpc_closure *notify); |
| 136 |
| 137 /** retrieve the grpc_connected_subchannel - or NULL if called before |
| 138 the subchannel becomes connected */ |
| 139 grpc_connected_subchannel *grpc_subchannel_get_connected_subchannel( |
| 140 grpc_subchannel *subchannel); |
| 141 |
| 142 /** continue processing a transport op */ |
| 143 void grpc_subchannel_call_process_op(grpc_exec_ctx *exec_ctx, |
| 144 grpc_subchannel_call *subchannel_call, |
| 145 grpc_transport_stream_op *op); |
| 146 |
| 147 /** continue querying for peer */ |
| 148 char *grpc_subchannel_call_get_peer(grpc_exec_ctx *exec_ctx, |
| 149 grpc_subchannel_call *subchannel_call); |
| 150 |
| 151 grpc_call_stack *grpc_subchannel_call_get_call_stack( |
| 152 grpc_subchannel_call *subchannel_call); |
| 153 |
| 154 struct grpc_subchannel_args { |
| 155 /* When updating this struct, also update subchannel_index.c */ |
| 156 |
| 157 /** Channel filters for this channel - wrapped factories will likely |
| 158 want to mutate this */ |
| 159 const grpc_channel_filter **filters; |
| 160 /** The number of filters in the above array */ |
| 161 size_t filter_count; |
| 162 /** Channel arguments to be supplied to the newly created channel */ |
| 163 const grpc_channel_args *args; |
| 164 /** Address to connect to */ |
| 165 struct sockaddr *addr; |
| 166 size_t addr_len; |
| 167 }; |
| 168 |
| 169 /** create a subchannel given a connector */ |
| 170 grpc_subchannel *grpc_subchannel_create(grpc_exec_ctx *exec_ctx, |
| 171 grpc_connector *connector, |
| 172 grpc_subchannel_args *args); |
| 173 |
| 174 #endif /* GRPC_INTERNAL_CORE_CLIENT_CONFIG_SUBCHANNEL_H */ |
OLD | NEW |