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