src.ctf.fs: make ctf_fs_ds_index_create return a unique_ptr
[babeltrace.git] / src / plugins / ctf / fs-src / data-stream-file.hpp
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright (C) 2016 Philippe Proulx <pproulx@efficios.com>
5 */
6
7 #ifndef CTF_FS_DS_FILE_H
8 #define CTF_FS_DS_FILE_H
9
10 #include <memory>
11 #include <string>
12 #include <vector>
13
14 #include <glib.h>
15 #include <stdio.h>
16
17 #include <babeltrace2/babeltrace.h>
18
19 #include "cpp-common/bt2c/data-len.hpp"
20 #include "cpp-common/bt2c/logging.hpp"
21
22 #include "../common/src/msg-iter/msg-iter.hpp"
23
24 struct ctf_fs_ds_file_info
25 {
26 using UP = std::unique_ptr<ctf_fs_ds_file_info>;
27
28 std::string path;
29
30 /* Guaranteed to be set, as opposed to the index. */
31 int64_t begin_ns = 0;
32 };
33
34 struct ctf_fs_ds_file
35 {
36 explicit ctf_fs_ds_file(const bt2c::Logger& parentLogger) :
37 logger {parentLogger, "PLUGIN/SRC.CTF.FS/DS"}
38 {
39 }
40
41 bt2c::Logger logger;
42
43 /* Weak */
44 struct ctf_fs_metadata *metadata = nullptr;
45
46 /* Owned by this */
47 struct ctf_fs_file *file = nullptr;
48
49 /* Owned by this */
50 bt_stream *stream = nullptr;
51
52 void *mmap_addr = nullptr;
53
54 /*
55 * Max length of chunk to mmap() when updating the current mapping.
56 * This value must be page-aligned.
57 */
58 size_t mmap_max_len = 0;
59
60 /* Length of the current mapping. Never exceeds the file's length. */
61 size_t mmap_len = 0;
62
63 /* Offset in the file where the current mapping starts. */
64 off_t mmap_offset_in_file = 0;
65
66 /*
67 * Offset, in the current mapping, of the address to return on the next
68 * request.
69 */
70 off_t request_offset_in_mapping = 0;
71 };
72
73 struct ctf_fs_ds_index_entry
74 {
75 explicit ctf_fs_ds_index_entry(const bt2c::DataLen offsetParam,
76 const bt2c::DataLen packetSizeParam) noexcept :
77 offset(offsetParam),
78 packetSize(packetSizeParam)
79 {
80 }
81
82 /* Weak, belongs to ctf_fs_ds_file_info. */
83 const char *path = nullptr;
84
85 /* Position of the packet from the beginning of the file. */
86 bt2c::DataLen offset;
87
88 /* Size of the packet. */
89 bt2c::DataLen packetSize;
90
91 /*
92 * Extracted from the packet context, relative to the respective fields'
93 * mapped clock classes (in cycles).
94 */
95 uint64_t timestamp_begin = 0, timestamp_end = 0;
96
97 /*
98 * Converted from the packet context, relative to the trace's EPOCH
99 * (in ns since EPOCH).
100 */
101 int64_t timestamp_begin_ns = 0, timestamp_end_ns = 0;
102
103 /*
104 * Packet sequence number, or UINT64_MAX if not present in the index.
105 */
106 uint64_t packet_seq_num = 0;
107 };
108
109 struct ctf_fs_ds_index_deleter
110 {
111 void operator()(struct ctf_fs_ds_index *index) noexcept;
112 };
113
114 struct ctf_fs_ds_index
115 {
116 using UP = std::unique_ptr<ctf_fs_ds_index, ctf_fs_ds_index_deleter>;
117
118 /* Array of pointer to struct ctf_fs_ds_index_entry. */
119 GPtrArray *entries = nullptr;
120 };
121
122 struct ctf_fs_ds_file_group_deleter
123 {
124 void operator()(struct ctf_fs_ds_file_group *group) noexcept;
125 };
126
127 struct ctf_fs_ds_file_group
128 {
129 using UP = std::unique_ptr<ctf_fs_ds_file_group, ctf_fs_ds_file_group_deleter>;
130
131 /*
132 * This is an _ordered_ array of data stream file infos which
133 * belong to this group (a single stream instance).
134 *
135 * You can call ctf_fs_ds_file_create() with one of those paths
136 * and the trace IR stream below.
137 */
138 std::vector<ctf_fs_ds_file_info::UP> ds_file_infos;
139
140 /* Owned by this */
141 struct ctf_stream_class *sc = nullptr;
142
143 /* Owned by this */
144 bt_stream *stream = nullptr;
145
146 /* Stream (instance) ID; -1ULL means none */
147 uint64_t stream_id = 0;
148
149 /* Weak, belongs to component */
150 struct ctf_fs_trace *ctf_fs_trace = nullptr;
151
152 /*
153 * Owned by this.
154 */
155 struct ctf_fs_ds_index *index = nullptr;
156 };
157
158 struct ctf_fs_ds_file *ctf_fs_ds_file_create(struct ctf_fs_trace *ctf_fs_trace, bt_stream *stream,
159 const char *path, const bt2c::Logger& logger);
160
161 void ctf_fs_ds_file_destroy(struct ctf_fs_ds_file *stream);
162
163 ctf_fs_ds_index::UP ctf_fs_ds_file_build_index(struct ctf_fs_ds_file *ds_file,
164 struct ctf_fs_ds_file_info *ds_file_info,
165 struct ctf_msg_iter *msg_iter);
166
167 ctf_fs_ds_index::UP ctf_fs_ds_index_create(const bt2c::Logger& logger);
168
169 void ctf_fs_ds_index_destroy(struct ctf_fs_ds_index *index);
170
171 ctf_fs_ds_file_info::UP ctf_fs_ds_file_info_create(const char *path, int64_t begin_ns);
172
173 ctf_fs_ds_file_group::UP ctf_fs_ds_file_group_create(struct ctf_fs_trace *ctf_fs_trace,
174 struct ctf_stream_class *sc,
175 uint64_t stream_instance_id,
176 struct ctf_fs_ds_index *index);
177
178 /*
179 * Medium operations to iterate on a single ctf_fs_ds_file.
180 *
181 * The data pointer when using this must be a pointer to the ctf_fs_ds_file.
182 */
183 extern struct ctf_msg_iter_medium_ops ctf_fs_ds_file_medops;
184
185 /*
186 * Medium operations to iterate on the packet of a ctf_fs_ds_group.
187 *
188 * The iteration is done based on the index of the group.
189 *
190 * The data pointer when using these medops must be a pointer to a ctf_fs_ds
191 * group_medops_data structure.
192 */
193 extern struct ctf_msg_iter_medium_ops ctf_fs_ds_group_medops;
194
195 enum ctf_msg_iter_medium_status ctf_fs_ds_group_medops_data_create(
196 struct ctf_fs_ds_file_group *ds_file_group, bt_self_message_iterator *self_msg_iter,
197 const bt2c::Logger& logger, struct ctf_fs_ds_group_medops_data **out);
198
199 void ctf_fs_ds_group_medops_data_reset(struct ctf_fs_ds_group_medops_data *data);
200
201 void ctf_fs_ds_group_medops_data_destroy(struct ctf_fs_ds_group_medops_data *data);
202
203 #endif /* CTF_FS_DS_FILE_H */
This page took 0.03557 seconds and 4 git commands to generate.