GRPC Core  0.10.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
grpc.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015, 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 <stddef.h>
40 #include <grpc/byte_buffer.h>
41 #include <grpc/support/slice.h>
42 #include <grpc/support/time.h>
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
60 
62 typedef struct grpc_channel grpc_channel;
63 
65 typedef struct grpc_server grpc_server;
66 
70 typedef struct grpc_call grpc_call;
71 
73 typedef enum {
78 
91 typedef struct {
93  char *key;
94  union {
95  char *string;
96  int integer;
97  struct {
98  void *p;
99  void *(*copy)(void *p);
100  void (*destroy)(void *p);
101  } pointer;
102  } value;
103 } grpc_arg;
104 
113 typedef struct {
114  size_t num_args;
117 
118 /* Channel argument keys: */
120 #define GRPC_ARG_ENABLE_CENSUS "grpc.census"
121 
123 #define GRPC_ARG_MAX_CONCURRENT_STREAMS "grpc.max_concurrent_streams"
124 
125 #define GRPC_ARG_MAX_MESSAGE_LENGTH "grpc.max_message_length"
126 
127 #define GRPC_ARG_HTTP2_INITIAL_SEQUENCE_NUMBER \
128  "grpc.http2.initial_sequence_number"
129 
130 #define GRPC_ARG_DEFAULT_AUTHORITY "grpc.default_authority"
131 
133 #define GRPC_ARG_PRIMARY_USER_AGENT_STRING "grpc.primary_user_agent"
134 
136 #define GRPC_ARG_SECONDARY_USER_AGENT_STRING "grpc.secondary_user_agent"
137 
139 typedef enum {
151 
156 typedef enum grpc_call_error {
184 
185 /* Write Flags: */
189 #define GRPC_WRITE_BUFFER_HINT (0x00000001u)
190 
192 #define GRPC_WRITE_NO_COMPRESS (0x00000002u)
193 
194 #define GRPC_WRITE_USED_MASK (GRPC_WRITE_BUFFER_HINT | GRPC_WRITE_NO_COMPRESS)
195 
197 typedef struct grpc_metadata {
198  const char *key;
199  const char *value;
200  size_t value_length;
201 
206  struct {
207  void *obfuscated[3];
208  } internal_data;
209 } grpc_metadata;
210 
212 typedef enum grpc_completion_type {
220 
224 typedef struct grpc_event {
229  int success;
232  void *tag;
233 } grpc_event;
234 
235 typedef struct {
236  size_t count;
237  size_t capacity;
240 
243 
244 typedef struct {
245  char *method;
247  char *host;
251 
254 
255 typedef enum {
283 } grpc_op_type;
284 
287 typedef struct grpc_op {
292  union {
293  struct {
294  size_t count;
298  struct {
302  const char *status_details;
314  struct {
346  struct {
349  int *cancelled;
351  } data;
352 } grpc_op;
353 
360 void grpc_init(void);
361 
368 void grpc_shutdown(void);
369 
371 const char *grpc_version_string(void);
372 
375 
385  gpr_timespec deadline);
386 
396  gpr_timespec deadline);
397 
406 
410 
413  grpc_channel *channel, int try_to_connect);
414 
421  grpc_channel *channel, grpc_connectivity_state last_observed_state,
422  gpr_timespec deadline, grpc_completion_queue *cq, void *tag);
423 
428  grpc_completion_queue *completion_queue,
429  const char *method, const char *host,
430  gpr_timespec deadline);
431 
433 void *grpc_channel_register_call(grpc_channel *channel, const char *method,
434  const char *host);
435 
438  grpc_channel *channel, grpc_completion_queue *completion_queue,
439  void *registered_call_handle, gpr_timespec deadline);
440 
453  size_t nops, void *tag);
454 
463 char *grpc_call_get_peer(grpc_call *call);
464 
465 struct census_context;
466 
467 /* Set census context for a call; Must be called before first call to
468  grpc_call_start_batch(). */
470  struct census_context *context);
471 
472 /* Retrieve the calls current census context. */
474 
477 char *grpc_channel_get_target(grpc_channel *channel);
478 
484 grpc_channel *grpc_insecure_channel_create(const char *target,
485  const grpc_channel_args *args);
486 
488 grpc_channel *grpc_lame_client_channel_create(const char *target);
489 
491 void grpc_channel_destroy(grpc_channel *channel);
492 
493 /* Error handling for grpc_call
494  Most grpc_call functions return a grpc_error. If the error is not GRPC_OK
495  then the operation failed due to some unsatisfied precondition.
496  If a grpc_call fails, it's guaranteed that no change to the call state
497  has been made. */
498 
505 
513  grpc_status_code status,
514  const char *description);
515 
518 void grpc_call_destroy(grpc_call *call);
519 
524  grpc_server *server, grpc_call **call, grpc_call_details *details,
525  grpc_metadata_array *request_metadata,
526  grpc_completion_queue *cq_bound_to_call,
527  grpc_completion_queue *cq_for_notification, void *tag_new);
528 
536 void *grpc_server_register_method(grpc_server *server, const char *method,
537  const char *host);
538 
543  grpc_server *server, void *registered_method, grpc_call **call,
544  gpr_timespec *deadline, grpc_metadata_array *request_metadata,
545  grpc_byte_buffer **optional_payload,
546  grpc_completion_queue *cq_bound_to_call,
547  grpc_completion_queue *cq_for_notification, void *tag_new);
548 
554 
561 
565 int grpc_server_add_http2_port(grpc_server *server, const char *addr);
566 
568 void grpc_server_start(grpc_server *server);
569 
578  grpc_completion_queue *cq, void *tag);
579 
583 
588 void grpc_server_destroy(grpc_server *server);
589 
598 int grpc_tracer_set_enabled(const char *name, int enabled);
599 
600 #ifdef __cplusplus
601 }
602 #endif
603 
604 #endif /* GRPC_GRPC_H */
completion queue for notification has not been registered with the server
Definition: grpc.h:182
Operation completion.
Definition: grpc.h:218
void * tag
The tag passed to grpc_call_start_batch etc to start this operation.
Definition: grpc.h:232
grpc_op_type op
Operation type, as defined by grpc_op_type.
Definition: grpc.h:289
grpc_connectivity_state
Connectivity state of a channel.
Definition: grpc.h:139
const char * value
Definition: hpack_table.c:44
Send a close from the client: one and only one instance MUST be sent from the client, unless the call was cancelled - in which case this can be skipped.
Definition: grpc.h:264
void grpc_server_destroy(grpc_server *server)
Destroy a server.
Definition: server.c:1063
char ** status_details
status_details is a buffer owned by the application before the op completes and after the op has comp...
Definition: grpc.h:343
grpc_op_type
Definition: grpc.h:255
gpr_uint32 flags
Write flags bitset for grpc_begin_messages.
Definition: grpc.h:291
struct grpc_op grpc_op
Operation data: one field for each op type (except SEND_CLOSE_FROM_CLIENT which has no arguments) ...
void grpc_server_register_completion_queue(grpc_server *server, grpc_completion_queue *cq)
Register a completion queue with the server.
Definition: server.c:742
grpc_metadata_array * recv_initial_metadata
ownership of the array is with the caller, but ownership of the elements stays with the call object (...
Definition: grpc.h:309
grpc_event grpc_completion_queue_pluck(grpc_completion_queue *cq, void *tag, gpr_timespec deadline)
Blocks until an event with tag 'tag' is available, the completion queue is being shutdown or deadline...
Definition: completion_queue.c:187
void grpc_call_details_destroy(grpc_call_details *details)
Definition: call_details.c:43
An array of arguments that can be passed around.
Definition: grpc.h:113
Definition: channel.c:61
grpc_arg * args
Definition: grpc.h:115
grpc_arg_type
Type specifier for grpc_arg.
Definition: grpc.h:73
the flags value was illegal for this call
Definition: grpc.h:177
grpc_status_code status
Definition: grpc.h:301
gpr_timespec deadline
Definition: grpc.h:249
Definition: grpc.h:76
The result of an operation.
Definition: grpc.h:224
grpc_channel * grpc_lame_client_channel_create(const char *target)
Create a lame client: this client fails every operation attempted on it.
Definition: lame_client.c:141
int integer
Definition: grpc.h:96
grpc_channel * grpc_insecure_channel_create(const char *target, const grpc_channel_args *args)
Create a client channel to 'target'.
Definition: channel_create.c:157
Send status from the server: one and only one instance MUST be sent from the server unless the call w...
Definition: grpc.h:268
char * string
Definition: grpc.h:95
void grpc_call_details_init(grpc_call_details *details)
Definition: call_details.c:39
char * host
Definition: grpc.h:247
int success
non-zero if the operation was successful, 0 upon failure.
Definition: grpc.h:229
void grpc_call_destroy(grpc_call *call)
Destroy a call.
Definition: call.c:1177
union grpc_op::@6 data
size_t count
Definition: grpc.h:294
A single argument...
Definition: grpc.h:91
Definition: grpc.h:244
something failed, we don't know what
Definition: grpc.h:160
Definition: server.c:169
Definition: byte_buffer.h:49
grpc_byte_buffer ** recv_message
ownership of the byte buffer is moved to the caller; the caller must call grpc_byte_buffer_destroy on...
Definition: grpc.h:313
void grpc_server_start(grpc_server *server)
Start a server - tells all listeners to start listening.
Definition: server.c:845
Definition: grpc.h:235
uint32_t gpr_uint32
Definition: port_platform.h:309
void * p
Definition: grpc.h:98
size_t * status_details_capacity
Definition: grpc.h:344
Receive a message: 0 or more of these operations can occur for each call.
Definition: grpc.h:274
size_t method_capacity
Definition: grpc.h:246
grpc_connectivity_state grpc_channel_check_connectivity_state(grpc_channel *channel, int try_to_connect)
Check the connectivity state of a channel.
Definition: channel_connectivity.c:43
grpc_status_code * status
Definition: grpc.h:322
struct grpc_op::@6::@9 recv_status_on_client
void grpc_server_shutdown_and_notify(grpc_server *server, grpc_completion_queue *cq, void *tag)
Begin shutting down a server.
Definition: server.c:989
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.
Definition: channel_connectivity.c:151
grpc_metadata * metadata
Definition: grpc.h:238
this method must be called before invoke
Definition: grpc.h:168
void * grpc_channel_register_call(grpc_channel *channel, const char *method, const char *host)
Pre-register a method/host pair on a channel.
Definition: channel.c:181
Send initial metadata: one and only one instance MUST be sent for each call, unless the call was canc...
Definition: grpc.h:258
Definition: grpc.h:75
grpc_call_error
Result of a grpc call.
Definition: grpc.h:156
grpc_metadata * trailing_metadata
Definition: grpc.h:300
grpc_server * grpc_server_create(const grpc_channel_args *args)
Create a server.
Definition: server_create.c:39
size_t capacity
Definition: grpc.h:237
const char * key
Definition: grpc.h:198
void grpc_server_cancel_all_calls(grpc_server *server)
Cancel all in-progress calls.
Definition: server.c:1053
invalid metadata was passed to this call
Definition: grpc.h:179
const char * status_details
Definition: grpc.h:302
grpc_call_error grpc_call_cancel(grpc_call *call)
Called by clients to cancel an RPC on the server.
Definition: call.c:1189
A single metadata element.
Definition: grpc.h:197
this method is not available on the server
Definition: grpc.h:162
Shutting down.
Definition: grpc.h:214
Receive initial metadata: one and only one MUST be made on the client, must not be made on the server...
Definition: grpc.h:271
Operation data: one field for each op type (except SEND_CLOSE_FROM_CLIENT which has no arguments) ...
Definition: grpc.h:287
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.
Definition: server.c:1148
void * obfuscated[3]
Definition: grpc.h:207
Send a message: 0 or more of these operations can occur for each call.
Definition: grpc.h:260
everything went ok
Definition: grpc.h:158
grpc_event grpc_completion_queue_next(grpc_completion_queue *cq, gpr_timespec deadline)
Blocks until an event is available, the completion queue is being shut down, or deadline is reached...
Definition: completion_queue.c:147
this call is already finished (writes_done or write_status has already been called) ...
Definition: grpc.h:173
struct grpc_event grpc_event
The result of an operation.
grpc_completion_type
The type of completion (for grpc_event)
Definition: grpc.h:212
Definition: completion_queue.c:49
size_t trailing_metadata_count
Definition: grpc.h:299
size_t host_capacity
Definition: grpc.h:248
void * grpc_server_register_method(grpc_server *server, const char *method, const char *host)
Registers a method in the server.
Definition: server.c:820
char * grpc_channel_get_target(grpc_channel *channel)
Return a newly allocated string representing the target a channel was created for.
Definition: channel.c:144
void grpc_channel_destroy(grpc_channel *channel)
Close and destroy a grpc channel.
Definition: channel.c:257
struct grpc_op::@6::@7 send_initial_metadata
const char * grpc_version_string(void)
Return a string representing the current version of grpc.
Definition: version.c:39
struct grpc_metadata::@5 internal_data
The following fields are reserved for grpc internal use.
size_t num_args
Definition: grpc.h:114
Definition: context.h:41
size_t count
Definition: grpc.h:236
Receive status on the client: one and only one must be made on the client.
Definition: grpc.h:279
channel is ready for work
Definition: grpc.h:145
char * key
Definition: grpc.h:93
int grpc_server_add_http2_port(grpc_server *server, const char *addr)
Add a HTTP2 over plaintext over tcp listener.
Definition: server_chttp2.c:83
char * grpc_call_get_peer(grpc_call *call)
Returns a newly allocated string representing the endpoint to which this call is communicating with...
Definition: call.c:1256
channel has seen a failure but expects to recover
Definition: grpc.h:147
struct grpc_metadata grpc_metadata
A single metadata element.
const char * value
Definition: grpc.h:199
this method is not available on the client
Definition: grpc.h:164
grpc_call_error grpc_call_start_batch(grpc_call *call, const grpc_op *ops, size_t nops, void *tag)
Start a batch of operations defined in the array ops; when complete, post a completion of type 'tag' ...
Definition: call.c:1431
channel is idle
Definition: grpc.h:141
channel has seen a failure that it cannot recover from
Definition: grpc.h:149
struct grpc_op::@6::@10 recv_close_on_server
Definition: time.h:60
grpc_status_code
Definition: status.h:41
grpc_call * grpc_channel_create_call(grpc_channel *channel, grpc_completion_queue *completion_queue, const char *method, const char *host, gpr_timespec deadline)
Create a call given a grpc_channel, in order to call 'method'.
Definition: channel.c:165
struct census_context * grpc_census_call_get_context(grpc_call *call)
Definition: grpc_context.c:60
void grpc_metadata_array_destroy(grpc_metadata_array *array)
Definition: metadata_array.c:43
No event before timeout.
Definition: grpc.h:216
void grpc_init(void)
Initialize the grpc library.
Definition: init.c:61
channel is connecting
Definition: grpc.h:143
struct grpc_op::@6::@8 send_status_from_server
grpc_byte_buffer * send_message
Definition: grpc.h:297
grpc_metadata_array * trailing_metadata
ownership of the array is with the caller, but ownership of the elements stays with the call object (...
Definition: grpc.h:321
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.
Definition: server.c:1173
void grpc_shutdown(void)
Shut down the grpc library.
Definition: init.c:94
void grpc_metadata_array_init(grpc_metadata_array *array)
Definition: metadata_array.c:39
void grpc_completion_queue_destroy(grpc_completion_queue *cq)
Destroy a completion queue.
Definition: completion_queue.c:255
grpc_call * grpc_channel_create_registered_call(grpc_channel *channel, grpc_completion_queue *completion_queue, void *registered_call_handle, gpr_timespec deadline)
Create a call given a handle returned from grpc_channel_register_call.
Definition: channel.c:197
size_t value_length
Definition: grpc.h:200
there is already an outstanding read/write operation on the call
Definition: grpc.h:175
Receive close on the server: one and only one must be made on the server.
Definition: grpc.h:282
grpc_completion_type type
The type of the completion.
Definition: grpc.h:226
this method must be called before server_accept
Definition: grpc.h:166
grpc_arg_type type
Definition: grpc.h:92
void grpc_completion_queue_shutdown(grpc_completion_queue *cq)
Begin destruction of a completion queue.
Definition: completion_queue.c:237
Definition: grpc.h:74
grpc_metadata * metadata
Definition: grpc.h:295
grpc_call_error grpc_call_cancel_with_status(grpc_call *call, grpc_status_code status, const char *description)
Called by clients to cancel an RPC on the server.
Definition: call.c:1193
Definition: call.c:143
int * cancelled
out argument, set to 1 if the call failed in any way (seen as a cancellation on the server)...
Definition: grpc.h:349
grpc_completion_queue * grpc_completion_queue_create(void)
Create a completion queue.
Definition: completion_queue.c:65
this method must be called after invoke
Definition: grpc.h:170
char * method
Definition: grpc.h:245
int grpc_tracer_set_enabled(const char *name, int enabled)
Enable or disable a tracer.
Definition: trace.c:112
Definition: server.c:181
void grpc_census_call_set_context(grpc_call *call, struct census_context *context)
Definition: grpc_context.c:42