blob: d631885aafdbd285405884030066b14f4ec40c79 [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
Craig Tillerb7959a02015-06-25 08:50:54 -070048static void noop_mutate_op(grpc_call_element *elem,
49 grpc_transport_stream_op *op) {
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080050 /* grab pointers to our data from the call element */
51 call_data *calld = elem->call_data;
52 channel_data *channeld = elem->channel_data;
53
54 ignore_unused(calld);
55 ignore_unused(channeld);
56
Craig Tiller50d9db52015-04-23 10:52:14 -070057 /* do nothing */
58}
59
60/* Called either:
61 - in response to an API call (or similar) from above, to send something
62 - a network event (or similar) from below, to receive something
63 op contains type and call direction information, in addition to the data
64 that is being sent or received. */
Craig Tillere039f032015-06-25 12:54:23 -070065static void noop_start_transport_stream_op(grpc_call_element *elem,
66 grpc_transport_stream_op *op) {
Craig Tiller50d9db52015-04-23 10:52:14 -070067 noop_mutate_op(elem, op);
68
Craig Tiller83f88d92015-04-21 16:02:05 -070069 /* pass control down the stack */
70 grpc_call_next_op(elem, op);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080071}
72
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080073/* Constructor for call_data */
74static void init_call_elem(grpc_call_element *elem,
Craig Tiller06aeea72015-04-23 10:54:45 -070075 const void *server_transport_data,
Craig Tillerb7959a02015-06-25 08:50:54 -070076 grpc_transport_stream_op *initial_op) {
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080077 /* grab pointers to our data from the call element */
78 call_data *calld = elem->call_data;
79 channel_data *channeld = elem->channel_data;
80
81 /* initialize members */
82 calld->unused = channeld->unused;
Craig Tiller50d9db52015-04-23 10:52:14 -070083
84 if (initial_op) noop_mutate_op(elem, initial_op);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080085}
86
87/* Destructor for call_data */
88static void destroy_call_elem(grpc_call_element *elem) {
89 /* grab pointers to our data from the call element */
90 call_data *calld = elem->call_data;
91 channel_data *channeld = elem->channel_data;
92
93 ignore_unused(calld);
94 ignore_unused(channeld);
95}
96
97/* Constructor for channel_data */
Craig Tiller079a11b2015-06-30 10:07:15 -070098static void init_channel_elem(grpc_channel_element *elem, grpc_channel *master,
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080099 const grpc_channel_args *args, grpc_mdctx *mdctx,
100 int is_first, int is_last) {
101 /* grab pointers to our data from the channel element */
102 channel_data *channeld = elem->channel_data;
103
104 /* The first and the last filters tend to be implemented differently to
105 handle the case that there's no 'next' filter to call on the up or down
106 path */
107 GPR_ASSERT(!is_first);
108 GPR_ASSERT(!is_last);
109
110 /* initialize members */
111 channeld->unused = 0;
112}
113
114/* Destructor for channel data */
115static void destroy_channel_elem(grpc_channel_element *elem) {
116 /* grab pointers to our data from the channel element */
117 channel_data *channeld = elem->channel_data;
118
119 ignore_unused(channeld);
120}
121
Craig Tillere039f032015-06-25 12:54:23 -0700122const grpc_channel_filter grpc_no_op_filter = {noop_start_transport_stream_op,
123 grpc_channel_next_op,
124 sizeof(call_data),
125 init_call_elem,
126 destroy_call_elem,
127 sizeof(channel_data),
128 init_channel_elem,
129 destroy_channel_elem,
Craig Tiller1b22b9d2015-07-20 13:42:22 -0700130 grpc_call_next_get_peer,
Craig Tillere039f032015-06-25 12:54:23 -0700131 "no-op"};