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