blob: 7b20cc14d43fdc25b00e4c6295eb9b4bc63dc4b2 [file] [log] [blame]
David Garcia Quintas2425bbb2016-01-25 17:32:48 -08001/*
2 *
Craig Tiller6169d5f2016-03-31 07:46:18 -07003 * Copyright 2015, Google Inc.
David Garcia Quintas2425bbb2016-01-25 17:32:48 -08004 * 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_IMPL_CODEGEN_GRPC_TYPES_H
35#define GRPC_IMPL_CODEGEN_GRPC_TYPES_H
36
37#include <grpc/impl/codegen/byte_buffer.h>
38#include <grpc/impl/codegen/status.h>
39
40#include <stddef.h>
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
46/** Completion Queues enable notification of the completion of asynchronous
47 actions. */
48typedef struct grpc_completion_queue grpc_completion_queue;
49
50/** An alarm associated with a completion queue. */
51typedef struct grpc_alarm grpc_alarm;
52
53/** The Channel interface allows creation of Call objects. */
54typedef struct grpc_channel grpc_channel;
55
56/** A server listens to some port and responds to request calls */
57typedef struct grpc_server grpc_server;
58
59/** A Call represents an RPC. When created, it is in a configuration state
60 allowing properties to be set until it is invoked. After invoke, the Call
61 can have messages written to it and read from it. */
62typedef struct grpc_call grpc_call;
63
64/** Type specifier for grpc_arg */
65typedef enum {
66 GRPC_ARG_STRING,
67 GRPC_ARG_INTEGER,
68 GRPC_ARG_POINTER
69} grpc_arg_type;
70
Craig Tiller841c7262016-02-02 09:23:22 -080071typedef struct grpc_arg_pointer_vtable {
Craig Tillere1a10312016-02-02 09:23:47 -080072 void *(*copy)(void *p);
73 void (*destroy)(void *p);
74 int (*cmp)(void *p, void *q);
75} grpc_arg_pointer_vtable;
Craig Tiller841c7262016-02-02 09:23:22 -080076
David Garcia Quintas2425bbb2016-01-25 17:32:48 -080077/** A single argument... each argument has a key and a value
78
79 A note on naming keys:
80 Keys are namespaced into groups, usually grouped by library, and are
81 keys for module XYZ are named XYZ.key1, XYZ.key2, etc. Module names must
82 be restricted to the regex [A-Za-z][_A-Za-z0-9]{,15}.
83 Key names must be restricted to the regex [A-Za-z][_A-Za-z0-9]{,47}.
84
85 GRPC core library keys are prefixed by grpc.
86
87 Library authors are strongly encouraged to \#define symbolic constants for
88 their keys so that it's possible to change them in the future. */
89typedef struct {
90 grpc_arg_type type;
91 char *key;
92 union {
93 char *string;
94 int integer;
95 struct {
96 void *p;
Craig Tiller841c7262016-02-02 09:23:22 -080097 const grpc_arg_pointer_vtable *vtable;
David Garcia Quintas2425bbb2016-01-25 17:32:48 -080098 } pointer;
99 } value;
100} grpc_arg;
101
102/** An array of arguments that can be passed around.
103
104 Used to set optional channel-level configuration.
105 These configuration options are modelled as key-value pairs as defined
106 by grpc_arg; keys are strings to allow easy backwards-compatible extension
107 by arbitrary parties.
108 All evaluation is performed at channel creation time (i.e. the values in
109 this structure need only live through the creation invocation). */
110typedef struct {
111 size_t num_args;
112 grpc_arg *args;
113} grpc_channel_args;
114
115/* Channel argument keys: */
116/** Enable census for tracing and stats collection */
117#define GRPC_ARG_ENABLE_CENSUS "grpc.census"
118/** Maximum number of concurrent incoming streams to allow on a http2
119 connection */
120#define GRPC_ARG_MAX_CONCURRENT_STREAMS "grpc.max_concurrent_streams"
121/** Maximum message length that the channel can receive */
122#define GRPC_ARG_MAX_MESSAGE_LENGTH "grpc.max_message_length"
123/** Initial sequence number for http2 transports */
124#define GRPC_ARG_HTTP2_INITIAL_SEQUENCE_NUMBER \
125 "grpc.http2.initial_sequence_number"
126/** Amount to read ahead on individual streams. Defaults to 64kb, larger
127 values can help throughput on high-latency connections.
128 NOTE: at some point we'd like to auto-tune this, and this parameter
129 will become a no-op. */
130#define GRPC_ARG_HTTP2_STREAM_LOOKAHEAD_BYTES "grpc.http2.lookahead_bytes"
131/** How much memory to use for hpack decoding */
132#define GRPC_ARG_HTTP2_HPACK_TABLE_SIZE_DECODER \
133 "grpc.http2.hpack_table_size.decoder"
134/** How much memory to use for hpack encoding */
135#define GRPC_ARG_HTTP2_HPACK_TABLE_SIZE_ENCODER \
136 "grpc.http2.hpack_table_size.encoder"
137/** Default authority to pass if none specified on call construction */
138#define GRPC_ARG_DEFAULT_AUTHORITY "grpc.default_authority"
139/** Primary user agent: goes at the start of the user-agent metadata
140 sent on each request */
141#define GRPC_ARG_PRIMARY_USER_AGENT_STRING "grpc.primary_user_agent"
142/** Secondary user agent: goes at the end of the user-agent metadata
143 sent on each request */
144#define GRPC_ARG_SECONDARY_USER_AGENT_STRING "grpc.secondary_user_agent"
Aaron Isotton24e69bf2016-02-26 11:53:22 -0800145/** The maximum time between subsequent connection attempts, in ms */
146#define GRPC_ARG_MAX_RECONNECT_BACKOFF_MS "grpc.max_reconnect_backoff_ms"
David Garcia Quintas2425bbb2016-01-25 17:32:48 -0800147/* The caller of the secure_channel_create functions may override the target
148 name used for SSL host name checking using this channel argument which is of
149 type GRPC_ARG_STRING. This *should* be used for testing only.
150 If this argument is not specified, the name used for SSL host name checking
151 will be the target parameter (assuming that the secure channel is an SSL
152 channel). If this parameter is specified and the underlying is not an SSL
153 channel, it will just be ignored. */
154#define GRPC_SSL_TARGET_NAME_OVERRIDE_ARG "grpc.ssl_target_name_override"
155
156/** Result of a grpc call. If the caller satisfies the prerequisites of a
157 particular operation, the grpc_call_error returned will be GRPC_CALL_OK.
158 Receiving any other value listed here is an indication of a bug in the
159 caller. */
160typedef enum grpc_call_error {
161 /** everything went ok */
162 GRPC_CALL_OK = 0,
163 /** something failed, we don't know what */
164 GRPC_CALL_ERROR,
165 /** this method is not available on the server */
166 GRPC_CALL_ERROR_NOT_ON_SERVER,
167 /** this method is not available on the client */
168 GRPC_CALL_ERROR_NOT_ON_CLIENT,
169 /** this method must be called before server_accept */
170 GRPC_CALL_ERROR_ALREADY_ACCEPTED,
171 /** this method must be called before invoke */
172 GRPC_CALL_ERROR_ALREADY_INVOKED,
173 /** this method must be called after invoke */
174 GRPC_CALL_ERROR_NOT_INVOKED,
175 /** this call is already finished
176 (writes_done or write_status has already been called) */
177 GRPC_CALL_ERROR_ALREADY_FINISHED,
178 /** there is already an outstanding read/write operation on the call */
179 GRPC_CALL_ERROR_TOO_MANY_OPERATIONS,
180 /** the flags value was illegal for this call */
181 GRPC_CALL_ERROR_INVALID_FLAGS,
182 /** invalid metadata was passed to this call */
183 GRPC_CALL_ERROR_INVALID_METADATA,
184 /** invalid message was passed to this call */
185 GRPC_CALL_ERROR_INVALID_MESSAGE,
186 /** completion queue for notification has not been registered with the
187 server */
188 GRPC_CALL_ERROR_NOT_SERVER_COMPLETION_QUEUE,
189 /** this batch of operations leads to more operations than allowed */
Craig Tiller06cb1a92016-04-04 08:10:47 -0700190 GRPC_CALL_ERROR_BATCH_TOO_BIG,
191 /** payload type requested is not the type registered */
192 GRPC_CALL_ERROR_PAYLOAD_TYPE_MISMATCH
David Garcia Quintas2425bbb2016-01-25 17:32:48 -0800193} grpc_call_error;
194
195/* Write Flags: */
196/** Hint that the write may be buffered and need not go out on the wire
197 immediately. GRPC is free to buffer the message until the next non-buffered
198 write, or until writes_done, but it need not buffer completely or at all. */
199#define GRPC_WRITE_BUFFER_HINT (0x00000001u)
200/** Force compression to be disabled for a particular write
201 (start_write/add_metadata). Illegal on invoke/accept. */
202#define GRPC_WRITE_NO_COMPRESS (0x00000002u)
203/** Mask of all valid flags. */
204#define GRPC_WRITE_USED_MASK (GRPC_WRITE_BUFFER_HINT | GRPC_WRITE_NO_COMPRESS)
205
Craig Tillerc6549762016-03-09 17:10:43 -0800206/* Initial metadata flags */
207/** Signal that the call is idempotent */
208#define GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST (0x00000010u)
Craig Tiller8c0d96f2016-03-11 14:27:52 -0800209/** Signal that the call should not return UNAVAILABLE before it has started */
210#define GRPC_INITIAL_METADATA_IGNORE_CONNECTIVITY (0x00000020u)
Craig Tillerc6549762016-03-09 17:10:43 -0800211/** Mask of all valid flags */
Craig Tiller8c0d96f2016-03-11 14:27:52 -0800212#define GRPC_INITIAL_METADATA_USED_MASK \
213 (GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST | \
214 GRPC_INITIAL_METADATA_IGNORE_CONNECTIVITY)
Craig Tillerc6549762016-03-09 17:10:43 -0800215
David Garcia Quintas2425bbb2016-01-25 17:32:48 -0800216/** A single metadata element */
217typedef struct grpc_metadata {
218 const char *key;
219 const char *value;
220 size_t value_length;
221 uint32_t flags;
222
223 /** The following fields are reserved for grpc internal use.
224 There is no need to initialize them, and they will be set to garbage
225 during calls to grpc. */
226 struct {
227 void *obfuscated[4];
228 } internal_data;
229} grpc_metadata;
230
231/** The type of completion (for grpc_event) */
232typedef enum grpc_completion_type {
233 /** Shutting down */
234 GRPC_QUEUE_SHUTDOWN,
235 /** No event before timeout */
236 GRPC_QUEUE_TIMEOUT,
237 /** Operation completion */
238 GRPC_OP_COMPLETE
239} grpc_completion_type;
240
241/** The result of an operation.
242
243 Returned by a completion queue when the operation started with tag. */
244typedef struct grpc_event {
245 /** The type of the completion. */
246 grpc_completion_type type;
247 /** non-zero if the operation was successful, 0 upon failure.
248 Only GRPC_OP_COMPLETE can succeed or fail. */
249 int success;
250 /** The tag passed to grpc_call_start_batch etc to start this operation.
251 Only GRPC_OP_COMPLETE has a tag. */
252 void *tag;
253} grpc_event;
254
255typedef struct {
256 size_t count;
257 size_t capacity;
258 grpc_metadata *metadata;
259} grpc_metadata_array;
260
261typedef struct {
262 char *method;
263 size_t method_capacity;
264 char *host;
265 size_t host_capacity;
266 gpr_timespec deadline;
Craig Tiller5987c702016-03-09 16:55:23 -0800267 uint32_t flags;
David Garcia Quintas2425bbb2016-01-25 17:32:48 -0800268 void *reserved;
269} grpc_call_details;
270
271typedef enum {
272 /** Send initial metadata: one and only one instance MUST be sent for each
273 call, unless the call was cancelled - in which case this can be skipped.
274 This op completes after all bytes of metadata have been accepted by
275 outgoing flow control. */
276 GRPC_OP_SEND_INITIAL_METADATA = 0,
277 /** Send a message: 0 or more of these operations can occur for each call.
278 This op completes after all bytes for the message have been accepted by
279 outgoing flow control. */
280 GRPC_OP_SEND_MESSAGE,
281 /** Send a close from the client: one and only one instance MUST be sent from
282 the client, unless the call was cancelled - in which case this can be
283 skipped.
284 This op completes after all bytes for the call (including the close)
285 have passed outgoing flow control. */
286 GRPC_OP_SEND_CLOSE_FROM_CLIENT,
287 /** Send status from the server: one and only one instance MUST be sent from
288 the server unless the call was cancelled - in which case this can be
289 skipped.
290 This op completes after all bytes for the call (including the status)
291 have passed outgoing flow control. */
292 GRPC_OP_SEND_STATUS_FROM_SERVER,
293 /** Receive initial metadata: one and only one MUST be made on the client,
294 must not be made on the server.
295 This op completes after all initial metadata has been read from the
296 peer. */
297 GRPC_OP_RECV_INITIAL_METADATA,
298 /** Receive a message: 0 or more of these operations can occur for each call.
299 This op completes after all bytes of the received message have been
300 read, or after a half-close has been received on this call. */
301 GRPC_OP_RECV_MESSAGE,
302 /** Receive status on the client: one and only one must be made on the client.
303 This operation always succeeds, meaning ops paired with this operation
304 will also appear to succeed, even though they may not have. In that case
305 the status will indicate some failure.
306 This op completes after all activity on the call has completed. */
307 GRPC_OP_RECV_STATUS_ON_CLIENT,
308 /** Receive close on the server: one and only one must be made on the
309 server.
Jan Tattermusched4d89e2016-05-03 16:01:38 -0700310 This op completes after the close has been received by the server.
Jan Tattermusch19abba32016-05-03 10:06:29 -0700311 This operation always succeeds, meaning ops paired with this operation
312 will also appear to succeed, even though they may not have. */
David Garcia Quintas2425bbb2016-01-25 17:32:48 -0800313 GRPC_OP_RECV_CLOSE_ON_SERVER
314} grpc_op_type;
315
316/** Operation data: one field for each op type (except SEND_CLOSE_FROM_CLIENT
317 which has no arguments) */
318typedef struct grpc_op {
319 /** Operation type, as defined by grpc_op_type */
320 grpc_op_type op;
321 /** Write flags bitset for grpc_begin_messages */
322 uint32_t flags;
323 /** Reserved for future usage */
324 void *reserved;
325 union {
326 /** Reserved for future usage */
327 struct {
328 void *reserved[8];
329 } reserved;
330 struct {
331 size_t count;
332 grpc_metadata *metadata;
333 } send_initial_metadata;
334 grpc_byte_buffer *send_message;
335 struct {
336 size_t trailing_metadata_count;
337 grpc_metadata *trailing_metadata;
338 grpc_status_code status;
339 const char *status_details;
340 } send_status_from_server;
341 /** ownership of the array is with the caller, but ownership of the elements
342 stays with the call object (ie key, value members are owned by the call
343 object, recv_initial_metadata->array is owned by the caller).
344 After the operation completes, call grpc_metadata_array_destroy on this
345 value, or reuse it in a future op. */
346 grpc_metadata_array *recv_initial_metadata;
347 /** ownership of the byte buffer is moved to the caller; the caller must
348 call grpc_byte_buffer_destroy on this value, or reuse it in a future op.
349 */
350 grpc_byte_buffer **recv_message;
351 struct {
352 /** ownership of the array is with the caller, but ownership of the
353 elements stays with the call object (ie key, value members are owned
354 by the call object, trailing_metadata->array is owned by the caller).
355 After the operation completes, call grpc_metadata_array_destroy on
356 this
357 value, or reuse it in a future op. */
358 grpc_metadata_array *trailing_metadata;
359 grpc_status_code *status;
360 /** status_details is a buffer owned by the application before the op
361 completes and after the op has completed. During the operation
362 status_details may be reallocated to a size larger than
363 *status_details_capacity, in which case *status_details_capacity will
364 be updated with the new array capacity.
365
366 Pre-allocating space:
367 size_t my_capacity = 8;
368 char *my_details = gpr_malloc(my_capacity);
369 x.status_details = &my_details;
370 x.status_details_capacity = &my_capacity;
371
372 Not pre-allocating space:
373 size_t my_capacity = 0;
374 char *my_details = NULL;
375 x.status_details = &my_details;
376 x.status_details_capacity = &my_capacity;
377
378 After the call:
379 gpr_free(my_details); */
380 char **status_details;
381 size_t *status_details_capacity;
382 } recv_status_on_client;
383 struct {
384 /** out argument, set to 1 if the call failed in any way (seen as a
385 cancellation on the server), or 0 if the call succeeded */
386 int *cancelled;
387 } recv_close_on_server;
388 } data;
389} grpc_op;
390
391#ifdef __cplusplus
392}
393#endif
394
395#endif /* GRPC_IMPL_CODEGEN_GRPC_TYPES_H */