.clang-tidy: enable cppcoreguidelines-avoid-const-or-ref-data-members
[babeltrace.git] / src / plugins / ctf / lttng-live / lttng-live.hpp
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright 2019 Francis Deslauriers <francis.deslauriers@efficios.com>
5 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 * Copyright 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 *
8 * BabelTrace - LTTng-live client Component
9 */
10
11 #ifndef BABELTRACE_PLUGIN_CTF_LTTNG_LIVE_H
12 #define BABELTRACE_PLUGIN_CTF_LTTNG_LIVE_H
13
14 #include <glib.h>
15 #include <stdint.h>
16
17 #include <babeltrace2/babeltrace.h>
18
19 #include "../common/msg-iter/msg-iter.hpp"
20 #include "viewer-connection.hpp"
21
22 enum lttng_live_stream_state
23 {
24 /* This stream won't have data until some known time in the future. */
25 LTTNG_LIVE_STREAM_QUIESCENT,
26 /*
27 * This stream won't have data until some known time in the future and
28 * the message iterator inactivity message was already sent downstream.
29 */
30 LTTNG_LIVE_STREAM_QUIESCENT_NO_DATA, /* */
31 /* This stream has data ready to be consumed. */
32 LTTNG_LIVE_STREAM_ACTIVE_DATA,
33 /*
34 * This stream has no data left to consume. We should asked the relay
35 * for more.
36 */
37 LTTNG_LIVE_STREAM_ACTIVE_NO_DATA,
38 /* This stream won't have anymore data, ever. */
39 LTTNG_LIVE_STREAM_EOF,
40 };
41
42 /* Iterator over a live stream. */
43 struct lttng_live_stream_iterator
44 {
45 bt_logging_level log_level;
46 bt_self_component *self_comp;
47
48 /* Owned by this. */
49 bt_stream *stream;
50
51 /* Weak reference. */
52 struct lttng_live_trace *trace;
53
54 /*
55 * Since only a single iterator per viewer connection, we have
56 * only a single message iterator per stream.
57 */
58 struct ctf_msg_iter *msg_iter;
59
60 uint64_t viewer_stream_id;
61
62 struct
63 {
64 bool is_set;
65 uint64_t value;
66 } ctf_stream_class_id;
67
68 /* base offset in current index. */
69 uint64_t base_offset;
70 /* len to read in current index. */
71 uint64_t len;
72 /* offset in current index. */
73 uint64_t offset;
74
75 /*
76 * Clock Snapshot value of the last message iterator inactivity message
77 * sent downstream.
78 */
79 struct
80 {
81 bool is_set;
82 uint64_t value;
83 } last_inactivity_ts;
84
85 /*
86 * Clock Snapshot value of the current message iterator inactivity
87 * message we might want to send downstream.
88 */
89 uint64_t current_inactivity_ts;
90
91 enum lttng_live_stream_state state;
92
93 /*
94 * The current message produced by this live stream iterator. Owned by
95 * this.
96 */
97 const bt_message *current_msg;
98
99 /* Timestamp in nanoseconds of the current message (current_msg). */
100 int64_t current_msg_ts_ns;
101
102 /* Owned by this. */
103 uint8_t *buf;
104 size_t buflen;
105
106 /* Owned by this. */
107 GString *name;
108
109 bool has_stream_hung_up;
110 };
111
112 struct lttng_live_metadata
113 {
114 bt_logging_level log_level;
115 bt_self_component *self_comp;
116
117 uint64_t stream_id;
118 /* Weak reference. */
119 struct ctf_metadata_decoder *decoder;
120 };
121
122 enum lttng_live_metadata_stream_state
123 {
124 /*
125 * The metadata needs to be updated. This is either because we just
126 * created the trace and haven't asked yet, or the relay specifically
127 * told us that new metadata is available.
128 */
129 LTTNG_LIVE_METADATA_STREAM_STATE_NEEDED,
130 /*
131 * The metadata was updated and the relay has not told us we need to
132 * update it yet.
133 */
134 LTTNG_LIVE_METADATA_STREAM_STATE_NOT_NEEDED,
135 /*
136 * The relay has closed this metadata stream. We set this in reaction
137 * to a LTTNG_VIEWER_METADATA_ERR reply to a LTTNG_VIEWER_GET_METADATA
138 * command to the relay. If this field is set, we have received all the
139 * metadata that we are ever going to get for that metadata stream.
140 */
141 LTTNG_LIVE_METADATA_STREAM_STATE_CLOSED,
142 };
143
144 struct lttng_live_trace
145 {
146 bt_logging_level log_level;
147 bt_self_component *self_comp;
148
149 /* Back reference to session. */
150 struct lttng_live_session *session;
151
152 /* ctf trace ID within the session. */
153 uint64_t id;
154
155 /* Owned by this. */
156 bt_trace *trace;
157
158 /* Weak reference. */
159 bt_trace_class *trace_class;
160
161 struct lttng_live_metadata *metadata;
162
163 const bt_clock_class *clock_class;
164
165 /* Array of pointers to struct lttng_live_stream_iterator. */
166 /* Owned by this. */
167 GPtrArray *stream_iterators;
168
169 enum lttng_live_metadata_stream_state metadata_stream_state;
170 };
171
172 struct lttng_live_session
173 {
174 bt_logging_level log_level;
175 bt_self_component *self_comp;
176
177 /* Weak reference. */
178 struct lttng_live_msg_iter *lttng_live_msg_iter;
179
180 /* Owned by this. */
181 GString *hostname;
182
183 /* Owned by this. */
184 GString *session_name;
185
186 uint64_t id;
187
188 /* Array of pointers to struct lttng_live_trace. */
189 GPtrArray *traces;
190
191 bool attached;
192 bool new_streams_needed;
193 bool lazy_stream_msg_init;
194 bool closed;
195 };
196
197 enum session_not_found_action
198 {
199 SESSION_NOT_FOUND_ACTION_CONTINUE,
200 SESSION_NOT_FOUND_ACTION_FAIL,
201 SESSION_NOT_FOUND_ACTION_END,
202 };
203
204 /*
205 * A component instance is an iterator on a single session.
206 */
207 struct lttng_live_component
208 {
209 bt_logging_level log_level;
210
211 /* Weak reference. */
212 bt_self_component *self_comp;
213
214 struct
215 {
216 GString *url;
217 enum session_not_found_action sess_not_found_act;
218 } params;
219
220 size_t max_query_size;
221
222 /*
223 * Keeps track of whether the downstream component already has a
224 * message iterator on this component.
225 */
226 bool has_msg_iter;
227 };
228
229 struct lttng_live_msg_iter
230 {
231 bt_logging_level log_level;
232 bt_self_component *self_comp;
233
234 /* Weak reference. */
235 struct lttng_live_component *lttng_live_comp;
236
237 /* Weak reference. */
238 bt_self_message_iterator *self_msg_iter;
239
240 /* Owned by this. */
241 struct live_viewer_connection *viewer_connection;
242
243 /* Array of pointers to struct lttng_live_session. */
244 GPtrArray *sessions;
245
246 /* Number of live stream iterator this message iterator has.*/
247 uint64_t active_stream_iter;
248
249 /* Timestamp in nanosecond of the last message sent downstream. */
250 int64_t last_msg_ts_ns;
251
252 /* True if the iterator was interrupted. */
253 bool was_interrupted;
254 };
255
256 enum lttng_live_iterator_status
257 {
258 /** Iterator state has progressed. Continue iteration immediately. */
259 LTTNG_LIVE_ITERATOR_STATUS_CONTINUE = 3,
260 /** No message available for now. Try again later. */
261 LTTNG_LIVE_ITERATOR_STATUS_AGAIN = 2,
262 /** No more CTF_LTTNG_LIVEs to be delivered. */
263 LTTNG_LIVE_ITERATOR_STATUS_END = 1,
264 /** No error, okay. */
265 LTTNG_LIVE_ITERATOR_STATUS_OK = 0,
266 /** Invalid arguments. */
267 LTTNG_LIVE_ITERATOR_STATUS_INVAL = -1,
268 /** General error. */
269 LTTNG_LIVE_ITERATOR_STATUS_ERROR = -2,
270 /** Out of memory. */
271 LTTNG_LIVE_ITERATOR_STATUS_NOMEM = -3,
272 /** Unsupported iterator feature. */
273 LTTNG_LIVE_ITERATOR_STATUS_UNSUPPORTED = -4,
274 };
275
276 bt_component_class_initialize_method_status
277 lttng_live_component_init(bt_self_component_source *self_comp,
278 bt_self_component_source_configuration *config, const bt_value *params,
279 void *init_method_data);
280
281 bt_component_class_query_method_status lttng_live_query(bt_self_component_class_source *comp_class,
282 bt_private_query_executor *priv_query_exec,
283 const char *object, const bt_value *params,
284 void *method_data, const bt_value **result);
285
286 void lttng_live_component_finalize(bt_self_component_source *component);
287
288 bt_message_iterator_class_next_method_status
289 lttng_live_msg_iter_next(bt_self_message_iterator *iterator, bt_message_array_const msgs,
290 uint64_t capacity, uint64_t *count);
291
292 bt_message_iterator_class_initialize_method_status
293 lttng_live_msg_iter_init(bt_self_message_iterator *self_msg_it,
294 bt_self_message_iterator_configuration *config,
295 bt_self_component_port_output *self_port);
296
297 void lttng_live_msg_iter_finalize(bt_self_message_iterator *it);
298
299 enum lttng_live_viewer_status lttng_live_session_attach(struct lttng_live_session *session,
300 bt_self_message_iterator *self_msg_iter);
301
302 enum lttng_live_viewer_status lttng_live_session_detach(struct lttng_live_session *session);
303
304 enum lttng_live_iterator_status
305 lttng_live_session_get_new_streams(struct lttng_live_session *session,
306 bt_self_message_iterator *self_msg_iter);
307
308 struct lttng_live_trace *
309 lttng_live_session_borrow_or_create_trace_by_id(struct lttng_live_session *session,
310 uint64_t trace_id);
311
312 int lttng_live_add_session(struct lttng_live_msg_iter *lttng_live_msg_iter, uint64_t session_id,
313 const char *hostname, const char *session_name);
314
315 /*
316 * lttng_live_get_one_metadata_packet() asks the Relay Daemon for new metadata.
317 * If new metadata is received, the function writes it to the provided file
318 * handle and updates the reply_len output parameter. This function should be
319 * called in loop until _END status is received to ensure all metadata is
320 * written to the file.
321 */
322 enum lttng_live_get_one_metadata_status
323 lttng_live_get_one_metadata_packet(struct lttng_live_trace *trace, FILE *fp, size_t *reply_len);
324
325 enum lttng_live_iterator_status
326 lttng_live_get_next_index(struct lttng_live_msg_iter *lttng_live_msg_iter,
327 struct lttng_live_stream_iterator *stream, struct packet_index *index);
328
329 enum ctf_msg_iter_medium_status
330 lttng_live_get_stream_bytes(struct lttng_live_msg_iter *lttng_live_msg_iter,
331 struct lttng_live_stream_iterator *stream, uint8_t *buf,
332 uint64_t offset, uint64_t req_len, uint64_t *recv_len);
333
334 bool lttng_live_graph_is_canceled(struct lttng_live_msg_iter *msg_iter);
335
336 void lttng_live_stream_iterator_set_state(struct lttng_live_stream_iterator *stream_iter,
337 enum lttng_live_stream_state new_state);
338
339 #endif /* BABELTRACE_PLUGIN_CTF_LTTNG_LIVE_H */
This page took 0.036732 seconds and 4 git commands to generate.