Commit | Line | Data |
---|---|---|
cab3f160 JG |
1 | /* |
2 | * iterator.c | |
3 | * | |
4 | * Babeltrace Trace Trimmer Iterator | |
5 | * | |
6 | * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
7 | * | |
8 | * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
9 | * | |
10 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
11 | * of this software and associated documentation files (the "Software"), to deal | |
12 | * in the Software without restriction, including without limitation the rights | |
13 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
14 | * copies of the Software, and to permit persons to whom the Software is | |
15 | * furnished to do so, subject to the following conditions: | |
16 | * | |
17 | * The above copyright notice and this permission notice shall be included in | |
18 | * all copies or substantial portions of the Software. | |
19 | * | |
20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
23 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
24 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
25 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
26 | * SOFTWARE. | |
27 | */ | |
28 | ||
b2e0c907 PP |
29 | #include <babeltrace/graph/notification-iterator.h> |
30 | #include <babeltrace/graph/private-notification-iterator.h> | |
31 | #include <babeltrace/graph/notification.h> | |
32 | #include <babeltrace/graph/notification-event.h> | |
33 | #include <babeltrace/graph/notification-stream.h> | |
34 | #include <babeltrace/graph/notification-packet.h> | |
35 | #include <babeltrace/graph/component-filter.h> | |
36 | #include <babeltrace/graph/private-component-filter.h> | |
37 | #include <babeltrace/graph/private-port.h> | |
38 | #include <babeltrace/graph/private-connection.h> | |
39 | #include <babeltrace/graph/private-component.h> | |
44d3cbf0 JG |
40 | #include <babeltrace/ctf-ir/event.h> |
41 | #include <babeltrace/ctf-ir/stream.h> | |
42 | #include <babeltrace/ctf-ir/stream-class.h> | |
ac0c6bdd | 43 | #include <babeltrace/ctf-ir/clock-class.h> |
44d3cbf0 JG |
44 | #include <babeltrace/ctf-ir/packet.h> |
45 | #include <babeltrace/ctf-ir/trace.h> | |
72208f03 | 46 | #include <babeltrace/ctf-ir/fields.h> |
44d3cbf0 | 47 | #include <assert.h> |
8b0ce102 | 48 | #include <plugins-common.h> |
44d3cbf0 | 49 | |
19ce87a4 JD |
50 | #include "trimmer.h" |
51 | #include "iterator.h" | |
52 | #include "copy.h" | |
53 | ||
d3eb6e8f | 54 | BT_HIDDEN |
64cadc66 | 55 | void trimmer_iterator_finalize(struct bt_private_notification_iterator *it) |
44d3cbf0 JG |
56 | { |
57 | struct trimmer_iterator *it_data; | |
58 | ||
890882ef | 59 | it_data = bt_private_notification_iterator_get_user_data(it); |
44d3cbf0 JG |
60 | assert(it_data); |
61 | ||
99cdb69e | 62 | bt_put(it_data->input_iterator); |
19ce87a4 | 63 | g_hash_table_destroy(it_data->packet_map); |
44d3cbf0 JG |
64 | g_free(it_data); |
65 | } | |
cab3f160 JG |
66 | |
67 | BT_HIDDEN | |
d3eb6e8f | 68 | enum bt_notification_iterator_status trimmer_iterator_init( |
91457551 PP |
69 | struct bt_private_notification_iterator *iterator, |
70 | struct bt_private_port *port) | |
cab3f160 | 71 | { |
d3eb6e8f PP |
72 | enum bt_notification_iterator_status ret = |
73 | BT_NOTIFICATION_ITERATOR_STATUS_OK; | |
cab3f160 | 74 | enum bt_notification_iterator_status it_ret; |
890882ef PP |
75 | struct bt_private_port *input_port = NULL; |
76 | struct bt_private_connection *connection = NULL; | |
91457551 PP |
77 | struct bt_private_component *component = |
78 | bt_private_notification_iterator_get_private_component(iterator); | |
44d3cbf0 JG |
79 | struct trimmer_iterator *it_data = g_new0(struct trimmer_iterator, 1); |
80 | ||
81 | if (!it_data) { | |
d3eb6e8f | 82 | ret = BT_NOTIFICATION_ITERATOR_STATUS_NOMEM; |
44d3cbf0 JG |
83 | goto end; |
84 | } | |
85 | ||
99cdb69e | 86 | /* Create a new iterator on the upstream component. */ |
b9d103be PP |
87 | input_port = bt_private_component_filter_get_input_private_port_by_name( |
88 | component, "in"); | |
99cdb69e | 89 | assert(input_port); |
890882ef | 90 | connection = bt_private_port_get_private_connection(input_port); |
99cdb69e JG |
91 | assert(connection); |
92 | ||
890882ef | 93 | it_data->input_iterator = |
fa054faf PP |
94 | bt_private_connection_create_notification_iterator(connection, |
95 | NULL); | |
99cdb69e JG |
96 | if (!it_data->input_iterator) { |
97 | ret = BT_NOTIFICATION_ITERATOR_STATUS_NOMEM; | |
98 | goto end; | |
99 | } | |
100 | ||
19ce87a4 JD |
101 | it_data->err = stderr; |
102 | it_data->packet_map = g_hash_table_new_full(g_direct_hash, | |
103 | g_direct_equal, NULL, NULL); | |
104 | ||
890882ef PP |
105 | it_ret = bt_private_notification_iterator_set_user_data(iterator, |
106 | it_data); | |
44d3cbf0 JG |
107 | if (it_ret) { |
108 | goto end; | |
109 | } | |
cab3f160 | 110 | end: |
91457551 | 111 | bt_put(component); |
99cdb69e JG |
112 | bt_put(connection); |
113 | bt_put(input_port); | |
cab3f160 JG |
114 | return ret; |
115 | } | |
116 | ||
528debdf MD |
117 | static |
118 | int update_lazy_bound(struct trimmer_bound *bound, const char *name, | |
55595636 | 119 | int64_t ts, bool *lazy_update) |
528debdf MD |
120 | { |
121 | struct tm tm; | |
122 | int64_t value; | |
123 | time_t timeval; | |
124 | ||
55595636 MD |
125 | *lazy_update = false; |
126 | ||
528debdf MD |
127 | if (!bound->lazy) { |
128 | return 0; | |
129 | } | |
130 | tm.tm_isdst = -1; | |
131 | timeval = ts / NSEC_PER_SEC; | |
132 | ||
133 | if (bound->lazy_values.gmt) { | |
134 | /* Get day, month, year. */ | |
135 | if (!gmtime_r(&timeval, &tm)) { | |
55595636 | 136 | printf_error("Failure in gmtime_r()"); |
528debdf MD |
137 | goto error; |
138 | } | |
139 | tm.tm_sec = bound->lazy_values.ss; | |
140 | tm.tm_min = bound->lazy_values.mm; | |
141 | tm.tm_hour = bound->lazy_values.hh; | |
142 | timeval = timegm(&tm); | |
143 | if (timeval < 0) { | |
55595636 MD |
144 | printf_error("Failure in timegm(), incorrectly formatted %s timestamp", |
145 | name); | |
528debdf MD |
146 | goto error; |
147 | } | |
148 | } else { | |
149 | /* Get day, month, year. */ | |
150 | if (!localtime_r(&timeval, &tm)) { | |
55595636 | 151 | printf_error("Failure in localtime_r()"); |
528debdf MD |
152 | goto error; |
153 | } | |
154 | tm.tm_sec = bound->lazy_values.ss; | |
155 | tm.tm_min = bound->lazy_values.mm; | |
156 | tm.tm_hour = bound->lazy_values.hh; | |
157 | timeval = mktime(&tm); | |
158 | if (timeval < 0) { | |
55595636 | 159 | printf_error("Failure in mktime(), incorrectly formatted %s timestamp", |
528debdf MD |
160 | name); |
161 | goto error; | |
162 | } | |
163 | } | |
164 | value = (int64_t) timeval; | |
165 | value *= NSEC_PER_SEC; | |
166 | value += bound->lazy_values.ns; | |
167 | bound->value = value; | |
168 | bound->set = true; | |
169 | bound->lazy = false; | |
55595636 | 170 | *lazy_update = true; |
528debdf MD |
171 | return 0; |
172 | ||
173 | error: | |
528debdf MD |
174 | return -1; |
175 | } | |
176 | ||
44d3cbf0 | 177 | static |
19ce87a4 JD |
178 | struct bt_notification *evaluate_event_notification( |
179 | struct bt_notification *notification, | |
180 | struct trimmer_iterator *trim_it, | |
55595636 MD |
181 | struct trimmer_bound *begin, struct trimmer_bound *end, |
182 | bool *_event_in_range) | |
44d3cbf0 | 183 | { |
72208f03 JG |
184 | int64_t ts; |
185 | int clock_ret; | |
19ce87a4 | 186 | struct bt_ctf_event *event = NULL, *writer_event; |
72208f03 | 187 | bool in_range = true; |
ac0c6bdd | 188 | struct bt_ctf_clock_class *clock_class = NULL; |
72208f03 | 189 | struct bt_ctf_trace *trace = NULL; |
44d3cbf0 | 190 | struct bt_ctf_stream *stream = NULL; |
72208f03 JG |
191 | struct bt_ctf_stream_class *stream_class = NULL; |
192 | struct bt_ctf_clock_value *clock_value = NULL; | |
55595636 | 193 | bool lazy_update = false; |
19ce87a4 JD |
194 | struct bt_notification *new_notification = NULL; |
195 | struct bt_clock_class_priority_map *cc_prio_map; | |
44d3cbf0 | 196 | |
72208f03 JG |
197 | event = bt_notification_event_get_event(notification); |
198 | assert(event); | |
19ce87a4 JD |
199 | cc_prio_map = bt_notification_event_get_clock_class_priority_map( |
200 | notification); | |
201 | assert(cc_prio_map); | |
202 | writer_event = trimmer_output_event(trim_it, event); | |
203 | assert(writer_event); | |
204 | new_notification = bt_notification_event_create(writer_event, cc_prio_map); | |
205 | assert(new_notification); | |
206 | bt_put(cc_prio_map); | |
44d3cbf0 | 207 | |
72208f03 JG |
208 | stream = bt_ctf_event_get_stream(event); |
209 | assert(stream); | |
44d3cbf0 | 210 | |
72208f03 JG |
211 | stream_class = bt_ctf_stream_get_class(stream); |
212 | assert(stream_class); | |
213 | ||
214 | trace = bt_ctf_stream_class_get_trace(stream_class); | |
215 | assert(trace); | |
216 | ||
217 | /* FIXME multi-clock? */ | |
9ac68eb1 | 218 | clock_class = bt_ctf_trace_get_clock_class_by_index(trace, 0); |
ac0c6bdd | 219 | if (!clock_class) { |
72208f03 | 220 | goto end; |
44d3cbf0 | 221 | } |
44d3cbf0 | 222 | |
ac0c6bdd | 223 | clock_value = bt_ctf_event_get_clock_value(event, clock_class); |
72208f03 | 224 | if (!clock_value) { |
55595636 | 225 | printf_error("Failed to retrieve clock value"); |
19ce87a4 | 226 | goto error; |
44d3cbf0 | 227 | } |
72208f03 JG |
228 | |
229 | clock_ret = bt_ctf_clock_value_get_value_ns_from_epoch( | |
230 | clock_value, &ts); | |
231 | if (clock_ret) { | |
55595636 | 232 | printf_error("Failed to retrieve clock value timestamp"); |
19ce87a4 | 233 | goto error; |
44d3cbf0 | 234 | } |
55595636 | 235 | if (update_lazy_bound(begin, "begin", ts, &lazy_update)) { |
528debdf MD |
236 | goto end; |
237 | } | |
55595636 | 238 | if (update_lazy_bound(end, "end", ts, &lazy_update)) { |
528debdf MD |
239 | goto end; |
240 | } | |
55595636 MD |
241 | if (lazy_update && begin->set && end->set) { |
242 | if (begin->value > end->value) { | |
243 | printf_error("Unexpected: time range begin value is above end value"); | |
19ce87a4 | 244 | goto error; |
55595636 MD |
245 | } |
246 | } | |
72208f03 JG |
247 | if (begin->set && ts < begin->value) { |
248 | in_range = false; | |
249 | } | |
250 | if (end->set && ts > end->value) { | |
251 | in_range = false; | |
252 | } | |
19ce87a4 JD |
253 | |
254 | goto end; | |
255 | ||
256 | error: | |
257 | BT_PUT(new_notification); | |
44d3cbf0 | 258 | end: |
72208f03 | 259 | bt_put(event); |
19ce87a4 | 260 | bt_put(writer_event); |
ac0c6bdd | 261 | bt_put(clock_class); |
72208f03 JG |
262 | bt_put(trace); |
263 | bt_put(stream); | |
264 | bt_put(stream_class); | |
265 | bt_put(clock_value); | |
55595636 | 266 | *_event_in_range = in_range; |
19ce87a4 | 267 | return new_notification; |
44d3cbf0 JG |
268 | } |
269 | ||
44d3cbf0 | 270 | static |
72208f03 | 271 | int ns_from_integer_field(struct bt_ctf_field *integer, int64_t *ns) |
44d3cbf0 | 272 | { |
72208f03 JG |
273 | int ret = 0; |
274 | int is_signed; | |
275 | uint64_t raw_clock_value; | |
276 | struct bt_ctf_field_type *integer_type = NULL; | |
ac0c6bdd | 277 | struct bt_ctf_clock_class *clock_class = NULL; |
44d3cbf0 JG |
278 | struct bt_ctf_clock_value *clock_value = NULL; |
279 | ||
72208f03 JG |
280 | integer_type = bt_ctf_field_get_type(integer); |
281 | assert(integer_type); | |
ac0c6bdd PP |
282 | clock_class = bt_ctf_field_type_integer_get_mapped_clock_class( |
283 | integer_type); | |
284 | if (!clock_class) { | |
72208f03 | 285 | ret = -1; |
44d3cbf0 JG |
286 | goto end; |
287 | } | |
288 | ||
72208f03 JG |
289 | is_signed = bt_ctf_field_type_integer_get_signed(integer_type); |
290 | if (!is_signed) { | |
291 | ret = bt_ctf_field_unsigned_integer_get_value(integer, | |
292 | &raw_clock_value); | |
293 | if (ret) { | |
44d3cbf0 JG |
294 | goto end; |
295 | } | |
72208f03 JG |
296 | } else { |
297 | /* Signed clock values are unsupported. */ | |
298 | goto end; | |
299 | } | |
44d3cbf0 | 300 | |
ac0c6bdd | 301 | clock_value = bt_ctf_clock_value_create(clock_class, raw_clock_value); |
72208f03 JG |
302 | if (!clock_value) { |
303 | goto end; | |
304 | } | |
44d3cbf0 | 305 | |
72208f03 JG |
306 | ret = bt_ctf_clock_value_get_value_ns_from_epoch(clock_value, ns); |
307 | end: | |
308 | bt_put(integer_type); | |
ac0c6bdd | 309 | bt_put(clock_class); |
72208f03 JG |
310 | bt_put(clock_value); |
311 | return ret; | |
312 | } | |
44d3cbf0 | 313 | |
19ce87a4 JD |
314 | static uint64_t ns_from_value(uint64_t frequency, uint64_t value) |
315 | { | |
316 | uint64_t ns; | |
317 | ||
318 | if (frequency == NSEC_PER_SEC) { | |
319 | ns = value; | |
320 | } else { | |
321 | ns = (uint64_t) ((1e9 * (double) value) / (double) frequency); | |
322 | } | |
323 | ||
324 | return ns; | |
325 | } | |
326 | ||
327 | /* | |
328 | * timestamp minus the offset. | |
329 | */ | |
72208f03 | 330 | static |
19ce87a4 JD |
331 | int64_t get_raw_timestamp(struct bt_ctf_packet *writer_packet, |
332 | int64_t timestamp) | |
333 | { | |
334 | struct bt_ctf_clock_class *writer_clock_class; | |
335 | int64_t sec_offset, cycles_offset, ns; | |
336 | struct bt_ctf_trace *writer_trace; | |
337 | struct bt_ctf_stream *writer_stream; | |
338 | struct bt_ctf_stream_class *writer_stream_class; | |
339 | int ret; | |
340 | uint64_t freq; | |
341 | ||
342 | writer_stream = bt_ctf_packet_get_stream(writer_packet); | |
343 | assert(writer_stream); | |
344 | ||
345 | writer_stream_class = bt_ctf_stream_get_class(writer_stream); | |
346 | assert(writer_stream_class); | |
347 | ||
348 | writer_trace = bt_ctf_stream_class_get_trace(writer_stream_class); | |
349 | assert(writer_trace); | |
350 | ||
351 | /* FIXME multi-clock? */ | |
9ac68eb1 PP |
352 | writer_clock_class = bt_ctf_trace_get_clock_class_by_index( |
353 | writer_trace, 0); | |
19ce87a4 JD |
354 | assert(writer_clock_class); |
355 | ||
356 | ret = bt_ctf_clock_class_get_offset_s(writer_clock_class, &sec_offset); | |
357 | assert(!ret); | |
358 | ns = sec_offset * NSEC_PER_SEC; | |
359 | ||
360 | freq = bt_ctf_clock_class_get_frequency(writer_clock_class); | |
361 | assert(freq != -1ULL); | |
362 | ||
363 | ret = bt_ctf_clock_class_get_offset_cycles(writer_clock_class, &cycles_offset); | |
364 | assert(!ret); | |
365 | ||
366 | ns += ns_from_value(freq, cycles_offset); | |
367 | ||
368 | bt_put(writer_clock_class); | |
369 | bt_put(writer_trace); | |
370 | bt_put(writer_stream_class); | |
371 | bt_put(writer_stream); | |
372 | ||
373 | return timestamp - ns; | |
374 | } | |
375 | ||
376 | static | |
377 | struct bt_notification *evaluate_packet_notification( | |
55595636 | 378 | struct bt_notification *notification, |
19ce87a4 | 379 | struct trimmer_iterator *trim_it, |
55595636 MD |
380 | struct trimmer_bound *begin, struct trimmer_bound *end, |
381 | bool *_packet_in_range) | |
72208f03 | 382 | { |
72208f03 JG |
383 | int64_t begin_ns, pkt_begin_ns, end_ns, pkt_end_ns; |
384 | bool in_range = true; | |
19ce87a4 | 385 | struct bt_ctf_packet *packet = NULL, *writer_packet = NULL; |
72208f03 JG |
386 | struct bt_ctf_field *packet_context = NULL, |
387 | *timestamp_begin = NULL, | |
388 | *timestamp_end = NULL; | |
19ce87a4 JD |
389 | struct bt_notification *new_notification = NULL; |
390 | enum bt_component_status ret; | |
391 | bool lazy_update = false; | |
72208f03 JG |
392 | |
393 | switch (bt_notification_get_type(notification)) { | |
394 | case BT_NOTIFICATION_TYPE_PACKET_BEGIN: | |
395 | packet = bt_notification_packet_begin_get_packet(notification); | |
19ce87a4 JD |
396 | assert(packet); |
397 | writer_packet = trimmer_new_packet(trim_it, packet); | |
398 | assert(writer_packet); | |
44d3cbf0 | 399 | break; |
72208f03 JG |
400 | case BT_NOTIFICATION_TYPE_PACKET_END: |
401 | packet = bt_notification_packet_end_get_packet(notification); | |
19ce87a4 JD |
402 | assert(packet); |
403 | writer_packet = trimmer_close_packet(trim_it, packet); | |
404 | assert(writer_packet); | |
72208f03 JG |
405 | break; |
406 | default: | |
19ce87a4 | 407 | goto end; |
44d3cbf0 | 408 | } |
72208f03 | 409 | |
19ce87a4 | 410 | packet_context = bt_ctf_packet_get_context(writer_packet); |
72208f03 | 411 | if (!packet_context) { |
19ce87a4 | 412 | goto end_no_notif; |
72208f03 JG |
413 | } |
414 | ||
415 | if (!bt_ctf_field_is_structure(packet_context)) { | |
19ce87a4 | 416 | goto end_no_notif; |
72208f03 JG |
417 | } |
418 | ||
419 | timestamp_begin = bt_ctf_field_structure_get_field( | |
420 | packet_context, "timestamp_begin"); | |
421 | if (!timestamp_begin || !bt_ctf_field_is_integer(timestamp_begin)) { | |
19ce87a4 | 422 | goto end_no_notif; |
72208f03 JG |
423 | } |
424 | timestamp_end = bt_ctf_field_structure_get_field( | |
425 | packet_context, "timestamp_end"); | |
426 | if (!timestamp_end || !bt_ctf_field_is_integer(timestamp_end)) { | |
19ce87a4 | 427 | goto end_no_notif; |
72208f03 JG |
428 | } |
429 | ||
55595636 | 430 | if (ns_from_integer_field(timestamp_begin, &pkt_begin_ns)) { |
19ce87a4 | 431 | goto end_no_notif; |
72208f03 | 432 | } |
55595636 | 433 | if (ns_from_integer_field(timestamp_end, &pkt_end_ns)) { |
19ce87a4 JD |
434 | goto end_no_notif; |
435 | } | |
436 | ||
437 | if (update_lazy_bound(begin, "begin", pkt_begin_ns, &lazy_update)) { | |
438 | goto end_no_notif; | |
439 | } | |
440 | if (update_lazy_bound(end, "end", pkt_end_ns, &lazy_update)) { | |
441 | goto end_no_notif; | |
442 | } | |
443 | if (lazy_update && begin->set && end->set) { | |
444 | if (begin->value > end->value) { | |
445 | printf_error("Unexpected: time range begin value is above end value"); | |
446 | goto end_no_notif; | |
447 | } | |
72208f03 JG |
448 | } |
449 | ||
450 | begin_ns = begin->set ? begin->value : INT64_MIN; | |
451 | end_ns = end->set ? end->value : INT64_MAX; | |
452 | ||
453 | /* | |
454 | * Accept if there is any overlap between the selected region and the | |
455 | * packet. | |
456 | */ | |
457 | in_range = (pkt_end_ns >= begin_ns) && (pkt_begin_ns <= end_ns); | |
19ce87a4 JD |
458 | if (!in_range) { |
459 | goto end_no_notif; | |
460 | } | |
461 | ||
462 | if (begin_ns > pkt_begin_ns) { | |
463 | ret = update_packet_context_field(trim_it->err, writer_packet, | |
464 | "timestamp_begin", | |
465 | get_raw_timestamp(writer_packet, begin_ns)); | |
466 | assert(!ret); | |
467 | } | |
468 | ||
469 | if (end_ns < pkt_end_ns) { | |
470 | ret = update_packet_context_field(trim_it->err, writer_packet, | |
471 | "timestamp_end", | |
472 | get_raw_timestamp(writer_packet, end_ns)); | |
473 | assert(!ret); | |
474 | } | |
475 | ||
72208f03 | 476 | end: |
19ce87a4 JD |
477 | switch (bt_notification_get_type(notification)) { |
478 | case BT_NOTIFICATION_TYPE_PACKET_BEGIN: | |
479 | new_notification = bt_notification_packet_begin_create(writer_packet); | |
480 | assert(new_notification); | |
481 | break; | |
482 | case BT_NOTIFICATION_TYPE_PACKET_END: | |
483 | new_notification = bt_notification_packet_end_create(writer_packet); | |
484 | assert(new_notification); | |
485 | break; | |
486 | default: | |
487 | break; | |
488 | } | |
489 | end_no_notif: | |
55595636 | 490 | *_packet_in_range = in_range; |
72208f03 | 491 | bt_put(packet); |
19ce87a4 | 492 | bt_put(writer_packet); |
72208f03 JG |
493 | bt_put(packet_context); |
494 | bt_put(timestamp_begin); | |
495 | bt_put(timestamp_end); | |
19ce87a4 JD |
496 | return new_notification; |
497 | } | |
498 | ||
499 | static | |
500 | struct bt_notification *evaluate_stream_notification( | |
501 | struct bt_notification *notification, | |
502 | struct trimmer_iterator *trim_it) | |
503 | { | |
504 | struct bt_ctf_stream *stream; | |
505 | ||
506 | stream = bt_notification_stream_end_get_stream(notification); | |
507 | assert(stream); | |
508 | ||
509 | /* FIXME: useless copy */ | |
510 | return bt_notification_stream_end_create(stream); | |
72208f03 JG |
511 | } |
512 | ||
513 | /* Return true if the notification should be forwarded. */ | |
514 | static | |
55595636 | 515 | enum bt_notification_iterator_status evaluate_notification( |
19ce87a4 JD |
516 | struct bt_notification **notification, |
517 | struct trimmer_iterator *trim_it, | |
55595636 MD |
518 | struct trimmer_bound *begin, struct trimmer_bound *end, |
519 | bool *in_range) | |
72208f03 | 520 | { |
72208f03 | 521 | enum bt_notification_type type; |
19ce87a4 | 522 | struct bt_notification *new_notification = NULL; |
72208f03 | 523 | |
b61397c4 | 524 | *in_range = true; |
19ce87a4 | 525 | type = bt_notification_get_type(*notification); |
72208f03 JG |
526 | switch (type) { |
527 | case BT_NOTIFICATION_TYPE_EVENT: | |
19ce87a4 JD |
528 | new_notification = evaluate_event_notification(*notification, |
529 | trim_it, begin, end, in_range); | |
72208f03 JG |
530 | break; |
531 | case BT_NOTIFICATION_TYPE_PACKET_BEGIN: | |
532 | case BT_NOTIFICATION_TYPE_PACKET_END: | |
19ce87a4 JD |
533 | new_notification = evaluate_packet_notification(*notification, |
534 | trim_it, begin, end, in_range); | |
535 | break; | |
536 | case BT_NOTIFICATION_TYPE_STREAM_END: | |
537 | new_notification = evaluate_stream_notification(*notification, | |
538 | trim_it); | |
72208f03 | 539 | break; |
44d3cbf0 | 540 | default: |
72208f03 | 541 | /* Accept all other notifications. */ |
44d3cbf0 JG |
542 | break; |
543 | } | |
19ce87a4 JD |
544 | BT_PUT(*notification); |
545 | *notification = new_notification; | |
546 | ||
547 | return BT_NOTIFICATION_ITERATOR_STATUS_OK; | |
cab3f160 JG |
548 | } |
549 | ||
550 | BT_HIDDEN | |
41a2b7ae | 551 | struct bt_notification_iterator_next_return trimmer_iterator_next( |
890882ef | 552 | struct bt_private_notification_iterator *iterator) |
cab3f160 | 553 | { |
44d3cbf0 | 554 | struct trimmer_iterator *trim_it = NULL; |
890882ef | 555 | struct bt_private_component *component = NULL; |
44d3cbf0 JG |
556 | struct trimmer *trimmer = NULL; |
557 | struct bt_notification_iterator *source_it = NULL; | |
41a2b7ae PP |
558 | struct bt_notification_iterator_next_return ret = { |
559 | .status = BT_NOTIFICATION_ITERATOR_STATUS_OK, | |
560 | .notification = NULL, | |
561 | }; | |
72208f03 | 562 | bool notification_in_range = false; |
cab3f160 | 563 | |
890882ef | 564 | trim_it = bt_private_notification_iterator_get_user_data(iterator); |
44d3cbf0 JG |
565 | assert(trim_it); |
566 | ||
890882ef PP |
567 | component = bt_private_notification_iterator_get_private_component( |
568 | iterator); | |
44d3cbf0 | 569 | assert(component); |
890882ef | 570 | trimmer = bt_private_component_get_user_data(component); |
44d3cbf0 JG |
571 | assert(trimmer); |
572 | ||
99cdb69e JG |
573 | source_it = trim_it->input_iterator; |
574 | assert(source_it); | |
44d3cbf0 | 575 | |
72208f03 | 576 | while (!notification_in_range) { |
41a2b7ae PP |
577 | ret.status = bt_notification_iterator_next(source_it); |
578 | if (ret.status != BT_NOTIFICATION_ITERATOR_STATUS_OK) { | |
44d3cbf0 JG |
579 | goto end; |
580 | } | |
581 | ||
41a2b7ae | 582 | ret.notification = bt_notification_iterator_get_notification( |
44d3cbf0 | 583 | source_it); |
41a2b7ae PP |
584 | if (!ret.notification) { |
585 | ret.status = BT_NOTIFICATION_ITERATOR_STATUS_ERROR; | |
44d3cbf0 JG |
586 | goto end; |
587 | } | |
588 | ||
19ce87a4 | 589 | ret.status = evaluate_notification(&ret.notification, trim_it, |
55595636 MD |
590 | &trimmer->begin, &trimmer->end, |
591 | ¬ification_in_range); | |
41a2b7ae | 592 | if (!notification_in_range) { |
19ce87a4 | 593 | BT_PUT(ret.notification); |
44d3cbf0 | 594 | } |
6d5f6792 | 595 | |
41a2b7ae | 596 | if (ret.status != BT_NOTIFICATION_ITERATOR_STATUS_OK) { |
6d5f6792 JG |
597 | break; |
598 | } | |
44d3cbf0 | 599 | } |
cab3f160 | 600 | end: |
44d3cbf0 | 601 | bt_put(component); |
cab3f160 JG |
602 | return ret; |
603 | } | |
604 | ||
605 | BT_HIDDEN | |
606 | enum bt_notification_iterator_status trimmer_iterator_seek_time( | |
890882ef PP |
607 | struct bt_private_notification_iterator *iterator, |
608 | int64_t time) | |
cab3f160 | 609 | { |
72b913fb | 610 | return BT_NOTIFICATION_ITERATOR_STATUS_OK; |
cab3f160 | 611 | } |