2 * Copyright (C) 2020 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: LGPL-2.1-only
8 #include "payload-view.hpp"
11 #include <common/buffer-view.hpp>
12 #include <common/dynamic-array.hpp>
16 bool lttng_payload_view_is_valid(const struct lttng_payload_view
*view
)
18 return view
&& lttng_buffer_view_is_valid(&view
->buffer
);
21 struct lttng_payload_view
22 lttng_payload_view_from_payload(const struct lttng_payload
*payload
, size_t offset
, ptrdiff_t len
)
25 (struct lttng_payload_view
){
26 .buffer
= lttng_buffer_view_from_dynamic_buffer(
27 &payload
->buffer
, offset
, len
),
28 ._fd_handles
= payload
->_fd_handles
,
31 (struct lttng_payload_view
){
38 struct lttng_payload_view
39 lttng_payload_view_from_view(struct lttng_payload_view
*view
, size_t offset
, ptrdiff_t len
)
41 return view
? (struct lttng_payload_view
) {
42 .buffer
= lttng_buffer_view_from_view(
43 &view
->buffer
, offset
, len
),
44 ._fd_handles
= view
->_fd_handles
,
46 .p_fd_handles_position
= view
->_iterator
.p_fd_handles_position
?:
47 &view
->_iterator
.fd_handles_position
,
48 .fd_handles_position
= 0,
50 } : (struct lttng_payload_view
) {
57 struct lttng_payload_view
lttng_payload_view_from_dynamic_buffer(
58 const struct lttng_dynamic_buffer
*buffer
, size_t offset
, ptrdiff_t len
)
61 (struct lttng_payload_view
){
62 .buffer
= lttng_buffer_view_from_dynamic_buffer(buffer
, offset
, len
),
66 (struct lttng_payload_view
){
73 struct lttng_payload_view
lttng_payload_view_from_buffer_view(const struct lttng_buffer_view
*view
,
78 (struct lttng_payload_view
){
79 .buffer
= lttng_buffer_view_from_view(view
, offset
, len
),
83 (struct lttng_payload_view
){
90 struct lttng_payload_view
91 lttng_payload_view_init_from_buffer(const char *src
, size_t offset
, ptrdiff_t len
)
93 return (struct lttng_payload_view
){
94 .buffer
= lttng_buffer_view_init(src
, offset
, len
),
100 int lttng_payload_view_get_fd_handle_count(const struct lttng_payload_view
*payload_view
)
110 ret
= lttng_dynamic_pointer_array_get_count(&payload_view
->_fd_handles
);
115 position
= payload_view
->_iterator
.p_fd_handles_position
?
116 *payload_view
->_iterator
.p_fd_handles_position
:
117 payload_view
->_iterator
.fd_handles_position
;
118 ret
= ret
- (int) position
;
123 struct fd_handle
*lttng_payload_view_pop_fd_handle(struct lttng_payload_view
*view
)
125 struct fd_handle
*handle
= nullptr;
126 size_t fd_handle_count
;
133 fd_handle_count
= lttng_payload_view_get_fd_handle_count(view
);
134 if (fd_handle_count
== 0) {
138 pos
= view
->_iterator
.p_fd_handles_position
? view
->_iterator
.p_fd_handles_position
:
139 &view
->_iterator
.fd_handles_position
;
140 handle
= (fd_handle
*) lttng_dynamic_pointer_array_get_pointer(&view
->_fd_handles
, *pos
);
142 fd_handle_get(handle
);
This page took 0.031566 seconds and 4 git commands to generate.