src.ctf.fs: make ctf_fs_ds_group_medops_data_create return a unique_ptr
[deliverable/babeltrace.git] / src / plugins / ctf / fs-src / data-stream-file.hpp
CommitLineData
e98a2d6e 1/*
0235b0db 2 * SPDX-License-Identifier: MIT
e98a2d6e 3 *
0235b0db 4 * Copyright (C) 2016 Philippe Proulx <pproulx@efficios.com>
e98a2d6e
PP
5 */
6
0235b0db
MJ
7#ifndef CTF_FS_DS_FILE_H
8#define CTF_FS_DS_FILE_H
9
e98a2d6e 10#include <stdio.h>
94cf822e 11#include <stdbool.h>
e98a2d6e 12#include <glib.h>
f0ab0592 13#include <memory>
473546f5 14#include <string>
91d81473 15#include "common/macros.h"
3fadfbc0 16#include <babeltrace2/babeltrace.h>
49befcfd 17#include <vector>
e98a2d6e 18
364f5320 19#include "../common/src/msg-iter/msg-iter.hpp"
0b067334 20#include "cpp-common/data-len.hpp"
087cd0f5 21#include "lttng-index.hpp"
27a14e13 22#include "cpp-common/log-cfg.hpp"
17d8205a 23#include "cpp-common/bt2/trace-ir.hpp"
2d54e7ff 24#include "file.hpp"
b6c3dcb2
JG
25
26struct ctf_fs_component;
27struct ctf_fs_file;
1a9f7075 28struct ctf_fs_trace;
f6e68e70 29struct ctf_fs_ds_group_medops_data;
b6c3dcb2 30
4164020e
SM
31struct ctf_fs_ds_file_info
32{
f2b5ec1f
SM
33 using UP = std::unique_ptr<ctf_fs_ds_file_info>;
34
473546f5 35 std::string path;
97ade20b 36
4164020e 37 /* Guaranteed to be set, as opposed to the index. */
6269f212 38 int64_t begin_ns = 0;
97ade20b
JG
39};
40
44c440bc
PP
41struct ctf_fs_metadata;
42
4164020e
SM
43struct ctf_fs_ds_file
44{
6d0b3c49
SM
45 using UP = std::unique_ptr<ctf_fs_ds_file>;
46
27a14e13
SM
47 explicit ctf_fs_ds_file(const bt2_common::LogCfg& logCfgParam) noexcept : logCfg {logCfgParam}
48 {
49 }
98903a3e 50
42871aa4
SM
51 ~ctf_fs_ds_file();
52
27a14e13 53 const bt2_common::LogCfg logCfg;
4c65a157 54
4164020e 55 /* Weak */
6269f212 56 struct ctf_fs_metadata *metadata = nullptr;
5c563278 57
2d54e7ff 58 ctf_fs_file::UP file;
97ade20b 59
4164020e 60 /* Owned by this */
22c7ae6c 61 nonstd::optional<bt2::Stream::Shared> stream;
97ade20b 62
6269f212 63 void *mmap_addr = nullptr;
97ade20b 64
4164020e
SM
65 /*
66 * Max length of chunk to mmap() when updating the current mapping.
67 * This value must be page-aligned.
68 */
6269f212 69 size_t mmap_max_len = 0;
97ade20b 70
4164020e 71 /* Length of the current mapping. Never exceeds the file's length. */
6269f212 72 size_t mmap_len = 0;
97ade20b 73
4164020e 74 /* Offset in the file where the current mapping starts. */
6269f212 75 off_t mmap_offset_in_file = 0;
97ade20b 76
4164020e
SM
77 /*
78 * Offset, in the current mapping, of the address to return on the next
79 * request.
80 */
6269f212 81 off_t request_offset_in_mapping = 0;
b6c3dcb2 82};
e98a2d6e 83
0b067334
SM
84struct ctf_fs_ds_index_entry
85{
3b5041e6
SM
86 using UP = std::unique_ptr<ctf_fs_ds_index_entry>;
87
0b067334
SM
88 ctf_fs_ds_index_entry(bt2_common::DataLen offsetParam, bt2_common::DataLen packetSizeParam) :
89 offset(offsetParam), packetSize(packetSizeParam)
90 {
91 }
92
93 /* Weak, belongs to ctf_fs_ds_file_info. */
94 const char *path = nullptr;
95
96 /* Position of the packet from the beginning of the file. */
97 const bt2_common::DataLen offset;
98
99 /* Size of the packet. */
100 const bt2_common::DataLen packetSize;
101
102 /*
103 * Extracted from the packet context, relative to the respective fields'
104 * mapped clock classes (in cycles).
105 */
106 uint64_t timestamp_begin = 0, timestamp_end = 0;
107
108 /*
109 * Converted from the packet context, relative to the trace's EPOCH
110 * (in ns since EPOCH).
111 */
112 int64_t timestamp_begin_ns = 0, timestamp_end_ns = 0;
113
114 /*
115 * Packet sequence number, or UINT64_MAX if not present in the index.
116 */
117 uint64_t packet_seq_num = 0;
118};
119
120struct ctf_fs_ds_index
121{
aa463ab6 122 using UP = std::unique_ptr<ctf_fs_ds_index>;
11e6a045 123
5ce40cf7 124 std::vector<ctf_fs_ds_index_entry::UP> entries;
0b067334
SM
125};
126
127struct ctf_fs_ds_file_group
128{
1857ccb8 129 using UP = std::unique_ptr<ctf_fs_ds_file_group>;
f0ab0592 130
0b067334 131 /*
0b067334
SM
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 */
49befcfd 138 std::vector<ctf_fs_ds_file_info::UP> ds_file_infos;
0b067334
SM
139
140 /* Owned by this */
141 struct ctf_stream_class *sc = nullptr;
142
143 /* Owned by this */
17d8205a 144 nonstd::optional<bt2::Stream::Shared> stream;
0b067334
SM
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
6cde7b05 152 ctf_fs_ds_index::UP index;
0b067334
SM
153};
154
e98a2d6e 155BT_HIDDEN
6d0b3c49
SM
156ctf_fs_ds_file::UP ctf_fs_ds_file_create(struct ctf_fs_trace *ctf_fs_trace,
157 nonstd::optional<bt2::Stream::Shared> stream,
158 const char *path, const bt2_common::LogCfg& logCfg);
e98a2d6e 159
97ade20b 160BT_HIDDEN
11e6a045
SM
161ctf_fs_ds_index::UP ctf_fs_ds_file_build_index(struct ctf_fs_ds_file *ds_file,
162 struct ctf_fs_ds_file_info *ds_file_info,
163 struct ctf_msg_iter *msg_iter);
97ade20b 164
7ed5243a 165BT_HIDDEN
11e6a045 166ctf_fs_ds_index::UP ctf_fs_ds_index_create(const bt2_common::LogCfg& logCfg);
7ed5243a 167
f2b5ec1f 168BT_HIDDEN ctf_fs_ds_file_info::UP ctf_fs_ds_file_info_create(const char *path, int64_t begin_ns);
0b067334 169
f0ab0592
SM
170BT_HIDDEN ctf_fs_ds_file_group::UP ctf_fs_ds_file_group_create(struct ctf_fs_trace *ctf_fs_trace,
171 struct ctf_stream_class *sc,
172 uint64_t stream_instance_id,
6cde7b05 173 ctf_fs_ds_index::UP index);
0b067334 174
f6e68e70
SM
175/*
176 * Medium operations to iterate on a single ctf_fs_ds_file.
177 *
178 * The data pointer when using this must be a pointer to the ctf_fs_ds_file.
179 */
18a1979b 180extern struct ctf_msg_iter_medium_ops ctf_fs_ds_file_medops;
6de92955 181
f6e68e70
SM
182/*
183 * Medium operations to iterate on the packet of a ctf_fs_ds_group.
184 *
185 * The iteration is done based on the index of the group.
186 *
187 * The data pointer when using these medops must be a pointer to a ctf_fs_ds
188 * group_medops_data structure.
189 */
dfcb42a6 190BT_HIDDEN
f6e68e70
SM
191extern struct ctf_msg_iter_medium_ops ctf_fs_ds_group_medops;
192
37638dce
SM
193struct ctf_fs_ds_group_medops_data_deleter
194{
195 void operator()(ctf_fs_ds_group_medops_data *data);
196};
197
198using ctf_fs_ds_group_medops_data_up =
199 std::unique_ptr<ctf_fs_ds_group_medops_data, ctf_fs_ds_group_medops_data_deleter>;
200
f6e68e70
SM
201BT_HIDDEN
202enum ctf_msg_iter_medium_status ctf_fs_ds_group_medops_data_create(
4164020e 203 struct ctf_fs_ds_file_group *ds_file_group, bt_self_message_iterator *self_msg_iter,
37638dce 204 const bt2_common::LogCfg& logCfg, ctf_fs_ds_group_medops_data_up& out);
f6e68e70
SM
205
206BT_HIDDEN
207void ctf_fs_ds_group_medops_data_reset(struct ctf_fs_ds_group_medops_data *data);
208
209BT_HIDDEN
4164020e 210void ctf_fs_ds_group_medops_data_destroy(struct ctf_fs_ds_group_medops_data *data);
f6e68e70 211
94cf822e 212#endif /* CTF_FS_DS_FILE_H */
This page took 0.075702 seconds and 5 git commands to generate.