lttng-live: ensure that port connections go to the same 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
0f5e83e5
PP
31extern int bt_lttng_live_log_level;
32
7cdc2bab
MD
33#include <stdbool.h>
34
f3bc2010 35#include <babeltrace/babeltrace-internal.h>
087bc060
MD
36
37#define BT_LOG_OUTPUT_LEVEL bt_lttng_live_log_level
38#include <babeltrace/logging-internal.h>
39
b2e0c907 40#include <babeltrace/graph/component.h>
7cdc2bab
MD
41#include <babeltrace/graph/notification-iterator.h>
42#include <babeltrace/graph/clock-class-priority-map.h>
43#include "viewer-connection.h"
44
45//TODO: this should not be used by plugins. Should copy code into plugin
46//instead.
47#include "babeltrace/object-internal.h"
48#include "babeltrace/list-internal.h"
49#include "../common/metadata/decoder.h"
50
51#define STREAM_NAME_PREFIX "stream-"
52/* Account for u64 max string length. */
53#define U64_STR_MAX_LEN 20
54#define STREAM_NAME_MAX_LEN (sizeof(STREAM_NAME_PREFIX) + U64_STR_MAX_LEN)
55
7cdc2bab
MD
56struct lttng_live_component;
57struct lttng_live_session;
58
59enum lttng_live_stream_state {
60 LTTNG_LIVE_STREAM_ACTIVE_NO_DATA,
61 LTTNG_LIVE_STREAM_QUIESCENT_NO_DATA,
62 LTTNG_LIVE_STREAM_QUIESCENT,
63 LTTNG_LIVE_STREAM_ACTIVE_DATA,
64 LTTNG_LIVE_STREAM_EOF,
65};
66
67enum live_stream_type {
68 LIVE_STREAM_TYPE_NO_STREAM,
69 LIVE_STREAM_TYPE_STREAM,
70};
71
72struct lttng_live_stream_iterator_generic {
73 enum live_stream_type type;
74};
75
76/* Iterator over a live stream. */
77struct lttng_live_stream_iterator {
78 struct lttng_live_stream_iterator_generic p;
79
80 struct bt_ctf_stream *stream;
81 struct lttng_live_trace *trace;
82 struct bt_private_port *port;
83
84 /* Node of stream list within the trace. */
85 struct bt_list_head node;
86
87 /*
88 * Since only a single iterator per viewer connection, we have
89 * only a single notification iterator per stream.
90 */
91 struct bt_ctf_notif_iter *notif_iter;
92
93 uint64_t viewer_stream_id;
94
95 uint64_t ctf_stream_class_id;
96 uint64_t base_offset; /* base offset in current index. */
97 uint64_t len; /* len to read in current index. */
98 uint64_t offset; /* offset in current index. */
99
100 int64_t last_returned_inactivity_timestamp;
101 int64_t current_inactivity_timestamp;
102
103 enum lttng_live_stream_state state;
104
105 uint64_t current_packet_end_timestamp;
106 struct bt_notification *packet_end_notif_queue;
107
108 uint8_t *buf;
109 size_t buflen;
110
111 char name[STREAM_NAME_MAX_LEN];
112};
113
114struct lttng_live_no_stream_iterator {
115 struct lttng_live_stream_iterator_generic p;
116
117 struct lttng_live_component *lttng_live;
118 struct bt_private_port *port;
119};
120
121struct lttng_live_component_options {
122 bool opt_dummy : 1;
123};
124
125struct lttng_live_metadata {
126 struct lttng_live_trace *trace;
127 uint64_t stream_id;
128 uint8_t uuid[16];
129 bool is_uuid_set;
130 int bo;
131 char *text;
132
133 struct ctf_metadata_decoder *decoder;
134
135 bool closed;
136};
137
138struct lttng_live_trace {
139 struct bt_object obj;
140
141 /* Node of trace list within the session. */
142 struct bt_list_head node;
143
144 /* Back reference to session. */
145 struct lttng_live_session *session;
146
147 uint64_t id; /* ctf trace ID within the session. */
148
149 struct bt_ctf_trace *trace;
150
151 struct lttng_live_metadata *metadata;
152 struct bt_clock_class_priority_map *cc_prio_map;
153
154 /* List of struct lttng_live_stream_iterator */
155 struct bt_list_head streams;
156
157 bool new_metadata_needed;
158};
159
160struct lttng_live_session {
161 /* Node of session list within the component. */
162 struct bt_list_head node;
163
164 struct lttng_live_component *lttng_live;
165
166 uint64_t id;
167
168 /* List of struct lttng_live_trace */
169 struct bt_list_head traces;
170
171 bool attached;
172 bool new_streams_needed;
173 bool lazy_stream_notif_init;
174 bool closed;
175};
176
177/*
178 * A component instance is an iterator on a single session.
179 */
180struct lttng_live_component {
181 struct bt_object obj;
182 struct bt_private_component *private_component; /* weak */
183 struct bt_live_viewer_connection *viewer_connection;
184
185 /* List of struct lttng_live_session */
186 struct bt_list_head sessions;
187
188 GString *url;
7cdc2bab
MD
189 size_t max_query_size;
190 struct lttng_live_component_options options;
191
192 struct bt_private_port *no_stream_port;
193 struct lttng_live_no_stream_iterator *no_stream_iter;
d85ef162
MD
194
195 struct bt_component *downstream_component;
7cdc2bab
MD
196};
197
198enum bt_ctf_lttng_live_iterator_status {
199 /** Iterator state has progressed. Continue iteration immediately. */
200 BT_CTF_LTTNG_LIVE_ITERATOR_STATUS_CONTINUE = 3,
201 /** No notification available for now. Try again later. */
202 BT_CTF_LTTNG_LIVE_ITERATOR_STATUS_AGAIN = 2,
203 /** No more CTF_LTTNG_LIVEs to be delivered. */
204 BT_CTF_LTTNG_LIVE_ITERATOR_STATUS_END = 1,
205 /** No error, okay. */
206 BT_CTF_LTTNG_LIVE_ITERATOR_STATUS_OK = 0,
207 /** Invalid arguments. */
208 BT_CTF_LTTNG_LIVE_ITERATOR_STATUS_INVAL = -1,
209 /** General error. */
210 BT_CTF_LTTNG_LIVE_ITERATOR_STATUS_ERROR = -2,
211 /** Out of memory. */
212 BT_CTF_LTTNG_LIVE_ITERATOR_STATUS_NOMEM = -3,
213 /** Unsupported iterator feature. */
214 BT_CTF_LTTNG_LIVE_ITERATOR_STATUS_UNSUPPORTED = -4,
215};
f3bc2010 216
7cdc2bab 217enum bt_component_status lttng_live_component_init(struct bt_private_component *source,
6358c163 218 struct bt_value *params, void *init_method_data);
f3bc2010 219
7cdc2bab
MD
220struct bt_value *lttng_live_query(struct bt_component_class *comp_class,
221 const char *object, struct bt_value *params);
222
223void lttng_live_component_finalize(struct bt_private_component *component);
224
41a2b7ae 225struct bt_notification_iterator_next_return lttng_live_iterator_next(
890882ef 226 struct bt_private_notification_iterator *iterator);
d3eb6e8f 227
d85ef162
MD
228enum bt_component_status lttng_live_accept_port_connection(
229 struct bt_private_component *private_component,
230 struct bt_private_port *self_private_port,
231 struct bt_port *other_port);
7cdc2bab
MD
232
233enum bt_notification_iterator_status lttng_live_iterator_init(
234 struct bt_private_notification_iterator *it,
235 struct bt_private_port *port);
236
237void lttng_live_iterator_finalize(struct bt_private_notification_iterator *it);
238
239int lttng_live_create_viewer_session(struct lttng_live_component *lttng_live);
240int lttng_live_attach_session(struct lttng_live_session *session);
241int lttng_live_detach_session(struct lttng_live_session *session);
242enum bt_ctf_lttng_live_iterator_status lttng_live_get_new_streams(
243 struct lttng_live_session *session);
244
245int lttng_live_add_session(struct lttng_live_component *lttng_live, uint64_t session_id);
246
247ssize_t lttng_live_get_one_metadata_packet(struct lttng_live_trace *trace,
248 FILE *fp);
249enum bt_ctf_lttng_live_iterator_status lttng_live_get_next_index(
250 struct lttng_live_component *lttng_live,
251 struct lttng_live_stream_iterator *stream,
252 struct packet_index *index);
253enum bt_ctf_notif_iter_medium_status lttng_live_get_stream_bytes(
254 struct lttng_live_component *lttng_live,
255 struct lttng_live_stream_iterator *stream, uint8_t *buf, uint64_t offset,
256 uint64_t req_len, uint64_t *recv_len);
257
258int lttng_live_add_port(struct lttng_live_component *lttng_live,
259 struct lttng_live_stream_iterator *stream_iter);
260int lttng_live_remove_port(struct lttng_live_component *lttng_live,
261 struct bt_private_port *port);
262
263struct lttng_live_trace *lttng_live_ref_trace(
264 struct lttng_live_session *session, uint64_t trace_id);
265void lttng_live_unref_trace(struct lttng_live_trace *trace);
266void lttng_live_need_new_streams(struct lttng_live_component *lttng_live);
267
f3bc2010 268#endif /* BABELTRACE_PLUGIN_CTF_LTTNG_LIVE_INTERNAL_H */
This page took 0.040645 seconds and 4 git commands to generate.