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