Implement ctf.lttng-live component
[babeltrace.git] / plugins / ctf / lttng-live / lttng-live-internal.h
CommitLineData
f3bc2010
JG
1#ifndef BABELTRACE_PLUGIN_CTF_LTTNG_LIVE_INTERNAL_H
2#define BABELTRACE_PLUGIN_CTF_LTTNG_LIVE_INTERNAL_H
3
4/*
5 * BabelTrace - LTTng-live client Component
6 *
7 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
7cdc2bab 8 * Copyright 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
f3bc2010
JG
9 *
10 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
11 *
12 * Permission is hereby granted, free of charge, to any person obtaining a copy
13 * of this software and associated documentation files (the "Software"), to deal
14 * in the Software without restriction, including without limitation the rights
15 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16 * copies of the Software, and to permit persons to whom the Software is
17 * furnished to do so, subject to the following conditions:
18 *
19 * The above copyright notice and this permission notice shall be included in
20 * all copies or substantial portions of the Software.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 * SOFTWARE.
29 */
30
7cdc2bab
MD
31#include <stdbool.h>
32
f3bc2010 33#include <babeltrace/babeltrace-internal.h>
b2e0c907 34#include <babeltrace/graph/component.h>
7cdc2bab
MD
35#include <babeltrace/graph/notification-iterator.h>
36#include <babeltrace/graph/clock-class-priority-map.h>
37#include "viewer-connection.h"
38
39//TODO: this should not be used by plugins. Should copy code into plugin
40//instead.
41#include "babeltrace/object-internal.h"
42#include "babeltrace/list-internal.h"
43#include "../common/metadata/decoder.h"
44
45#define STREAM_NAME_PREFIX "stream-"
46/* Account for u64 max string length. */
47#define U64_STR_MAX_LEN 20
48#define STREAM_NAME_MAX_LEN (sizeof(STREAM_NAME_PREFIX) + U64_STR_MAX_LEN)
49
50extern bool lttng_live_debug;
51
52struct lttng_live_component;
53struct lttng_live_session;
54
55enum lttng_live_stream_state {
56 LTTNG_LIVE_STREAM_ACTIVE_NO_DATA,
57 LTTNG_LIVE_STREAM_QUIESCENT_NO_DATA,
58 LTTNG_LIVE_STREAM_QUIESCENT,
59 LTTNG_LIVE_STREAM_ACTIVE_DATA,
60 LTTNG_LIVE_STREAM_EOF,
61};
62
63enum live_stream_type {
64 LIVE_STREAM_TYPE_NO_STREAM,
65 LIVE_STREAM_TYPE_STREAM,
66};
67
68struct lttng_live_stream_iterator_generic {
69 enum live_stream_type type;
70};
71
72/* Iterator over a live stream. */
73struct lttng_live_stream_iterator {
74 struct lttng_live_stream_iterator_generic p;
75
76 struct bt_ctf_stream *stream;
77 struct lttng_live_trace *trace;
78 struct bt_private_port *port;
79
80 /* Node of stream list within the trace. */
81 struct bt_list_head node;
82
83 /*
84 * Since only a single iterator per viewer connection, we have
85 * only a single notification iterator per stream.
86 */
87 struct bt_ctf_notif_iter *notif_iter;
88
89 uint64_t viewer_stream_id;
90
91 uint64_t ctf_stream_class_id;
92 uint64_t base_offset; /* base offset in current index. */
93 uint64_t len; /* len to read in current index. */
94 uint64_t offset; /* offset in current index. */
95
96 int64_t last_returned_inactivity_timestamp;
97 int64_t current_inactivity_timestamp;
98
99 enum lttng_live_stream_state state;
100
101 uint64_t current_packet_end_timestamp;
102 struct bt_notification *packet_end_notif_queue;
103
104 uint8_t *buf;
105 size_t buflen;
106
107 char name[STREAM_NAME_MAX_LEN];
108};
109
110struct lttng_live_no_stream_iterator {
111 struct lttng_live_stream_iterator_generic p;
112
113 struct lttng_live_component *lttng_live;
114 struct bt_private_port *port;
115};
116
117struct lttng_live_component_options {
118 bool opt_dummy : 1;
119};
120
121struct lttng_live_metadata {
122 struct lttng_live_trace *trace;
123 uint64_t stream_id;
124 uint8_t uuid[16];
125 bool is_uuid_set;
126 int bo;
127 char *text;
128
129 struct ctf_metadata_decoder *decoder;
130
131 bool closed;
132};
133
134struct lttng_live_trace {
135 struct bt_object obj;
136
137 /* Node of trace list within the session. */
138 struct bt_list_head node;
139
140 /* Back reference to session. */
141 struct lttng_live_session *session;
142
143 uint64_t id; /* ctf trace ID within the session. */
144
145 struct bt_ctf_trace *trace;
146
147 struct lttng_live_metadata *metadata;
148 struct bt_clock_class_priority_map *cc_prio_map;
149
150 /* List of struct lttng_live_stream_iterator */
151 struct bt_list_head streams;
152
153 bool new_metadata_needed;
154};
155
156struct lttng_live_session {
157 /* Node of session list within the component. */
158 struct bt_list_head node;
159
160 struct lttng_live_component *lttng_live;
161
162 uint64_t id;
163
164 /* List of struct lttng_live_trace */
165 struct bt_list_head traces;
166
167 bool attached;
168 bool new_streams_needed;
169 bool lazy_stream_notif_init;
170 bool closed;
171};
172
173/*
174 * A component instance is an iterator on a single session.
175 */
176struct lttng_live_component {
177 struct bt_object obj;
178 struct bt_private_component *private_component; /* weak */
179 struct bt_live_viewer_connection *viewer_connection;
180
181 /* List of struct lttng_live_session */
182 struct bt_list_head sessions;
183
184 GString *url;
185 FILE *error_fp;
186 size_t max_query_size;
187 struct lttng_live_component_options options;
188
189 struct bt_private_port *no_stream_port;
190 struct lttng_live_no_stream_iterator *no_stream_iter;
191};
192
193enum bt_ctf_lttng_live_iterator_status {
194 /** Iterator state has progressed. Continue iteration immediately. */
195 BT_CTF_LTTNG_LIVE_ITERATOR_STATUS_CONTINUE = 3,
196 /** No notification available for now. Try again later. */
197 BT_CTF_LTTNG_LIVE_ITERATOR_STATUS_AGAIN = 2,
198 /** No more CTF_LTTNG_LIVEs to be delivered. */
199 BT_CTF_LTTNG_LIVE_ITERATOR_STATUS_END = 1,
200 /** No error, okay. */
201 BT_CTF_LTTNG_LIVE_ITERATOR_STATUS_OK = 0,
202 /** Invalid arguments. */
203 BT_CTF_LTTNG_LIVE_ITERATOR_STATUS_INVAL = -1,
204 /** General error. */
205 BT_CTF_LTTNG_LIVE_ITERATOR_STATUS_ERROR = -2,
206 /** Out of memory. */
207 BT_CTF_LTTNG_LIVE_ITERATOR_STATUS_NOMEM = -3,
208 /** Unsupported iterator feature. */
209 BT_CTF_LTTNG_LIVE_ITERATOR_STATUS_UNSUPPORTED = -4,
210};
f3bc2010 211
f3bc2010 212BT_HIDDEN
7cdc2bab 213enum bt_component_status lttng_live_component_init(struct bt_private_component *source,
6358c163 214 struct bt_value *params, void *init_method_data);
f3bc2010 215
7cdc2bab
MD
216struct bt_value *lttng_live_query(struct bt_component_class *comp_class,
217 const char *object, struct bt_value *params);
218
219void lttng_live_component_finalize(struct bt_private_component *component);
220
d3eb6e8f 221BT_HIDDEN
41a2b7ae 222struct bt_notification_iterator_next_return lttng_live_iterator_next(
890882ef 223 struct bt_private_notification_iterator *iterator);
d3eb6e8f 224
7cdc2bab
MD
225
226enum bt_notification_iterator_status lttng_live_iterator_init(
227 struct bt_private_notification_iterator *it,
228 struct bt_private_port *port);
229
230void lttng_live_iterator_finalize(struct bt_private_notification_iterator *it);
231
232int lttng_live_create_viewer_session(struct lttng_live_component *lttng_live);
233int lttng_live_attach_session(struct lttng_live_session *session);
234int lttng_live_detach_session(struct lttng_live_session *session);
235enum bt_ctf_lttng_live_iterator_status lttng_live_get_new_streams(
236 struct lttng_live_session *session);
237
238int lttng_live_add_session(struct lttng_live_component *lttng_live, uint64_t session_id);
239
240ssize_t lttng_live_get_one_metadata_packet(struct lttng_live_trace *trace,
241 FILE *fp);
242enum bt_ctf_lttng_live_iterator_status lttng_live_get_next_index(
243 struct lttng_live_component *lttng_live,
244 struct lttng_live_stream_iterator *stream,
245 struct packet_index *index);
246enum bt_ctf_notif_iter_medium_status lttng_live_get_stream_bytes(
247 struct lttng_live_component *lttng_live,
248 struct lttng_live_stream_iterator *stream, uint8_t *buf, uint64_t offset,
249 uint64_t req_len, uint64_t *recv_len);
250
251int lttng_live_add_port(struct lttng_live_component *lttng_live,
252 struct lttng_live_stream_iterator *stream_iter);
253int lttng_live_remove_port(struct lttng_live_component *lttng_live,
254 struct bt_private_port *port);
255
256struct lttng_live_trace *lttng_live_ref_trace(
257 struct lttng_live_session *session, uint64_t trace_id);
258void lttng_live_unref_trace(struct lttng_live_trace *trace);
259void lttng_live_need_new_streams(struct lttng_live_component *lttng_live);
260
f3bc2010 261#endif /* BABELTRACE_PLUGIN_CTF_LTTNG_LIVE_INTERNAL_H */
This page took 0.036121 seconds and 4 git commands to generate.