blob: d987fa2bc10febe63bb5cfd428bdadbc1211d37c [file] [log] [blame]
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001/*
2 *
Craig Tiller06059952015-02-18 08:34:56 -08003 * Copyright 2015, Google Inc.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08004 * 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/channel/noop_filter.h"
35#include <grpc/support/log.h>
36
37typedef struct call_data {
38 int unused; /* C89 requires at least one struct element */
39} call_data;
40
41typedef struct channel_data {
42 int unused; /* C89 requires at least one struct element */
43} channel_data;
44
45/* used to silence 'variable not used' warnings */
46static void ignore_unused(void *ignored) {}
47
48/* Called either:
49 - in response to an API call (or similar) from above, to send something
50 - a network event (or similar) from below, to receive something
51 op contains type and call direction information, in addition to the data
52 that is being sent or received. */
ctillerf962f522014-12-10 15:28:27 -080053static void call_op(grpc_call_element *elem, grpc_call_element *from_elem,
54 grpc_call_op *op) {
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080055 /* grab pointers to our data from the call element */
56 call_data *calld = elem->call_data;
57 channel_data *channeld = elem->channel_data;
58
59 ignore_unused(calld);
60 ignore_unused(channeld);
61
62 switch (op->type) {
63 default:
64 /* pass control up or down the stack depending on op->dir */
65 grpc_call_next_op(elem, op);
66 break;
67 }
68}
69
70/* Called on special channel events, such as disconnection or new incoming
71 calls on the server */
ctillerf962f522014-12-10 15:28:27 -080072static void channel_op(grpc_channel_element *elem,
73 grpc_channel_element *from_elem, grpc_channel_op *op) {
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080074 /* grab pointers to our data from the channel element */
75 channel_data *channeld = elem->channel_data;
76
77 ignore_unused(channeld);
78
79 switch (op->type) {
80 default:
81 /* pass control up or down the stack depending on op->dir */
82 grpc_channel_next_op(elem, op);
83 break;
84 }
85}
86
87/* Constructor for call_data */
88static void init_call_elem(grpc_call_element *elem,
89 const void *server_transport_data) {
90 /* grab pointers to our data from the call element */
91 call_data *calld = elem->call_data;
92 channel_data *channeld = elem->channel_data;
93
94 /* initialize members */
95 calld->unused = channeld->unused;
96}
97
98/* Destructor for call_data */
99static void destroy_call_elem(grpc_call_element *elem) {
100 /* grab pointers to our data from the call element */
101 call_data *calld = elem->call_data;
102 channel_data *channeld = elem->channel_data;
103
104 ignore_unused(calld);
105 ignore_unused(channeld);
106}
107
108/* Constructor for channel_data */
109static void init_channel_elem(grpc_channel_element *elem,
110 const grpc_channel_args *args, grpc_mdctx *mdctx,
111 int is_first, int is_last) {
112 /* grab pointers to our data from the channel element */
113 channel_data *channeld = elem->channel_data;
114
115 /* The first and the last filters tend to be implemented differently to
116 handle the case that there's no 'next' filter to call on the up or down
117 path */
118 GPR_ASSERT(!is_first);
119 GPR_ASSERT(!is_last);
120
121 /* initialize members */
122 channeld->unused = 0;
123}
124
125/* Destructor for channel data */
126static void destroy_channel_elem(grpc_channel_element *elem) {
127 /* grab pointers to our data from the channel element */
128 channel_data *channeld = elem->channel_data;
129
130 ignore_unused(channeld);
131}
132
133const grpc_channel_filter grpc_no_op_filter = {
Yang Gao5fd0d292015-01-26 00:19:48 -0800134 call_op, channel_op, sizeof(call_data),
135 init_call_elem, destroy_call_elem, sizeof(channel_data),
Craig Tiller190d3602015-02-18 09:23:38 -0800136 init_channel_elem, destroy_channel_elem, "no-op"};