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/surface/client.h" |
| 35 | |
| 36 | #include "src/core/surface/call.h" |
Craig Tiller | da66937 | 2015-02-05 10:10:15 -0800 | [diff] [blame] | 37 | #include "src/core/surface/channel.h" |
Craig Tiller | 485d776 | 2015-01-23 12:54:05 -0800 | [diff] [blame] | 38 | #include "src/core/support/string.h" |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 39 | #include <grpc/support/alloc.h> |
| 40 | #include <grpc/support/log.h> |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 41 | |
Craig Tiller | 87d5b19 | 2015-04-16 14:37:57 -0700 | [diff] [blame] | 42 | typedef struct { void *unused; } call_data; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 43 | |
Craig Tiller | 87d5b19 | 2015-04-16 14:37:57 -0700 | [diff] [blame] | 44 | typedef struct { void *unused; } channel_data; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 45 | |
ctiller | f962f52 | 2014-12-10 15:28:27 -0800 | [diff] [blame] | 46 | static void call_op(grpc_call_element *elem, grpc_call_element *from_elem, |
| 47 | grpc_call_op *op) { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 48 | GRPC_CALL_LOG_OP(GPR_INFO, elem, op); |
| 49 | |
| 50 | switch (op->type) { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 51 | case GRPC_RECV_METADATA: |
Craig Tiller | 6902ad2 | 2015-04-16 08:01:49 -0700 | [diff] [blame] | 52 | grpc_call_recv_metadata(elem, &op->data.metadata); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 53 | break; |
| 54 | case GRPC_RECV_MESSAGE: |
Craig Tiller | cce17ac | 2015-01-20 09:29:28 -0800 | [diff] [blame] | 55 | grpc_call_recv_message(elem, op->data.message); |
| 56 | op->done_cb(op->user_data, GRPC_OP_OK); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 57 | break; |
| 58 | case GRPC_RECV_HALF_CLOSE: |
Craig Tiller | cce17ac | 2015-01-20 09:29:28 -0800 | [diff] [blame] | 59 | grpc_call_read_closed(elem); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 60 | break; |
| 61 | case GRPC_RECV_FINISH: |
Craig Tiller | cce17ac | 2015-01-20 09:29:28 -0800 | [diff] [blame] | 62 | grpc_call_stream_closed(elem); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 63 | break; |
Craig Tiller | 8b282cb | 2015-04-17 14:57:44 -0700 | [diff] [blame] | 64 | case GRPC_RECV_SYNTHETIC_STATUS: |
Craig Tiller | 76f5d46 | 2015-04-17 14:58:12 -0700 | [diff] [blame] | 65 | grpc_call_recv_synthetic_status(elem, op->data.synthetic_status.status, |
| 66 | op->data.synthetic_status.message); |
Craig Tiller | 8b282cb | 2015-04-17 14:57:44 -0700 | [diff] [blame] | 67 | break; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 68 | default: |
| 69 | GPR_ASSERT(op->dir == GRPC_CALL_DOWN); |
| 70 | grpc_call_next_op(elem, op); |
| 71 | } |
| 72 | } |
| 73 | |
ctiller | f962f52 | 2014-12-10 15:28:27 -0800 | [diff] [blame] | 74 | static void channel_op(grpc_channel_element *elem, |
| 75 | grpc_channel_element *from_elem, grpc_channel_op *op) { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 76 | switch (op->type) { |
| 77 | case GRPC_ACCEPT_CALL: |
| 78 | gpr_log(GPR_ERROR, "Client cannot accept new calls"); |
| 79 | break; |
| 80 | case GRPC_TRANSPORT_CLOSED: |
Craig Tiller | da66937 | 2015-02-05 10:10:15 -0800 | [diff] [blame] | 81 | grpc_client_channel_closed(elem); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 82 | break; |
nnoble | 0c475f0 | 2014-12-05 15:37:39 -0800 | [diff] [blame] | 83 | case GRPC_TRANSPORT_GOAWAY: |
| 84 | gpr_slice_unref(op->data.goaway.message); |
| 85 | break; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 86 | default: |
| 87 | GPR_ASSERT(op->dir == GRPC_CALL_DOWN); |
| 88 | grpc_channel_next_op(elem, op); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | static void init_call_elem(grpc_call_element *elem, |
| 93 | const void *transport_server_data) {} |
| 94 | |
| 95 | static void destroy_call_elem(grpc_call_element *elem) {} |
| 96 | |
| 97 | static void init_channel_elem(grpc_channel_element *elem, |
| 98 | const grpc_channel_args *args, grpc_mdctx *mdctx, |
| 99 | int is_first, int is_last) { |
| 100 | GPR_ASSERT(is_first); |
| 101 | GPR_ASSERT(!is_last); |
| 102 | } |
| 103 | |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 104 | static void destroy_channel_elem(grpc_channel_element *elem) {} |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 105 | |
| 106 | const grpc_channel_filter grpc_client_surface_filter = { |
Craig Tiller | 87d5b19 | 2015-04-16 14:37:57 -0700 | [diff] [blame] | 107 | call_op, channel_op, sizeof(call_data), init_call_elem, destroy_call_elem, |
| 108 | sizeof(channel_data), init_channel_elem, destroy_channel_elem, "client", |
| 109 | }; |