2 * SPDX-License-Identifier: MIT
4 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 * Copyright 2016 Philippe Proulx <pproulx@efficios.com>
7 * BabelTrace - CTF on File System Component
10 #ifndef BABELTRACE_PLUGIN_CTF_FS_H
11 #define BABELTRACE_PLUGIN_CTF_FS_H
15 #include <babeltrace2/babeltrace.h>
17 #include "cpp-common/bt2c/glib-up.hpp"
18 #include "cpp-common/bt2c/logging.hpp"
20 #include "data-stream-file.hpp"
21 #include "plugins/ctf/common/src/metadata/tsdl/decoder.hpp"
23 extern bool ctf_fs_debug;
27 explicit ctf_fs_file(const bt2c::Logger& parentLogger) :
28 logger {parentLogger, "PLUGIN/SRC.CTF.FS/FILE"}
35 GString *path = nullptr;
43 struct ctf_fs_metadata
46 ctf_metadata_decoder_up decoder;
49 bt_trace_class *trace_class = nullptr;
51 /* Weak (owned by `decoder` above) */
52 struct ctf_trace_class *tc = nullptr;
60 struct ctf_fs_trace_deleter
62 void operator()(ctf_fs_trace *) noexcept;
67 using UP = std::unique_ptr<ctf_fs_trace, ctf_fs_trace_deleter>;
69 explicit ctf_fs_trace(const bt2c::Logger& parentLogger) :
70 logger {parentLogger, "PLUGIN/SRC.CTF.FS/TRACE"}
77 struct ctf_fs_metadata *metadata = nullptr;
80 bt_trace *trace = nullptr;
82 std::vector<ctf_fs_ds_file_group::UP> ds_file_groups;
85 GString *path = nullptr;
87 /* Next automatic stream ID when not provided by packet header */
88 uint64_t next_stream_id = 0;
91 struct ctf_fs_port_data
93 using UP = std::unique_ptr<ctf_fs_port_data>;
95 /* Weak, belongs to ctf_fs_trace */
96 struct ctf_fs_ds_file_group *ds_file_group = nullptr;
99 struct ctf_fs_component *ctf_fs = nullptr;
102 struct ctf_fs_component_deleter
104 void operator()(ctf_fs_component *);
107 struct ctf_fs_component
109 using UP = std::unique_ptr<ctf_fs_component, ctf_fs_component_deleter>;
111 explicit ctf_fs_component(const bt2c::Logger& parentLogger) noexcept :
112 logger {parentLogger, "PLUGIN/SRC.CTF.FS/COMP"}
118 std::vector<ctf_fs_port_data::UP> port_data;
120 ctf_fs_trace::UP trace;
122 ctf::src::ClkClsCfg clkClsCfg;
125 struct ctf_fs_msg_iter_data
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"}
134 bt_self_message_iterator *self_msg_iter = nullptr;
138 /* Weak, belongs to ctf_fs_trace */
139 struct ctf_fs_ds_file_group *ds_file_group = nullptr;
142 struct ctf_msg_iter *msg_iter = nullptr;
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.
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;
153 struct ctf_fs_ds_group_medops_data *msg_iter_medops_data = nullptr;
156 bt_component_class_initialize_method_status
157 ctf_fs_init(bt_self_component_source *source, bt_self_component_source_configuration *config,
158 const bt_value *params, void *init_method_data);
160 void ctf_fs_finalize(bt_self_component_source *component);
162 bt_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);
167 bt_message_iterator_class_initialize_method_status
168 ctf_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);
172 void ctf_fs_iterator_finalize(bt_self_message_iterator *it);
174 bt_message_iterator_class_next_method_status
175 ctf_fs_iterator_next(bt_self_message_iterator *iterator, bt_message_array_const msgs,
176 uint64_t capacity, uint64_t *count);
178 bt_message_iterator_class_seek_beginning_method_status
179 ctf_fs_iterator_seek_beginning(bt_self_message_iterator *message_iterator);
181 /* Create and initialize a new, empty ctf_fs_component. */
183 ctf_fs_component::UP ctf_fs_component_create(const bt2c::Logger& parentLogger);
186 * Create one `struct ctf_fs_trace` from one trace, or multiple traces sharing
189 * `paths_value` must be an array of strings,
191 * The created `struct ctf_fs_trace` is assigned to `ctf_fs->trace`.
193 * `self_comp` and `self_comp_class` are used for logging, only one of them
197 int 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,
200 bt_self_component *selfComp);
202 /* Free `ctf_fs` and everything it owns. */
204 void ctf_fs_destroy(struct ctf_fs_component *ctf_fs);
207 * Read and validate parameters taken by the src.ctf.fs plugin.
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.
212 * - The optional `trace-name` parameter is returned in `*trace_name` if
213 * present, else `*trace_name` is set to NULL.
215 * `self_comp` and `self_comp_class` are used for logging, only one of them
218 * Return true on success, false if any parameter didn't pass validation.
221 bool read_src_fs_parameters(const bt_value *params, const bt_value **paths,
222 const bt_value **trace_name, struct ctf_fs_component *ctf_fs);
225 * Generate the port name to be used for a given data stream file group.
228 bt2c::GCharUP ctf_fs_make_port_name(struct ctf_fs_ds_file_group *ds_file_group);
230 #endif /* BABELTRACE_PLUGIN_CTF_FS_H */