Commit | Line | Data |
---|---|---|
c0a66c84 JG |
1 | /* |
2 | * Copyright (C) 2020 Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
3 | * | |
4 | * SPDX-License-Identifier: LGPL-2.1-only | |
5 | * | |
6 | */ | |
7 | ||
8 | #ifndef LTTNG_PAYLOAD_H | |
9 | #define LTTNG_PAYLOAD_H | |
10 | ||
11 | #include <common/dynamic-buffer.h> | |
12 | #include <common/dynamic-array.h> | |
fe489250 | 13 | #include <common/fd-handle.h> |
c0a66c84 | 14 | |
7966af57 SM |
15 | #ifdef __cplusplus |
16 | extern "C" { | |
17 | #endif | |
18 | ||
c0a66c84 JG |
19 | /* |
20 | * An lttng_payload encompasses the 'data' (bytes) and any passed file | |
21 | * descriptors as part of a message between liblttng-ctl and the session | |
22 | * daemon. | |
23 | */ | |
24 | struct lttng_payload { | |
25 | struct lttng_dynamic_buffer buffer; | |
26 | /* private */ | |
fe489250 | 27 | struct lttng_dynamic_pointer_array _fd_handles; |
c0a66c84 JG |
28 | }; |
29 | ||
30 | /* | |
31 | * Initialize a payload. This performs no allocation and is meant | |
de837173 | 32 | * to be used instead of zero-ing the payload structure. |
c0a66c84 | 33 | */ |
c0a66c84 JG |
34 | void lttng_payload_init(struct lttng_payload *payload); |
35 | ||
e368fb43 | 36 | /* Copy a payload. */ |
e368fb43 JG |
37 | int lttng_payload_copy(const struct lttng_payload *src_payload, |
38 | struct lttng_payload *dst_payload); | |
39 | ||
fe489250 | 40 | /* Release any memory and references held by the payload. */ |
c0a66c84 JG |
41 | void lttng_payload_reset(struct lttng_payload *payload); |
42 | ||
fe489250 JG |
43 | /* |
44 | * Empty the contents of a payload, releasing all references held. | |
45 | * This should be used to put a payload in a re-usable state. | |
46 | * | |
47 | * lttng_payload_reset must still be called on an lttng_payload to | |
48 | * free all allocated memory. | |
49 | */ | |
fe489250 JG |
50 | void lttng_payload_clear(struct lttng_payload *payload); |
51 | ||
c0a66c84 JG |
52 | /** |
53 | * Add an fd to the payload. | |
fe489250 | 54 | * The payload acquires a reference to the fd_handle. |
c0a66c84 JG |
55 | * |
56 | * @payload Payload instance | |
fe489250 | 57 | * @fd_handle File descriptor handle to add to the payload |
c0a66c84 JG |
58 | * |
59 | * Returns 0 on success, -1 on allocation error. | |
60 | */ | |
fe489250 JG |
61 | int lttng_payload_push_fd_handle(struct lttng_payload *payload, |
62 | struct fd_handle *fd_handle); | |
c0a66c84 | 63 | |
7966af57 SM |
64 | #ifdef __cplusplus |
65 | } | |
66 | #endif | |
67 | ||
c0a66c84 | 68 | #endif /* LTTNG_PAYLOAD_H */ |