blob: 185bfccb77dd7887d8674124e95f58a3c2924984 [file] [log] [blame]
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001/*
2 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02003 * Copyright 2015 gRPC authors.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08004 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02005 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08008 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02009 * http://www.apache.org/licenses/LICENSE-2.0
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080010 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +020011 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080016 *
17 */
18
Craig Tiller9a4dddd2016-03-25 17:08:13 -070019#ifndef GRPC_CORE_LIB_SURFACE_CALL_H
20#define GRPC_CORE_LIB_SURFACE_CALL_H
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080021
Craig Tiller9533d042016-03-25 17:11:06 -070022#include "src/core/lib/channel/channel_stack.h"
23#include "src/core/lib/channel/context.h"
24#include "src/core/lib/surface/api_trace.h"
David Garcia Quintas13c2f6e2016-03-17 22:51:52 -070025
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080026#include <grpc/grpc.h>
David Garcia Quintas13c2f6e2016-03-17 22:51:52 -070027#include <grpc/impl/codegen/compression_types.h>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080028
David Garcia Quintas9c512bd2015-07-20 23:43:53 -070029#ifdef __cplusplus
Craig Tillera82950e2015-09-22 12:33:20 -070030extern "C" {
David Garcia Quintas9c512bd2015-07-20 23:43:53 -070031#endif
32
Craig Tillera82950e2015-09-22 12:33:20 -070033typedef void (*grpc_ioreq_completion_func)(grpc_exec_ctx *exec_ctx,
34 grpc_call *call, int success,
35 void *user_data);
Craig Tillercce17ac2015-01-20 09:29:28 -080036
Craig Tiller8e214652016-08-19 09:54:31 -070037typedef struct grpc_call_create_args {
38 grpc_channel *channel;
39
40 grpc_call *parent_call;
41 uint32_t propagation_mask;
42
43 grpc_completion_queue *cq;
44 /* if not NULL, it'll be used in lieu of cq */
45 grpc_pollset_set *pollset_set_alternative;
46
47 const void *server_transport_data;
48
Craig Tiller7c70b6c2017-01-23 07:48:42 -080049 grpc_mdelem *add_initial_metadata;
Craig Tiller8e214652016-08-19 09:54:31 -070050 size_t add_initial_metadata_count;
51
52 gpr_timespec send_deadline;
53} grpc_call_create_args;
54
55/* Create a new call based on \a args.
56 Regardless of success or failure, always returns a valid new call into *call
57 */
Craig Tillera59c16c2016-10-31 07:25:01 -070058grpc_error *grpc_call_create(grpc_exec_ctx *exec_ctx,
59 const grpc_call_create_args *args,
Craig Tiller8e214652016-08-19 09:54:31 -070060 grpc_call **call);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080061
Craig Tillera82950e2015-09-22 12:33:20 -070062void grpc_call_set_completion_queue(grpc_exec_ctx *exec_ctx, grpc_call *call,
63 grpc_completion_queue *cq);
Craig Tiller166e2502015-02-03 20:14:41 -080064
ncteisen9c43fc02017-06-08 16:06:23 -070065#ifndef NDEBUG
Craig Tillera82950e2015-09-22 12:33:20 -070066void grpc_call_internal_ref(grpc_call *call, const char *reason);
67void grpc_call_internal_unref(grpc_exec_ctx *exec_ctx, grpc_call *call,
68 const char *reason);
Craig Tiller16a3e132015-05-29 22:33:28 -070069#define GRPC_CALL_INTERNAL_REF(call, reason) \
70 grpc_call_internal_ref(call, reason)
Craig Tiller9f7dc3a2015-09-22 10:47:08 -070071#define GRPC_CALL_INTERNAL_UNREF(exec_ctx, call, reason) \
72 grpc_call_internal_unref(exec_ctx, call, reason)
Craig Tiller4df412b2015-04-28 07:57:54 -070073#else
Craig Tillera82950e2015-09-22 12:33:20 -070074void grpc_call_internal_ref(grpc_call *call);
75void grpc_call_internal_unref(grpc_exec_ctx *exec_ctx, grpc_call *call);
Craig Tiller4df412b2015-04-28 07:57:54 -070076#define GRPC_CALL_INTERNAL_REF(call, reason) grpc_call_internal_ref(call)
Craig Tiller9f7dc3a2015-09-22 10:47:08 -070077#define GRPC_CALL_INTERNAL_UNREF(exec_ctx, call, reason) \
78 grpc_call_internal_unref(exec_ctx, call)
Craig Tiller4df412b2015-04-28 07:57:54 -070079#endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080080
Craig Tillera82950e2015-09-22 12:33:20 -070081grpc_call_stack *grpc_call_get_call_stack(grpc_call *call);
Craig Tillerd631cf32015-01-27 10:35:01 -080082
Craig Tillerc7e1a2a2015-11-02 14:17:32 -080083grpc_call_error grpc_call_start_batch_and_execute(grpc_exec_ctx *exec_ctx,
84 grpc_call *call,
85 const grpc_op *ops,
86 size_t nops,
87 grpc_closure *closure);
88
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080089/* Given the top call_element, get the call object. */
Craig Tillera82950e2015-09-22 12:33:20 -070090grpc_call *grpc_call_from_top_element(grpc_call_element *surface_element);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080091
Craig Tillera82950e2015-09-22 12:33:20 -070092void grpc_call_log_batch(char *file, int line, gpr_log_severity severity,
93 grpc_call *call, const grpc_op *ops, size_t nops,
94 void *tag);
murgatroid99d47946b2015-03-09 14:27:07 -070095
Craig Tiller935cf422015-05-01 14:10:46 -070096/* Set a context pointer.
97 No thread safety guarantees are made wrt this value. */
David Garcia Quintasfafe9952017-02-15 10:53:25 -080098/* TODO(#9731): add exec_ctx to destroy */
Craig Tillera82950e2015-09-22 12:33:20 -070099void grpc_call_context_set(grpc_call *call, grpc_context_index elem,
100 void *value, void (*destroy)(void *value));
Craig Tiller935cf422015-05-01 14:10:46 -0700101/* Get a context pointer. */
Craig Tillera82950e2015-09-22 12:33:20 -0700102void *grpc_call_context_get(grpc_call *call, grpc_context_index elem);
Craig Tiller935cf422015-05-01 14:10:46 -0700103
murgatroid99d47946b2015-03-09 14:27:07 -0700104#define GRPC_CALL_LOG_BATCH(sev, call, ops, nops, tag) \
Craig Tiller84f75d42017-05-03 13:06:35 -0700105 if (GRPC_TRACER_ON(grpc_api_trace)) \
106 grpc_call_log_batch(sev, call, ops, nops, tag)
murgatroid99d47946b2015-03-09 14:27:07 -0700107
Craig Tiller7536af02015-12-22 13:49:30 -0800108uint8_t grpc_call_is_client(grpc_call *call);
Julien Boeuf9f218dd2015-04-23 10:24:02 -0700109
David Garcia Quintas13c2f6e2016-03-17 22:51:52 -0700110/* Return an appropriate compression algorithm for the requested compression \a
111 * level in the context of \a call. */
112grpc_compression_algorithm grpc_call_compression_for_level(
113 grpc_call *call, grpc_compression_level level);
114
Craig Tiller84f75d42017-05-03 13:06:35 -0700115extern grpc_tracer_flag grpc_call_error_trace;
116extern grpc_tracer_flag grpc_compression_trace;
Craig Tiller58b30cd2017-01-31 17:07:36 -0800117
David Garcia Quintas9c512bd2015-07-20 23:43:53 -0700118#ifdef __cplusplus
119}
120#endif
121
Craig Tiller9a4dddd2016-03-25 17:08:13 -0700122#endif /* GRPC_CORE_LIB_SURFACE_CALL_H */