Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 0605995 | 2015-02-18 08:34:56 -0800 | [diff] [blame] | 3 | * Copyright 2015, Google Inc. |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 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/channel/noop_filter.h" |
| 35 | #include <grpc/support/log.h> |
| 36 | |
| 37 | typedef struct call_data { |
| 38 | int unused; /* C89 requires at least one struct element */ |
| 39 | } call_data; |
| 40 | |
| 41 | typedef 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 */ |
| 46 | static void ignore_unused(void *ignored) {} |
| 47 | |
Craig Tiller | b7959a0 | 2015-06-25 08:50:54 -0700 | [diff] [blame] | 48 | static void noop_mutate_op(grpc_call_element *elem, |
| 49 | grpc_transport_stream_op *op) { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 50 | /* 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 Tiller | 50d9db5 | 2015-04-23 10:52:14 -0700 | [diff] [blame] | 57 | /* 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 Tiller | e039f03 | 2015-06-25 12:54:23 -0700 | [diff] [blame] | 65 | static void noop_start_transport_stream_op(grpc_call_element *elem, |
| 66 | grpc_transport_stream_op *op) { |
Craig Tiller | 50d9db5 | 2015-04-23 10:52:14 -0700 | [diff] [blame] | 67 | noop_mutate_op(elem, op); |
| 68 | |
Craig Tiller | 83f88d9 | 2015-04-21 16:02:05 -0700 | [diff] [blame] | 69 | /* pass control down the stack */ |
| 70 | grpc_call_next_op(elem, op); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 71 | } |
| 72 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 73 | /* Constructor for call_data */ |
| 74 | static void init_call_elem(grpc_call_element *elem, |
Craig Tiller | 06aeea7 | 2015-04-23 10:54:45 -0700 | [diff] [blame] | 75 | const void *server_transport_data, |
Craig Tiller | b7959a0 | 2015-06-25 08:50:54 -0700 | [diff] [blame] | 76 | grpc_transport_stream_op *initial_op) { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 77 | /* 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 Tiller | 50d9db5 | 2015-04-23 10:52:14 -0700 | [diff] [blame] | 83 | |
| 84 | if (initial_op) noop_mutate_op(elem, initial_op); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | /* Destructor for call_data */ |
| 88 | static 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 Tiller | 079a11b | 2015-06-30 10:07:15 -0700 | [diff] [blame] | 98 | static void init_channel_elem(grpc_channel_element *elem, grpc_channel *master, |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 99 | 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 */ |
| 115 | static 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 Tiller | e039f03 | 2015-06-25 12:54:23 -0700 | [diff] [blame] | 122 | const 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, |
| 130 | "no-op"}; |