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" |
Craig Tiller | 935cf42 | 2015-05-01 14:10:46 -0700 | [diff] [blame] | 38 | #include "src/core/channel/context.h" |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 39 | #include <grpc/grpc.h> |
| 40 | |
Craig Tiller | 1e0d4c4 | 2015-01-30 16:17:29 -0800 | [diff] [blame] | 41 | /* Primitive operation types - grpc_op's get rewritten into these */ |
| 42 | typedef enum { |
| 43 | GRPC_IOREQ_RECV_INITIAL_METADATA, |
| 44 | GRPC_IOREQ_RECV_MESSAGE, |
| 45 | GRPC_IOREQ_RECV_TRAILING_METADATA, |
| 46 | GRPC_IOREQ_RECV_STATUS, |
Craig Tiller | fb189f8 | 2015-02-03 12:07:07 -0800 | [diff] [blame] | 47 | GRPC_IOREQ_RECV_STATUS_DETAILS, |
Craig Tiller | 05140d0 | 2015-01-30 16:43:40 -0800 | [diff] [blame] | 48 | GRPC_IOREQ_RECV_CLOSE, |
Craig Tiller | 1e0d4c4 | 2015-01-30 16:17:29 -0800 | [diff] [blame] | 49 | GRPC_IOREQ_SEND_INITIAL_METADATA, |
| 50 | GRPC_IOREQ_SEND_MESSAGE, |
| 51 | GRPC_IOREQ_SEND_TRAILING_METADATA, |
| 52 | GRPC_IOREQ_SEND_STATUS, |
| 53 | GRPC_IOREQ_SEND_CLOSE, |
| 54 | GRPC_IOREQ_OP_COUNT |
| 55 | } grpc_ioreq_op; |
| 56 | |
Craig Tiller | 1e0d4c4 | 2015-01-30 16:17:29 -0800 | [diff] [blame] | 57 | typedef union { |
| 58 | grpc_metadata_array *recv_metadata; |
| 59 | grpc_byte_buffer **recv_message; |
Craig Tiller | fb189f8 | 2015-02-03 12:07:07 -0800 | [diff] [blame] | 60 | struct { |
| 61 | void (*set_value)(grpc_status_code status, void *user_data); |
| 62 | void *user_data; |
| 63 | } recv_status; |
| 64 | struct { |
| 65 | char **details; |
| 66 | size_t *details_capacity; |
| 67 | } recv_status_details; |
Craig Tiller | 1e0d4c4 | 2015-01-30 16:17:29 -0800 | [diff] [blame] | 68 | struct { |
| 69 | size_t count; |
Craig Tiller | 6902ad2 | 2015-04-16 08:01:49 -0700 | [diff] [blame] | 70 | grpc_metadata *metadata; |
Craig Tiller | 1e0d4c4 | 2015-01-30 16:17:29 -0800 | [diff] [blame] | 71 | } send_metadata; |
| 72 | grpc_byte_buffer *send_message; |
| 73 | struct { |
| 74 | grpc_status_code code; |
Craig Tiller | fb189f8 | 2015-02-03 12:07:07 -0800 | [diff] [blame] | 75 | const char *details; |
Craig Tiller | 1e0d4c4 | 2015-01-30 16:17:29 -0800 | [diff] [blame] | 76 | } send_status; |
| 77 | } grpc_ioreq_data; |
| 78 | |
| 79 | typedef struct { |
| 80 | grpc_ioreq_op op; |
| 81 | grpc_ioreq_data data; |
| 82 | } grpc_ioreq; |
| 83 | |
Craig Tiller | 62ac155 | 2015-01-27 15:41:44 -0800 | [diff] [blame] | 84 | typedef void (*grpc_ioreq_completion_func)(grpc_call *call, |
| 85 | grpc_op_error status, |
| 86 | void *user_data); |
Craig Tiller | cce17ac | 2015-01-20 09:29:28 -0800 | [diff] [blame] | 87 | |
Craig Tiller | fb189f8 | 2015-02-03 12:07:07 -0800 | [diff] [blame] | 88 | grpc_call *grpc_call_create(grpc_channel *channel, grpc_completion_queue *cq, |
Craig Tiller | 87d5b19 | 2015-04-16 14:37:57 -0700 | [diff] [blame] | 89 | const void *server_transport_data, |
| 90 | grpc_mdelem **add_initial_metadata, |
| 91 | size_t add_initial_metadata_count, |
| 92 | gpr_timespec send_deadline); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 93 | |
Craig Tiller | 166e250 | 2015-02-03 20:14:41 -0800 | [diff] [blame] | 94 | 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] | 95 | grpc_completion_queue *grpc_call_get_completion_queue(grpc_call *call); |
Craig Tiller | 166e250 | 2015-02-03 20:14:41 -0800 | [diff] [blame] | 96 | |
Craig Tiller | 4df412b | 2015-04-28 07:57:54 -0700 | [diff] [blame] | 97 | #ifdef GRPC_CALL_REF_COUNT_DEBUG |
| 98 | void grpc_call_internal_ref(grpc_call *call, const char *reason); |
| 99 | void grpc_call_internal_unref(grpc_call *call, const char *reason, int allow_immediate_deletion); |
| 100 | #define GRPC_CALL_INTERNAL_REF(call, reason) grpc_call_internal_ref(call, reason) |
Julien Boeuf | 9f218dd | 2015-04-23 10:24:02 -0700 | [diff] [blame^] | 101 | #define GRPC_CALL_INTERNAL_UNREF(call, reason, allow_immediate_deletion) \ |
| 102 | grpc_call_internal_unref(call, reason, allow_immediate_deletion) |
Craig Tiller | 4df412b | 2015-04-28 07:57:54 -0700 | [diff] [blame] | 103 | #else |
Craig Tiller | 64bc3fd | 2015-04-24 17:07:12 -0700 | [diff] [blame] | 104 | void grpc_call_internal_ref(grpc_call *call); |
| 105 | void grpc_call_internal_unref(grpc_call *call, int allow_immediate_deletion); |
Craig Tiller | 4df412b | 2015-04-28 07:57:54 -0700 | [diff] [blame] | 106 | #define GRPC_CALL_INTERNAL_REF(call, reason) grpc_call_internal_ref(call) |
Julien Boeuf | 9f218dd | 2015-04-23 10:24:02 -0700 | [diff] [blame^] | 107 | #define GRPC_CALL_INTERNAL_UNREF(call, reason, allow_immediate_deletion) \ |
| 108 | grpc_call_internal_unref(call, allow_immediate_deletion) |
Craig Tiller | 4df412b | 2015-04-28 07:57:54 -0700 | [diff] [blame] | 109 | #endif |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 110 | |
Craig Tiller | 62ac155 | 2015-01-27 15:41:44 -0800 | [diff] [blame] | 111 | grpc_call_error grpc_call_start_ioreq_and_call_back( |
| 112 | grpc_call *call, const grpc_ioreq *reqs, size_t nreqs, |
| 113 | grpc_ioreq_completion_func on_complete, void *user_data); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 114 | |
Craig Tiller | d631cf3 | 2015-01-27 10:35:01 -0800 | [diff] [blame] | 115 | grpc_call_stack *grpc_call_get_call_stack(grpc_call *call); |
| 116 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 117 | /* Given the top call_element, get the call object. */ |
| 118 | grpc_call *grpc_call_from_top_element(grpc_call_element *surface_element); |
| 119 | |
murgatroid99 | d47946b | 2015-03-09 14:27:07 -0700 | [diff] [blame] | 120 | extern int grpc_trace_batch; |
| 121 | |
| 122 | void grpc_call_log_batch(char *file, int line, gpr_log_severity severity, |
| 123 | grpc_call *call, const grpc_op *ops, size_t nops, |
| 124 | void *tag); |
| 125 | |
Craig Tiller | 935cf42 | 2015-05-01 14:10:46 -0700 | [diff] [blame] | 126 | /* Set a context pointer. |
| 127 | No thread safety guarantees are made wrt this value. */ |
| 128 | void grpc_call_context_set(grpc_call *call, grpc_context_index elem, void *value, |
| 129 | void (*destroy)(void *value)); |
| 130 | /* Get a context pointer. */ |
| 131 | void *grpc_call_context_get(grpc_call *call, grpc_context_index elem); |
| 132 | |
murgatroid99 | d47946b | 2015-03-09 14:27:07 -0700 | [diff] [blame] | 133 | #define GRPC_CALL_LOG_BATCH(sev, call, ops, nops, tag) \ |
| 134 | if (grpc_trace_batch) grpc_call_log_batch(sev, call, ops, nops, tag) |
| 135 | |
Julien Boeuf | 9f218dd | 2015-04-23 10:24:02 -0700 | [diff] [blame^] | 136 | gpr_uint8 grpc_call_is_client(grpc_call *call); |
| 137 | |
Craig Tiller | 87d5b19 | 2015-04-16 14:37:57 -0700 | [diff] [blame] | 138 | #endif /* GRPC_INTERNAL_CORE_SURFACE_CALL_H */ |