blob: 466af3a4cde24cadba21b7ca4ee013877710d3ce [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"
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 */
190 GRPC_CALL_ERROR_BATCH_TOO_BIG
191} grpc_call_error;
192
193/* Write Flags: */
194/** Hint that the write may be buffered and need not go out on the wire
195 immediately. GRPC is free to buffer the message until the next non-buffered
196 write, or until writes_done, but it need not buffer completely or at all. */
197#define GRPC_WRITE_BUFFER_HINT (0x00000001u)
198/** Force compression to be disabled for a particular write
199 (start_write/add_metadata). Illegal on invoke/accept. */
200#define GRPC_WRITE_NO_COMPRESS (0x00000002u)
201/** Mask of all valid flags. */
202#define GRPC_WRITE_USED_MASK (GRPC_WRITE_BUFFER_HINT | GRPC_WRITE_NO_COMPRESS)
203
204/** A single metadata element */
205typedef struct grpc_metadata {
206 const char *key;
207 const char *value;
208 size_t value_length;
209 uint32_t flags;
210
211 /** The following fields are reserved for grpc internal use.
212 There is no need to initialize them, and they will be set to garbage
213 during calls to grpc. */
214 struct {
215 void *obfuscated[4];
216 } internal_data;
217} grpc_metadata;
218
219/** The type of completion (for grpc_event) */
220typedef enum grpc_completion_type {
221 /** Shutting down */
222 GRPC_QUEUE_SHUTDOWN,
223 /** No event before timeout */
224 GRPC_QUEUE_TIMEOUT,
225 /** Operation completion */
226 GRPC_OP_COMPLETE
227} grpc_completion_type;
228
229/** The result of an operation.
230
231 Returned by a completion queue when the operation started with tag. */
232typedef struct grpc_event {
233 /** The type of the completion. */
234 grpc_completion_type type;
235 /** non-zero if the operation was successful, 0 upon failure.
236 Only GRPC_OP_COMPLETE can succeed or fail. */
237 int success;
238 /** The tag passed to grpc_call_start_batch etc to start this operation.
239 Only GRPC_OP_COMPLETE has a tag. */
240 void *tag;
241} grpc_event;
242
243typedef struct {
244 size_t count;
245 size_t capacity;
246 grpc_metadata *metadata;
247} grpc_metadata_array;
248
249typedef struct {
250 char *method;
251 size_t method_capacity;
252 char *host;
253 size_t host_capacity;
254 gpr_timespec deadline;
255 void *reserved;
256} grpc_call_details;
257
258typedef enum {
259 /** Send initial metadata: one and only one instance MUST be sent for each
260 call, unless the call was cancelled - in which case this can be skipped.
261 This op completes after all bytes of metadata have been accepted by
262 outgoing flow control. */
263 GRPC_OP_SEND_INITIAL_METADATA = 0,
264 /** Send a message: 0 or more of these operations can occur for each call.
265 This op completes after all bytes for the message have been accepted by
266 outgoing flow control. */
267 GRPC_OP_SEND_MESSAGE,
268 /** Send a close from the client: one and only one instance MUST be sent from
269 the client, unless the call was cancelled - in which case this can be
270 skipped.
271 This op completes after all bytes for the call (including the close)
272 have passed outgoing flow control. */
273 GRPC_OP_SEND_CLOSE_FROM_CLIENT,
274 /** Send status from the server: one and only one instance MUST be sent from
275 the server unless the call was cancelled - in which case this can be
276 skipped.
277 This op completes after all bytes for the call (including the status)
278 have passed outgoing flow control. */
279 GRPC_OP_SEND_STATUS_FROM_SERVER,
280 /** Receive initial metadata: one and only one MUST be made on the client,
281 must not be made on the server.
282 This op completes after all initial metadata has been read from the
283 peer. */
284 GRPC_OP_RECV_INITIAL_METADATA,
285 /** Receive a message: 0 or more of these operations can occur for each call.
286 This op completes after all bytes of the received message have been
287 read, or after a half-close has been received on this call. */
288 GRPC_OP_RECV_MESSAGE,
289 /** Receive status on the client: one and only one must be made on the client.
290 This operation always succeeds, meaning ops paired with this operation
291 will also appear to succeed, even though they may not have. In that case
292 the status will indicate some failure.
293 This op completes after all activity on the call has completed. */
294 GRPC_OP_RECV_STATUS_ON_CLIENT,
295 /** Receive close on the server: one and only one must be made on the
296 server.
297 This op completes after the close has been received by the server. */
298 GRPC_OP_RECV_CLOSE_ON_SERVER
299} grpc_op_type;
300
301/** Operation data: one field for each op type (except SEND_CLOSE_FROM_CLIENT
302 which has no arguments) */
303typedef struct grpc_op {
304 /** Operation type, as defined by grpc_op_type */
305 grpc_op_type op;
306 /** Write flags bitset for grpc_begin_messages */
307 uint32_t flags;
308 /** Reserved for future usage */
309 void *reserved;
310 union {
311 /** Reserved for future usage */
312 struct {
313 void *reserved[8];
314 } reserved;
315 struct {
316 size_t count;
317 grpc_metadata *metadata;
318 } send_initial_metadata;
319 grpc_byte_buffer *send_message;
320 struct {
321 size_t trailing_metadata_count;
322 grpc_metadata *trailing_metadata;
323 grpc_status_code status;
324 const char *status_details;
325 } send_status_from_server;
326 /** ownership of the array is with the caller, but ownership of the elements
327 stays with the call object (ie key, value members are owned by the call
328 object, recv_initial_metadata->array is owned by the caller).
329 After the operation completes, call grpc_metadata_array_destroy on this
330 value, or reuse it in a future op. */
331 grpc_metadata_array *recv_initial_metadata;
332 /** ownership of the byte buffer is moved to the caller; the caller must
333 call grpc_byte_buffer_destroy on this value, or reuse it in a future op.
334 */
335 grpc_byte_buffer **recv_message;
336 struct {
337 /** ownership of the array is with the caller, but ownership of the
338 elements stays with the call object (ie key, value members are owned
339 by the call object, trailing_metadata->array is owned by the caller).
340 After the operation completes, call grpc_metadata_array_destroy on
341 this
342 value, or reuse it in a future op. */
343 grpc_metadata_array *trailing_metadata;
344 grpc_status_code *status;
345 /** status_details is a buffer owned by the application before the op
346 completes and after the op has completed. During the operation
347 status_details may be reallocated to a size larger than
348 *status_details_capacity, in which case *status_details_capacity will
349 be updated with the new array capacity.
350
351 Pre-allocating space:
352 size_t my_capacity = 8;
353 char *my_details = gpr_malloc(my_capacity);
354 x.status_details = &my_details;
355 x.status_details_capacity = &my_capacity;
356
357 Not pre-allocating space:
358 size_t my_capacity = 0;
359 char *my_details = NULL;
360 x.status_details = &my_details;
361 x.status_details_capacity = &my_capacity;
362
363 After the call:
364 gpr_free(my_details); */
365 char **status_details;
366 size_t *status_details_capacity;
367 } recv_status_on_client;
368 struct {
369 /** out argument, set to 1 if the call failed in any way (seen as a
370 cancellation on the server), or 0 if the call succeeded */
371 int *cancelled;
372 } recv_close_on_server;
373 } data;
374} grpc_op;
375
376#ifdef __cplusplus
377}
378#endif
379
380#endif /* GRPC_IMPL_CODEGEN_GRPC_TYPES_H */