Sort includes in C++ files
[babeltrace.git] / src / plugins / ctf / fs-sink / fs-sink-stream.hpp
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright 2019 Philippe Proulx <pproulx@efficios.com>
5 */
6
7 #ifndef BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_STREAM_H
8 #define BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_STREAM_H
9
10 #include <glib.h>
11 #include <stdbool.h>
12 #include <stdint.h>
13
14 #include <babeltrace2/babeltrace.h>
15
16 #include "common/macros.h"
17 #include "ctfser/ctfser.h"
18
19 #include "fs-sink-ctf-meta.hpp"
20
21 struct fs_sink_trace;
22
23 struct fs_sink_stream
24 {
25 bt_logging_level log_level;
26 struct fs_sink_trace *trace;
27 struct bt_ctfser ctfser;
28
29 /* Stream's file name */
30 GString *file_name;
31
32 /* Weak */
33 const bt_stream *ir_stream;
34
35 struct fs_sink_ctf_stream_class *sc;
36
37 /* Current packet's state */
38 struct
39 {
40 /*
41 * True if we're, for this stream, within an opened
42 * packet (got a packet beginning message, but no
43 * packet end message yet).
44 */
45 bool is_open;
46
47 /*
48 * Current beginning default clock snapshot for the
49 * current packet (`UINT64_C(-1)` if not set).
50 */
51 uint64_t beginning_cs;
52
53 /*
54 * Current end default clock snapshot for the current
55 * packet (`UINT64_C(-1)` if not set).
56 */
57 uint64_t end_cs;
58
59 /*
60 * Current packet's content size (bits) for the current
61 * packet.
62 */
63 uint64_t content_size;
64
65 /*
66 * Current packet's total size (bits) for the current
67 * packet.
68 */
69 uint64_t total_size;
70
71 /*
72 * Discarded events (free running) counter for the
73 * current packet.
74 */
75 uint64_t discarded_events_counter;
76
77 /* Sequence number (free running) of the current packet */
78 uint64_t seq_num;
79
80 /*
81 * Offset of the packet context structure within the
82 * current packet (bits).
83 */
84 uint64_t context_offset_bits;
85
86 /*
87 * Owned by this; `NULL` if the current packet is closed
88 * or if the trace IR stream does not support packets.
89 */
90 const bt_packet *packet;
91 } packet_state;
92
93 /* Previous packet's state */
94 struct
95 {
96 /* End default clock snapshot (`UINT64_C(-1)` if not set) */
97 uint64_t end_cs;
98
99 /* Discarded events (free running) counter */
100 uint64_t discarded_events_counter;
101
102 /* Sequence number (free running) */
103 uint64_t seq_num;
104 } prev_packet_state;
105
106 /* State to handle discarded events */
107 struct
108 {
109 /*
110 * True if we're in the time range given by a previously
111 * received discarded events message. In this case,
112 * `beginning_cs` and `end_cs` below contain the
113 * beginning and end clock snapshots for this range.
114 *
115 * This is used to validate that, when receiving a
116 * packet end message, the current discarded events time
117 * range matches what's expected for CTF 1.8, that is:
118 *
119 * * Its beginning time is the previous packet's end
120 * time (or the current packet's beginning time if
121 * this is the first packet).
122 *
123 * * Its end time is the current packet's end time.
124 */
125 bool in_range;
126
127 /*
128 * Beginning and end times of the time range given by a
129 * previously received discarded events message.
130 */
131 uint64_t beginning_cs;
132 uint64_t end_cs;
133 } discarded_events_state;
134
135 /* State to handle discarded packets */
136 struct
137 {
138 /*
139 * True if we're in the time range given by a previously
140 * received discarded packets message. In this case,
141 * `beginning_cs` and `end_cs` below contain the
142 * beginning and end clock snapshots for this range.
143 *
144 * This is used to validate that, when receiving a
145 * packet beginning message, the current discarded
146 * packets time range matches what's expected for CTF
147 * 1.8, that is:
148 *
149 * * Its beginning time is the previous packet's end
150 * time.
151 *
152 * * Its end time is the current packet's beginning
153 * time.
154 */
155 bool in_range;
156
157 /*
158 * Beginning and end times of the time range given by a
159 * previously received discarded packets message.
160 */
161 uint64_t beginning_cs;
162 uint64_t end_cs;
163 } discarded_packets_state;
164 };
165
166 struct fs_sink_stream *fs_sink_stream_create(struct fs_sink_trace *trace,
167 const bt_stream *ir_stream);
168
169 void fs_sink_stream_destroy(struct fs_sink_stream *stream);
170
171 int fs_sink_stream_write_event(struct fs_sink_stream *stream, const bt_clock_snapshot *cs,
172 const bt_event *event, struct fs_sink_ctf_event_class *ec);
173
174 int fs_sink_stream_open_packet(struct fs_sink_stream *stream, const bt_clock_snapshot *cs,
175 const bt_packet *packet);
176
177 int fs_sink_stream_close_packet(struct fs_sink_stream *stream, const bt_clock_snapshot *cs);
178
179 #endif /* BABELTRACE_PLUGIN_CTF_FS_SINK_FS_SINK_STREAM_H */
This page took 0.033001 seconds and 4 git commands to generate.