blob: e268949be35acb7d1cdbb8df1ed65d11ba4dbaec [file] [log] [blame]
Craig Tilleraf691802015-06-23 14:57:07 -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
34#include "src/core/client_config/subchannel.h"
Craig Tiller2595ab72015-06-25 15:26:00 -070035
36#include <grpc/support/alloc.h>
37
38struct grpc_subchannel {
39 gpr_refcount refs;
40};
41
42struct grpc_subchannel_call {
43 grpc_subchannel *subchannel;
44 gpr_refcount refs;
45};
46
47#define SUBCHANNEL_CALL_TO_CALL_STACK(call) (((grpc_call_stack *)(call)) + 1)
48
49/*
50 * grpc_subchannel implementation
51 */
52
53void grpc_subchannel_ref(grpc_subchannel *channel) { gpr_ref(&channel->refs); }
54
55void grpc_subchannel_unref(grpc_subchannel *channel) {
56 if (gpr_unref(&channel->refs)) {
57 gpr_free(channel);
58 }
59}
60
61/*
62 * grpc_subchannel_call implementation
63 */
64
65void grpc_subchannel_call_ref(grpc_subchannel_call *call) {
66 gpr_ref(&call->refs);
67}
68
69void grpc_subchannel_call_unref(grpc_subchannel_call *call) {
70 if (gpr_unref(&call->refs)) {
71 grpc_call_stack_destroy(SUBCHANNEL_CALL_TO_CALL_STACK(call));
72 grpc_subchannel_unref(call->subchannel);
73 gpr_free(call);
74 }
75}
76
77void grpc_subchannel_call_process_op(grpc_subchannel_call *call,
78 grpc_transport_stream_op *op) {
79 grpc_call_stack *call_stack = SUBCHANNEL_CALL_TO_CALL_STACK(call);
80 grpc_call_element *top_elem = grpc_call_stack_element(call_stack, 0);
81 top_elem->filter->start_transport_stream_op(top_elem, op);
82}