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