Commit | Line | Data |
---|---|---|
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 | 23 | extern bool ctf_fs_debug; |
56a1cced | 24 | |
4164020e SM |
25 | struct 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 |
43 | struct 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 |
60 | struct ctf_fs_trace_deleter |
61 | { | |
62 | void operator()(ctf_fs_trace *) noexcept; | |
63 | }; | |
64 | ||
4164020e SM |
65 | struct 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 |
92 | struct ctf_fs_port_data |
93 | { | |
945312a2 SM |
94 | using UP = std::unique_ptr<ctf_fs_port_data>; |
95 | ||
09721481 SM |
96 | /* Weak, belongs to ctf_fs_trace */ |
97 | struct ctf_fs_ds_file_group *ds_file_group = nullptr; | |
98 | ||
99 | /* Weak */ | |
100 | struct ctf_fs_component *ctf_fs = nullptr; | |
101 | }; | |
102 | ||
103 | struct ctf_fs_component_deleter | |
104 | { | |
105 | void operator()(ctf_fs_component *); | |
106 | }; | |
107 | ||
108 | struct ctf_fs_component | |
109 | { | |
110 | using UP = std::unique_ptr<ctf_fs_component, ctf_fs_component_deleter>; | |
111 | ||
112 | explicit ctf_fs_component(const bt2c::Logger& parentLogger) noexcept : | |
113 | logger {parentLogger, "PLUGIN/SRC.CTF.FS/COMP"} | |
114 | { | |
115 | } | |
116 | ||
117 | bt2c::Logger logger; | |
118 | ||
945312a2 | 119 | std::vector<ctf_fs_port_data::UP> port_data; |
09721481 | 120 | |
7df773f2 | 121 | ctf_fs_trace::UP trace; |
09721481 SM |
122 | |
123 | ctf::src::ClkClsCfg clkClsCfg; | |
124 | }; | |
125 | ||
4164020e SM |
126 | struct ctf_fs_msg_iter_data |
127 | { | |
0f5c5d5c SM |
128 | explicit ctf_fs_msg_iter_data(bt_self_message_iterator *selfMsgIter) : |
129 | self_msg_iter {selfMsgIter}, logger {bt2::SelfMessageIterator {self_msg_iter}, | |
130 | "PLUGIN/SRC.CTF.FS/MSG-ITER"} | |
131 | { | |
132 | } | |
4c65a157 | 133 | |
4164020e | 134 | /* Weak */ |
afb0f12b | 135 | bt_self_message_iterator *self_msg_iter = nullptr; |
5c563278 | 136 | |
0f5c5d5c SM |
137 | bt2c::Logger logger; |
138 | ||
4164020e | 139 | /* Weak, belongs to ctf_fs_trace */ |
afb0f12b | 140 | struct ctf_fs_ds_file_group *ds_file_group = nullptr; |
94cf822e | 141 | |
4164020e | 142 | /* Owned by this */ |
afb0f12b | 143 | struct ctf_msg_iter *msg_iter = nullptr; |
cbca1c06 | 144 | |
4164020e SM |
145 | /* |
146 | * Saved error. If we hit an error in the _next method, but have some | |
147 | * messages ready to return, we save the error here and return it on | |
148 | * the next _next call. | |
149 | */ | |
afb0f12b SM |
150 | bt_message_iterator_class_next_method_status next_saved_status = |
151 | BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK; | |
152 | const struct bt_error *next_saved_error = nullptr; | |
f6e68e70 | 153 | |
afb0f12b | 154 | struct ctf_fs_ds_group_medops_data *msg_iter_medops_data = nullptr; |
94cf822e PP |
155 | }; |
156 | ||
4164020e SM |
157 | bt_component_class_initialize_method_status |
158 | ctf_fs_init(bt_self_component_source *source, bt_self_component_source_configuration *config, | |
159 | const bt_value *params, void *init_method_data); | |
490db841 | 160 | |
b19ff26f | 161 | void ctf_fs_finalize(bt_self_component_source *component); |
d3e4dcd8 | 162 | |
4164020e SM |
163 | bt_component_class_query_method_status ctf_fs_query(bt_self_component_class_source *comp_class, |
164 | bt_private_query_executor *priv_query_exec, | |
165 | const char *object, const bt_value *params, | |
166 | void *method_data, const bt_value **result); | |
55314f2a | 167 | |
4164020e SM |
168 | bt_message_iterator_class_initialize_method_status |
169 | ctf_fs_iterator_init(bt_self_message_iterator *self_msg_iter, | |
170 | bt_self_message_iterator_configuration *config, | |
171 | bt_self_component_port_output *self_port); | |
d94d92ac | 172 | |
d6e69534 | 173 | void ctf_fs_iterator_finalize(bt_self_message_iterator *it); |
d3eb6e8f | 174 | |
4164020e SM |
175 | bt_message_iterator_class_next_method_status |
176 | ctf_fs_iterator_next(bt_self_message_iterator *iterator, bt_message_array_const msgs, | |
177 | uint64_t capacity, uint64_t *count); | |
d3eb6e8f | 178 | |
4164020e SM |
179 | bt_message_iterator_class_seek_beginning_method_status |
180 | ctf_fs_iterator_seek_beginning(bt_self_message_iterator *message_iterator); | |
6a9bb5e9 | 181 | |
f280892e SM |
182 | /* Create and initialize a new, empty ctf_fs_component. */ |
183 | ||
f340a3e8 | 184 | ctf_fs_component::UP ctf_fs_component_create(const bt2c::Logger& parentLogger); |
f280892e SM |
185 | |
186 | /* | |
a0cd55ad SM |
187 | * Create one `struct ctf_fs_trace` from one trace, or multiple traces sharing |
188 | * the same UUID. | |
189 | * | |
190 | * `paths_value` must be an array of strings, | |
191 | * | |
192 | * The created `struct ctf_fs_trace` is assigned to `ctf_fs->trace`. | |
d23b766e SM |
193 | * |
194 | * `self_comp` and `self_comp_class` are used for logging, only one of them | |
195 | * should be set. | |
f280892e SM |
196 | */ |
197 | ||
4164020e SM |
198 | int ctf_fs_component_create_ctf_fs_trace(struct ctf_fs_component *ctf_fs, |
199 | const bt_value *paths_value, | |
200 | const bt_value *trace_name_value, | |
0f5c5d5c | 201 | bt_self_component *selfComp); |
f280892e SM |
202 | |
203 | /* Free `ctf_fs` and everything it owns. */ | |
204 | ||
f280892e SM |
205 | void ctf_fs_destroy(struct ctf_fs_component *ctf_fs); |
206 | ||
d907165c SM |
207 | /* |
208 | * Read and validate parameters taken by the src.ctf.fs plugin. | |
209 | * | |
210 | * - The mandatory `paths` parameter is returned in `*paths`. | |
211 | * - The optional `clock-class-offset-s` and `clock-class-offset-ns`, if | |
212 | * present, are recorded in the `ctf_fs` structure. | |
005d49d6 SM |
213 | * - The optional `trace-name` parameter is returned in `*trace_name` if |
214 | * present, else `*trace_name` is set to NULL. | |
d907165c | 215 | * |
d23b766e SM |
216 | * `self_comp` and `self_comp_class` are used for logging, only one of them |
217 | * should be set. | |
218 | * | |
d907165c SM |
219 | * Return true on success, false if any parameter didn't pass validation. |
220 | */ | |
f280892e | 221 | |
4164020e | 222 | bool read_src_fs_parameters(const bt_value *params, const bt_value **paths, |
0f5c5d5c | 223 | const bt_value **trace_name, struct ctf_fs_component *ctf_fs); |
f280892e | 224 | |
a38d7650 SM |
225 | /* |
226 | * Generate the port name to be used for a given data stream file group. | |
a38d7650 SM |
227 | */ |
228 | ||
49b956cc | 229 | bt2c::GCharUP ctf_fs_make_port_name(struct ctf_fs_ds_file_group *ds_file_group); |
a38d7650 | 230 | |
541b0a11 | 231 | #endif /* BABELTRACE_PLUGIN_CTF_FS_H */ |