blob: 993fc97adb6809082d0a9f20724bd4101da77889 [file] [log] [blame]
David Garcia Quintas2425bbb2016-01-25 17:32:48 -08001/*
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_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"
145/* The caller of the secure_channel_create functions may override the target
146 name used for SSL host name checking using this channel argument which is of
147 type GRPC_ARG_STRING. This *should* be used for testing only.
148 If this argument is not specified, the name used for SSL host name checking
149 will be the target parameter (assuming that the secure channel is an SSL
150 channel). If this parameter is specified and the underlying is not an SSL
151 channel, it will just be ignored. */
152#define GRPC_SSL_TARGET_NAME_OVERRIDE_ARG "grpc.ssl_target_name_override"
153
154/** Result of a grpc call. If the caller satisfies the prerequisites of a
155 particular operation, the grpc_call_error returned will be GRPC_CALL_OK.
156 Receiving any other value listed here is an indication of a bug in the
157 caller. */
158typedef enum grpc_call_error {
159 /** everything went ok */
160 GRPC_CALL_OK = 0,
161 /** something failed, we don't know what */
162 GRPC_CALL_ERROR,
163 /** this method is not available on the server */
164 GRPC_CALL_ERROR_NOT_ON_SERVER,
165 /** this method is not available on the client */
166 GRPC_CALL_ERROR_NOT_ON_CLIENT,
167 /** this method must be called before server_accept */
168 GRPC_CALL_ERROR_ALREADY_ACCEPTED,
169 /** this method must be called before invoke */
170 GRPC_CALL_ERROR_ALREADY_INVOKED,
171 /** this method must be called after invoke */
172 GRPC_CALL_ERROR_NOT_INVOKED,
173 /** this call is already finished
174 (writes_done or write_status has already been called) */
175 GRPC_CALL_ERROR_ALREADY_FINISHED,
176 /** there is already an outstanding read/write operation on the call */
177 GRPC_CALL_ERROR_TOO_MANY_OPERATIONS,
178 /** the flags value was illegal for this call */
179 GRPC_CALL_ERROR_INVALID_FLAGS,
180 /** invalid metadata was passed to this call */
181 GRPC_CALL_ERROR_INVALID_METADATA,
182 /** invalid message was passed to this call */
183 GRPC_CALL_ERROR_INVALID_MESSAGE,
184 /** completion queue for notification has not been registered with the
185 server */
186 GRPC_CALL_ERROR_NOT_SERVER_COMPLETION_QUEUE,
187 /** this batch of operations leads to more operations than allowed */
188 GRPC_CALL_ERROR_BATCH_TOO_BIG
189} grpc_call_error;
190
191/* Write Flags: */
192/** Hint that the write may be buffered and need not go out on the wire
193 immediately. GRPC is free to buffer the message until the next non-buffered
194 write, or until writes_done, but it need not buffer completely or at all. */
195#define GRPC_WRITE_BUFFER_HINT (0x00000001u)
196/** Force compression to be disabled for a particular write
197 (start_write/add_metadata). Illegal on invoke/accept. */
198#define GRPC_WRITE_NO_COMPRESS (0x00000002u)
199/** Mask of all valid flags. */
200#define GRPC_WRITE_USED_MASK (GRPC_WRITE_BUFFER_HINT | GRPC_WRITE_NO_COMPRESS)
201
Craig Tillerc6549762016-03-09 17:10:43 -0800202/* Initial metadata flags */
203/** Signal that the call is idempotent */
204#define GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST (0x00000010u)
205/** Mask of all valid flags */
206#define GRPC_INITIAL_METADATA_USED_MASK GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST
207
David Garcia Quintas2425bbb2016-01-25 17:32:48 -0800208/** A single metadata element */
209typedef struct grpc_metadata {
210 const char *key;
211 const char *value;
212 size_t value_length;
213 uint32_t flags;
214
215 /** The following fields are reserved for grpc internal use.
216 There is no need to initialize them, and they will be set to garbage
217 during calls to grpc. */
218 struct {
219 void *obfuscated[4];
220 } internal_data;
221} grpc_metadata;
222
223/** The type of completion (for grpc_event) */
224typedef enum grpc_completion_type {
225 /** Shutting down */
226 GRPC_QUEUE_SHUTDOWN,
227 /** No event before timeout */
228 GRPC_QUEUE_TIMEOUT,
229 /** Operation completion */
230 GRPC_OP_COMPLETE
231} grpc_completion_type;
232
233/** The result of an operation.
234
235 Returned by a completion queue when the operation started with tag. */
236typedef struct grpc_event {
237 /** The type of the completion. */
238 grpc_completion_type type;
239 /** non-zero if the operation was successful, 0 upon failure.
240 Only GRPC_OP_COMPLETE can succeed or fail. */
241 int success;
242 /** The tag passed to grpc_call_start_batch etc to start this operation.
243 Only GRPC_OP_COMPLETE has a tag. */
244 void *tag;
245} grpc_event;
246
247typedef struct {
248 size_t count;
249 size_t capacity;
250 grpc_metadata *metadata;
251} grpc_metadata_array;
252
253typedef struct {
254 char *method;
255 size_t method_capacity;
256 char *host;
257 size_t host_capacity;
258 gpr_timespec deadline;
Craig Tiller5987c702016-03-09 16:55:23 -0800259 uint32_t flags;
David Garcia Quintas2425bbb2016-01-25 17:32:48 -0800260 void *reserved;
261} grpc_call_details;
262
263typedef enum {
264 /** Send initial metadata: one and only one instance MUST be sent for each
265 call, unless the call was cancelled - in which case this can be skipped.
266 This op completes after all bytes of metadata have been accepted by
267 outgoing flow control. */
268 GRPC_OP_SEND_INITIAL_METADATA = 0,
269 /** Send a message: 0 or more of these operations can occur for each call.
270 This op completes after all bytes for the message have been accepted by
271 outgoing flow control. */
272 GRPC_OP_SEND_MESSAGE,
273 /** Send a close from the client: one and only one instance MUST be sent from
274 the client, unless the call was cancelled - in which case this can be
275 skipped.
276 This op completes after all bytes for the call (including the close)
277 have passed outgoing flow control. */
278 GRPC_OP_SEND_CLOSE_FROM_CLIENT,
279 /** Send status from the server: one and only one instance MUST be sent from
280 the server unless the call was cancelled - in which case this can be
281 skipped.
282 This op completes after all bytes for the call (including the status)
283 have passed outgoing flow control. */
284 GRPC_OP_SEND_STATUS_FROM_SERVER,
285 /** Receive initial metadata: one and only one MUST be made on the client,
286 must not be made on the server.
287 This op completes after all initial metadata has been read from the
288 peer. */
289 GRPC_OP_RECV_INITIAL_METADATA,
290 /** Receive a message: 0 or more of these operations can occur for each call.
291 This op completes after all bytes of the received message have been
292 read, or after a half-close has been received on this call. */
293 GRPC_OP_RECV_MESSAGE,
294 /** Receive status on the client: one and only one must be made on the client.
295 This operation always succeeds, meaning ops paired with this operation
296 will also appear to succeed, even though they may not have. In that case
297 the status will indicate some failure.
298 This op completes after all activity on the call has completed. */
299 GRPC_OP_RECV_STATUS_ON_CLIENT,
300 /** Receive close on the server: one and only one must be made on the
301 server.
302 This op completes after the close has been received by the server. */
303 GRPC_OP_RECV_CLOSE_ON_SERVER
304} grpc_op_type;
305
306/** Operation data: one field for each op type (except SEND_CLOSE_FROM_CLIENT
307 which has no arguments) */
308typedef struct grpc_op {
309 /** Operation type, as defined by grpc_op_type */
310 grpc_op_type op;
311 /** Write flags bitset for grpc_begin_messages */
312 uint32_t flags;
313 /** Reserved for future usage */
314 void *reserved;
315 union {
316 /** Reserved for future usage */
317 struct {
318 void *reserved[8];
319 } reserved;
320 struct {
321 size_t count;
322 grpc_metadata *metadata;
323 } send_initial_metadata;
324 grpc_byte_buffer *send_message;
325 struct {
326 size_t trailing_metadata_count;
327 grpc_metadata *trailing_metadata;
328 grpc_status_code status;
329 const char *status_details;
330 } send_status_from_server;
331 /** ownership of the array is with the caller, but ownership of the elements
332 stays with the call object (ie key, value members are owned by the call
333 object, recv_initial_metadata->array is owned by the caller).
334 After the operation completes, call grpc_metadata_array_destroy on this
335 value, or reuse it in a future op. */
336 grpc_metadata_array *recv_initial_metadata;
337 /** ownership of the byte buffer is moved to the caller; the caller must
338 call grpc_byte_buffer_destroy on this value, or reuse it in a future op.
339 */
340 grpc_byte_buffer **recv_message;
341 struct {
342 /** ownership of the array is with the caller, but ownership of the
343 elements stays with the call object (ie key, value members are owned
344 by the call object, trailing_metadata->array is owned by the caller).
345 After the operation completes, call grpc_metadata_array_destroy on
346 this
347 value, or reuse it in a future op. */
348 grpc_metadata_array *trailing_metadata;
349 grpc_status_code *status;
350 /** status_details is a buffer owned by the application before the op
351 completes and after the op has completed. During the operation
352 status_details may be reallocated to a size larger than
353 *status_details_capacity, in which case *status_details_capacity will
354 be updated with the new array capacity.
355
356 Pre-allocating space:
357 size_t my_capacity = 8;
358 char *my_details = gpr_malloc(my_capacity);
359 x.status_details = &my_details;
360 x.status_details_capacity = &my_capacity;
361
362 Not pre-allocating space:
363 size_t my_capacity = 0;
364 char *my_details = NULL;
365 x.status_details = &my_details;
366 x.status_details_capacity = &my_capacity;
367
368 After the call:
369 gpr_free(my_details); */
370 char **status_details;
371 size_t *status_details_capacity;
372 } recv_status_on_client;
373 struct {
374 /** out argument, set to 1 if the call failed in any way (seen as a
375 cancellation on the server), or 0 if the call succeeded */
376 int *cancelled;
377 } recv_close_on_server;
378 } data;
379} grpc_op;
380
381#ifdef __cplusplus
382}
383#endif
384
385#endif /* GRPC_IMPL_CODEGEN_GRPC_TYPES_H */