Build fix: missing initializer for member 'payload'
[lttng-tools.git] / src / common / payload-view.cpp
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 #include <common/dynamic-array.hpp>
9 #include <common/buffer-view.hpp>
10 #include "payload-view.hpp"
11 #include "payload.hpp"
12 #include <stddef.h>
13
14 bool lttng_payload_view_is_valid(const struct lttng_payload_view *view)
15 {
16 return view && lttng_buffer_view_is_valid(&view->buffer);
17 }
18
19 struct lttng_payload_view lttng_payload_view_from_payload(
20 const struct lttng_payload *payload, size_t offset,
21 ptrdiff_t len)
22 {
23 return payload ? (struct lttng_payload_view) {
24 .buffer = lttng_buffer_view_from_dynamic_buffer(
25 &payload->buffer, offset, len),
26 ._fd_handles = payload->_fd_handles,
27 ._iterator = {},
28 } : (struct lttng_payload_view) {
29 .buffer = {},
30 ._fd_handles = {},
31 ._iterator = {},
32 };
33 }
34
35 struct lttng_payload_view lttng_payload_view_from_view(
36 struct lttng_payload_view *view, size_t offset,
37 ptrdiff_t len)
38 {
39 return view ? (struct lttng_payload_view) {
40 .buffer = lttng_buffer_view_from_view(
41 &view->buffer, offset, len),
42 ._fd_handles = view->_fd_handles,
43 ._iterator = {
44 .p_fd_handles_position = view->_iterator.p_fd_handles_position ?:
45 &view->_iterator.fd_handles_position,
46 .fd_handles_position = 0,
47 }
48 } : (struct lttng_payload_view) {
49 .buffer = {},
50 ._fd_handles = {},
51 ._iterator = {},
52 };
53 }
54
55 struct lttng_payload_view lttng_payload_view_from_dynamic_buffer(
56 const struct lttng_dynamic_buffer *buffer, size_t offset,
57 ptrdiff_t len)
58 {
59 return buffer ? (struct lttng_payload_view) {
60 .buffer = lttng_buffer_view_from_dynamic_buffer(
61 buffer, offset, len),
62 ._fd_handles = {},
63 ._iterator = {},
64 } : (struct lttng_payload_view) {
65 .buffer = {},
66 ._fd_handles = {},
67 ._iterator = {},
68 };
69 }
70
71 struct lttng_payload_view lttng_payload_view_from_buffer_view(
72 const struct lttng_buffer_view *view, size_t offset,
73 ptrdiff_t len)
74 {
75 return view ? (struct lttng_payload_view) {
76 .buffer = lttng_buffer_view_from_view(
77 view, offset, len),
78 ._fd_handles = {},
79 ._iterator = {},
80 } : (struct lttng_payload_view) {
81 .buffer = {},
82 ._fd_handles = {},
83 ._iterator = {},
84 };
85 }
86
87 struct lttng_payload_view lttng_payload_view_init_from_buffer(
88 const char *src, size_t offset, ptrdiff_t len)
89 {
90 return (struct lttng_payload_view) {
91 .buffer = lttng_buffer_view_init(
92 src, offset, len),
93 ._fd_handles = {},
94 ._iterator = {},
95 };
96 }
97
98 int lttng_payload_view_get_fd_handle_count(
99 const struct lttng_payload_view *payload_view)
100 {
101 int ret;
102 size_t position;
103
104 if (!payload_view) {
105 ret = -1;
106 goto end;
107 }
108
109 ret = lttng_dynamic_pointer_array_get_count(&payload_view->_fd_handles);
110 if (ret < 0) {
111 goto end;
112 }
113
114 position = payload_view->_iterator.p_fd_handles_position ?
115 *payload_view->_iterator.p_fd_handles_position :
116 payload_view->_iterator.fd_handles_position;
117 ret = ret - (int) position;
118 end:
119 return ret;
120 }
121
122 struct fd_handle *lttng_payload_view_pop_fd_handle(
123 struct lttng_payload_view *view)
124 {
125 struct fd_handle *handle = NULL;
126 size_t fd_handle_count;
127 size_t *pos;
128
129 if (!view) {
130 goto end;
131 }
132
133 fd_handle_count = lttng_payload_view_get_fd_handle_count(view);
134 if (fd_handle_count == 0) {
135 goto end;
136 }
137
138 pos = view->_iterator.p_fd_handles_position ?
139 view->_iterator.p_fd_handles_position :
140 &view->_iterator.fd_handles_position;
141 handle = (fd_handle *) lttng_dynamic_pointer_array_get_pointer(&view->_fd_handles,
142 *pos);
143 (*pos)++;
144 fd_handle_get(handle);
145 end:
146 return handle;
147 }
This page took 0.032864 seconds and 4 git commands to generate.