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