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