grpc.h 27 KB

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