src.ctf.fs: make ctf_fs_ds_file_group_create return a ctf_fs_ds_file_group::UP
[babeltrace.git] / src / plugins / ctf / fs-src / fs.hpp
... / ...
CommitLineData
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 "metadata.hpp"
21#include "plugins/ctf/common/src/metadata/tsdl/decoder.hpp"
22
23extern bool ctf_fs_debug;
24
25struct 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
43struct 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
60struct ctf_fs_trace_deleter
61{
62 void operator()(ctf_fs_trace *) noexcept;
63};
64
65struct 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 /* Array of struct ctf_fs_ds_file_group *, owned by this */
83 GPtrArray *ds_file_groups = nullptr;
84
85 /* Owned by this */
86 GString *path = nullptr;
87
88 /* Next automatic stream ID when not provided by packet header */
89 uint64_t next_stream_id = 0;
90};
91
92struct ctf_fs_port_data
93{
94 using UP = std::unique_ptr<ctf_fs_port_data>;
95
96 /* Weak, belongs to ctf_fs_trace */
97 struct ctf_fs_ds_file_group *ds_file_group = nullptr;
98
99 /* Weak */
100 struct ctf_fs_component *ctf_fs = nullptr;
101};
102
103struct ctf_fs_component_deleter
104{
105 void operator()(ctf_fs_component *);
106};
107
108struct ctf_fs_component
109{
110 using UP = std::unique_ptr<ctf_fs_component, ctf_fs_component_deleter>;
111
112 explicit ctf_fs_component(const bt2c::Logger& parentLogger) noexcept :
113 logger {parentLogger, "PLUGIN/SRC.CTF.FS/COMP"}
114 {
115 }
116
117 bt2c::Logger logger;
118
119 std::vector<ctf_fs_port_data::UP> port_data;
120
121 ctf_fs_trace::UP trace;
122
123 ctf::src::ClkClsCfg clkClsCfg;
124};
125
126struct ctf_fs_msg_iter_data
127{
128 explicit ctf_fs_msg_iter_data(bt_self_message_iterator *selfMsgIter) :
129 self_msg_iter {selfMsgIter}, logger {bt2::SelfMessageIterator {self_msg_iter},
130 "PLUGIN/SRC.CTF.FS/MSG-ITER"}
131 {
132 }
133
134 /* Weak */
135 bt_self_message_iterator *self_msg_iter = nullptr;
136
137 bt2c::Logger logger;
138
139 /* Weak, belongs to ctf_fs_trace */
140 struct ctf_fs_ds_file_group *ds_file_group = nullptr;
141
142 /* Owned by this */
143 struct ctf_msg_iter *msg_iter = nullptr;
144
145 /*
146 * Saved error. If we hit an error in the _next method, but have some
147 * messages ready to return, we save the error here and return it on
148 * the next _next call.
149 */
150 bt_message_iterator_class_next_method_status next_saved_status =
151 BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK;
152 const struct bt_error *next_saved_error = nullptr;
153
154 struct ctf_fs_ds_group_medops_data *msg_iter_medops_data = nullptr;
155};
156
157bt_component_class_initialize_method_status
158ctf_fs_init(bt_self_component_source *source, bt_self_component_source_configuration *config,
159 const bt_value *params, void *init_method_data);
160
161void ctf_fs_finalize(bt_self_component_source *component);
162
163bt_component_class_query_method_status ctf_fs_query(bt_self_component_class_source *comp_class,
164 bt_private_query_executor *priv_query_exec,
165 const char *object, const bt_value *params,
166 void *method_data, const bt_value **result);
167
168bt_message_iterator_class_initialize_method_status
169ctf_fs_iterator_init(bt_self_message_iterator *self_msg_iter,
170 bt_self_message_iterator_configuration *config,
171 bt_self_component_port_output *self_port);
172
173void ctf_fs_iterator_finalize(bt_self_message_iterator *it);
174
175bt_message_iterator_class_next_method_status
176ctf_fs_iterator_next(bt_self_message_iterator *iterator, bt_message_array_const msgs,
177 uint64_t capacity, uint64_t *count);
178
179bt_message_iterator_class_seek_beginning_method_status
180ctf_fs_iterator_seek_beginning(bt_self_message_iterator *message_iterator);
181
182/* Create and initialize a new, empty ctf_fs_component. */
183
184ctf_fs_component::UP ctf_fs_component_create(const bt2c::Logger& parentLogger);
185
186/*
187 * Create one `struct ctf_fs_trace` from one trace, or multiple traces sharing
188 * the same UUID.
189 *
190 * `paths_value` must be an array of strings,
191 *
192 * The created `struct ctf_fs_trace` is assigned to `ctf_fs->trace`.
193 *
194 * `self_comp` and `self_comp_class` are used for logging, only one of them
195 * should be set.
196 */
197
198int ctf_fs_component_create_ctf_fs_trace(struct ctf_fs_component *ctf_fs,
199 const bt_value *paths_value,
200 const bt_value *trace_name_value,
201 bt_self_component *selfComp);
202
203/* Free `ctf_fs` and everything it owns. */
204
205void ctf_fs_destroy(struct ctf_fs_component *ctf_fs);
206
207/*
208 * Read and validate parameters taken by the src.ctf.fs plugin.
209 *
210 * - The mandatory `paths` parameter is returned in `*paths`.
211 * - The optional `clock-class-offset-s` and `clock-class-offset-ns`, if
212 * present, are recorded in the `ctf_fs` structure.
213 * - The optional `trace-name` parameter is returned in `*trace_name` if
214 * present, else `*trace_name` is set to NULL.
215 *
216 * `self_comp` and `self_comp_class` are used for logging, only one of them
217 * should be set.
218 *
219 * Return true on success, false if any parameter didn't pass validation.
220 */
221
222bool read_src_fs_parameters(const bt_value *params, const bt_value **paths,
223 const bt_value **trace_name, struct ctf_fs_component *ctf_fs);
224
225/*
226 * Generate the port name to be used for a given data stream file group.
227 */
228
229bt2c::GCharUP ctf_fs_make_port_name(struct ctf_fs_ds_file_group *ds_file_group);
230
231#endif /* BABELTRACE_PLUGIN_CTF_FS_H */
This page took 0.039839 seconds and 4 git commands to generate.