Craig Tiller | 9d0e047 | 2015-06-23 09:12:48 -0700 | [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 | |
Craig Tiller | 9e8f911 | 2015-06-23 10:56:11 -0700 | [diff] [blame] | 34 | #ifndef GRPC_INTERNAL_CORE_CLIENT_CONFIG_SUBCHANNEL_H |
| 35 | #define GRPC_INTERNAL_CORE_CLIENT_CONFIG_SUBCHANNEL_H |
Craig Tiller | 9d0e047 | 2015-06-23 09:12:48 -0700 | [diff] [blame] | 36 | |
Craig Tiller | f5f1712 | 2015-06-25 08:47:26 -0700 | [diff] [blame] | 37 | #include "src/core/channel/channel_stack.h" |
Craig Tiller | 9162466 | 2015-06-25 16:31:02 -0700 | [diff] [blame] | 38 | #include "src/core/client_config/connector.h" |
Craig Tiller | af69180 | 2015-06-23 14:57:07 -0700 | [diff] [blame] | 39 | |
Craig Tiller | 9d0e047 | 2015-06-23 09:12:48 -0700 | [diff] [blame] | 40 | /** A (sub-)channel that knows how to connect to exactly one target |
| 41 | address. Provides a target for load balancing. */ |
Craig Tiller | 9e8f911 | 2015-06-23 10:56:11 -0700 | [diff] [blame] | 42 | typedef struct grpc_subchannel grpc_subchannel; |
Craig Tiller | f5f1712 | 2015-06-25 08:47:26 -0700 | [diff] [blame] | 43 | typedef struct grpc_subchannel_call grpc_subchannel_call; |
Craig Tiller | f7afa1f | 2015-06-26 09:02:20 -0700 | [diff] [blame] | 44 | typedef struct grpc_subchannel_args grpc_subchannel_args; |
Craig Tiller | 9d0e047 | 2015-06-23 09:12:48 -0700 | [diff] [blame] | 45 | |
Craig Tiller | c396753 | 2015-06-29 14:59:38 -0700 | [diff] [blame] | 46 | #ifdef GRPC_SUBCHANNEL_REFCOUNT_DEBUG |
Craig Tiller | 079a11b | 2015-06-30 10:07:15 -0700 | [diff] [blame] | 47 | #define GRPC_SUBCHANNEL_REF(p, r) \ |
| 48 | grpc_subchannel_ref((p), __FILE__, __LINE__, (r)) |
| 49 | #define GRPC_SUBCHANNEL_UNREF(p, r) \ |
| 50 | grpc_subchannel_unref((p), __FILE__, __LINE__, (r)) |
| 51 | #define GRPC_SUBCHANNEL_CALL_REF(p, r) \ |
| 52 | grpc_subchannel_call_ref((p), __FILE__, __LINE__, (r)) |
| 53 | #define GRPC_SUBCHANNEL_CALL_UNREF(p, r) \ |
| 54 | grpc_subchannel_call_unref((p), __FILE__, __LINE__, (r)) |
| 55 | #define GRPC_SUBCHANNEL_REF_EXTRA_ARGS \ |
| 56 | , const char *file, int line, const char *reason |
Craig Tiller | c396753 | 2015-06-29 14:59:38 -0700 | [diff] [blame] | 57 | #else |
| 58 | #define GRPC_SUBCHANNEL_REF(p, r) grpc_subchannel_ref((p)) |
| 59 | #define GRPC_SUBCHANNEL_UNREF(p, r) grpc_subchannel_unref((p)) |
| 60 | #define GRPC_SUBCHANNEL_CALL_REF(p, r) grpc_subchannel_call_ref((p)) |
| 61 | #define GRPC_SUBCHANNEL_CALL_UNREF(p, r) grpc_subchannel_call_unref((p)) |
| 62 | #define GRPC_SUBCHANNEL_REF_EXTRA_ARGS |
| 63 | #endif |
| 64 | |
Craig Tiller | 079a11b | 2015-06-30 10:07:15 -0700 | [diff] [blame] | 65 | void grpc_subchannel_ref( |
| 66 | grpc_subchannel *channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS); |
| 67 | void grpc_subchannel_unref( |
| 68 | grpc_subchannel *channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS); |
| 69 | void grpc_subchannel_call_ref( |
| 70 | grpc_subchannel_call *call GRPC_SUBCHANNEL_REF_EXTRA_ARGS); |
| 71 | void grpc_subchannel_call_unref( |
| 72 | grpc_subchannel_call *call GRPC_SUBCHANNEL_REF_EXTRA_ARGS); |
Craig Tiller | 9d0e047 | 2015-06-23 09:12:48 -0700 | [diff] [blame] | 73 | |
Craig Tiller | c7b5f76 | 2015-06-27 11:48:42 -0700 | [diff] [blame] | 74 | /** construct a call (possibly asynchronously) */ |
| 75 | void grpc_subchannel_create_call(grpc_subchannel *subchannel, |
Craig Tiller | abf3638 | 2015-06-29 16:13:27 -0700 | [diff] [blame] | 76 | grpc_pollset *pollset, |
Craig Tiller | c7b5f76 | 2015-06-27 11:48:42 -0700 | [diff] [blame] | 77 | grpc_subchannel_call **target, |
| 78 | grpc_iomgr_closure *notify); |
| 79 | |
| 80 | /** process a transport level op */ |
Craig Tiller | 4ab82d2 | 2015-06-29 09:40:33 -0700 | [diff] [blame] | 81 | void grpc_subchannel_process_transport_op(grpc_subchannel *subchannel, |
| 82 | grpc_transport_op *op); |
Craig Tiller | c7b5f76 | 2015-06-27 11:48:42 -0700 | [diff] [blame] | 83 | |
Craig Tiller | 9d0e047 | 2015-06-23 09:12:48 -0700 | [diff] [blame] | 84 | /** poll the current connectivity state of a channel */ |
Craig Tiller | 9e8f911 | 2015-06-23 10:56:11 -0700 | [diff] [blame] | 85 | grpc_connectivity_state grpc_subchannel_check_connectivity( |
| 86 | grpc_subchannel *channel); |
Craig Tiller | d58b5b8 | 2015-06-23 12:30:00 -0700 | [diff] [blame] | 87 | |
Craig Tiller | 9d0e047 | 2015-06-23 09:12:48 -0700 | [diff] [blame] | 88 | /** call notify when the connectivity state of a channel changes from *state. |
| 89 | Updates *state with the new state of the channel */ |
Craig Tiller | 9e8f911 | 2015-06-23 10:56:11 -0700 | [diff] [blame] | 90 | void grpc_subchannel_notify_on_state_change(grpc_subchannel *channel, |
| 91 | grpc_connectivity_state *state, |
| 92 | grpc_iomgr_closure *notify); |
Craig Tiller | d58b5b8 | 2015-06-23 12:30:00 -0700 | [diff] [blame] | 93 | |
Craig Tiller | 4ab82d2 | 2015-06-29 09:40:33 -0700 | [diff] [blame] | 94 | void grpc_subchannel_add_interested_party(grpc_subchannel *channel, |
| 95 | grpc_pollset *pollset); |
| 96 | void grpc_subchannel_del_interested_party(grpc_subchannel *channel, |
| 97 | grpc_pollset *pollset); |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 98 | |
Craig Tiller | f5f1712 | 2015-06-25 08:47:26 -0700 | [diff] [blame] | 99 | /** continue processing a transport op */ |
Craig Tiller | b7959a0 | 2015-06-25 08:50:54 -0700 | [diff] [blame] | 100 | void grpc_subchannel_call_process_op(grpc_subchannel_call *subchannel_call, |
| 101 | grpc_transport_stream_op *op); |
Craig Tiller | 9d0e047 | 2015-06-23 09:12:48 -0700 | [diff] [blame] | 102 | |
Craig Tiller | 1b22b9d | 2015-07-20 13:42:22 -0700 | [diff] [blame] | 103 | /** continue querying for peer */ |
| 104 | char *grpc_subchannel_call_get_peer(grpc_subchannel_call *subchannel_call); |
| 105 | |
Craig Tiller | f7afa1f | 2015-06-26 09:02:20 -0700 | [diff] [blame] | 106 | struct grpc_subchannel_args { |
| 107 | /** Channel filters for this channel - wrapped factories will likely |
| 108 | want to mutate this */ |
| 109 | const grpc_channel_filter **filters; |
| 110 | /** The number of filters in the above array */ |
| 111 | size_t filter_count; |
| 112 | /** Channel arguments to be supplied to the newly created channel */ |
| 113 | const grpc_channel_args *args; |
| 114 | /** Address to connect to */ |
| 115 | struct sockaddr *addr; |
| 116 | size_t addr_len; |
Craig Tiller | 5f84c84 | 2015-06-26 16:08:21 -0700 | [diff] [blame] | 117 | /** metadata context to use */ |
| 118 | grpc_mdctx *mdctx; |
Craig Tiller | 9846503 | 2015-06-29 14:36:42 -0700 | [diff] [blame] | 119 | /** master channel */ |
| 120 | grpc_channel *master; |
Craig Tiller | f7afa1f | 2015-06-26 09:02:20 -0700 | [diff] [blame] | 121 | }; |
| 122 | |
Craig Tiller | 9162466 | 2015-06-25 16:31:02 -0700 | [diff] [blame] | 123 | /** create a subchannel given a connector */ |
Craig Tiller | f7afa1f | 2015-06-26 09:02:20 -0700 | [diff] [blame] | 124 | grpc_subchannel *grpc_subchannel_create(grpc_connector *connector, |
| 125 | grpc_subchannel_args *args); |
Craig Tiller | 9162466 | 2015-06-25 16:31:02 -0700 | [diff] [blame] | 126 | |
Craig Tiller | 9e8f911 | 2015-06-23 10:56:11 -0700 | [diff] [blame] | 127 | #endif /* GRPC_INTERNAL_CORE_CLIENT_CONFIG_SUBCHANNEL_H */ |