blob: d1cd33b2afb80561c5167cafc19371338953e38a [file] [log] [blame]
Craig Tiller9d0e0472015-06-23 09:12:48 -07001/*
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 Tiller9e8f9112015-06-23 10:56:11 -070034#ifndef GRPC_INTERNAL_CORE_CLIENT_CONFIG_SUBCHANNEL_H
35#define GRPC_INTERNAL_CORE_CLIENT_CONFIG_SUBCHANNEL_H
Craig Tiller9d0e0472015-06-23 09:12:48 -070036
Craig Tillerf5f17122015-06-25 08:47:26 -070037#include "src/core/channel/channel_stack.h"
Craig Tiller91624662015-06-25 16:31:02 -070038#include "src/core/client_config/connector.h"
Craig Tilleraf691802015-06-23 14:57:07 -070039
Craig Tiller9d0e0472015-06-23 09:12:48 -070040/** A (sub-)channel that knows how to connect to exactly one target
41 address. Provides a target for load balancing. */
Craig Tiller9e8f9112015-06-23 10:56:11 -070042typedef struct grpc_subchannel grpc_subchannel;
Craig Tillerf5f17122015-06-25 08:47:26 -070043typedef struct grpc_subchannel_call grpc_subchannel_call;
Craig Tillerf7afa1f2015-06-26 09:02:20 -070044typedef struct grpc_subchannel_args grpc_subchannel_args;
Craig Tiller9d0e0472015-06-23 09:12:48 -070045
Craig Tillerc3967532015-06-29 14:59:38 -070046#ifdef GRPC_SUBCHANNEL_REFCOUNT_DEBUG
Craig Tiller079a11b2015-06-30 10:07:15 -070047#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 Tillerc3967532015-06-29 14:59:38 -070057#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 Tiller079a11b2015-06-30 10:07:15 -070065void grpc_subchannel_ref(
66 grpc_subchannel *channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS);
67void grpc_subchannel_unref(
68 grpc_subchannel *channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS);
69void grpc_subchannel_call_ref(
70 grpc_subchannel_call *call GRPC_SUBCHANNEL_REF_EXTRA_ARGS);
71void grpc_subchannel_call_unref(
72 grpc_subchannel_call *call GRPC_SUBCHANNEL_REF_EXTRA_ARGS);
Craig Tiller9d0e0472015-06-23 09:12:48 -070073
Craig Tillerc7b5f762015-06-27 11:48:42 -070074/** construct a call (possibly asynchronously) */
75void grpc_subchannel_create_call(grpc_subchannel *subchannel,
Craig Tillerabf36382015-06-29 16:13:27 -070076 grpc_pollset *pollset,
Craig Tillerc7b5f762015-06-27 11:48:42 -070077 grpc_subchannel_call **target,
78 grpc_iomgr_closure *notify);
79
80/** process a transport level op */
Craig Tiller4ab82d22015-06-29 09:40:33 -070081void grpc_subchannel_process_transport_op(grpc_subchannel *subchannel,
82 grpc_transport_op *op);
Craig Tillerc7b5f762015-06-27 11:48:42 -070083
Craig Tiller9d0e0472015-06-23 09:12:48 -070084/** poll the current connectivity state of a channel */
Craig Tiller9e8f9112015-06-23 10:56:11 -070085grpc_connectivity_state grpc_subchannel_check_connectivity(
86 grpc_subchannel *channel);
Craig Tillerd58b5b82015-06-23 12:30:00 -070087
Craig Tiller9d0e0472015-06-23 09:12:48 -070088/** call notify when the connectivity state of a channel changes from *state.
89 Updates *state with the new state of the channel */
Craig Tiller9e8f9112015-06-23 10:56:11 -070090void grpc_subchannel_notify_on_state_change(grpc_subchannel *channel,
91 grpc_connectivity_state *state,
92 grpc_iomgr_closure *notify);
Craig Tillerd58b5b82015-06-23 12:30:00 -070093
Craig Tiller4ab82d22015-06-29 09:40:33 -070094void grpc_subchannel_add_interested_party(grpc_subchannel *channel,
95 grpc_pollset *pollset);
96void grpc_subchannel_del_interested_party(grpc_subchannel *channel,
97 grpc_pollset *pollset);
Craig Tillereb3b12e2015-06-26 14:42:49 -070098
Craig Tillerf5f17122015-06-25 08:47:26 -070099/** continue processing a transport op */
Craig Tillerb7959a02015-06-25 08:50:54 -0700100void grpc_subchannel_call_process_op(grpc_subchannel_call *subchannel_call,
101 grpc_transport_stream_op *op);
Craig Tiller9d0e0472015-06-23 09:12:48 -0700102
Craig Tiller1b22b9d2015-07-20 13:42:22 -0700103/** continue querying for peer */
104char *grpc_subchannel_call_get_peer(grpc_subchannel_call *subchannel_call);
105
Craig Tillerf7afa1f2015-06-26 09:02:20 -0700106struct 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 Tiller5f84c842015-06-26 16:08:21 -0700117 /** metadata context to use */
118 grpc_mdctx *mdctx;
Craig Tiller98465032015-06-29 14:36:42 -0700119 /** master channel */
120 grpc_channel *master;
Craig Tillerf7afa1f2015-06-26 09:02:20 -0700121};
122
Craig Tiller91624662015-06-25 16:31:02 -0700123/** create a subchannel given a connector */
Craig Tillerf7afa1f2015-06-26 09:02:20 -0700124grpc_subchannel *grpc_subchannel_create(grpc_connector *connector,
125 grpc_subchannel_args *args);
Craig Tiller91624662015-06-25 16:31:02 -0700126
Craig Tiller9e8f9112015-06-23 10:56:11 -0700127#endif /* GRPC_INTERNAL_CORE_CLIENT_CONFIG_SUBCHANNEL_H */