src.ctf.fs: move `ctf_fs_ds_*` structures and functions to data-stream-file.hpp
[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
49b956cc 17#include "cpp-common/bt2c/glib-up.hpp"
0f5c5d5c
SM
18#include "cpp-common/bt2c/logging.hpp"
19
087cd0f5 20#include "metadata.hpp"
1fa280c9 21#include "plugins/ctf/common/src/metadata/tsdl/decoder.hpp"
490db841 22
78bb6992 23extern bool ctf_fs_debug;
56a1cced 24
4164020e
SM
25struct ctf_fs_file
26{
0f5c5d5c
SM
27 explicit ctf_fs_file(const bt2c::Logger& parentLogger) :
28 logger {parentLogger, "PLUGIN/SRC.CTF.FS/FILE"}
29 {
30 }
98903a3e 31
0f5c5d5c 32 bt2c::Logger logger;
4c65a157 33
4164020e 34 /* Owned by this */
afb0f12b 35 GString *path = nullptr;
1a9f7075 36
4164020e 37 /* Owned by this */
afb0f12b 38 FILE *fp = nullptr;
1a9f7075 39
afb0f12b 40 off_t size = 0;
56a1cced
JG
41};
42
4164020e
SM
43struct ctf_fs_metadata
44{
45 /* Owned by this */
1fa280c9 46 ctf_metadata_decoder_up decoder;
44c440bc 47
4164020e 48 /* Owned by this */
afb0f12b 49 bt_trace_class *trace_class = nullptr;
1a9f7075 50
4164020e 51 /* Weak (owned by `decoder` above) */
afb0f12b 52 struct ctf_trace_class *tc = nullptr;
44c440bc 53
4164020e 54 /* Owned by this */
afb0f12b 55 char *text = nullptr;
1a9f7075 56
afb0f12b 57 int bo = 0;
56a1cced
JG
58};
59
7df773f2
SM
60struct ctf_fs_trace_deleter
61{
62 void operator()(ctf_fs_trace *) noexcept;
63};
64
4164020e
SM
65struct ctf_fs_trace
66{
7df773f2
SM
67 using UP = std::unique_ptr<ctf_fs_trace, ctf_fs_trace_deleter>;
68
0f5c5d5c
SM
69 explicit ctf_fs_trace(const bt2c::Logger& parentLogger) :
70 logger {parentLogger, "PLUGIN/SRC.CTF.FS/TRACE"}
71 {
72 }
98903a3e 73
0f5c5d5c 74 bt2c::Logger logger;
4c65a157 75
4164020e 76 /* Owned by this */
afb0f12b 77 struct ctf_fs_metadata *metadata = nullptr;
1a9f7075 78
4164020e 79 /* Owned by this */
afb0f12b 80 bt_trace *trace = nullptr;
862ca4ed 81
4164020e 82 /* Array of struct ctf_fs_ds_file_group *, owned by this */
afb0f12b 83 GPtrArray *ds_file_groups = nullptr;
94cf822e 84
4164020e 85 /* Owned by this */
afb0f12b 86 GString *path = nullptr;
1a9f7075 87
4164020e 88 /* Next automatic stream ID when not provided by packet header */
afb0f12b 89 uint64_t next_stream_id = 0;
1a9f7075
PP
90};
91
09721481
SM
92struct ctf_fs_port_data
93{
94 /* Weak, belongs to ctf_fs_trace */
95 struct ctf_fs_ds_file_group *ds_file_group = nullptr;
96
97 /* Weak */
98 struct ctf_fs_component *ctf_fs = nullptr;
99};
100
101struct ctf_fs_component_deleter
102{
103 void operator()(ctf_fs_component *);
104};
105
106struct ctf_fs_component
107{
108 using UP = std::unique_ptr<ctf_fs_component, ctf_fs_component_deleter>;
109
110 explicit ctf_fs_component(const bt2c::Logger& parentLogger) noexcept :
111 logger {parentLogger, "PLUGIN/SRC.CTF.FS/COMP"}
112 {
113 }
114
115 bt2c::Logger logger;
116
117 /* Array of struct ctf_fs_port_data *, owned by this */
118 GPtrArray *port_data = nullptr;
119
7df773f2 120 ctf_fs_trace::UP trace;
09721481
SM
121
122 ctf::src::ClkClsCfg clkClsCfg;
123};
124
4164020e
SM
125struct ctf_fs_msg_iter_data
126{
0f5c5d5c
SM
127 explicit ctf_fs_msg_iter_data(bt_self_message_iterator *selfMsgIter) :
128 self_msg_iter {selfMsgIter}, logger {bt2::SelfMessageIterator {self_msg_iter},
129 "PLUGIN/SRC.CTF.FS/MSG-ITER"}
130 {
131 }
4c65a157 132
4164020e 133 /* Weak */
afb0f12b 134 bt_self_message_iterator *self_msg_iter = nullptr;
5c563278 135
0f5c5d5c
SM
136 bt2c::Logger logger;
137
4164020e 138 /* Weak, belongs to ctf_fs_trace */
afb0f12b 139 struct ctf_fs_ds_file_group *ds_file_group = nullptr;
94cf822e 140
4164020e 141 /* Owned by this */
afb0f12b 142 struct ctf_msg_iter *msg_iter = nullptr;
cbca1c06 143
4164020e
SM
144 /*
145 * Saved error. If we hit an error in the _next method, but have some
146 * messages ready to return, we save the error here and return it on
147 * the next _next call.
148 */
afb0f12b
SM
149 bt_message_iterator_class_next_method_status next_saved_status =
150 BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK;
151 const struct bt_error *next_saved_error = nullptr;
f6e68e70 152
afb0f12b 153 struct ctf_fs_ds_group_medops_data *msg_iter_medops_data = nullptr;
94cf822e
PP
154};
155
4164020e
SM
156bt_component_class_initialize_method_status
157ctf_fs_init(bt_self_component_source *source, bt_self_component_source_configuration *config,
158 const bt_value *params, void *init_method_data);
490db841 159
b19ff26f 160void ctf_fs_finalize(bt_self_component_source *component);
d3e4dcd8 161
4164020e
SM
162bt_component_class_query_method_status ctf_fs_query(bt_self_component_class_source *comp_class,
163 bt_private_query_executor *priv_query_exec,
164 const char *object, const bt_value *params,
165 void *method_data, const bt_value **result);
55314f2a 166
4164020e
SM
167bt_message_iterator_class_initialize_method_status
168ctf_fs_iterator_init(bt_self_message_iterator *self_msg_iter,
169 bt_self_message_iterator_configuration *config,
170 bt_self_component_port_output *self_port);
d94d92ac 171
d6e69534 172void ctf_fs_iterator_finalize(bt_self_message_iterator *it);
d3eb6e8f 173
4164020e
SM
174bt_message_iterator_class_next_method_status
175ctf_fs_iterator_next(bt_self_message_iterator *iterator, bt_message_array_const msgs,
176 uint64_t capacity, uint64_t *count);
d3eb6e8f 177
4164020e
SM
178bt_message_iterator_class_seek_beginning_method_status
179ctf_fs_iterator_seek_beginning(bt_self_message_iterator *message_iterator);
6a9bb5e9 180
f280892e
SM
181/* Create and initialize a new, empty ctf_fs_component. */
182
f340a3e8 183ctf_fs_component::UP ctf_fs_component_create(const bt2c::Logger& parentLogger);
f280892e
SM
184
185/*
a0cd55ad
SM
186 * Create one `struct ctf_fs_trace` from one trace, or multiple traces sharing
187 * the same UUID.
188 *
189 * `paths_value` must be an array of strings,
190 *
191 * The created `struct ctf_fs_trace` is assigned to `ctf_fs->trace`.
d23b766e
SM
192 *
193 * `self_comp` and `self_comp_class` are used for logging, only one of them
194 * should be set.
f280892e
SM
195 */
196
4164020e
SM
197int ctf_fs_component_create_ctf_fs_trace(struct ctf_fs_component *ctf_fs,
198 const bt_value *paths_value,
199 const bt_value *trace_name_value,
0f5c5d5c 200 bt_self_component *selfComp);
f280892e
SM
201
202/* Free `ctf_fs` and everything it owns. */
203
f280892e
SM
204void ctf_fs_destroy(struct ctf_fs_component *ctf_fs);
205
d907165c
SM
206/*
207 * Read and validate parameters taken by the src.ctf.fs plugin.
208 *
209 * - The mandatory `paths` parameter is returned in `*paths`.
210 * - The optional `clock-class-offset-s` and `clock-class-offset-ns`, if
211 * present, are recorded in the `ctf_fs` structure.
005d49d6
SM
212 * - The optional `trace-name` parameter is returned in `*trace_name` if
213 * present, else `*trace_name` is set to NULL.
d907165c 214 *
d23b766e
SM
215 * `self_comp` and `self_comp_class` are used for logging, only one of them
216 * should be set.
217 *
d907165c
SM
218 * Return true on success, false if any parameter didn't pass validation.
219 */
f280892e 220
4164020e 221bool read_src_fs_parameters(const bt_value *params, const bt_value **paths,
0f5c5d5c 222 const bt_value **trace_name, struct ctf_fs_component *ctf_fs);
f280892e 223
a38d7650
SM
224/*
225 * Generate the port name to be used for a given data stream file group.
a38d7650
SM
226 */
227
49b956cc 228bt2c::GCharUP ctf_fs_make_port_name(struct ctf_fs_ds_file_group *ds_file_group);
a38d7650 229
541b0a11 230#endif /* BABELTRACE_PLUGIN_CTF_FS_H */
This page took 0.110858 seconds and 4 git commands to generate.