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