GRPC Core  3.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
grpc.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015-2016, Google Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above
13  * copyright notice, this list of conditions and the following disclaimer
14  * in the documentation and/or other materials provided with the
15  * distribution.
16  * * Neither the name of Google Inc. nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  */
33 
34 #ifndef GRPC_GRPC_H
35 #define GRPC_GRPC_H
36 
37 #include <grpc/status.h>
38 
39 #include <grpc/byte_buffer.h>
43 #include <grpc/slice.h>
44 #include <grpc/support/time.h>
45 #include <stddef.h>
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
60 
63 
72 GRPCAPI void grpc_register_plugin(void (*init)(void), void (*destroy)(void));
73 
80 GRPCAPI void grpc_init(void);
81 
88 GRPCAPI void grpc_shutdown(void);
89 
91 GRPCAPI const char *grpc_version_string(void);
92 
94 GRPCAPI const char *grpc_g_stands_for(void);
95 
97 typedef enum {
98  /* Events are popped out by calling grpc_completion_queue_next() API ONLY */
100 
101  /* Events are popped out by calling grpc_completion_queue_pluck() API ONLY */
104 
114 typedef enum {
118 
119  /* Similar to GRPC_CQ_DEFAULT_POLLING except that the completion queues will
120  not contain any 'listening file descriptors' (i.e file descriptors used to
121  listen to incoming channels) */
123 
124  /* The completion queue will not have an associated pollset. Note that
125  grpc_completion_queue_next() or grpc_completion_queue_pluck() MUST still be
126  called to pop events from the completion queue; it is not required to call
127  them actively to make I/O progress */
130 
131 #define GRPC_CQ_CURRENT_VERSION 1
133  /* The version number of this structure. More fields might be added to this
134  structure in future. */
135  int version; /* Set to GRPC_CQ_CURRENT_VERSION */
136 
138 
141 
144 
149  const grpc_completion_queue_attributes *attributes);
150 
154  void *reserved);
155 
159  void *reserved);
160 
163 
173  gpr_timespec deadline,
174  void *reserved);
175 
188  void *tag, gpr_timespec deadline,
189  void *reserved);
190 
193 #define GRPC_MAX_COMPLETION_QUEUE_PLUCKERS 6
194 
203 
207 
215  gpr_timespec deadline, void *tag);
216 
220 
223 
226  grpc_channel *channel, int try_to_connect);
227 
234  grpc_channel *channel, grpc_connectivity_state last_observed_state,
235  gpr_timespec deadline, grpc_completion_queue *cq, void *tag);
236 
245  grpc_channel *channel, grpc_call *parent_call, uint32_t propagation_mask,
246  grpc_completion_queue *completion_queue, grpc_slice method,
247  const grpc_slice *host, gpr_timespec deadline, void *reserved);
248 
252  void *tag, void *reserved);
253 
256  const char *method, const char *host,
257  void *reserved);
258 
262  grpc_channel *channel, grpc_call *parent_call, uint32_t propagation_mask,
263  grpc_completion_queue *completion_queue, void *registered_call_handle,
264  gpr_timespec deadline, void *reserved);
265 
284  const grpc_op *ops, size_t nops,
285  void *tag, void *reserved);
286 
296 
298 
299 /* Associate costs contained in \a cost_context to \a call. */
301  grpc_call *call, struct grpc_load_reporting_cost_context *context);
302 
303 struct census_context;
304 
308  struct census_context *context);
309 
312 
316 
322  const grpc_channel_info *channel_info);
323 
330  const char *target, const grpc_channel_args *args, void *reserved);
331 
334  const char *target, grpc_status_code error_code, const char *error_message);
335 
338 
339 /* Error handling for grpc_call
340  Most grpc_call functions return a grpc_error. If the error is not GRPC_OK
341  then the operation failed due to some unsatisfied precondition.
342  If a grpc_call fails, it's guaranteed that no change to the call state
343  has been made. */
344 
350 GRPCAPI grpc_call_error grpc_call_cancel(grpc_call *call, void *reserved);
351 
359  grpc_status_code status,
360  const char *description,
361  void *reserved);
362 
366 
376  grpc_server *server, grpc_call **call, grpc_call_details *details,
377  grpc_metadata_array *request_metadata,
378  grpc_completion_queue *cq_bound_to_call,
379  grpc_completion_queue *cq_for_notification, void *tag_new);
380 
382 typedef enum {
388 
397  grpc_server *server, const char *method, const char *host,
399  uint32_t flags);
400 
405  grpc_server *server, void *registered_method, grpc_call **call,
406  gpr_timespec *deadline, grpc_metadata_array *request_metadata,
407  grpc_byte_buffer **optional_payload,
408  grpc_completion_queue *cq_bound_to_call,
409  grpc_completion_queue *cq_for_notification, void *tag_new);
410 
416  void *reserved);
417 
424  void *reserved);
425 
433  grpc_server *server, grpc_completion_queue *q, void *reserved);
434 
439  const char *addr);
440 
443 
453  void *tag);
454 
458 
464 
473 GRPCAPI int grpc_tracer_set_enabled(const char *name, int enabled);
474 
477 
481 
484 
487 
490 
493 
496 
499  size_t new_size);
500 
504 
505 #ifdef __cplusplus
506 }
507 #endif
508 
509 #endif /* GRPC_GRPC_H */
struct grpc_call grpc_call
A Call represents an RPC.
Definition: grpc_types.h:85
GRPCAPI grpc_call_error grpc_call_cancel_with_status(grpc_call *call, grpc_status_code status, const char *description, void *reserved)
Called by clients to cancel an RPC on the server.
GRPCAPI void grpc_server_shutdown_and_notify(grpc_server *server, grpc_completion_queue *cq, void *tag)
Begin shutting down a server.
GRPCAPI grpc_completion_queue * grpc_completion_queue_create_for_next(void *reserved)
Helper function to create a completion queue with grpc_cq_completion_type of GRPC_CQ_NEXT and grpc_cq...
GRPCAPI grpc_event grpc_completion_queue_next(grpc_completion_queue *cq, gpr_timespec deadline, void *reserved)
Blocks until an event is available, the completion queue is being shut down, or deadline is reached...
An array of arguments that can be passed around.
Definition: grpc_types.h:142
Definition: grpc_types.h:100
Read the initial payload as a byte buffer.
Definition: grpc.h:386
struct grpc_channel grpc_channel
The Channel interface allows creation of Call objects.
Definition: grpc_types.h:77
grpc_server_register_method_payload_handling
How to handle payloads for a registered method.
Definition: grpc.h:382
GRPCAPI void grpc_server_register_completion_queue(grpc_server *server, grpc_completion_queue *cq, void *reserved)
Register a completion queue with the server.
GRPCAPI const char * grpc_g_stands_for(void)
Return a string specifying what the 'g' in gRPC stands for.
GRPCAPI const char * grpc_version_string(void)
Return a string representing the current version of grpc.
The result of an operation.
Definition: grpc_types.h:393
GRPCAPI void grpc_channel_ping(grpc_channel *channel, grpc_completion_queue *cq, void *tag, void *reserved)
Ping the channels peer (load balanced channels will select one sub-channel to ping); if the channel i...
GRPCAPI void grpc_alarm_destroy(grpc_alarm *alarm)
Destroy the given completion queue alarm, cancelling it in the process.
grpc_cq_completion_type cq_completion_type
Definition: grpc.h:137
Definition: slice.h:90
GRPCAPI grpc_call_error grpc_call_cancel(grpc_call *call, void *reserved)
Called by clients to cancel an RPC on the server.
GRPCAPI void grpc_call_details_destroy(grpc_call_details *details)
GRPCAPI void grpc_resource_quota_unref(grpc_resource_quota *resource_quota)
Drop a reference to a buffer pool.
GRPCAPI void grpc_server_start(grpc_server *server)
Start a server - tells all listeners to start listening.
GRPCAPI void grpc_alarm_cancel(grpc_alarm *alarm)
Cancel a completion queue alarm.
struct grpc_server grpc_server
A server listens to some port and responds to request calls.
Definition: grpc_types.h:80
GRPCAPI void grpc_server_register_non_listening_completion_queue(grpc_server *server, grpc_completion_queue *q, void *reserved)
Register a non-listening completion queue with the server.
GRPCAPI const grpc_arg_pointer_vtable * grpc_resource_quota_arg_vtable(void)
Fetch a vtable for a grpc_channel_arg that points to a grpc_resource_quota.
Definition: grpc_types.h:410
Definition: grpc_types.h:55
Don't try to read the payload.
Definition: grpc.h:384
GRPCAPI grpc_call_error grpc_server_request_call(grpc_server *server, grpc_call **call, grpc_call_details *details, grpc_metadata_array *request_metadata, grpc_completion_queue *cq_bound_to_call, grpc_completion_queue *cq_for_notification, void *tag_new)
Request notification of a new call.
GRPCAPI char * grpc_call_get_peer(grpc_call *call)
Returns a newly allocated string representing the endpoint to which this call is communicating with...
Definition: grpc_types.h:404
GRPCAPI void grpc_server_cancel_all_calls(grpc_server *server)
Cancel all in-progress calls.
GRPCAPI grpc_connectivity_state grpc_channel_check_connectivity_state(grpc_channel *channel, int try_to_connect)
Check the connectivity state of a channel.
Definition: grpc.h:122
Definition: grpc.h:132
grpc_call_error
Result of a grpc call.
Definition: grpc_types.h:291
GRPCAPI grpc_completion_queue * grpc_completion_queue_create(void *reserved)
Create a completion queue.
GRPCAPI char * grpc_channel_get_target(grpc_channel *channel)
Return a newly allocated string representing the target a channel was created for.
GRPCAPI int grpc_is_binary_header(grpc_slice slice)
Check whether a metadata key corresponds to a binary value.
grpc_connectivity_state
Connectivity state of a channel.
Definition: connectivity_state.h:42
GRPCAPI void grpc_channel_get_info(grpc_channel *channel, const grpc_channel_info *channel_info)
Request info about the channel.
GRPCAPI void grpc_call_details_init(grpc_call_details *details)
grpc_cq_completion_type
Specifies the type of APIs to use to pop events from the completion queue.
Definition: grpc.h:97
GRPCAPI grpc_channel * grpc_lame_client_channel_create(const char *target, grpc_status_code error_code, const char *error_message)
Create a lame client: this client fails every operation attempted on it.
GRPCAPI void * grpc_server_register_method(grpc_server *server, const char *method, const char *host, grpc_server_register_method_payload_handling payload_handling, uint32_t flags)
Registers a method in the server.
Definition: grpc.h:99
GRPCAPI grpc_call * grpc_channel_create_registered_call(grpc_channel *channel, grpc_call *parent_call, uint32_t propagation_mask, grpc_completion_queue *completion_queue, void *registered_call_handle, gpr_timespec deadline, void *reserved)
Create a call given a handle returned from grpc_channel_register_call.
GRPCAPI void grpc_resource_quota_ref(grpc_resource_quota *resource_quota)
Add a reference to a buffer pool.
GRPCAPI void grpc_server_destroy(grpc_server *server)
Destroy a server.
GRPCAPI grpc_call * grpc_channel_create_call(grpc_channel *channel, grpc_call *parent_call, uint32_t propagation_mask, grpc_completion_queue *completion_queue, grpc_slice method, const grpc_slice *host, gpr_timespec deadline, void *reserved)
Create a call given a grpc_channel, in order to call 'method'.
Definition: grpc.h:128
GRPCAPI void grpc_metadata_array_init(grpc_metadata_array *array)
GRPCAPI struct census_context * grpc_census_call_get_context(grpc_call *call)
Retrieve the calls current census context.
A sequence of values for load reporting purposes.
Definition: load_reporting.h:54
GRPCAPI void grpc_completion_queue_destroy(grpc_completion_queue *cq)
Destroy a completion queue.
GRPCAPI grpc_resource_quota * grpc_resource_quota_create(const char *trace_name)
Create a buffer pool.
GRPCAPI void grpc_channel_destroy(grpc_channel *channel)
Close and destroy a grpc channel.
Operation data: one field for each op type (except SEND_CLOSE_FROM_CLIENT which has no arguments) ...
Definition: grpc_types.h:467
GRPCAPI int grpc_server_add_insecure_http2_port(grpc_server *server, const char *addr)
Add a HTTP2 over plaintext over tcp listener.
GRPCAPI const grpc_completion_queue_factory * grpc_completion_queue_factory_lookup(const grpc_completion_queue_attributes *attributes)
Returns the completion queue factory based on the attributes.
GRPCAPI void grpc_completion_queue_shutdown(grpc_completion_queue *cq)
Begin destruction of a completion queue.
struct grpc_alarm grpc_alarm
An alarm associated with a completion queue.
Definition: grpc_types.h:74
The completion queue will have an associated pollset and there is no restriction on the type of file ...
Definition: grpc.h:117
GRPCAPI void grpc_init(void)
Initialize the grpc library.
GRPCAPI grpc_alarm * grpc_alarm_create(grpc_completion_queue *cq, gpr_timespec deadline, void *tag)
Create a completion queue alarm instance associated to cq.
grpc_cq_polling_type
Completion queues internally MAY maintain a set of file descriptors in a structure called 'pollset'...
Definition: grpc.h:114
#define GRPCAPI
Definition: port_platform.h:414
GRPCAPI void grpc_metadata_array_destroy(grpc_metadata_array *array)
GRPCAPI grpc_channel * grpc_insecure_channel_create(const char *target, const grpc_channel_args *args, void *reserved)
Create a client channel to 'target'.
GRPCAPI grpc_call_error grpc_call_start_batch(grpc_call *call, const grpc_op *ops, size_t nops, void *tag, void *reserved)
Start a batch of operations defined in the array ops; when complete, post a completion of type 'tag' ...
GRPCAPI void grpc_shutdown(void)
Shut down the grpc library.
GRPCAPI void grpc_channel_watch_connectivity_state(grpc_channel *channel, grpc_connectivity_state last_observed_state, gpr_timespec deadline, grpc_completion_queue *cq, void *tag)
Watch for a change in connectivity state.
GRPCAPI void * grpc_channel_register_call(grpc_channel *channel, const char *method, const char *host, void *reserved)
Pre-register a method/host pair on a channel.
GRPCAPI grpc_server * grpc_server_create(const grpc_channel_args *args, void *reserved)
Create a server.
GRPCAPI int grpc_header_nonbin_value_is_legal(grpc_slice slice)
Check whether a non-binary metadata value is legal (will be accepted by core)
struct grpc_completion_queue_attributes grpc_completion_queue_attributes
Information requested from the channel.
Definition: grpc_types.h:535
GRPCAPI void grpc_call_destroy(grpc_call *call)
Destroy a call.
GRPCAPI int grpc_header_key_is_legal(grpc_slice slice)
Check whether a metadata key is legal (will be accepted by core)
struct grpc_resource_quota grpc_resource_quota
Definition: grpc_types.h:544
Definition: grpc.h:102
Definition: gpr_types.h:63
GRPCAPI grpc_event grpc_completion_queue_pluck(grpc_completion_queue *cq, void *tag, gpr_timespec deadline, void *reserved)
Blocks until an event with tag 'tag' is available, the completion queue is being shutdown or deadline...
GRPCAPI void grpc_census_call_set_context(grpc_call *call, struct census_context *context)
Set census context for a call; Must be called before first call to grpc_call_start_batch().
GRPCAPI grpc_completion_queue * grpc_completion_queue_create_for_pluck(void *reserved)
Helper function to create a completion queue with grpc_cq_completion_type of GRPC_CQ_PLUCK and grpc_c...
struct grpc_completion_queue_factory grpc_completion_queue_factory
The completion queue factory structure is opaque to the callers of grpc.
Definition: grpc.h:143
GRPCAPI grpc_call_error grpc_server_request_registered_call(grpc_server *server, void *registered_method, grpc_call **call, gpr_timespec *deadline, grpc_metadata_array *request_metadata, grpc_byte_buffer **optional_payload, grpc_completion_queue *cq_bound_to_call, grpc_completion_queue *cq_for_notification, void *tag_new)
Request notification of a new pre-registered call.
struct grpc_completion_queue grpc_completion_queue
Completion Queues enable notification of the completion of asynchronous actions.
Definition: grpc_types.h:71
grpc_status_code
Definition: status.h:41
GRPCAPI int grpc_tracer_set_enabled(const char *name, int enabled)
Enable or disable a tracer.
GRPCAPI void grpc_register_plugin(void(*init)(void), void(*destroy)(void))
Registers a plugin to be initialized and destroyed with the library.
grpc_cq_polling_type cq_polling_type
Definition: grpc.h:139
GRPCAPI void grpc_resource_quota_resize(grpc_resource_quota *resource_quota, size_t new_size)
Update the size of a buffer pool.
GRPCAPI void grpc_call_set_load_reporting_cost_context(grpc_call *call, struct grpc_load_reporting_cost_context *context)
GRPCAPI const char * grpc_call_error_to_string(grpc_call_error error)
Convert grpc_call_error values to a string.
struct census_context census_context
A Census Context is a handle used by Census to represent the current tracing and stats collection inf...
Definition: census.h:83
int version
Definition: grpc.h:135