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