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