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 | |
Nicolas "Pixel" Noble | 1ff52d5 | 2015-03-01 05:24:36 +0100 | [diff] [blame] | 34 | #ifndef GRPC_INTERNAL_CORE_SURFACE_CALL_H |
| 35 | #define GRPC_INTERNAL_CORE_SURFACE_CALL_H |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 36 | |
| 37 | #include "src/core/channel/channel_stack.h" |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 38 | #include <grpc/grpc.h> |
| 39 | |
Craig Tiller | 1e0d4c4 | 2015-01-30 16:17:29 -0800 | [diff] [blame] | 40 | /* Primitive operation types - grpc_op's get rewritten into these */ |
| 41 | typedef enum { |
| 42 | GRPC_IOREQ_RECV_INITIAL_METADATA, |
| 43 | GRPC_IOREQ_RECV_MESSAGE, |
| 44 | GRPC_IOREQ_RECV_TRAILING_METADATA, |
| 45 | GRPC_IOREQ_RECV_STATUS, |
Craig Tiller | fb189f8 | 2015-02-03 12:07:07 -0800 | [diff] [blame] | 46 | GRPC_IOREQ_RECV_STATUS_DETAILS, |
Craig Tiller | 05140d0 | 2015-01-30 16:43:40 -0800 | [diff] [blame] | 47 | GRPC_IOREQ_RECV_CLOSE, |
Craig Tiller | 1e0d4c4 | 2015-01-30 16:17:29 -0800 | [diff] [blame] | 48 | GRPC_IOREQ_SEND_INITIAL_METADATA, |
| 49 | GRPC_IOREQ_SEND_MESSAGE, |
| 50 | GRPC_IOREQ_SEND_TRAILING_METADATA, |
| 51 | GRPC_IOREQ_SEND_STATUS, |
| 52 | GRPC_IOREQ_SEND_CLOSE, |
| 53 | GRPC_IOREQ_OP_COUNT |
| 54 | } grpc_ioreq_op; |
| 55 | |
Craig Tiller | 1e0d4c4 | 2015-01-30 16:17:29 -0800 | [diff] [blame] | 56 | typedef union { |
| 57 | grpc_metadata_array *recv_metadata; |
| 58 | grpc_byte_buffer **recv_message; |
Craig Tiller | fb189f8 | 2015-02-03 12:07:07 -0800 | [diff] [blame] | 59 | struct { |
| 60 | void (*set_value)(grpc_status_code status, void *user_data); |
| 61 | void *user_data; |
| 62 | } recv_status; |
| 63 | struct { |
| 64 | char **details; |
| 65 | size_t *details_capacity; |
| 66 | } recv_status_details; |
Craig Tiller | 1e0d4c4 | 2015-01-30 16:17:29 -0800 | [diff] [blame] | 67 | struct { |
| 68 | size_t count; |
Craig Tiller | 6902ad2 | 2015-04-16 08:01:49 -0700 | [diff] [blame] | 69 | grpc_metadata *metadata; |
Craig Tiller | 1e0d4c4 | 2015-01-30 16:17:29 -0800 | [diff] [blame] | 70 | } send_metadata; |
| 71 | grpc_byte_buffer *send_message; |
| 72 | struct { |
| 73 | grpc_status_code code; |
Craig Tiller | fb189f8 | 2015-02-03 12:07:07 -0800 | [diff] [blame] | 74 | const char *details; |
Craig Tiller | 1e0d4c4 | 2015-01-30 16:17:29 -0800 | [diff] [blame] | 75 | } send_status; |
| 76 | } grpc_ioreq_data; |
| 77 | |
| 78 | typedef struct { |
| 79 | grpc_ioreq_op op; |
| 80 | grpc_ioreq_data data; |
| 81 | } grpc_ioreq; |
| 82 | |
Craig Tiller | 62ac155 | 2015-01-27 15:41:44 -0800 | [diff] [blame] | 83 | typedef void (*grpc_ioreq_completion_func)(grpc_call *call, |
| 84 | grpc_op_error status, |
| 85 | void *user_data); |
Craig Tiller | cce17ac | 2015-01-20 09:29:28 -0800 | [diff] [blame] | 86 | |
Craig Tiller | fb189f8 | 2015-02-03 12:07:07 -0800 | [diff] [blame] | 87 | grpc_call *grpc_call_create(grpc_channel *channel, grpc_completion_queue *cq, |
Craig Tiller | 87d5b19 | 2015-04-16 14:37:57 -0700 | [diff] [blame] | 88 | const void *server_transport_data, |
| 89 | grpc_mdelem **add_initial_metadata, |
| 90 | size_t add_initial_metadata_count, |
| 91 | gpr_timespec send_deadline); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 92 | |
Craig Tiller | 166e250 | 2015-02-03 20:14:41 -0800 | [diff] [blame] | 93 | void grpc_call_set_completion_queue(grpc_call *call, grpc_completion_queue *cq); |
Craig Tiller | 24be0f7 | 2015-02-10 14:04:22 -0800 | [diff] [blame] | 94 | grpc_completion_queue *grpc_call_get_completion_queue(grpc_call *call); |
Craig Tiller | 166e250 | 2015-02-03 20:14:41 -0800 | [diff] [blame] | 95 | |
Craig Tiller | f63fed7 | 2015-01-29 10:49:34 -0800 | [diff] [blame] | 96 | void grpc_call_internal_ref(grpc_call *call); |
Craig Tiller | aef25da | 2015-01-29 17:19:45 -0800 | [diff] [blame] | 97 | void grpc_call_internal_unref(grpc_call *call, int allow_immediate_deletion); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 98 | |
| 99 | /* Helpers for grpc_client, grpc_server filters to publish received data to |
| 100 | the completion queue/surface layer */ |
Craig Tiller | 6902ad2 | 2015-04-16 08:01:49 -0700 | [diff] [blame] | 101 | /* receive metadata - returns 1 if this was initial metadata */ |
| 102 | int grpc_call_recv_metadata(grpc_call_element *surface_element, |
Craig Tiller | 205aee1 | 2015-04-16 14:46:41 -0700 | [diff] [blame] | 103 | grpc_metadata_batch *md); |
Craig Tiller | 62ac155 | 2015-01-27 15:41:44 -0800 | [diff] [blame] | 104 | void grpc_call_recv_message(grpc_call_element *surface_element, |
| 105 | grpc_byte_buffer *message); |
Craig Tiller | cce17ac | 2015-01-20 09:29:28 -0800 | [diff] [blame] | 106 | void grpc_call_read_closed(grpc_call_element *surface_element); |
| 107 | void grpc_call_stream_closed(grpc_call_element *surface_element); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 108 | |
| 109 | void grpc_call_execute_op(grpc_call *call, grpc_call_op *op); |
Craig Tiller | 62ac155 | 2015-01-27 15:41:44 -0800 | [diff] [blame] | 110 | grpc_call_error grpc_call_start_ioreq_and_call_back( |
| 111 | grpc_call *call, const grpc_ioreq *reqs, size_t nreqs, |
| 112 | grpc_ioreq_completion_func on_complete, void *user_data); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 113 | |
Craig Tiller | d631cf3 | 2015-01-27 10:35:01 -0800 | [diff] [blame] | 114 | grpc_call_stack *grpc_call_get_call_stack(grpc_call *call); |
| 115 | |
Craig Tiller | 76f5d46 | 2015-04-17 14:58:12 -0700 | [diff] [blame] | 116 | void grpc_call_recv_synthetic_status(grpc_call_element *elem, |
| 117 | grpc_status_code status, |
| 118 | const char *message); |
Craig Tiller | 8b282cb | 2015-04-17 14:57:44 -0700 | [diff] [blame] | 119 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 120 | /* Given the top call_element, get the call object. */ |
| 121 | grpc_call *grpc_call_from_top_element(grpc_call_element *surface_element); |
| 122 | |
murgatroid99 | d47946b | 2015-03-09 14:27:07 -0700 | [diff] [blame] | 123 | extern int grpc_trace_batch; |
| 124 | |
| 125 | void grpc_call_log_batch(char *file, int line, gpr_log_severity severity, |
| 126 | grpc_call *call, const grpc_op *ops, size_t nops, |
| 127 | void *tag); |
| 128 | |
| 129 | #define GRPC_CALL_LOG_BATCH(sev, call, ops, nops, tag) \ |
| 130 | if (grpc_trace_batch) grpc_call_log_batch(sev, call, ops, nops, tag) |
| 131 | |
Craig Tiller | 87d5b19 | 2015-04-16 14:37:57 -0700 | [diff] [blame] | 132 | #endif /* GRPC_INTERNAL_CORE_SURFACE_CALL_H */ |