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