Debian Codegraph @

c/include/proton/delivery.h

raw
1 #ifndef PROTON_DELIVERY_H
2 #define PROTON_DELIVERY_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 <proton/disposition.h>
27 #include <proton/type_compat.h>
28 #include <stddef.h>
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 /**
35 * @file
36 *
37 * @copybrief delivery
38 *
39 * @addtogroup delivery
40 * @{
41 */
42
43 /**
44 * An AMQP delivery tag.
45 */
46 typedef pn_bytes_t pn_delivery_tag_t;
47
48 /**
49 * Construct a delivery tag.
50 *
51 * @param[in] bytes a pointer to the beginning of the tag
52 * @param[in] size the size of the tag
53 * @return the delivery tag
54 */
55 PN_EXTERN pn_delivery_tag_t pn_dtag(const char *bytes, size_t size);
56
57 /**
58 * Create a delivery on a link.
59 *
60 * Every delivery object within a link must be supplied with a unique
61 * tag. Links maintain a sequence of delivery object in the order that
62 * they are created.
63 *
64 * @param[in] link a link object
65 * @param[in] tag the delivery tag
66 * @return a newly created delivery, or NULL if there was an error
67 */
68 PN_EXTERN pn_delivery_t *pn_delivery(pn_link_t *link, pn_delivery_tag_t tag);
69
70 /**
71 * Get the application context that is associated with a delivery object.
72 *
73 * The application context for a delivery may be set using
74 * ::pn_delivery_set_context.
75 *
76 * @param[in] delivery the delivery whose context is to be returned.
77 * @return the application context for the delivery object
78 */
79 PN_EXTERN void *pn_delivery_get_context(pn_delivery_t *delivery);
80
81 /**
82 * Set a new application context for a delivery object.
83 *
84 * The application context for a delivery object may be retrieved using
85 * ::pn_delivery_get_context.
86 *
87 * @param[in] delivery the delivery object
88 * @param[in] context the application context
89 */
90 PN_EXTERN void pn_delivery_set_context(pn_delivery_t *delivery, void *context);
91
92 /**
93 * Get the attachments that are associated with a delivery object.
94 *
95 * @param[in] delivery the delivery whose attachments are to be returned.
96 * @return the attachments for the delivery object
97 */
98 PN_EXTERN pn_record_t *pn_delivery_attachments(pn_delivery_t *delivery);
99
100 /**
101 * Get the tag for a delivery object.
102 *
103 * @param[in] delivery a delivery object
104 * @return the delivery tag
105 */
106 PN_EXTERN pn_delivery_tag_t pn_delivery_tag(pn_delivery_t *delivery);
107
108 /**
109 * Get the parent link for a delivery object.
110 *
111 * @param[in] delivery a delivery object
112 * @return the parent link
113 */
114 PN_EXTERN pn_link_t *pn_delivery_link(pn_delivery_t *delivery);
115
116 /**
117 * Get the local disposition for a delivery.
118 *
119 * The pointer returned by this object is valid until the delivery is
120 * settled.
121 *
122 * @param[in] delivery a delivery object
123 * @return a pointer to the local disposition
124 */
125 PN_EXTERN pn_disposition_t *pn_delivery_local(pn_delivery_t *delivery);
126
127 /**
128 * Get the local disposition state for a delivery.
129 *
130 * @param[in] delivery a delivery object
131 * @return the local disposition state
132 */
133 PN_EXTERN uint64_t pn_delivery_local_state(pn_delivery_t *delivery);
134
135 /**
136 * Get the remote disposition for a delivery.
137 *
138 * The pointer returned by this object is valid until the delivery is
139 * settled.
140 *
141 * @param[in] delivery a delivery object
142 * @return a pointer to the remote disposition
143 */
144 PN_EXTERN pn_disposition_t *pn_delivery_remote(pn_delivery_t *delivery);
145
146 /**
147 * Get the remote disposition state for a delivery.
148 *
149 * @param[in] delivery a delivery object
150 * @return the remote disposition state
151 */
152 PN_EXTERN uint64_t pn_delivery_remote_state(pn_delivery_t *delivery);
153
154 /**
155 * Check if a delivery is remotely settled.
156 *
157 * @param[in] delivery a delivery object
158 * @return true if the delivery is settled at the remote endpoint, false otherwise
159 */
160 PN_EXTERN bool pn_delivery_settled(pn_delivery_t *delivery);
161
162 /**
163 * Get the amount of pending message data for a delivery.
164 *
165 * @param[in] delivery a delivery object
166 * @return the amount of pending message data in bytes
167 */
168 PN_EXTERN size_t pn_delivery_pending(pn_delivery_t *delivery);
169
170 /**
171 * Check if a delivery only has partial message data.
172 *
173 * The receiver can expect more ::PN_DELIVERY events for this delivery containing
174 * the remainder of this message.
175 *
176 * @param[in] delivery a delivery object
177 * @return true if the delivery only contains part of a message, false otherwise
178 */
179 PN_EXTERN bool pn_delivery_partial(pn_delivery_t *delivery);
180
181 /**
182 * Check if a received delivery has been aborted.
183 *
184 * An aborted delivery means the sender cannot complete this message and the
185 * receiver should discard any data already received. The link remains open for
186 * future messages.
187 *
188 * You must still call pn_delivery_settle() to free local resources. An aborted
189 * delivery consumes a credit, use pn_link_flow() to issue new credit as for a
190 * successful delivery.
191 *
192 * Calling pn_link_recv() when the current delivery is aborted returns
193 * ::PN_ABORTED.
194 *
195 * @see pn_delivery_abort()
196 * @param[in] delivery a delivery object
197 * @return true if the delivery has been aborted, false otherwise
198 */
199 PN_EXTERN bool pn_delivery_aborted(pn_delivery_t *delivery);
200
201 /**
202 * Check if a delivery is writable.
203 *
204 * A delivery is considered writable if it is the current delivery on
205 * an outgoing link, and the link has positive credit.
206 *
207 * @param[in] delivery a delivery object
208 * @return true if the delivery is writable, false otherwise
209 */
210 PN_EXTERN bool pn_delivery_writable(pn_delivery_t *delivery);
211
212 /**
213 * Check if a delivery is readable.
214 *
215 * A delivery is considered readable if it is the current delivery on
216 * an incoming link.
217 *
218 * @param[in] delivery a delivery object
219 * @return true if the delivery is readable, false otherwise
220 */
221 PN_EXTERN bool pn_delivery_readable(pn_delivery_t *delivery);
222
223 /**
224 * Check if a delivery is updated.
225 *
226 * A delivery is considered updated whenever the peer communicates a
227 * new disposition for the delivery. Once a delivery becomes updated,
228 * it will remain so until ::pn_delivery_clear is called.
229 *
230 * @param[in] delivery a delivery object
231 * @return true if the delivery is updated, false otherwise
232 */
233 PN_EXTERN bool pn_delivery_updated(pn_delivery_t *delivery);
234
235 /**
236 * Update the disposition of a delivery.
237 *
238 * When update is invoked the updated disposition of the delivery will
239 * be communicated to the peer.
240 *
241 * @param[in] delivery a delivery object
242 * @param[in] state the updated delivery state
243 */
244 PN_EXTERN void pn_delivery_update(pn_delivery_t *delivery, uint64_t state);
245
246 /**
247 * Clear the updated flag for a delivery.
248 *
249 * See ::pn_delivery_updated.
250 *
251 * @param[in] delivery a delivery object
252 */
253 PN_EXTERN void pn_delivery_clear(pn_delivery_t *delivery);
254
255 /**
256 * Return true if delivery is the current delivery for its link.
257 *
258 * @param[in] delivery a delivery object
259 * @return true if delivery is the current delivery for its link.
260 */
261 PN_EXTERN bool pn_delivery_current(pn_delivery_t *delivery);
262
263 /**
264 * Abort a delivery being sent.
265 *
266 * Aborting means the sender cannot complete this message. It will not send any
267 * more data, and data sent so far should be discarded by the receiver. The
268 * link remains open for future messages.
269 *
270 * If some data has already been sent on the network, an AMQP "aborted" frame
271 * will be sent to inform the peer. If no data has yet been sent, the delivery
272 * will simply be forgotten.
273 *
274 * The delivery will be freed, and cannot be used after the call.
275 *
276 * @see pn_delivery_aborted()
277 *
278 * @param[in] delivery a delivery object
279 */
280 PN_EXTERN void pn_delivery_abort(pn_delivery_t *delivery);
281
282 /**
283 * Settle a delivery.
284 *
285 * A settled delivery can never be used again.
286 *
287 * @note If pn_delivery_current(delivery) is true before the call then
288 * pn_link_advance(pn_delivery_link(deliver)) is called automatically.
289 *
290 * @param[in] delivery a delivery object
291 */
292 PN_EXTERN void pn_delivery_settle(pn_delivery_t *delivery);
293
294 /**
295 * Utility function for printing details of a delivery.
296 *
297 * @param[in] delivery a delivery object
298 */
299 PN_EXTERN void pn_delivery_dump(pn_delivery_t *delivery);
300
301 /**
302 * Check if a delivery is buffered.
303 *
304 * A delivery that is buffered has not yet been written to the wire.
305 *
306 * Note that returning false does not imply that a delivery was
307 * definitely written to the wire. If false is returned, it is not
308 * known whether the delivery was actually written to the wire or not.
309 *
310 * @param[in] delivery a delivery object
311 * @return true if the delivery is buffered
312 */
313 PN_EXTERN bool pn_delivery_buffered(pn_delivery_t *delivery);
314
315 /**
316 * Extracts the first delivery on the connection that has pending
317 * operations.
318 *
319 * Retrieves the first delivery on the Connection that has pending
320 * operations. A readable delivery indicates message data is waiting
321 * to be read. A writable delivery indicates that message data may be
322 * sent. An updated delivery indicates that the delivery's disposition
323 * has changed. A delivery will never be both readable and writable,
324 * but it may be both readable and updated or both writable and
325 * updated.
326 *
327 * @param[in] connection the connection
328 * @return the first delivery object that needs to be serviced, else
329 * NULL if none
330 */
331 PN_DEPRECATED("Use the PN_DELIVERY event to track deliveries with pending operations")
332 PN_EXTERN pn_delivery_t *pn_work_head(pn_connection_t *connection);
333
334 /**
335 * Get the next delivery on the connection that needs has pending
336 * operations.
337 *
338 * @param[in] delivery the previous delivery retrieved from
339 * either pn_work_head or pn_work_next
340 * @return the next delivery that has pending operations, else
341 * NULL if none
342 */
343 PN_DEPRECATED("Use the PN_DELIVERY event to track deliveries with pending operations")
344 PN_EXTERN pn_delivery_t *pn_work_next(pn_delivery_t *delivery);
345
346 /**
347 * @}
348 */
349
350 #ifdef __cplusplus
351 }
352 #endif
353
354 #endif /* delivery.h */