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