Change backing type of lttng_uuid to std::array
[lttng-tools.git] / src / common / payload.cpp
CommitLineData
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
c9e313bc
SM
8#include "payload.hpp"
9#include <common/dynamic-array.hpp>
10#include <common/dynamic-buffer.hpp>
11#include <common/error.hpp>
c0a66c84 12
fe489250
JG
13static
14void release_fd_handle_ref(void *ptr)
15{
a6bc4ca9 16 struct fd_handle *fd_handle = (struct fd_handle *) ptr;
fe489250
JG
17
18 fd_handle_put(fd_handle);
19}
20
c0a66c84
JG
21void lttng_payload_init(struct lttng_payload *payload)
22{
a0377dfe 23 LTTNG_ASSERT(payload);
c0a66c84 24 lttng_dynamic_buffer_init(&payload->buffer);
fe489250
JG
25 lttng_dynamic_pointer_array_init(&payload->_fd_handles,
26 release_fd_handle_ref);
c0a66c84
JG
27}
28
e368fb43
JG
29int lttng_payload_copy(const struct lttng_payload *src_payload,
30 struct lttng_payload *dst_payload)
31{
32 int ret;
33 size_t i;
34
e368fb43
JG
35 ret = lttng_dynamic_buffer_append_buffer(
36 &dst_payload->buffer, &src_payload->buffer);
37 if (ret) {
fe489250 38 goto end;
e368fb43
JG
39 }
40
fe489250
JG
41 for (i = 0; i < lttng_dynamic_pointer_array_get_count(
42 &src_payload->_fd_handles);
e368fb43 43 i++) {
fe489250
JG
44 struct fd_handle *new_fd_handle;
45 const struct fd_handle *src_fd_handle =
a6bc4ca9 46 (fd_handle *) lttng_dynamic_pointer_array_get_pointer(
fe489250
JG
47 &src_payload->_fd_handles, i);
48
49 new_fd_handle = fd_handle_copy(src_fd_handle);
50 if (!new_fd_handle) {
51 PERROR("Failed to copy fd_handle while copying a payload");
52 ret = -1;
53 goto end;
e368fb43
JG
54 }
55
fe489250
JG
56 ret = lttng_payload_push_fd_handle(dst_payload, new_fd_handle);
57 fd_handle_put(new_fd_handle);
e368fb43 58 if (ret) {
fe489250 59 goto end;
e368fb43
JG
60 }
61 }
62
63end:
64 return ret;
e368fb43
JG
65}
66
c0a66c84
JG
67void lttng_payload_reset(struct lttng_payload *payload)
68{
69 if (!payload) {
70 return;
71 }
72
73 lttng_dynamic_buffer_reset(&payload->buffer);
fe489250 74 lttng_dynamic_pointer_array_reset(&payload->_fd_handles);
c0a66c84
JG
75}
76
fe489250
JG
77void lttng_payload_clear(struct lttng_payload *payload)
78{
035cc184 79 (void) lttng_dynamic_buffer_set_size(&payload->buffer, 0);
fe489250
JG
80 lttng_dynamic_pointer_array_clear(&payload->_fd_handles);
81}
82
fe489250
JG
83int lttng_payload_push_fd_handle(struct lttng_payload *payload,
84 struct fd_handle *fd_handle)
c0a66c84
JG
85{
86 int ret;
87
88 if (!payload) {
89 ret = -1;
90 goto end;
91 }
92
fe489250
JG
93 ret = lttng_dynamic_pointer_array_add_pointer(
94 &payload->_fd_handles, fd_handle);
95 if (ret) {
96 goto end;
97 }
98
99 fd_handle_get(fd_handle);
c0a66c84
JG
100end:
101 return ret;
102}
This page took 0.04394 seconds and 4 git commands to generate.