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