blob: f8d0915349ee9774dd316f1e0afcbf6d48e08797 [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
Nicolas "Pixel" Noble1ff52d52015-03-01 05:24:36 +010034#ifndef GRPC_INTERNAL_CORE_SURFACE_CALL_H
35#define GRPC_INTERNAL_CORE_SURFACE_CALL_H
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080036
37#include "src/core/channel/channel_stack.h"
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080038#include <grpc/grpc.h>
39
Craig Tiller1e0d4c42015-01-30 16:17:29 -080040/* Primitive operation types - grpc_op's get rewritten into these */
41typedef enum {
42 GRPC_IOREQ_RECV_INITIAL_METADATA,
43 GRPC_IOREQ_RECV_MESSAGE,
44 GRPC_IOREQ_RECV_TRAILING_METADATA,
45 GRPC_IOREQ_RECV_STATUS,
Craig Tillerfb189f82015-02-03 12:07:07 -080046 GRPC_IOREQ_RECV_STATUS_DETAILS,
Craig Tiller05140d02015-01-30 16:43:40 -080047 GRPC_IOREQ_RECV_CLOSE,
Craig Tiller1e0d4c42015-01-30 16:17:29 -080048 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 Tiller1e0d4c42015-01-30 16:17:29 -080056typedef union {
57 grpc_metadata_array *recv_metadata;
58 grpc_byte_buffer **recv_message;
Craig Tillerfb189f82015-02-03 12:07:07 -080059 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 Tiller1e0d4c42015-01-30 16:17:29 -080067 struct {
68 size_t count;
Craig Tiller6902ad22015-04-16 08:01:49 -070069 grpc_metadata *metadata;
Craig Tiller1e0d4c42015-01-30 16:17:29 -080070 } send_metadata;
71 grpc_byte_buffer *send_message;
72 struct {
73 grpc_status_code code;
Craig Tillerfb189f82015-02-03 12:07:07 -080074 const char *details;
Craig Tiller1e0d4c42015-01-30 16:17:29 -080075 } send_status;
76} grpc_ioreq_data;
77
78typedef struct {
79 grpc_ioreq_op op;
80 grpc_ioreq_data data;
81} grpc_ioreq;
82
Craig Tiller62ac1552015-01-27 15:41:44 -080083typedef void (*grpc_ioreq_completion_func)(grpc_call *call,
84 grpc_op_error status,
85 void *user_data);
Craig Tillercce17ac2015-01-20 09:29:28 -080086
Craig Tillerfb189f82015-02-03 12:07:07 -080087grpc_call *grpc_call_create(grpc_channel *channel, grpc_completion_queue *cq,
Craig Tiller87d5b192015-04-16 14:37:57 -070088 const void *server_transport_data,
89 grpc_mdelem **add_initial_metadata,
90 size_t add_initial_metadata_count,
91 gpr_timespec send_deadline);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080092
Craig Tiller166e2502015-02-03 20:14:41 -080093void grpc_call_set_completion_queue(grpc_call *call, grpc_completion_queue *cq);
Craig Tiller24be0f72015-02-10 14:04:22 -080094grpc_completion_queue *grpc_call_get_completion_queue(grpc_call *call);
Craig Tiller166e2502015-02-03 20:14:41 -080095
Craig Tillerf63fed72015-01-29 10:49:34 -080096void grpc_call_internal_ref(grpc_call *call);
Craig Tilleraef25da2015-01-29 17:19:45 -080097void grpc_call_internal_unref(grpc_call *call, int allow_immediate_deletion);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080098
99/* Helpers for grpc_client, grpc_server filters to publish received data to
100 the completion queue/surface layer */
Craig Tiller6902ad22015-04-16 08:01:49 -0700101/* receive metadata - returns 1 if this was initial metadata */
102int grpc_call_recv_metadata(grpc_call_element *surface_element,
Craig Tiller205aee12015-04-16 14:46:41 -0700103 grpc_metadata_batch *md);
Craig Tiller62ac1552015-01-27 15:41:44 -0800104void grpc_call_recv_message(grpc_call_element *surface_element,
105 grpc_byte_buffer *message);
Craig Tillercce17ac2015-01-20 09:29:28 -0800106void grpc_call_read_closed(grpc_call_element *surface_element);
107void grpc_call_stream_closed(grpc_call_element *surface_element);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800108
109void grpc_call_execute_op(grpc_call *call, grpc_call_op *op);
Craig Tiller62ac1552015-01-27 15:41:44 -0800110grpc_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 Nobleb7ebd3b2014-11-26 16:33:03 -0800113
Craig Tillerd631cf32015-01-27 10:35:01 -0800114grpc_call_stack *grpc_call_get_call_stack(grpc_call *call);
115
Craig Tiller76f5d462015-04-17 14:58:12 -0700116void grpc_call_recv_synthetic_status(grpc_call_element *elem,
117 grpc_status_code status,
118 const char *message);
Craig Tiller8b282cb2015-04-17 14:57:44 -0700119
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800120/* Given the top call_element, get the call object. */
121grpc_call *grpc_call_from_top_element(grpc_call_element *surface_element);
122
murgatroid99d47946b2015-03-09 14:27:07 -0700123extern int grpc_trace_batch;
124
125void 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 Tiller87d5b192015-04-16 14:37:57 -0700132#endif /* GRPC_INTERNAL_CORE_SURFACE_CALL_H */