src.ctf.fs: make ctf_fs_component::trace a unique_ptr
[babeltrace.git] / src / plugins / ctf / fs-src / fs.hpp
CommitLineData
490db841 1/*
0235b0db 2 * SPDX-License-Identifier: MIT
490db841 3 *
f3bc2010 4 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
56a1cced 5 * Copyright 2016 Philippe Proulx <pproulx@efficios.com>
490db841 6 *
0235b0db 7 * BabelTrace - CTF on File System Component
490db841
JG
8 */
9
0235b0db
MJ
10#ifndef BABELTRACE_PLUGIN_CTF_FS_H
11#define BABELTRACE_PLUGIN_CTF_FS_H
12
c7e1be4b 13#include <glib.h>
c802cacb 14
c7e1be4b 15#include <babeltrace2/babeltrace.h>
c802cacb 16
ef7d7ac2 17#include "cpp-common/bt2c/data-len.hpp"
49b956cc 18#include "cpp-common/bt2c/glib-up.hpp"
0f5c5d5c
SM
19#include "cpp-common/bt2c/logging.hpp"
20
087cd0f5 21#include "metadata.hpp"
1fa280c9 22#include "plugins/ctf/common/src/metadata/tsdl/decoder.hpp"
490db841 23
78bb6992 24extern bool ctf_fs_debug;
56a1cced 25
4164020e
SM
26struct ctf_fs_file
27{
0f5c5d5c
SM
28 explicit ctf_fs_file(const bt2c::Logger& parentLogger) :
29 logger {parentLogger, "PLUGIN/SRC.CTF.FS/FILE"}
30 {
31 }
98903a3e 32
0f5c5d5c 33 bt2c::Logger logger;
4c65a157 34
4164020e 35 /* Owned by this */
afb0f12b 36 GString *path = nullptr;
1a9f7075 37
4164020e 38 /* Owned by this */
afb0f12b 39 FILE *fp = nullptr;
1a9f7075 40
afb0f12b 41 off_t size = 0;
56a1cced
JG
42};
43
4164020e
SM
44struct ctf_fs_metadata
45{
46 /* Owned by this */
1fa280c9 47 ctf_metadata_decoder_up decoder;
44c440bc 48
4164020e 49 /* Owned by this */
afb0f12b 50 bt_trace_class *trace_class = nullptr;
1a9f7075 51
4164020e 52 /* Weak (owned by `decoder` above) */
afb0f12b 53 struct ctf_trace_class *tc = nullptr;
44c440bc 54
4164020e 55 /* Owned by this */
afb0f12b 56 char *text = nullptr;
1a9f7075 57
afb0f12b 58 int bo = 0;
56a1cced
JG
59};
60
7df773f2
SM
61struct ctf_fs_trace_deleter
62{
63 void operator()(ctf_fs_trace *) noexcept;
64};
65
4164020e
SM
66struct ctf_fs_trace
67{
7df773f2
SM
68 using UP = std::unique_ptr<ctf_fs_trace, ctf_fs_trace_deleter>;
69
0f5c5d5c
SM
70 explicit ctf_fs_trace(const bt2c::Logger& parentLogger) :
71 logger {parentLogger, "PLUGIN/SRC.CTF.FS/TRACE"}
72 {
73 }
98903a3e 74
0f5c5d5c 75 bt2c::Logger logger;
4c65a157 76
4164020e 77 /* Owned by this */
afb0f12b 78 struct ctf_fs_metadata *metadata = nullptr;
1a9f7075 79
4164020e 80 /* Owned by this */
afb0f12b 81 bt_trace *trace = nullptr;
862ca4ed 82
4164020e 83 /* Array of struct ctf_fs_ds_file_group *, owned by this */
afb0f12b 84 GPtrArray *ds_file_groups = nullptr;
94cf822e 85
4164020e 86 /* Owned by this */
afb0f12b 87 GString *path = nullptr;
1a9f7075 88
4164020e 89 /* Next automatic stream ID when not provided by packet header */
afb0f12b 90 uint64_t next_stream_id = 0;
1a9f7075
PP
91};
92
09721481
SM
93struct ctf_fs_port_data
94{
95 /* Weak, belongs to ctf_fs_trace */
96 struct ctf_fs_ds_file_group *ds_file_group = nullptr;
97
98 /* Weak */
99 struct ctf_fs_component *ctf_fs = nullptr;
100};
101
102struct ctf_fs_component_deleter
103{
104 void operator()(ctf_fs_component *);
105};
106
107struct ctf_fs_component
108{
109 using UP = std::unique_ptr<ctf_fs_component, ctf_fs_component_deleter>;
110
111 explicit ctf_fs_component(const bt2c::Logger& parentLogger) noexcept :
112 logger {parentLogger, "PLUGIN/SRC.CTF.FS/COMP"}
113 {
114 }
115
116 bt2c::Logger logger;
117
118 /* Array of struct ctf_fs_port_data *, owned by this */
119 GPtrArray *port_data = nullptr;
120
7df773f2 121 ctf_fs_trace::UP trace;
09721481
SM
122
123 ctf::src::ClkClsCfg clkClsCfg;
124};
125
4164020e
SM
126struct ctf_fs_ds_index_entry
127{
ef7d7ac2
SM
128 explicit ctf_fs_ds_index_entry(const bt2c::DataLen offsetParam,
129 const bt2c::DataLen packetSizeParam) noexcept :
130 offset(offsetParam),
131 packetSize(packetSizeParam)
132 {
133 }
134
4164020e 135 /* Weak, belongs to ctf_fs_ds_file_info. */
afb0f12b 136 const char *path = nullptr;
4164020e 137
ef7d7ac2
SM
138 /* Position of the packet from the beginning of the file. */
139 bt2c::DataLen offset;
4164020e 140
ef7d7ac2
SM
141 /* Size of the packet. */
142 bt2c::DataLen packetSize;
4164020e
SM
143
144 /*
145 * Extracted from the packet context, relative to the respective fields'
146 * mapped clock classes (in cycles).
147 */
afb0f12b 148 uint64_t timestamp_begin = 0, timestamp_end = 0;
4164020e
SM
149
150 /*
151 * Converted from the packet context, relative to the trace's EPOCH
152 * (in ns since EPOCH).
153 */
afb0f12b 154 int64_t timestamp_begin_ns = 0, timestamp_end_ns = 0;
4164020e
SM
155
156 /*
157 * Packet sequence number, or UINT64_MAX if not present in the index.
158 */
afb0f12b 159 uint64_t packet_seq_num = 0;
7ed5243a
FD
160};
161
4164020e
SM
162struct ctf_fs_ds_index
163{
164 /* Array of pointer to struct ctf_fs_ds_index_entry. */
afb0f12b 165 GPtrArray *entries = nullptr;
7ed5243a
FD
166};
167
4164020e
SM
168struct ctf_fs_ds_file_group
169{
170 /*
171 * Array of struct ctf_fs_ds_file_info, owned by this.
172 *
173 * This is an _ordered_ array of data stream file infos which
174 * belong to this group (a single stream instance).
175 *
176 * You can call ctf_fs_ds_file_create() with one of those paths
177 * and the trace IR stream below.
178 */
afb0f12b 179 GPtrArray *ds_file_infos = nullptr;
4164020e
SM
180
181 /* Owned by this */
afb0f12b 182 struct ctf_stream_class *sc = nullptr;
4164020e
SM
183
184 /* Owned by this */
afb0f12b 185 bt_stream *stream = nullptr;
4164020e
SM
186
187 /* Stream (instance) ID; -1ULL means none */
afb0f12b 188 uint64_t stream_id = 0;
4164020e
SM
189
190 /* Weak, belongs to component */
afb0f12b 191 struct ctf_fs_trace *ctf_fs_trace = nullptr;
4164020e
SM
192
193 /*
194 * Owned by this.
195 */
afb0f12b 196 struct ctf_fs_ds_index *index = nullptr;
ea0b4b9e
JG
197};
198
4164020e
SM
199struct ctf_fs_msg_iter_data
200{
0f5c5d5c
SM
201 explicit ctf_fs_msg_iter_data(bt_self_message_iterator *selfMsgIter) :
202 self_msg_iter {selfMsgIter}, logger {bt2::SelfMessageIterator {self_msg_iter},
203 "PLUGIN/SRC.CTF.FS/MSG-ITER"}
204 {
205 }
4c65a157 206
4164020e 207 /* Weak */
afb0f12b 208 bt_self_message_iterator *self_msg_iter = nullptr;
5c563278 209
0f5c5d5c
SM
210 bt2c::Logger logger;
211
4164020e 212 /* Weak, belongs to ctf_fs_trace */
afb0f12b 213 struct ctf_fs_ds_file_group *ds_file_group = nullptr;
94cf822e 214
4164020e 215 /* Owned by this */
afb0f12b 216 struct ctf_msg_iter *msg_iter = nullptr;
cbca1c06 217
4164020e
SM
218 /*
219 * Saved error. If we hit an error in the _next method, but have some
220 * messages ready to return, we save the error here and return it on
221 * the next _next call.
222 */
afb0f12b
SM
223 bt_message_iterator_class_next_method_status next_saved_status =
224 BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK;
225 const struct bt_error *next_saved_error = nullptr;
f6e68e70 226
afb0f12b 227 struct ctf_fs_ds_group_medops_data *msg_iter_medops_data = nullptr;
94cf822e
PP
228};
229
4164020e
SM
230bt_component_class_initialize_method_status
231ctf_fs_init(bt_self_component_source *source, bt_self_component_source_configuration *config,
232 const bt_value *params, void *init_method_data);
490db841 233
b19ff26f 234void ctf_fs_finalize(bt_self_component_source *component);
d3e4dcd8 235
4164020e
SM
236bt_component_class_query_method_status ctf_fs_query(bt_self_component_class_source *comp_class,
237 bt_private_query_executor *priv_query_exec,
238 const char *object, const bt_value *params,
239 void *method_data, const bt_value **result);
55314f2a 240
4164020e
SM
241bt_message_iterator_class_initialize_method_status
242ctf_fs_iterator_init(bt_self_message_iterator *self_msg_iter,
243 bt_self_message_iterator_configuration *config,
244 bt_self_component_port_output *self_port);
d94d92ac 245
d6e69534 246void ctf_fs_iterator_finalize(bt_self_message_iterator *it);
d3eb6e8f 247
4164020e
SM
248bt_message_iterator_class_next_method_status
249ctf_fs_iterator_next(bt_self_message_iterator *iterator, bt_message_array_const msgs,
250 uint64_t capacity, uint64_t *count);
d3eb6e8f 251
4164020e
SM
252bt_message_iterator_class_seek_beginning_method_status
253ctf_fs_iterator_seek_beginning(bt_self_message_iterator *message_iterator);
6a9bb5e9 254
f280892e
SM
255/* Create and initialize a new, empty ctf_fs_component. */
256
f340a3e8 257ctf_fs_component::UP ctf_fs_component_create(const bt2c::Logger& parentLogger);
f280892e
SM
258
259/*
a0cd55ad
SM
260 * Create one `struct ctf_fs_trace` from one trace, or multiple traces sharing
261 * the same UUID.
262 *
263 * `paths_value` must be an array of strings,
264 *
265 * The created `struct ctf_fs_trace` is assigned to `ctf_fs->trace`.
d23b766e
SM
266 *
267 * `self_comp` and `self_comp_class` are used for logging, only one of them
268 * should be set.
f280892e
SM
269 */
270
4164020e
SM
271int ctf_fs_component_create_ctf_fs_trace(struct ctf_fs_component *ctf_fs,
272 const bt_value *paths_value,
273 const bt_value *trace_name_value,
0f5c5d5c 274 bt_self_component *selfComp);
f280892e
SM
275
276/* Free `ctf_fs` and everything it owns. */
277
f280892e
SM
278void ctf_fs_destroy(struct ctf_fs_component *ctf_fs);
279
d907165c
SM
280/*
281 * Read and validate parameters taken by the src.ctf.fs plugin.
282 *
283 * - The mandatory `paths` parameter is returned in `*paths`.
284 * - The optional `clock-class-offset-s` and `clock-class-offset-ns`, if
285 * present, are recorded in the `ctf_fs` structure.
005d49d6
SM
286 * - The optional `trace-name` parameter is returned in `*trace_name` if
287 * present, else `*trace_name` is set to NULL.
d907165c 288 *
d23b766e
SM
289 * `self_comp` and `self_comp_class` are used for logging, only one of them
290 * should be set.
291 *
d907165c
SM
292 * Return true on success, false if any parameter didn't pass validation.
293 */
f280892e 294
4164020e 295bool read_src_fs_parameters(const bt_value *params, const bt_value **paths,
0f5c5d5c 296 const bt_value **trace_name, struct ctf_fs_component *ctf_fs);
f280892e 297
a38d7650
SM
298/*
299 * Generate the port name to be used for a given data stream file group.
a38d7650
SM
300 */
301
49b956cc 302bt2c::GCharUP ctf_fs_make_port_name(struct ctf_fs_ds_file_group *ds_file_group);
a38d7650 303
541b0a11 304#endif /* BABELTRACE_PLUGIN_CTF_FS_H */
This page took 0.119678 seconds and 4 git commands to generate.