lttng: list valid condition / action names if missing or unknown
[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.h>
9 #include <common/buffer-view.h>
10 #include "payload-view.h"
11 #include "payload.h"
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 } : (struct lttng_payload_view) {
28 .buffer = {},
29 ._fd_handles = {}
30 };
31 }
32
33 struct lttng_payload_view lttng_payload_view_from_view(
34 struct lttng_payload_view *view, size_t offset,
35 ptrdiff_t len)
36 {
37 return view ? (struct lttng_payload_view) {
38 .buffer = lttng_buffer_view_from_view(
39 &view->buffer, offset, len),
40 ._fd_handles = view->_fd_handles,
41 ._iterator = {
42 .p_fd_handles_position = view->_iterator.p_fd_handles_position ?:
43 &view->_iterator.fd_handles_position,
44 }
45 } : (struct lttng_payload_view) {
46 .buffer = {},
47 ._fd_handles = {}
48 };
49 }
50
51 struct lttng_payload_view lttng_payload_view_from_dynamic_buffer(
52 const struct lttng_dynamic_buffer *buffer, size_t offset,
53 ptrdiff_t len)
54 {
55 return buffer ? (struct lttng_payload_view) {
56 .buffer = lttng_buffer_view_from_dynamic_buffer(
57 buffer, offset, len),
58 ._fd_handles = {}
59 } : (struct lttng_payload_view) {
60 .buffer = {},
61 ._fd_handles = {}
62 };
63 }
64
65 struct lttng_payload_view lttng_payload_view_from_buffer_view(
66 const struct lttng_buffer_view *view, size_t offset,
67 ptrdiff_t len)
68 {
69 return view ? (struct lttng_payload_view) {
70 .buffer = lttng_buffer_view_from_view(
71 view, offset, len),
72 ._fd_handles = {}
73 } : (struct lttng_payload_view) {
74 .buffer = {},
75 ._fd_handles = {}
76 };
77 }
78
79 struct lttng_payload_view lttng_payload_view_init_from_buffer(
80 const char *src, size_t offset, ptrdiff_t len)
81 {
82 return (struct lttng_payload_view) {
83 .buffer = lttng_buffer_view_init(
84 src, offset, len),
85 ._fd_handles = {}
86 };
87 }
88
89 int lttng_payload_view_get_fd_handle_count(
90 const struct lttng_payload_view *payload_view)
91 {
92 int ret;
93 size_t position;
94
95 if (!payload_view) {
96 ret = -1;
97 goto end;
98 }
99
100 ret = lttng_dynamic_pointer_array_get_count(&payload_view->_fd_handles);
101 if (ret < 0) {
102 goto end;
103 }
104
105 position = payload_view->_iterator.p_fd_handles_position ?
106 *payload_view->_iterator.p_fd_handles_position :
107 payload_view->_iterator.fd_handles_position;
108 ret = ret - (int) position;
109 end:
110 return ret;
111 }
112
113 struct fd_handle *lttng_payload_view_pop_fd_handle(
114 struct lttng_payload_view *view)
115 {
116 struct fd_handle *handle = NULL;
117 size_t fd_handle_count;
118 size_t *pos;
119
120 if (!view) {
121 goto end;
122 }
123
124 fd_handle_count = lttng_payload_view_get_fd_handle_count(view);
125 if (fd_handle_count == 0) {
126 goto end;
127 }
128
129 pos = view->_iterator.p_fd_handles_position ?
130 view->_iterator.p_fd_handles_position :
131 &view->_iterator.fd_handles_position;
132 handle = (fd_handle *) lttng_dynamic_pointer_array_get_pointer(&view->_fd_handles,
133 *pos);
134 (*pos)++;
135 fd_handle_get(handle);
136 end:
137 return handle;
138 }
This page took 0.032178 seconds and 4 git commands to generate.