blob: 02378b6e8ef632c897fa650833b86e92c3ef6bcc [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"
Craig Tiller935cf422015-05-01 14:10:46 -070038#include "src/core/channel/context.h"
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080039#include <grpc/grpc.h>
40
Craig Tiller1e0d4c42015-01-30 16:17:29 -080041/* Primitive operation types - grpc_op's get rewritten into these */
42typedef enum {
43 GRPC_IOREQ_RECV_INITIAL_METADATA,
44 GRPC_IOREQ_RECV_MESSAGE,
45 GRPC_IOREQ_RECV_TRAILING_METADATA,
46 GRPC_IOREQ_RECV_STATUS,
Craig Tillerfb189f82015-02-03 12:07:07 -080047 GRPC_IOREQ_RECV_STATUS_DETAILS,
Craig Tiller05140d02015-01-30 16:43:40 -080048 GRPC_IOREQ_RECV_CLOSE,
Craig Tiller1e0d4c42015-01-30 16:17:29 -080049 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 Tiller1e0d4c42015-01-30 16:17:29 -080057typedef union {
58 grpc_metadata_array *recv_metadata;
59 grpc_byte_buffer **recv_message;
Craig Tillerfb189f82015-02-03 12:07:07 -080060 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 Tiller1e0d4c42015-01-30 16:17:29 -080068 struct {
69 size_t count;
Craig Tiller6902ad22015-04-16 08:01:49 -070070 grpc_metadata *metadata;
Craig Tiller1e0d4c42015-01-30 16:17:29 -080071 } send_metadata;
72 grpc_byte_buffer *send_message;
73 struct {
74 grpc_status_code code;
Craig Tillerfb189f82015-02-03 12:07:07 -080075 const char *details;
Craig Tiller1e0d4c42015-01-30 16:17:29 -080076 } send_status;
77} grpc_ioreq_data;
78
79typedef struct {
80 grpc_ioreq_op op;
81 grpc_ioreq_data data;
82} grpc_ioreq;
83
Craig Tiller62ac1552015-01-27 15:41:44 -080084typedef void (*grpc_ioreq_completion_func)(grpc_call *call,
85 grpc_op_error status,
86 void *user_data);
Craig Tillercce17ac2015-01-20 09:29:28 -080087
Craig Tillerfb189f82015-02-03 12:07:07 -080088grpc_call *grpc_call_create(grpc_channel *channel, grpc_completion_queue *cq,
Craig Tiller87d5b192015-04-16 14:37:57 -070089 const void *server_transport_data,
90 grpc_mdelem **add_initial_metadata,
91 size_t add_initial_metadata_count,
92 gpr_timespec send_deadline);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080093
Craig Tiller166e2502015-02-03 20:14:41 -080094void grpc_call_set_completion_queue(grpc_call *call, grpc_completion_queue *cq);
Craig Tiller24be0f72015-02-10 14:04:22 -080095grpc_completion_queue *grpc_call_get_completion_queue(grpc_call *call);
Craig Tiller166e2502015-02-03 20:14:41 -080096
Craig Tiller4df412b2015-04-28 07:57:54 -070097#ifdef GRPC_CALL_REF_COUNT_DEBUG
98void grpc_call_internal_ref(grpc_call *call, const char *reason);
99void 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 Boeuf9f218dd2015-04-23 10:24:02 -0700101#define GRPC_CALL_INTERNAL_UNREF(call, reason, allow_immediate_deletion) \
102 grpc_call_internal_unref(call, reason, allow_immediate_deletion)
Craig Tiller4df412b2015-04-28 07:57:54 -0700103#else
Craig Tiller64bc3fd2015-04-24 17:07:12 -0700104void grpc_call_internal_ref(grpc_call *call);
105void grpc_call_internal_unref(grpc_call *call, int allow_immediate_deletion);
Craig Tiller4df412b2015-04-28 07:57:54 -0700106#define GRPC_CALL_INTERNAL_REF(call, reason) grpc_call_internal_ref(call)
Julien Boeuf9f218dd2015-04-23 10:24:02 -0700107#define GRPC_CALL_INTERNAL_UNREF(call, reason, allow_immediate_deletion) \
108 grpc_call_internal_unref(call, allow_immediate_deletion)
Craig Tiller4df412b2015-04-28 07:57:54 -0700109#endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800110
Craig Tiller62ac1552015-01-27 15:41:44 -0800111grpc_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 Nobleb7ebd3b2014-11-26 16:33:03 -0800114
Craig Tillerd631cf32015-01-27 10:35:01 -0800115grpc_call_stack *grpc_call_get_call_stack(grpc_call *call);
116
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800117/* Given the top call_element, get the call object. */
118grpc_call *grpc_call_from_top_element(grpc_call_element *surface_element);
119
murgatroid99d47946b2015-03-09 14:27:07 -0700120extern int grpc_trace_batch;
121
122void 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 Tiller935cf422015-05-01 14:10:46 -0700126/* Set a context pointer.
127 No thread safety guarantees are made wrt this value. */
128void grpc_call_context_set(grpc_call *call, grpc_context_index elem, void *value,
129 void (*destroy)(void *value));
130/* Get a context pointer. */
131void *grpc_call_context_get(grpc_call *call, grpc_context_index elem);
132
murgatroid99d47946b2015-03-09 14:27:07 -0700133#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 Boeuf9f218dd2015-04-23 10:24:02 -0700136gpr_uint8 grpc_call_is_client(grpc_call *call);
137
Craig Tiller87d5b192015-04-16 14:37:57 -0700138#endif /* GRPC_INTERNAL_CORE_SURFACE_CALL_H */