• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * 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
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * 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.
16  *
17  */
18 
19 #ifndef GRPC_CORE_LIB_SURFACE_CALL_H
20 #define GRPC_CORE_LIB_SURFACE_CALL_H
21 
22 #include <grpc/support/port_platform.h>
23 
24 #include "src/core/lib/channel/channel_stack.h"
25 #include "src/core/lib/channel/context.h"
26 #include "src/core/lib/surface/api_trace.h"
27 
28 #include <grpc/grpc.h>
29 #include <grpc/impl/codegen/compression_types.h>
30 
31 typedef void (*grpc_ioreq_completion_func)(grpc_call* call, int success,
32                                            void* user_data);
33 
34 typedef struct grpc_call_create_args {
35   grpc_channel* channel;
36   grpc_server* server;
37 
38   grpc_call* parent;
39   uint32_t propagation_mask;
40 
41   grpc_completion_queue* cq;
42   /* if not NULL, it'll be used in lieu of cq */
43   grpc_pollset_set* pollset_set_alternative;
44 
45   const void* server_transport_data;
46 
47   grpc_mdelem* add_initial_metadata;
48   size_t add_initial_metadata_count;
49 
50   grpc_millis send_deadline;
51 } grpc_call_create_args;
52 
53 /* Create a new call based on \a args.
54    Regardless of success or failure, always returns a valid new call into *call
55    */
56 grpc_error* grpc_call_create(const grpc_call_create_args* args,
57                              grpc_call** call);
58 
59 void grpc_call_set_completion_queue(grpc_call* call, grpc_completion_queue* cq);
60 
61 #ifndef NDEBUG
62 void grpc_call_internal_ref(grpc_call* call, const char* reason);
63 void grpc_call_internal_unref(grpc_call* call, const char* reason);
64 #define GRPC_CALL_INTERNAL_REF(call, reason) \
65   grpc_call_internal_ref(call, reason)
66 #define GRPC_CALL_INTERNAL_UNREF(call, reason) \
67   grpc_call_internal_unref(call, reason)
68 #else
69 void grpc_call_internal_ref(grpc_call* call);
70 void grpc_call_internal_unref(grpc_call* call);
71 #define GRPC_CALL_INTERNAL_REF(call, reason) grpc_call_internal_ref(call)
72 #define GRPC_CALL_INTERNAL_UNREF(call, reason) grpc_call_internal_unref(call)
73 #endif
74 
75 gpr_arena* grpc_call_get_arena(grpc_call* call);
76 
77 grpc_call_stack* grpc_call_get_call_stack(grpc_call* call);
78 
79 grpc_call_error grpc_call_start_batch_and_execute(grpc_call* call,
80                                                   const grpc_op* ops,
81                                                   size_t nops,
82                                                   grpc_closure* closure);
83 
84 /* Given the top call_element, get the call object. */
85 grpc_call* grpc_call_from_top_element(grpc_call_element* surface_element);
86 
87 void grpc_call_log_batch(const char* file, int line, gpr_log_severity severity,
88                          grpc_call* call, const grpc_op* ops, size_t nops,
89                          void* tag);
90 
91 /* Set a context pointer.
92    No thread safety guarantees are made wrt this value. */
93 /* TODO(#9731): add exec_ctx to destroy */
94 void grpc_call_context_set(grpc_call* call, grpc_context_index elem,
95                            void* value, void (*destroy)(void* value));
96 /* Get a context pointer. */
97 void* grpc_call_context_get(grpc_call* call, grpc_context_index elem);
98 
99 #define GRPC_CALL_LOG_BATCH(sev, call, ops, nops, tag) \
100   if (grpc_api_trace.enabled()) grpc_call_log_batch(sev, call, ops, nops, tag)
101 
102 uint8_t grpc_call_is_client(grpc_call* call);
103 
104 /* Get the estimated memory size for a call BESIDES the call stack. Combined
105  * with the size of the call stack, it helps estimate the arena size for the
106  * initial call. */
107 size_t grpc_call_get_initial_size_estimate();
108 
109 /* Return an appropriate compression algorithm for the requested compression \a
110  * level in the context of \a call. */
111 grpc_compression_algorithm grpc_call_compression_for_level(
112     grpc_call* call, grpc_compression_level level);
113 
114 extern grpc_core::TraceFlag grpc_call_error_trace;
115 extern grpc_core::TraceFlag grpc_compression_trace;
116 
117 #endif /* GRPC_CORE_LIB_SURFACE_CALL_H */
118