src.ctf.fs: make ctf_fs_trace::ds_file_groups a vector of ctf_fs_ds_file_group::UP
[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 "data-stream-file.hpp"
21 #include "plugins/ctf/common/src/metadata/tsdl/decoder.hpp"
22
23 extern bool ctf_fs_debug;
24
25 struct ctf_fs_file
26 {
27 explicit ctf_fs_file(const bt2c::Logger& parentLogger) :
28 logger {parentLogger, "PLUGIN/SRC.CTF.FS/FILE"}
29 {
30 }
31
32 bt2c::Logger logger;
33
34 /* Owned by this */
35 GString *path = nullptr;
36
37 /* Owned by this */
38 FILE *fp = nullptr;
39
40 off_t size = 0;
41 };
42
43 struct ctf_fs_metadata
44 {
45 /* Owned by this */
46 ctf_metadata_decoder_up decoder;
47
48 /* Owned by this */
49 bt_trace_class *trace_class = nullptr;
50
51 /* Weak (owned by `decoder` above) */
52 struct ctf_trace_class *tc = nullptr;
53
54 /* Owned by this */
55 char *text = nullptr;
56
57 int bo = 0;
58 };
59
60 struct ctf_fs_trace_deleter
61 {
62 void operator()(ctf_fs_trace *) noexcept;
63 };
64
65 struct ctf_fs_trace
66 {
67 using UP = std::unique_ptr<ctf_fs_trace, ctf_fs_trace_deleter>;
68
69 explicit ctf_fs_trace(const bt2c::Logger& parentLogger) :
70 logger {parentLogger, "PLUGIN/SRC.CTF.FS/TRACE"}
71 {
72 }
73
74 bt2c::Logger logger;
75
76 /* Owned by this */
77 struct ctf_fs_metadata *metadata = nullptr;
78
79 /* Owned by this */
80 bt_trace *trace = nullptr;
81
82 std::vector<ctf_fs_ds_file_group::UP> ds_file_groups;
83
84 /* Owned by this */
85 GString *path = nullptr;
86
87 /* Next automatic stream ID when not provided by packet header */
88 uint64_t next_stream_id = 0;
89 };
90
91 struct ctf_fs_port_data
92 {
93 using UP = std::unique_ptr<ctf_fs_port_data>;
94
95 /* Weak, belongs to ctf_fs_trace */
96 struct ctf_fs_ds_file_group *ds_file_group = nullptr;
97
98 /* Weak */
99 struct ctf_fs_component *ctf_fs = nullptr;
100 };
101
102 struct ctf_fs_component_deleter
103 {
104 void operator()(ctf_fs_component *);
105 };
106
107 struct ctf_fs_component
108 {
109 using UP = std::unique_ptr<ctf_fs_component, ctf_fs_component_deleter>;
110
111 explicit ctf_fs_component(const bt2c::Logger& parentLogger) noexcept :
112 logger {parentLogger, "PLUGIN/SRC.CTF.FS/COMP"}
113 {
114 }
115
116 bt2c::Logger logger;
117
118 std::vector<ctf_fs_port_data::UP> port_data;
119
120 ctf_fs_trace::UP trace;
121
122 ctf::src::ClkClsCfg clkClsCfg;
123 };
124
125 struct ctf_fs_msg_iter_data
126 {
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"}
130 {
131 }
132
133 /* Weak */
134 bt_self_message_iterator *self_msg_iter = nullptr;
135
136 bt2c::Logger logger;
137
138 /* Weak, belongs to ctf_fs_trace */
139 struct ctf_fs_ds_file_group *ds_file_group = nullptr;
140
141 /* Owned by this */
142 struct ctf_msg_iter *msg_iter = nullptr;
143
144 /*
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.
148 */
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;
152
153 struct ctf_fs_ds_group_medops_data *msg_iter_medops_data = nullptr;
154 };
155
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);
159
160 void ctf_fs_finalize(bt_self_component_source *component);
161
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);
166
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);
171
172 void ctf_fs_iterator_finalize(bt_self_message_iterator *it);
173
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);
177
178 bt_message_iterator_class_seek_beginning_method_status
179 ctf_fs_iterator_seek_beginning(bt_self_message_iterator *message_iterator);
180
181 /* Create and initialize a new, empty ctf_fs_component. */
182
183 ctf_fs_component::UP ctf_fs_component_create(const bt2c::Logger& parentLogger);
184
185 /*
186 * Create one `struct ctf_fs_trace` from one trace, or multiple traces sharing
187 * the same UUID.
188 *
189 * `paths_value` must be an array of strings,
190 *
191 * The created `struct ctf_fs_trace` is assigned to `ctf_fs->trace`.
192 *
193 * `self_comp` and `self_comp_class` are used for logging, only one of them
194 * should be set.
195 */
196
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);
201
202 /* Free `ctf_fs` and everything it owns. */
203
204 void ctf_fs_destroy(struct ctf_fs_component *ctf_fs);
205
206 /*
207 * Read and validate parameters taken by the src.ctf.fs plugin.
208 *
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.
214 *
215 * `self_comp` and `self_comp_class` are used for logging, only one of them
216 * should be set.
217 *
218 * Return true on success, false if any parameter didn't pass validation.
219 */
220
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);
223
224 /*
225 * Generate the port name to be used for a given data stream file group.
226 */
227
228 bt2c::GCharUP ctf_fs_make_port_name(struct ctf_fs_ds_file_group *ds_file_group);
229
230 #endif /* BABELTRACE_PLUGIN_CTF_FS_H */
This page took 0.033365 seconds and 4 git commands to generate.