Debian Codegraph @

c/include/proton/types.h

raw
1 #ifndef PROTON_TYPES_H
2 #define PROTON_TYPES_H 1
3
4 /*
5 *
6 * Licensed to the Apache Software Foundation (ASF) under one
7 * or more contributor license agreements. See the NOTICE file
8 * distributed with this work for additional information
9 * regarding copyright ownership. The ASF licenses this file
10 * to you under the Apache License, Version 2.0 (the
11 * "License"); you may not use this file except in compliance
12 * with the License. You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing,
17 * software distributed under the License is distributed on an
18 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19 * KIND, either express or implied. See the License for the
20 * specific language governing permissions and limitations
21 * under the License.
22 *
23 */
24
25 #include <proton/import_export.h>
26 #include <stddef.h>
27 #include <proton/type_compat.h>
28
29 /**
30 * @file
31 *
32 * @copybrief types
33 *
34 * @defgroup core Core
35 * @brief Core protocol entities and event handling.
36 *
37 * @defgroup connection Connection
38 * @brief A connection to a remote AMQP peer.
39 * @ingroup core
40 *
41 * @defgroup session Session
42 * @brief A container of links.
43 * @ingroup core
44 *
45 * @defgroup link Link
46 * @brief A channel for transferring messages.
47 * @ingroup core
48 *
49 * @defgroup terminus Terminus
50 * @brief A source or target for messages.
51 * @ingroup core
52 *
53 * @defgroup message Message
54 * @brief A mutable holder of application content.
55 * @ingroup core
56 *
57 * @defgroup delivery Delivery
58 * @brief A message transfer.
59 * @ingroup core
60 *
61 * @defgroup condition Condition
62 * @brief An endpoint error state.
63 * @ingroup core
64 *
65 * @defgroup event Event
66 * @brief Protocol and transport events.
67 * @ingroup core
68 *
69 * @defgroup transport Transport
70 * @brief A network channel supporting an AMQP connection.
71 * @ingroup core
72 *
73 * @defgroup sasl SASL
74 * @brief SASL secure transport layer.
75 * @ingroup core
76 *
77 * @defgroup ssl SSL
78 * @brief SSL secure transport layer.
79 * @ingroup core
80 *
81 * @defgroup error Error
82 * @brief A Proton API error.
83 * @ingroup core
84 *
85 * @defgroup types Types
86 * @brief AMQP and API data types.
87 *
88 * @defgroup amqp_types AMQP data types
89 * @brief AMQP data types.
90 * @ingroup types
91 *
92 * @defgroup api_types API data types
93 * @brief Additional data types used in the API.
94 * @ingroup types
95 *
96 * @defgroup codec Codec
97 * @brief AMQP data encoding and decoding.
98 *
99 * @defgroup data Data
100 * @brief A data structure for AMQP data.
101 * @ingroup codec
102 *
103 * @defgroup io IO
104 * @brief **Unsettled API** - Interfaces for IO integration.
105 *
106 * @defgroup proactor Proactor
107 * @brief **Unsettled API** - An API for multithreaded IO.
108 * @ingroup io
109 *
110 * @defgroup proactor_events Proactor events
111 * @brief **Unsettled API** - Events used by the proactor.
112 * @ingroup io
113 *
114 * @defgroup listener Listener
115 * @brief **Unsettled API** - A listener for incoming connections.
116 * @ingroup io
117 *
118 * @defgroup raw_connection Raw connection
119 * @brief **Unsettled API** - An API allowing raw sockets to be used with proactor
120 * @ingroup io
121 *
122 * @defgroup connection_driver Connection driver
123 * @brief **Unsettled API** - An API for low-level IO integration.
124 * @ingroup io
125 *
126 * @defgroup messenger Messenger
127 * @brief **Deprecated** - Use the @ref proactor API or Qpid Proton C++.
128 *
129 * @defgroup url URL
130 * @brief **Deprecated** - Use a third-party URL library.
131 */
132
133 #ifdef __cplusplus
134 extern "C" {
135 #endif
136
137 /**
138 * A sequence number.
139 *
140 * @ingroup api_types
141 */
142 typedef uint32_t pn_sequence_t;
143
144 /**
145 * A span of time in milliseconds.
146 *
147 * @ingroup api_types
148 */
149 typedef uint32_t pn_millis_t;
150
151 /**
152 * The maximum value for @ref pn_millis_t.
153 *
154 * @ingroup api_types
155 */
156 #define PN_MILLIS_MAX (~0U)
157
158 /**
159 * A span of time in seconds.
160 *
161 * @ingroup api_types
162 */
163 typedef uint32_t pn_seconds_t;
164
165 /**
166 * A 64-bit timestamp in milliseconds since the Unix epoch.
167 *
168 * @ingroup amqp_types
169 */
170 typedef int64_t pn_timestamp_t;
171
172 /**
173 * A 32-bit Unicode code point.
174 *
175 * @ingroup amqp_types
176 */
177 typedef uint32_t pn_char_t;
178
179 /**
180 * A 32-bit decimal floating-point number.
181 *
182 * @ingroup amqp_types
183 */
184 typedef uint32_t pn_decimal32_t;
185
186 /**
187 * A 64-bit decimal floating-point number.
188 *
189 * @ingroup amqp_types
190 */
191 typedef uint64_t pn_decimal64_t;
192
193 /**
194 * A 128-bit decimal floating-point number.
195 *
196 * @ingroup amqp_types
197 */
198 typedef struct {
199 char bytes[16];
200 } pn_decimal128_t;
201
202 /**
203 * A 16-byte universally unique identifier.
204 *
205 * @ingroup amqp_types
206 */
207 typedef struct {
208 char bytes[16];
209 } pn_uuid_t;
210
211 /**
212 * A const byte buffer.
213 *
214 * @ingroup api_types
215 */
216 typedef struct pn_bytes_t {
217 size_t size;
218 const char *start;
219 } pn_bytes_t;
220
221 /**
222 * Create a @ref pn_bytes_t
223 *
224 * @ingroup api_types
225 */
226 PN_EXTERN pn_bytes_t pn_bytes(size_t size, const char *start);
227
228 PN_EXTERN extern const pn_bytes_t pn_bytes_null;
229
230 /**
231 * A non-const byte buffer.
232 *
233 * @ingroup api_types
234 */
235 typedef struct pn_rwbytes_t {
236 size_t size;
237 char *start;
238 } pn_rwbytes_t;
239
240 /**
241 * Create a @ref pn_rwbytes_t
242 *
243 * @ingroup api_types
244 */
245 PN_EXTERN pn_rwbytes_t pn_rwbytes(size_t size, char *start);
246
247 PN_EXTERN extern const pn_rwbytes_t pn_rwbytes_null;
248
249 /**
250 * Holds the state flags for an AMQP endpoint.
251 *
252 * A pn_state_t is an integral value with flags that encode both the
253 * local and remote state of an AMQP Endpoint (@link pn_connection_t
254 * Connection @endlink, @link pn_session_t Session @endlink, or @link
255 * pn_link_t Link @endlink). The local portion of the state may be
256 * accessed using ::PN_LOCAL_MASK, and the remote portion may be
257 * accessed using ::PN_REMOTE_MASK. Individual bits may be accessed
258 * using ::PN_LOCAL_UNINIT, ::PN_LOCAL_ACTIVE, ::PN_LOCAL_CLOSED, and
259 * ::PN_REMOTE_UNINIT, ::PN_REMOTE_ACTIVE, ::PN_REMOTE_CLOSED.
260 *
261 * Every AMQP endpoint (@link pn_connection_t Connection @endlink,
262 * @link pn_session_t Session @endlink, or @link pn_link_t Link
263 * @endlink) starts out in an uninitialized state and then proceeds
264 * linearly to an active and then closed state. This lifecycle occurs
265 * at both endpoints involved, and so the state model for an endpoint
266 * includes not only the known local state, but also the last known
267 * state of the remote endpoint.
268 *
269 * @ingroup connection
270 */
271 typedef int pn_state_t;
272
273 /**
274 * An AMQP Connection object.
275 *
276 * A pn_connection_t object encapsulates all of the endpoint state
277 * associated with an AMQP Connection. A pn_connection_t object
278 * contains zero or more ::pn_session_t objects, which in turn contain
279 * zero or more ::pn_link_t objects. Each ::pn_link_t object contains
280 * an ordered sequence of ::pn_delivery_t objects. A link is either a
281 * sender or a receiver but never both.
282 *
283 * @ingroup connection
284 */
285 typedef struct pn_connection_t pn_connection_t;
286
287 /**
288 * An AMQP Session object.
289 *
290 * A pn_session_t object encapsulates all of the endpoint state
291 * associated with an AMQP Session. A pn_session_t object contains
292 * zero or more ::pn_link_t objects.
293 *
294 * @ingroup session
295 */
296 typedef struct pn_session_t pn_session_t;
297
298 /**
299 * An AMQP Link object.
300 *
301 * A pn_link_t object encapsulates all of the endpoint state
302 * associated with an AMQP Link. A pn_link_t object contains an
303 * ordered sequence of ::pn_delivery_t objects representing in-flight
304 * deliveries. A pn_link_t may be either sender or a receiver but
305 * never both.
306 *
307 * A pn_link_t object maintains a pointer to the *current* delivery
308 * within the ordered sequence of deliveries contained by the link
309 * (See ::pn_link_current). The *current* delivery is the target of a
310 * number of operations associated with the link, such as sending
311 * (::pn_link_send) and receiving (::pn_link_recv) message data.
312 *
313 * @ingroup link
314 */
315 typedef struct pn_link_t pn_link_t;
316
317 /**
318 * An AMQP Delivery object.
319 *
320 * A pn_delivery_t object encapsulates all of the endpoint state
321 * associated with an AMQP Delivery. Every delivery exists within the
322 * context of a ::pn_link_t object.
323 *
324 * The AMQP model for settlement is based on the lifecycle of a
325 * delivery at an endpoint. At each end of a link, a delivery is
326 * created, it exists for some period of time, and finally it is
327 * forgotten, aka settled. Note that because this lifecycle happens
328 * independently at both the sender and the receiver, there are
329 * actually four events of interest in the combined lifecycle of a
330 * given delivery:
331 *
332 * - created at sender
333 * - created at receiver
334 * - settled at sender
335 * - settled at receiver
336 *
337 * Because the sender and receiver are operating concurrently, these
338 * events can occur in a variety of different orders, and the order of
339 * these events impacts the types of failures that may occur when
340 * transferring a delivery. Eliminating scenarios where the receiver
341 * creates the delivery first, we have the following possible
342 * sequences of interest:
343 *
344 * Sender presettles (aka at-most-once):
345 * -------------------------------------
346 *
347 * 1. created at sender
348 * 2. settled at sender
349 * 3. created at receiver
350 * 4. settled at receiver
351 *
352 * In this configuration the sender settles (i.e. forgets about) the
353 * delivery before it even reaches the receiver, and if anything
354 * should happen to the delivery in-flight, there is no way to
355 * recover, hence the "at most once" semantics.
356 *
357 * Receiver settles first (aka at-least-once):
358 * -------------------------------------------
359 *
360 * 1. created at sender
361 * 2. created at receiver
362 * 3. settled at receiver
363 * 4. settled at sender
364 *
365 * In this configuration the receiver settles the delivery first, and
366 * the sender settles once it sees the receiver has settled. Should
367 * anything happen to the delivery in-flight, the sender can resend,
368 * however the receiver may have already forgotten the delivery and so
369 * it could interpret the resend as a new delivery, hence the "at
370 * least once" semantics.
371 *
372 * Receiver settles second (aka exactly-once):
373 * -------------------------------------------
374 *
375 * 1. created at sender
376 * 2. created at receiver
377 * 3. settled at sender
378 * 4. settled at receiver
379 *
380 * In this configuration the receiver settles only once it has seen
381 * that the sender has settled. This provides the sender the option to
382 * retransmit, and the receiver has the option to recognize (and
383 * discard) duplicates, allowing for exactly once semantics.
384 *
385 * Note that in the last scenario the sender needs some way to know
386 * when it is safe to settle. This is where delivery state comes in.
387 * In addition to these lifecycle related events surrounding
388 * deliveries there is also the notion of a delivery state that can
389 * change over the lifetime of a delivery, e.g. it might start out as
390 * nothing, transition to ::PN_RECEIVED and then transition to
391 * ::PN_ACCEPTED. In the first two scenarios the delivery state isn't
392 * required, however in final scenario the sender would typically
393 * trigger settlement based on seeing the delivery state transition to
394 * a terminal state like ::PN_ACCEPTED or ::PN_REJECTED.
395 *
396 * In practice settlement is controlled by application policy, so
397 * there may well be more options here, e.g. a sender might not settle
398 * strictly based on what has happened at the receiver, it might also
399 * choose to impose some time limit and settle after that period has
400 * expired, or it could simply have a sliding window of the last N
401 * deliveries and settle the oldest whenever a new one comes along.
402 *
403 * @ingroup delivery
404 */
405 typedef struct pn_delivery_t pn_delivery_t;
406
407 /**
408 * An event collector.
409 *
410 * A pn_collector_t may be used to register interest in being notified
411 * of high level events that can occur to the various objects
412 * representing AMQP endpoint state. See ::pn_event_t for more
413 * details.
414 *
415 * @ingroup event
416 */
417 typedef struct pn_collector_t pn_collector_t;
418
419 /**
420 * A listener for incoming connections.
421 *
422 * @ingroup listener
423 */
424 typedef struct pn_listener_t pn_listener_t;
425
426 /**
427 * A network channel supporting an AMQP connection.
428 *
429 * A pn_transport_t encapsulates the transport related state of all
430 * AMQP endpoint objects associated with a physical network connection
431 * at a given point in time.
432 *
433 * @ingroup transport
434 */
435 typedef struct pn_transport_t pn_transport_t;
436
437 /**
438 * A harness for multithreaded IO.
439 *
440 * @ingroup proactor
441 */
442 typedef struct pn_proactor_t pn_proactor_t;
443
444 /**
445 * A raw network connection used with the proactor.
446 *
447 * @ingroup raw_connection
448 */
449 typedef struct pn_raw_connection_t pn_raw_connection_t;
450
451 /**
452 * A batch of events that must be handled in sequence.
453 *
454 * A pn_event_batch_t encapsulates potentially multiple events that relate
455 * to an individual proactor related source that must be handled in sequence.
456 *
457 * Call pn_event_batch_next() in a loop until it returns NULL to extract
458 * the batch's events.
459 *
460 * @ingroup proactor
461 */
462 typedef struct pn_event_batch_t pn_event_batch_t;
463
464 /**
465 * @cond INTERNAL
466 *
467 * An event handler
468 *
469 * A pn_handler_t is target of ::pn_event_t dispatched by the pn_reactor_t
470 */
471 typedef struct pn_handler_t pn_handler_t;
472 /**
473 * @endcond
474 */
475
476 #ifdef __cplusplus
477 }
478 #endif
479
480 #endif /* types.h */