xref: /aosp_15_r20/external/grpc-grpc/include/grpc/grpc.h (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
1*cc02d7e2SAndroid Build Coastguard Worker /*
2*cc02d7e2SAndroid Build Coastguard Worker  *
3*cc02d7e2SAndroid Build Coastguard Worker  * Copyright 2015-2016 gRPC authors.
4*cc02d7e2SAndroid Build Coastguard Worker  *
5*cc02d7e2SAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
6*cc02d7e2SAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
7*cc02d7e2SAndroid Build Coastguard Worker  * You may obtain a copy of the License at
8*cc02d7e2SAndroid Build Coastguard Worker  *
9*cc02d7e2SAndroid Build Coastguard Worker  *     http://www.apache.org/licenses/LICENSE-2.0
10*cc02d7e2SAndroid Build Coastguard Worker  *
11*cc02d7e2SAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
12*cc02d7e2SAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
13*cc02d7e2SAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*cc02d7e2SAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
15*cc02d7e2SAndroid Build Coastguard Worker  * limitations under the License.
16*cc02d7e2SAndroid Build Coastguard Worker  *
17*cc02d7e2SAndroid Build Coastguard Worker  */
18*cc02d7e2SAndroid Build Coastguard Worker 
19*cc02d7e2SAndroid Build Coastguard Worker #ifndef GRPC_GRPC_H
20*cc02d7e2SAndroid Build Coastguard Worker #define GRPC_GRPC_H
21*cc02d7e2SAndroid Build Coastguard Worker 
22*cc02d7e2SAndroid Build Coastguard Worker #include <stddef.h>
23*cc02d7e2SAndroid Build Coastguard Worker 
24*cc02d7e2SAndroid Build Coastguard Worker #include <grpc/byte_buffer.h>
25*cc02d7e2SAndroid Build Coastguard Worker #include <grpc/impl/connectivity_state.h>  // IWYU pragma: export
26*cc02d7e2SAndroid Build Coastguard Worker #include <grpc/impl/grpc_types.h>          // IWYU pragma: export
27*cc02d7e2SAndroid Build Coastguard Worker #include <grpc/impl/propagation_bits.h>
28*cc02d7e2SAndroid Build Coastguard Worker #include <grpc/slice.h>
29*cc02d7e2SAndroid Build Coastguard Worker #include <grpc/status.h>
30*cc02d7e2SAndroid Build Coastguard Worker #include <grpc/support/port_platform.h>
31*cc02d7e2SAndroid Build Coastguard Worker #include <grpc/support/time.h>
32*cc02d7e2SAndroid Build Coastguard Worker 
33*cc02d7e2SAndroid Build Coastguard Worker #ifdef __cplusplus
34*cc02d7e2SAndroid Build Coastguard Worker extern "C" {
35*cc02d7e2SAndroid Build Coastguard Worker #endif
36*cc02d7e2SAndroid Build Coastguard Worker 
37*cc02d7e2SAndroid Build Coastguard Worker /*! \mainpage GRPC Core
38*cc02d7e2SAndroid Build Coastguard Worker  *
39*cc02d7e2SAndroid Build Coastguard Worker  * The GRPC Core library is a low-level library designed to be wrapped by higher
40*cc02d7e2SAndroid Build Coastguard Worker  * level libraries. The top-level API is provided in grpc.h. Security related
41*cc02d7e2SAndroid Build Coastguard Worker  * functionality lives in grpc_security.h.
42*cc02d7e2SAndroid Build Coastguard Worker  */
43*cc02d7e2SAndroid Build Coastguard Worker 
44*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI void grpc_metadata_array_init(grpc_metadata_array* array);
45*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI void grpc_metadata_array_destroy(grpc_metadata_array* array);
46*cc02d7e2SAndroid Build Coastguard Worker 
47*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI void grpc_call_details_init(grpc_call_details* details);
48*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI void grpc_call_details_destroy(grpc_call_details* details);
49*cc02d7e2SAndroid Build Coastguard Worker 
50*cc02d7e2SAndroid Build Coastguard Worker /** Initialize the grpc library.
51*cc02d7e2SAndroid Build Coastguard Worker 
52*cc02d7e2SAndroid Build Coastguard Worker     After it's called, a matching invocation to grpc_shutdown() is expected.
53*cc02d7e2SAndroid Build Coastguard Worker 
54*cc02d7e2SAndroid Build Coastguard Worker     It is not safe to call any other grpc functions before calling this.
55*cc02d7e2SAndroid Build Coastguard Worker     (To avoid overhead, little checking is done, and some things may work. We
56*cc02d7e2SAndroid Build Coastguard Worker     do not warrant that they will continue to do so in future revisions of this
57*cc02d7e2SAndroid Build Coastguard Worker     library). */
58*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI void grpc_init(void);
59*cc02d7e2SAndroid Build Coastguard Worker 
60*cc02d7e2SAndroid Build Coastguard Worker /** Shut down the grpc library.
61*cc02d7e2SAndroid Build Coastguard Worker 
62*cc02d7e2SAndroid Build Coastguard Worker     Before it's called, there should haven been a matching invocation to
63*cc02d7e2SAndroid Build Coastguard Worker     grpc_init().
64*cc02d7e2SAndroid Build Coastguard Worker 
65*cc02d7e2SAndroid Build Coastguard Worker     The last call to grpc_shutdown will initiate cleaning up of grpc library
66*cc02d7e2SAndroid Build Coastguard Worker     internals, which can happen in another thread. Once the clean-up is done,
67*cc02d7e2SAndroid Build Coastguard Worker     no memory is used by grpc, nor are any instructions executing within the
68*cc02d7e2SAndroid Build Coastguard Worker     grpc library.  Prior to calling, all application owned grpc objects must
69*cc02d7e2SAndroid Build Coastguard Worker     have been destroyed. */
70*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI void grpc_shutdown(void);
71*cc02d7e2SAndroid Build Coastguard Worker 
72*cc02d7e2SAndroid Build Coastguard Worker /** EXPERIMENTAL. Returns 1 if the grpc library has been initialized.
73*cc02d7e2SAndroid Build Coastguard Worker     TODO(ericgribkoff) Decide if this should be promoted to non-experimental as
74*cc02d7e2SAndroid Build Coastguard Worker     part of stabilizing the fork support API, as tracked in
75*cc02d7e2SAndroid Build Coastguard Worker     https://github.com/grpc/grpc/issues/15334 */
76*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI int grpc_is_initialized(void);
77*cc02d7e2SAndroid Build Coastguard Worker 
78*cc02d7e2SAndroid Build Coastguard Worker /** DEPRECATED. Recommend to use grpc_shutdown only */
79*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI void grpc_shutdown_blocking(void);
80*cc02d7e2SAndroid Build Coastguard Worker 
81*cc02d7e2SAndroid Build Coastguard Worker /** Return a string representing the current version of grpc */
82*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI const char* grpc_version_string(void);
83*cc02d7e2SAndroid Build Coastguard Worker 
84*cc02d7e2SAndroid Build Coastguard Worker /** Return a string specifying what the 'g' in gRPC stands for */
85*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI const char* grpc_g_stands_for(void);
86*cc02d7e2SAndroid Build Coastguard Worker 
87*cc02d7e2SAndroid Build Coastguard Worker /** Returns the completion queue factory based on the attributes. MAY return a
88*cc02d7e2SAndroid Build Coastguard Worker     NULL if no factory can be found */
89*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI const grpc_completion_queue_factory*
90*cc02d7e2SAndroid Build Coastguard Worker grpc_completion_queue_factory_lookup(
91*cc02d7e2SAndroid Build Coastguard Worker     const grpc_completion_queue_attributes* attributes);
92*cc02d7e2SAndroid Build Coastguard Worker 
93*cc02d7e2SAndroid Build Coastguard Worker /** Helper function to create a completion queue with grpc_cq_completion_type
94*cc02d7e2SAndroid Build Coastguard Worker     of GRPC_CQ_NEXT and grpc_cq_polling_type of GRPC_CQ_DEFAULT_POLLING */
95*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI grpc_completion_queue* grpc_completion_queue_create_for_next(
96*cc02d7e2SAndroid Build Coastguard Worker     void* reserved);
97*cc02d7e2SAndroid Build Coastguard Worker 
98*cc02d7e2SAndroid Build Coastguard Worker /** Helper function to create a completion queue with grpc_cq_completion_type
99*cc02d7e2SAndroid Build Coastguard Worker     of GRPC_CQ_PLUCK and grpc_cq_polling_type of GRPC_CQ_DEFAULT_POLLING */
100*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI grpc_completion_queue* grpc_completion_queue_create_for_pluck(
101*cc02d7e2SAndroid Build Coastguard Worker     void* reserved);
102*cc02d7e2SAndroid Build Coastguard Worker 
103*cc02d7e2SAndroid Build Coastguard Worker /** Helper function to create a completion queue with grpc_cq_completion_type
104*cc02d7e2SAndroid Build Coastguard Worker     of GRPC_CQ_CALLBACK and grpc_cq_polling_type of GRPC_CQ_DEFAULT_POLLING.
105*cc02d7e2SAndroid Build Coastguard Worker     This function is experimental. */
106*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI grpc_completion_queue* grpc_completion_queue_create_for_callback(
107*cc02d7e2SAndroid Build Coastguard Worker     grpc_completion_queue_functor* shutdown_callback, void* reserved);
108*cc02d7e2SAndroid Build Coastguard Worker 
109*cc02d7e2SAndroid Build Coastguard Worker /** Create a completion queue */
110*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI grpc_completion_queue* grpc_completion_queue_create(
111*cc02d7e2SAndroid Build Coastguard Worker     const grpc_completion_queue_factory* factory,
112*cc02d7e2SAndroid Build Coastguard Worker     const grpc_completion_queue_attributes* attributes, void* reserved);
113*cc02d7e2SAndroid Build Coastguard Worker 
114*cc02d7e2SAndroid Build Coastguard Worker /** Blocks until an event is available, the completion queue is being shut down,
115*cc02d7e2SAndroid Build Coastguard Worker     or deadline is reached.
116*cc02d7e2SAndroid Build Coastguard Worker 
117*cc02d7e2SAndroid Build Coastguard Worker     Returns a grpc_event with type GRPC_QUEUE_TIMEOUT on timeout,
118*cc02d7e2SAndroid Build Coastguard Worker     otherwise a grpc_event describing the event that occurred.
119*cc02d7e2SAndroid Build Coastguard Worker 
120*cc02d7e2SAndroid Build Coastguard Worker     Callers must not call grpc_completion_queue_next and
121*cc02d7e2SAndroid Build Coastguard Worker     grpc_completion_queue_pluck simultaneously on the same completion queue. */
122*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI grpc_event grpc_completion_queue_next(grpc_completion_queue* cq,
123*cc02d7e2SAndroid Build Coastguard Worker                                               gpr_timespec deadline,
124*cc02d7e2SAndroid Build Coastguard Worker                                               void* reserved);
125*cc02d7e2SAndroid Build Coastguard Worker 
126*cc02d7e2SAndroid Build Coastguard Worker /** Blocks until an event with tag 'tag' is available, the completion queue is
127*cc02d7e2SAndroid Build Coastguard Worker     being shutdown or deadline is reached.
128*cc02d7e2SAndroid Build Coastguard Worker 
129*cc02d7e2SAndroid Build Coastguard Worker     Returns a grpc_event with type GRPC_QUEUE_TIMEOUT on timeout,
130*cc02d7e2SAndroid Build Coastguard Worker     otherwise a grpc_event describing the event that occurred.
131*cc02d7e2SAndroid Build Coastguard Worker 
132*cc02d7e2SAndroid Build Coastguard Worker     Callers must not call grpc_completion_queue_next and
133*cc02d7e2SAndroid Build Coastguard Worker     grpc_completion_queue_pluck simultaneously on the same completion queue.
134*cc02d7e2SAndroid Build Coastguard Worker 
135*cc02d7e2SAndroid Build Coastguard Worker     Completion queues support a maximum of GRPC_MAX_COMPLETION_QUEUE_PLUCKERS
136*cc02d7e2SAndroid Build Coastguard Worker     concurrently executing plucks at any time. */
137*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI grpc_event grpc_completion_queue_pluck(grpc_completion_queue* cq,
138*cc02d7e2SAndroid Build Coastguard Worker                                                void* tag, gpr_timespec deadline,
139*cc02d7e2SAndroid Build Coastguard Worker                                                void* reserved);
140*cc02d7e2SAndroid Build Coastguard Worker 
141*cc02d7e2SAndroid Build Coastguard Worker /** Maximum number of outstanding grpc_completion_queue_pluck executions per
142*cc02d7e2SAndroid Build Coastguard Worker     completion queue */
143*cc02d7e2SAndroid Build Coastguard Worker #define GRPC_MAX_COMPLETION_QUEUE_PLUCKERS 6
144*cc02d7e2SAndroid Build Coastguard Worker 
145*cc02d7e2SAndroid Build Coastguard Worker /** Begin destruction of a completion queue. Once all possible events are
146*cc02d7e2SAndroid Build Coastguard Worker     drained then grpc_completion_queue_next will start to produce
147*cc02d7e2SAndroid Build Coastguard Worker     GRPC_QUEUE_SHUTDOWN events only. At that point it's safe to call
148*cc02d7e2SAndroid Build Coastguard Worker     grpc_completion_queue_destroy.
149*cc02d7e2SAndroid Build Coastguard Worker 
150*cc02d7e2SAndroid Build Coastguard Worker     After calling this function applications should ensure that no
151*cc02d7e2SAndroid Build Coastguard Worker     NEW work is added to be published on this completion queue. */
152*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI void grpc_completion_queue_shutdown(grpc_completion_queue* cq);
153*cc02d7e2SAndroid Build Coastguard Worker 
154*cc02d7e2SAndroid Build Coastguard Worker /** Destroy a completion queue. The caller must ensure that the queue is
155*cc02d7e2SAndroid Build Coastguard Worker     drained and no threads are executing grpc_completion_queue_next */
156*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI void grpc_completion_queue_destroy(grpc_completion_queue* cq);
157*cc02d7e2SAndroid Build Coastguard Worker 
158*cc02d7e2SAndroid Build Coastguard Worker /*********** EXPERIMENTAL API ************/
159*cc02d7e2SAndroid Build Coastguard Worker /** Initializes a thread local cache for \a cq.
160*cc02d7e2SAndroid Build Coastguard Worker  * grpc_flush_cq_tls_cache() MUST be called on the same thread,
161*cc02d7e2SAndroid Build Coastguard Worker  * with the same cq.
162*cc02d7e2SAndroid Build Coastguard Worker  */
163*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI void grpc_completion_queue_thread_local_cache_init(
164*cc02d7e2SAndroid Build Coastguard Worker     grpc_completion_queue* cq);
165*cc02d7e2SAndroid Build Coastguard Worker 
166*cc02d7e2SAndroid Build Coastguard Worker /*********** EXPERIMENTAL API ************/
167*cc02d7e2SAndroid Build Coastguard Worker /** Flushes the thread local cache for \a cq.
168*cc02d7e2SAndroid Build Coastguard Worker  * Returns 1 if there was contents in the cache.  If there was an event
169*cc02d7e2SAndroid Build Coastguard Worker  * in \a cq tls cache, its tag is placed in tag, and ok is set to the
170*cc02d7e2SAndroid Build Coastguard Worker  * event success.
171*cc02d7e2SAndroid Build Coastguard Worker  */
172*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI int grpc_completion_queue_thread_local_cache_flush(
173*cc02d7e2SAndroid Build Coastguard Worker     grpc_completion_queue* cq, void** tag, int* ok);
174*cc02d7e2SAndroid Build Coastguard Worker 
175*cc02d7e2SAndroid Build Coastguard Worker /** Check the connectivity state of a channel. */
176*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI grpc_connectivity_state grpc_channel_check_connectivity_state(
177*cc02d7e2SAndroid Build Coastguard Worker     grpc_channel* channel, int try_to_connect);
178*cc02d7e2SAndroid Build Coastguard Worker 
179*cc02d7e2SAndroid Build Coastguard Worker /** Watch for a change in connectivity state.
180*cc02d7e2SAndroid Build Coastguard Worker     Once the channel connectivity state is different from last_observed_state,
181*cc02d7e2SAndroid Build Coastguard Worker     tag will be enqueued on cq with success=1.
182*cc02d7e2SAndroid Build Coastguard Worker     If deadline expires BEFORE the state is changed, tag will be enqueued on cq
183*cc02d7e2SAndroid Build Coastguard Worker     with success=0. */
184*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI void grpc_channel_watch_connectivity_state(
185*cc02d7e2SAndroid Build Coastguard Worker     grpc_channel* channel, grpc_connectivity_state last_observed_state,
186*cc02d7e2SAndroid Build Coastguard Worker     gpr_timespec deadline, grpc_completion_queue* cq, void* tag);
187*cc02d7e2SAndroid Build Coastguard Worker 
188*cc02d7e2SAndroid Build Coastguard Worker /** Check whether a grpc channel supports connectivity watcher */
189*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI int grpc_channel_support_connectivity_watcher(grpc_channel* channel);
190*cc02d7e2SAndroid Build Coastguard Worker 
191*cc02d7e2SAndroid Build Coastguard Worker /** Create a call given a grpc_channel, in order to call 'method'. All
192*cc02d7e2SAndroid Build Coastguard Worker     completions are sent to 'completion_queue'. 'method' and 'host' need only
193*cc02d7e2SAndroid Build Coastguard Worker     live through the invocation of this function.
194*cc02d7e2SAndroid Build Coastguard Worker     If parent_call is non-NULL, it must be a server-side call. It will be used
195*cc02d7e2SAndroid Build Coastguard Worker     to propagate properties from the server call to this new client call,
196*cc02d7e2SAndroid Build Coastguard Worker     depending on the value of \a propagation_mask (see propagation_bits.h for
197*cc02d7e2SAndroid Build Coastguard Worker     possible values). */
198*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI grpc_call* grpc_channel_create_call(
199*cc02d7e2SAndroid Build Coastguard Worker     grpc_channel* channel, grpc_call* parent_call, uint32_t propagation_mask,
200*cc02d7e2SAndroid Build Coastguard Worker     grpc_completion_queue* completion_queue, grpc_slice method,
201*cc02d7e2SAndroid Build Coastguard Worker     const grpc_slice* host, gpr_timespec deadline, void* reserved);
202*cc02d7e2SAndroid Build Coastguard Worker 
203*cc02d7e2SAndroid Build Coastguard Worker /** Pre-register a method/host pair on a channel.
204*cc02d7e2SAndroid Build Coastguard Worker     method and host are not owned and must remain alive while the channel is
205*cc02d7e2SAndroid Build Coastguard Worker     alive. */
206*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI void* grpc_channel_register_call(grpc_channel* channel,
207*cc02d7e2SAndroid Build Coastguard Worker                                          const char* method, const char* host,
208*cc02d7e2SAndroid Build Coastguard Worker                                          void* reserved);
209*cc02d7e2SAndroid Build Coastguard Worker 
210*cc02d7e2SAndroid Build Coastguard Worker /** Create a call given a handle returned from grpc_channel_register_call.
211*cc02d7e2SAndroid Build Coastguard Worker     \sa grpc_channel_create_call. */
212*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI grpc_call* grpc_channel_create_registered_call(
213*cc02d7e2SAndroid Build Coastguard Worker     grpc_channel* channel, grpc_call* parent_call, uint32_t propagation_mask,
214*cc02d7e2SAndroid Build Coastguard Worker     grpc_completion_queue* completion_queue, void* registered_call_handle,
215*cc02d7e2SAndroid Build Coastguard Worker     gpr_timespec deadline, void* reserved);
216*cc02d7e2SAndroid Build Coastguard Worker 
217*cc02d7e2SAndroid Build Coastguard Worker /** Allocate memory in the grpc_call arena: this memory is automatically
218*cc02d7e2SAndroid Build Coastguard Worker     discarded at call completion */
219*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI void* grpc_call_arena_alloc(grpc_call* call, size_t size);
220*cc02d7e2SAndroid Build Coastguard Worker 
221*cc02d7e2SAndroid Build Coastguard Worker /** Start a batch of operations defined in the array ops; when complete, post a
222*cc02d7e2SAndroid Build Coastguard Worker     completion of type 'tag' to the completion queue bound to the call.
223*cc02d7e2SAndroid Build Coastguard Worker     The order of ops specified in the batch has no significance.
224*cc02d7e2SAndroid Build Coastguard Worker     Only one operation of each type can be active at once in any given
225*cc02d7e2SAndroid Build Coastguard Worker     batch.
226*cc02d7e2SAndroid Build Coastguard Worker     If a call to grpc_call_start_batch returns GRPC_CALL_OK you must call
227*cc02d7e2SAndroid Build Coastguard Worker     grpc_completion_queue_next or grpc_completion_queue_pluck on the completion
228*cc02d7e2SAndroid Build Coastguard Worker     queue associated with 'call' for work to be performed. If a call to
229*cc02d7e2SAndroid Build Coastguard Worker     grpc_call_start_batch returns any value other than GRPC_CALL_OK it is
230*cc02d7e2SAndroid Build Coastguard Worker     guaranteed that no state associated with 'call' is changed and it is not
231*cc02d7e2SAndroid Build Coastguard Worker     appropriate to call grpc_completion_queue_next or
232*cc02d7e2SAndroid Build Coastguard Worker     grpc_completion_queue_pluck consequent to the failed grpc_call_start_batch
233*cc02d7e2SAndroid Build Coastguard Worker     call.
234*cc02d7e2SAndroid Build Coastguard Worker     If a call to grpc_call_start_batch with an empty batch returns
235*cc02d7e2SAndroid Build Coastguard Worker     GRPC_CALL_OK, the tag is put in the completion queue immediately.
236*cc02d7e2SAndroid Build Coastguard Worker     THREAD SAFETY: access to grpc_call_start_batch in multi-threaded environment
237*cc02d7e2SAndroid Build Coastguard Worker     needs to be synchronized. As an optimization, you may synchronize batches
238*cc02d7e2SAndroid Build Coastguard Worker     containing just send operations independently from batches containing just
239*cc02d7e2SAndroid Build Coastguard Worker     receive operations. Access to grpc_call_start_batch with an empty batch is
240*cc02d7e2SAndroid Build Coastguard Worker     thread-compatible. */
241*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI grpc_call_error grpc_call_start_batch(grpc_call* call,
242*cc02d7e2SAndroid Build Coastguard Worker                                               const grpc_op* ops, size_t nops,
243*cc02d7e2SAndroid Build Coastguard Worker                                               void* tag, void* reserved);
244*cc02d7e2SAndroid Build Coastguard Worker 
245*cc02d7e2SAndroid Build Coastguard Worker /** Returns a newly allocated string representing the endpoint to which this
246*cc02d7e2SAndroid Build Coastguard Worker     call is communicating with. The string is in the uri format accepted by
247*cc02d7e2SAndroid Build Coastguard Worker     grpc_channel_create.
248*cc02d7e2SAndroid Build Coastguard Worker     The returned string should be disposed of with gpr_free().
249*cc02d7e2SAndroid Build Coastguard Worker 
250*cc02d7e2SAndroid Build Coastguard Worker     WARNING: this value is never authenticated or subject to any security
251*cc02d7e2SAndroid Build Coastguard Worker     related code. It must not be used for any authentication related
252*cc02d7e2SAndroid Build Coastguard Worker     functionality. Instead, use grpc_auth_context. */
253*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI char* grpc_call_get_peer(grpc_call* call);
254*cc02d7e2SAndroid Build Coastguard Worker 
255*cc02d7e2SAndroid Build Coastguard Worker struct census_context;
256*cc02d7e2SAndroid Build Coastguard Worker 
257*cc02d7e2SAndroid Build Coastguard Worker /** Set census context for a call; Must be called before first call to
258*cc02d7e2SAndroid Build Coastguard Worker    grpc_call_start_batch(). */
259*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI void grpc_census_call_set_context(grpc_call* call,
260*cc02d7e2SAndroid Build Coastguard Worker                                           struct census_context* context);
261*cc02d7e2SAndroid Build Coastguard Worker 
262*cc02d7e2SAndroid Build Coastguard Worker /** Retrieve the calls current census context. */
263*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI struct census_context* grpc_census_call_get_context(grpc_call* call);
264*cc02d7e2SAndroid Build Coastguard Worker 
265*cc02d7e2SAndroid Build Coastguard Worker /** Return a newly allocated string representing the target a channel was
266*cc02d7e2SAndroid Build Coastguard Worker     created for. */
267*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI char* grpc_channel_get_target(grpc_channel* channel);
268*cc02d7e2SAndroid Build Coastguard Worker 
269*cc02d7e2SAndroid Build Coastguard Worker /** Request info about the channel.
270*cc02d7e2SAndroid Build Coastguard Worker     \a channel_info indicates what information is being requested and
271*cc02d7e2SAndroid Build Coastguard Worker     how that information will be returned.
272*cc02d7e2SAndroid Build Coastguard Worker     \a channel_info is owned by the caller. */
273*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI void grpc_channel_get_info(grpc_channel* channel,
274*cc02d7e2SAndroid Build Coastguard Worker                                    const grpc_channel_info* channel_info);
275*cc02d7e2SAndroid Build Coastguard Worker 
276*cc02d7e2SAndroid Build Coastguard Worker /** EXPERIMENTAL.  Resets the channel's connect backoff.
277*cc02d7e2SAndroid Build Coastguard Worker     TODO(roth): When we see whether this proves useful, either promote
278*cc02d7e2SAndroid Build Coastguard Worker     to non-experimental or remove it. */
279*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI void grpc_channel_reset_connect_backoff(grpc_channel* channel);
280*cc02d7e2SAndroid Build Coastguard Worker 
281*cc02d7e2SAndroid Build Coastguard Worker /** --- grpc_channel_credentials object. ---
282*cc02d7e2SAndroid Build Coastguard Worker 
283*cc02d7e2SAndroid Build Coastguard Worker    A channel credentials object represents a way to authenticate a client on a
284*cc02d7e2SAndroid Build Coastguard Worker    channel. Different types of channel credentials are declared in
285*cc02d7e2SAndroid Build Coastguard Worker    grpc_security.h. */
286*cc02d7e2SAndroid Build Coastguard Worker 
287*cc02d7e2SAndroid Build Coastguard Worker typedef struct grpc_channel_credentials grpc_channel_credentials;
288*cc02d7e2SAndroid Build Coastguard Worker 
289*cc02d7e2SAndroid Build Coastguard Worker /** Releases a channel credentials object.
290*cc02d7e2SAndroid Build Coastguard Worker    The creator of the credentials object is responsible for its release. */
291*cc02d7e2SAndroid Build Coastguard Worker 
292*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI void grpc_channel_credentials_release(grpc_channel_credentials* creds);
293*cc02d7e2SAndroid Build Coastguard Worker 
294*cc02d7e2SAndroid Build Coastguard Worker /** --- grpc_server_credentials object. ---
295*cc02d7e2SAndroid Build Coastguard Worker 
296*cc02d7e2SAndroid Build Coastguard Worker    A server credentials object represents a way to authenticate a server.
297*cc02d7e2SAndroid Build Coastguard Worker    Different types of server credentials are declared in grpc_security.h. */
298*cc02d7e2SAndroid Build Coastguard Worker 
299*cc02d7e2SAndroid Build Coastguard Worker typedef struct grpc_server_credentials grpc_server_credentials;
300*cc02d7e2SAndroid Build Coastguard Worker 
301*cc02d7e2SAndroid Build Coastguard Worker /** Releases a server_credentials object.
302*cc02d7e2SAndroid Build Coastguard Worker    The creator of the server_credentials object is responsible for its release.
303*cc02d7e2SAndroid Build Coastguard Worker    */
304*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI void grpc_server_credentials_release(grpc_server_credentials* creds);
305*cc02d7e2SAndroid Build Coastguard Worker 
306*cc02d7e2SAndroid Build Coastguard Worker /** Creates a secure channel using the passed-in credentials. Additional
307*cc02d7e2SAndroid Build Coastguard Worker     channel level configuration MAY be provided by grpc_channel_args, though
308*cc02d7e2SAndroid Build Coastguard Worker     the expectation is that most clients will want to simply pass NULL. The
309*cc02d7e2SAndroid Build Coastguard Worker     user data in 'args' need only live through the invocation of this function.
310*cc02d7e2SAndroid Build Coastguard Worker     However, if any args of the 'pointer' type are passed, then the referenced
311*cc02d7e2SAndroid Build Coastguard Worker     vtable must be maintained by the caller until grpc_channel_destroy
312*cc02d7e2SAndroid Build Coastguard Worker     terminates. See grpc_channel_args definition for more on this. */
313*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI grpc_channel* grpc_channel_create(const char* target,
314*cc02d7e2SAndroid Build Coastguard Worker                                           grpc_channel_credentials* creds,
315*cc02d7e2SAndroid Build Coastguard Worker                                           const grpc_channel_args* args);
316*cc02d7e2SAndroid Build Coastguard Worker 
317*cc02d7e2SAndroid Build Coastguard Worker /** Create a lame client: this client fails every operation attempted on it. */
318*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI grpc_channel* grpc_lame_client_channel_create(
319*cc02d7e2SAndroid Build Coastguard Worker     const char* target, grpc_status_code error_code, const char* error_message);
320*cc02d7e2SAndroid Build Coastguard Worker 
321*cc02d7e2SAndroid Build Coastguard Worker /** Close and destroy a grpc channel */
322*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI void grpc_channel_destroy(grpc_channel* channel);
323*cc02d7e2SAndroid Build Coastguard Worker 
324*cc02d7e2SAndroid Build Coastguard Worker /** Error handling for grpc_call
325*cc02d7e2SAndroid Build Coastguard Worker    Most grpc_call functions return a grpc_error. If the error is not GRPC_OK
326*cc02d7e2SAndroid Build Coastguard Worker    then the operation failed due to some unsatisfied precondition.
327*cc02d7e2SAndroid Build Coastguard Worker    If a grpc_call fails, it's guaranteed that no change to the call state
328*cc02d7e2SAndroid Build Coastguard Worker    has been made. */
329*cc02d7e2SAndroid Build Coastguard Worker 
330*cc02d7e2SAndroid Build Coastguard Worker /** Cancel an RPC.
331*cc02d7e2SAndroid Build Coastguard Worker     Can be called multiple times, from any thread.
332*cc02d7e2SAndroid Build Coastguard Worker     THREAD-SAFETY grpc_call_cancel and grpc_call_cancel_with_status
333*cc02d7e2SAndroid Build Coastguard Worker     are thread-safe, and can be called at any point before grpc_call_unref
334*cc02d7e2SAndroid Build Coastguard Worker     is called.*/
335*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI grpc_call_error grpc_call_cancel(grpc_call* call, void* reserved);
336*cc02d7e2SAndroid Build Coastguard Worker 
337*cc02d7e2SAndroid Build Coastguard Worker /** Cancel an RPC.
338*cc02d7e2SAndroid Build Coastguard Worker     Can be called multiple times, from any thread.
339*cc02d7e2SAndroid Build Coastguard Worker     If a status has not been received for the call, set it to the status code
340*cc02d7e2SAndroid Build Coastguard Worker     and description passed in.
341*cc02d7e2SAndroid Build Coastguard Worker     Importantly, this function does not send status nor description to the
342*cc02d7e2SAndroid Build Coastguard Worker     remote endpoint.
343*cc02d7e2SAndroid Build Coastguard Worker     Note that \a description doesn't need be a static string.
344*cc02d7e2SAndroid Build Coastguard Worker     It doesn't need to be alive after the call to
345*cc02d7e2SAndroid Build Coastguard Worker     grpc_call_cancel_with_status completes.
346*cc02d7e2SAndroid Build Coastguard Worker     */
347*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI grpc_call_error grpc_call_cancel_with_status(grpc_call* call,
348*cc02d7e2SAndroid Build Coastguard Worker                                                      grpc_status_code status,
349*cc02d7e2SAndroid Build Coastguard Worker                                                      const char* description,
350*cc02d7e2SAndroid Build Coastguard Worker                                                      void* reserved);
351*cc02d7e2SAndroid Build Coastguard Worker 
352*cc02d7e2SAndroid Build Coastguard Worker /* Returns whether or not the call's receive message operation failed because of
353*cc02d7e2SAndroid Build Coastguard Worker  * an error (as opposed to a graceful end-of-stream) */
354*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI int grpc_call_failed_before_recv_message(const grpc_call* c);
355*cc02d7e2SAndroid Build Coastguard Worker 
356*cc02d7e2SAndroid Build Coastguard Worker /** Ref a call.
357*cc02d7e2SAndroid Build Coastguard Worker     THREAD SAFETY: grpc_call_ref is thread-compatible */
358*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI void grpc_call_ref(grpc_call* call);
359*cc02d7e2SAndroid Build Coastguard Worker 
360*cc02d7e2SAndroid Build Coastguard Worker /** Unref a call.
361*cc02d7e2SAndroid Build Coastguard Worker     THREAD SAFETY: grpc_call_unref is thread-compatible */
362*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI void grpc_call_unref(grpc_call* call);
363*cc02d7e2SAndroid Build Coastguard Worker 
364*cc02d7e2SAndroid Build Coastguard Worker /** Request notification of a new call.
365*cc02d7e2SAndroid Build Coastguard Worker     Once a call is received, a notification tagged with \a tag_new is added to
366*cc02d7e2SAndroid Build Coastguard Worker     \a cq_for_notification. \a call, \a details and \a request_metadata are
367*cc02d7e2SAndroid Build Coastguard Worker     updated with the appropriate call information. \a cq_bound_to_call is bound
368*cc02d7e2SAndroid Build Coastguard Worker     to \a call, and batch operation notifications for that call will be posted
369*cc02d7e2SAndroid Build Coastguard Worker     to \a cq_bound_to_call.
370*cc02d7e2SAndroid Build Coastguard Worker     Note that \a cq_for_notification must have been registered to the server via
371*cc02d7e2SAndroid Build Coastguard Worker     \a grpc_server_register_completion_queue. */
372*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI grpc_call_error grpc_server_request_call(
373*cc02d7e2SAndroid Build Coastguard Worker     grpc_server* server, grpc_call** call, grpc_call_details* details,
374*cc02d7e2SAndroid Build Coastguard Worker     grpc_metadata_array* request_metadata,
375*cc02d7e2SAndroid Build Coastguard Worker     grpc_completion_queue* cq_bound_to_call,
376*cc02d7e2SAndroid Build Coastguard Worker     grpc_completion_queue* cq_for_notification, void* tag_new);
377*cc02d7e2SAndroid Build Coastguard Worker 
378*cc02d7e2SAndroid Build Coastguard Worker /** How to handle payloads for a registered method */
379*cc02d7e2SAndroid Build Coastguard Worker typedef enum {
380*cc02d7e2SAndroid Build Coastguard Worker   /** Don't try to read the payload */
381*cc02d7e2SAndroid Build Coastguard Worker   GRPC_SRM_PAYLOAD_NONE,
382*cc02d7e2SAndroid Build Coastguard Worker   /** Read the initial payload as a byte buffer */
383*cc02d7e2SAndroid Build Coastguard Worker   GRPC_SRM_PAYLOAD_READ_INITIAL_BYTE_BUFFER
384*cc02d7e2SAndroid Build Coastguard Worker } grpc_server_register_method_payload_handling;
385*cc02d7e2SAndroid Build Coastguard Worker 
386*cc02d7e2SAndroid Build Coastguard Worker /** Registers a method in the server.
387*cc02d7e2SAndroid Build Coastguard Worker     Methods to this (host, method) pair will not be reported by
388*cc02d7e2SAndroid Build Coastguard Worker     grpc_server_request_call, but instead be reported by
389*cc02d7e2SAndroid Build Coastguard Worker     grpc_server_request_registered_call when passed the appropriate
390*cc02d7e2SAndroid Build Coastguard Worker     registered_method (as returned by this function).
391*cc02d7e2SAndroid Build Coastguard Worker     Must be called before grpc_server_start.
392*cc02d7e2SAndroid Build Coastguard Worker     Returns NULL on failure. */
393*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI void* grpc_server_register_method(
394*cc02d7e2SAndroid Build Coastguard Worker     grpc_server* server, const char* method, const char* host,
395*cc02d7e2SAndroid Build Coastguard Worker     grpc_server_register_method_payload_handling payload_handling,
396*cc02d7e2SAndroid Build Coastguard Worker     uint32_t flags);
397*cc02d7e2SAndroid Build Coastguard Worker 
398*cc02d7e2SAndroid Build Coastguard Worker /** Request notification of a new pre-registered call. 'cq_for_notification'
399*cc02d7e2SAndroid Build Coastguard Worker     must have been registered to the server via
400*cc02d7e2SAndroid Build Coastguard Worker     grpc_server_register_completion_queue. */
401*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI grpc_call_error grpc_server_request_registered_call(
402*cc02d7e2SAndroid Build Coastguard Worker     grpc_server* server, void* registered_method, grpc_call** call,
403*cc02d7e2SAndroid Build Coastguard Worker     gpr_timespec* deadline, grpc_metadata_array* request_metadata,
404*cc02d7e2SAndroid Build Coastguard Worker     grpc_byte_buffer** optional_payload,
405*cc02d7e2SAndroid Build Coastguard Worker     grpc_completion_queue* cq_bound_to_call,
406*cc02d7e2SAndroid Build Coastguard Worker     grpc_completion_queue* cq_for_notification, void* tag_new);
407*cc02d7e2SAndroid Build Coastguard Worker 
408*cc02d7e2SAndroid Build Coastguard Worker /** Create a server. Additional configuration for each incoming channel can
409*cc02d7e2SAndroid Build Coastguard Worker     be specified with args. If no additional configuration is needed, args can
410*cc02d7e2SAndroid Build Coastguard Worker     be NULL. The user data in 'args' need only live through the invocation of
411*cc02d7e2SAndroid Build Coastguard Worker     this function. However, if any args of the 'pointer' type are passed, then
412*cc02d7e2SAndroid Build Coastguard Worker     the referenced vtable must be maintained by the caller until
413*cc02d7e2SAndroid Build Coastguard Worker     grpc_server_destroy terminates. See grpc_channel_args definition for more
414*cc02d7e2SAndroid Build Coastguard Worker     on this. */
415*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI grpc_server* grpc_server_create(const grpc_channel_args* args,
416*cc02d7e2SAndroid Build Coastguard Worker                                         void* reserved);
417*cc02d7e2SAndroid Build Coastguard Worker 
418*cc02d7e2SAndroid Build Coastguard Worker /** Register a completion queue with the server. Must be done for any
419*cc02d7e2SAndroid Build Coastguard Worker     notification completion queue that is passed to grpc_server_request_*_call
420*cc02d7e2SAndroid Build Coastguard Worker     and to grpc_server_shutdown_and_notify. Must be performed prior to
421*cc02d7e2SAndroid Build Coastguard Worker     grpc_server_start. */
422*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI void grpc_server_register_completion_queue(grpc_server* server,
423*cc02d7e2SAndroid Build Coastguard Worker                                                    grpc_completion_queue* cq,
424*cc02d7e2SAndroid Build Coastguard Worker                                                    void* reserved);
425*cc02d7e2SAndroid Build Coastguard Worker 
426*cc02d7e2SAndroid Build Coastguard Worker // More members might be added in later, so users should take care to memset
427*cc02d7e2SAndroid Build Coastguard Worker // this to 0 before using it.
428*cc02d7e2SAndroid Build Coastguard Worker typedef struct {
429*cc02d7e2SAndroid Build Coastguard Worker   grpc_status_code code;
430*cc02d7e2SAndroid Build Coastguard Worker   const char* error_message;
431*cc02d7e2SAndroid Build Coastguard Worker } grpc_serving_status_update;
432*cc02d7e2SAndroid Build Coastguard Worker 
433*cc02d7e2SAndroid Build Coastguard Worker // There might be more methods added later, so users should take care to memset
434*cc02d7e2SAndroid Build Coastguard Worker // this to 0 before using it.
435*cc02d7e2SAndroid Build Coastguard Worker typedef struct {
436*cc02d7e2SAndroid Build Coastguard Worker   void (*on_serving_status_update)(void* user_data, const char* uri,
437*cc02d7e2SAndroid Build Coastguard Worker                                    grpc_serving_status_update update);
438*cc02d7e2SAndroid Build Coastguard Worker   void* user_data;
439*cc02d7e2SAndroid Build Coastguard Worker } grpc_server_xds_status_notifier;
440*cc02d7e2SAndroid Build Coastguard Worker 
441*cc02d7e2SAndroid Build Coastguard Worker typedef struct grpc_server_config_fetcher grpc_server_config_fetcher;
442*cc02d7e2SAndroid Build Coastguard Worker 
443*cc02d7e2SAndroid Build Coastguard Worker /** EXPERIMENTAL.  Creates an xDS config fetcher. */
444*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI grpc_server_config_fetcher* grpc_server_config_fetcher_xds_create(
445*cc02d7e2SAndroid Build Coastguard Worker     grpc_server_xds_status_notifier notifier, const grpc_channel_args* args);
446*cc02d7e2SAndroid Build Coastguard Worker 
447*cc02d7e2SAndroid Build Coastguard Worker /** EXPERIMENTAL.  Destroys a config fetcher. */
448*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI void grpc_server_config_fetcher_destroy(
449*cc02d7e2SAndroid Build Coastguard Worker     grpc_server_config_fetcher* config_fetcher);
450*cc02d7e2SAndroid Build Coastguard Worker 
451*cc02d7e2SAndroid Build Coastguard Worker /** EXPERIMENTAL.  Sets the server's config fetcher.  Takes ownership.
452*cc02d7e2SAndroid Build Coastguard Worker     Must be called before adding ports */
453*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI void grpc_server_set_config_fetcher(
454*cc02d7e2SAndroid Build Coastguard Worker     grpc_server* server, grpc_server_config_fetcher* config_fetcher);
455*cc02d7e2SAndroid Build Coastguard Worker 
456*cc02d7e2SAndroid Build Coastguard Worker /** Add a HTTP2 over an encrypted link over tcp listener.
457*cc02d7e2SAndroid Build Coastguard Worker    Returns bound port number on success, 0 on failure.
458*cc02d7e2SAndroid Build Coastguard Worker    REQUIRES: server not started */
459*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI int grpc_server_add_http2_port(grpc_server* server, const char* addr,
460*cc02d7e2SAndroid Build Coastguard Worker                                        grpc_server_credentials* creds);
461*cc02d7e2SAndroid Build Coastguard Worker 
462*cc02d7e2SAndroid Build Coastguard Worker /** Start a server - tells all listeners to start listening */
463*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI void grpc_server_start(grpc_server* server);
464*cc02d7e2SAndroid Build Coastguard Worker 
465*cc02d7e2SAndroid Build Coastguard Worker /** Begin shutting down a server.
466*cc02d7e2SAndroid Build Coastguard Worker     After completion, no new calls or connections will be admitted.
467*cc02d7e2SAndroid Build Coastguard Worker     Existing calls will be allowed to complete.
468*cc02d7e2SAndroid Build Coastguard Worker     Send a GRPC_OP_COMPLETE event when there are no more calls being serviced.
469*cc02d7e2SAndroid Build Coastguard Worker     Shutdown is idempotent, and all tags will be notified at once if multiple
470*cc02d7e2SAndroid Build Coastguard Worker     grpc_server_shutdown_and_notify calls are made. 'cq' must have been
471*cc02d7e2SAndroid Build Coastguard Worker     registered to this server via grpc_server_register_completion_queue. */
472*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI void grpc_server_shutdown_and_notify(grpc_server* server,
473*cc02d7e2SAndroid Build Coastguard Worker                                              grpc_completion_queue* cq,
474*cc02d7e2SAndroid Build Coastguard Worker                                              void* tag);
475*cc02d7e2SAndroid Build Coastguard Worker 
476*cc02d7e2SAndroid Build Coastguard Worker /** Cancel all in-progress calls.
477*cc02d7e2SAndroid Build Coastguard Worker     Only usable after shutdown. */
478*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI void grpc_server_cancel_all_calls(grpc_server* server);
479*cc02d7e2SAndroid Build Coastguard Worker 
480*cc02d7e2SAndroid Build Coastguard Worker /** Destroy a server.
481*cc02d7e2SAndroid Build Coastguard Worker     Shutdown must have completed beforehand (i.e. all tags generated by
482*cc02d7e2SAndroid Build Coastguard Worker     grpc_server_shutdown_and_notify must have been received, and at least
483*cc02d7e2SAndroid Build Coastguard Worker     one call to grpc_server_shutdown_and_notify must have been made). */
484*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI void grpc_server_destroy(grpc_server* server);
485*cc02d7e2SAndroid Build Coastguard Worker 
486*cc02d7e2SAndroid Build Coastguard Worker /** Enable or disable a tracer.
487*cc02d7e2SAndroid Build Coastguard Worker 
488*cc02d7e2SAndroid Build Coastguard Worker     Tracers (usually controlled by the environment variable GRPC_TRACE)
489*cc02d7e2SAndroid Build Coastguard Worker     allow printf-style debugging on GRPC internals, and are useful for
490*cc02d7e2SAndroid Build Coastguard Worker     tracking down problems in the field.
491*cc02d7e2SAndroid Build Coastguard Worker 
492*cc02d7e2SAndroid Build Coastguard Worker     Use of this function is not strictly thread-safe, but the
493*cc02d7e2SAndroid Build Coastguard Worker     thread-safety issues raised by it should not be of concern. */
494*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI int grpc_tracer_set_enabled(const char* name, int enabled);
495*cc02d7e2SAndroid Build Coastguard Worker 
496*cc02d7e2SAndroid Build Coastguard Worker /** Check whether a metadata key is legal (will be accepted by core) */
497*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI int grpc_header_key_is_legal(grpc_slice slice);
498*cc02d7e2SAndroid Build Coastguard Worker 
499*cc02d7e2SAndroid Build Coastguard Worker /** Check whether a non-binary metadata value is legal (will be accepted by
500*cc02d7e2SAndroid Build Coastguard Worker     core) */
501*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI int grpc_header_nonbin_value_is_legal(grpc_slice slice);
502*cc02d7e2SAndroid Build Coastguard Worker 
503*cc02d7e2SAndroid Build Coastguard Worker /** Check whether a metadata key corresponds to a binary value */
504*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI int grpc_is_binary_header(grpc_slice slice);
505*cc02d7e2SAndroid Build Coastguard Worker 
506*cc02d7e2SAndroid Build Coastguard Worker /** Convert grpc_call_error values to a string */
507*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI const char* grpc_call_error_to_string(grpc_call_error error);
508*cc02d7e2SAndroid Build Coastguard Worker 
509*cc02d7e2SAndroid Build Coastguard Worker /** Create a buffer pool */
510*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI grpc_resource_quota* grpc_resource_quota_create(const char* trace_name);
511*cc02d7e2SAndroid Build Coastguard Worker 
512*cc02d7e2SAndroid Build Coastguard Worker /** Add a reference to a buffer pool */
513*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI void grpc_resource_quota_ref(grpc_resource_quota* resource_quota);
514*cc02d7e2SAndroid Build Coastguard Worker 
515*cc02d7e2SAndroid Build Coastguard Worker /** Drop a reference to a buffer pool */
516*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI void grpc_resource_quota_unref(grpc_resource_quota* resource_quota);
517*cc02d7e2SAndroid Build Coastguard Worker 
518*cc02d7e2SAndroid Build Coastguard Worker /** Update the size of a buffer pool */
519*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI void grpc_resource_quota_resize(grpc_resource_quota* resource_quota,
520*cc02d7e2SAndroid Build Coastguard Worker                                         size_t new_size);
521*cc02d7e2SAndroid Build Coastguard Worker 
522*cc02d7e2SAndroid Build Coastguard Worker /** Update the size of the maximum number of threads allowed */
523*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI void grpc_resource_quota_set_max_threads(
524*cc02d7e2SAndroid Build Coastguard Worker     grpc_resource_quota* resource_quota, int new_max_threads);
525*cc02d7e2SAndroid Build Coastguard Worker 
526*cc02d7e2SAndroid Build Coastguard Worker /** EXPERIMENTAL.  Dumps xDS configs as a serialized ClientConfig proto.
527*cc02d7e2SAndroid Build Coastguard Worker     The full name of the proto is envoy.service.status.v3.ClientConfig. */
528*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI grpc_slice grpc_dump_xds_configs(void);
529*cc02d7e2SAndroid Build Coastguard Worker 
530*cc02d7e2SAndroid Build Coastguard Worker /** Fetch a vtable for a grpc_channel_arg that points to a grpc_resource_quota
531*cc02d7e2SAndroid Build Coastguard Worker  */
532*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI const grpc_arg_pointer_vtable* grpc_resource_quota_arg_vtable(void);
533*cc02d7e2SAndroid Build Coastguard Worker 
534*cc02d7e2SAndroid Build Coastguard Worker /************* CHANNELZ API *************/
535*cc02d7e2SAndroid Build Coastguard Worker /** Channelz is under active development. The following APIs will see some
536*cc02d7e2SAndroid Build Coastguard Worker     churn as the feature is implemented. This comment will be removed once
537*cc02d7e2SAndroid Build Coastguard Worker     channelz is officially supported, and these APIs become stable. For now
538*cc02d7e2SAndroid Build Coastguard Worker     you may track the progress by following this github issue:
539*cc02d7e2SAndroid Build Coastguard Worker     https://github.com/grpc/grpc/issues/15340
540*cc02d7e2SAndroid Build Coastguard Worker 
541*cc02d7e2SAndroid Build Coastguard Worker     the following APIs return allocated JSON strings that match the response
542*cc02d7e2SAndroid Build Coastguard Worker     objects from the channelz proto, found here:
543*cc02d7e2SAndroid Build Coastguard Worker     https://github.com/grpc/grpc/blob/master/src/proto/grpc/channelz/channelz.proto.
544*cc02d7e2SAndroid Build Coastguard Worker 
545*cc02d7e2SAndroid Build Coastguard Worker     For easy conversion to protobuf, The JSON is formatted according to:
546*cc02d7e2SAndroid Build Coastguard Worker     https://developers.google.com/protocol-buffers/docs/proto3#json. */
547*cc02d7e2SAndroid Build Coastguard Worker 
548*cc02d7e2SAndroid Build Coastguard Worker /* Gets all root channels (i.e. channels the application has directly
549*cc02d7e2SAndroid Build Coastguard Worker    created). This does not include subchannels nor non-top level channels.
550*cc02d7e2SAndroid Build Coastguard Worker    The returned string is allocated and must be freed by the application. */
551*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI char* grpc_channelz_get_top_channels(intptr_t start_channel_id);
552*cc02d7e2SAndroid Build Coastguard Worker 
553*cc02d7e2SAndroid Build Coastguard Worker /* Gets all servers that exist in the process. */
554*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI char* grpc_channelz_get_servers(intptr_t start_server_id);
555*cc02d7e2SAndroid Build Coastguard Worker 
556*cc02d7e2SAndroid Build Coastguard Worker /* Returns a single Server, or else a NOT_FOUND code. */
557*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI char* grpc_channelz_get_server(intptr_t server_id);
558*cc02d7e2SAndroid Build Coastguard Worker 
559*cc02d7e2SAndroid Build Coastguard Worker /* Gets all server sockets that exist in the server. */
560*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI char* grpc_channelz_get_server_sockets(intptr_t server_id,
561*cc02d7e2SAndroid Build Coastguard Worker                                                intptr_t start_socket_id,
562*cc02d7e2SAndroid Build Coastguard Worker                                                intptr_t max_results);
563*cc02d7e2SAndroid Build Coastguard Worker 
564*cc02d7e2SAndroid Build Coastguard Worker /* Returns a single Channel, or else a NOT_FOUND code. The returned string
565*cc02d7e2SAndroid Build Coastguard Worker    is allocated and must be freed by the application. */
566*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI char* grpc_channelz_get_channel(intptr_t channel_id);
567*cc02d7e2SAndroid Build Coastguard Worker 
568*cc02d7e2SAndroid Build Coastguard Worker /* Returns a single Subchannel, or else a NOT_FOUND code. The returned string
569*cc02d7e2SAndroid Build Coastguard Worker    is allocated and must be freed by the application. */
570*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI char* grpc_channelz_get_subchannel(intptr_t subchannel_id);
571*cc02d7e2SAndroid Build Coastguard Worker 
572*cc02d7e2SAndroid Build Coastguard Worker /* Returns a single Socket, or else a NOT_FOUND code. The returned string
573*cc02d7e2SAndroid Build Coastguard Worker    is allocated and must be freed by the application. */
574*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI char* grpc_channelz_get_socket(intptr_t socket_id);
575*cc02d7e2SAndroid Build Coastguard Worker 
576*cc02d7e2SAndroid Build Coastguard Worker /**
577*cc02d7e2SAndroid Build Coastguard Worker  * EXPERIMENTAL - Subject to change.
578*cc02d7e2SAndroid Build Coastguard Worker  * Fetch a vtable for grpc_channel_arg that points to
579*cc02d7e2SAndroid Build Coastguard Worker  * grpc_authorization_policy_provider.
580*cc02d7e2SAndroid Build Coastguard Worker  */
581*cc02d7e2SAndroid Build Coastguard Worker GRPCAPI const grpc_arg_pointer_vtable*
582*cc02d7e2SAndroid Build Coastguard Worker grpc_authorization_policy_provider_arg_vtable(void);
583*cc02d7e2SAndroid Build Coastguard Worker 
584*cc02d7e2SAndroid Build Coastguard Worker #ifdef __cplusplus
585*cc02d7e2SAndroid Build Coastguard Worker }
586*cc02d7e2SAndroid Build Coastguard Worker #endif
587*cc02d7e2SAndroid Build Coastguard Worker 
588*cc02d7e2SAndroid Build Coastguard Worker #endif /* GRPC_GRPC_H */
589