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 PP |
93 | it_data->input_iterator = |
94 | bt_private_connection_create_notification_iterator(connection); | |
99cdb69e JG |
95 | if (!it_data->input_iterator) { |
96 | ret = BT_NOTIFICATION_ITERATOR_STATUS_NOMEM; | |
97 | goto end; | |
98 | } | |
99 | ||
19ce87a4 JD |
100 | it_data->err = stderr; |
101 | it_data->packet_map = g_hash_table_new_full(g_direct_hash, | |
102 | g_direct_equal, NULL, NULL); | |
103 | ||
890882ef PP |
104 | it_ret = bt_private_notification_iterator_set_user_data(iterator, |
105 | it_data); | |
44d3cbf0 JG |
106 | if (it_ret) { |
107 | goto end; | |
108 | } | |
cab3f160 | 109 | end: |
91457551 | 110 | bt_put(component); |
99cdb69e JG |
111 | bt_put(connection); |
112 | bt_put(input_port); | |
cab3f160 JG |
113 | return ret; |
114 | } | |
115 | ||
528debdf MD |
116 | static |
117 | int update_lazy_bound(struct trimmer_bound *bound, const char *name, | |
55595636 | 118 | int64_t ts, bool *lazy_update) |
528debdf MD |
119 | { |
120 | struct tm tm; | |
121 | int64_t value; | |
122 | time_t timeval; | |
123 | ||
55595636 MD |
124 | *lazy_update = false; |
125 | ||
528debdf MD |
126 | if (!bound->lazy) { |
127 | return 0; | |
128 | } | |
129 | tm.tm_isdst = -1; | |
130 | timeval = ts / NSEC_PER_SEC; | |
131 | ||
132 | if (bound->lazy_values.gmt) { | |
133 | /* Get day, month, year. */ | |
134 | if (!gmtime_r(&timeval, &tm)) { | |
55595636 | 135 | printf_error("Failure in gmtime_r()"); |
528debdf MD |
136 | goto error; |
137 | } | |
138 | tm.tm_sec = bound->lazy_values.ss; | |
139 | tm.tm_min = bound->lazy_values.mm; | |
140 | tm.tm_hour = bound->lazy_values.hh; | |
141 | timeval = timegm(&tm); | |
142 | if (timeval < 0) { | |
55595636 MD |
143 | printf_error("Failure in timegm(), incorrectly formatted %s timestamp", |
144 | name); | |
528debdf MD |
145 | goto error; |
146 | } | |
147 | } else { | |
148 | /* Get day, month, year. */ | |
149 | if (!localtime_r(&timeval, &tm)) { | |
55595636 | 150 | printf_error("Failure in localtime_r()"); |
528debdf MD |
151 | goto error; |
152 | } | |
153 | tm.tm_sec = bound->lazy_values.ss; | |
154 | tm.tm_min = bound->lazy_values.mm; | |
155 | tm.tm_hour = bound->lazy_values.hh; | |
156 | timeval = mktime(&tm); | |
157 | if (timeval < 0) { | |
55595636 | 158 | printf_error("Failure in mktime(), incorrectly formatted %s timestamp", |
528debdf MD |
159 | name); |
160 | goto error; | |
161 | } | |
162 | } | |
163 | value = (int64_t) timeval; | |
164 | value *= NSEC_PER_SEC; | |
165 | value += bound->lazy_values.ns; | |
166 | bound->value = value; | |
167 | bound->set = true; | |
168 | bound->lazy = false; | |
55595636 | 169 | *lazy_update = true; |
528debdf MD |
170 | return 0; |
171 | ||
172 | error: | |
528debdf MD |
173 | return -1; |
174 | } | |
175 | ||
44d3cbf0 | 176 | static |
19ce87a4 JD |
177 | struct bt_notification *evaluate_event_notification( |
178 | struct bt_notification *notification, | |
179 | struct trimmer_iterator *trim_it, | |
55595636 MD |
180 | struct trimmer_bound *begin, struct trimmer_bound *end, |
181 | bool *_event_in_range) | |
44d3cbf0 | 182 | { |
72208f03 JG |
183 | int64_t ts; |
184 | int clock_ret; | |
19ce87a4 | 185 | struct bt_ctf_event *event = NULL, *writer_event; |
72208f03 | 186 | bool in_range = true; |
ac0c6bdd | 187 | struct bt_ctf_clock_class *clock_class = NULL; |
72208f03 | 188 | struct bt_ctf_trace *trace = NULL; |
44d3cbf0 | 189 | struct bt_ctf_stream *stream = NULL; |
72208f03 JG |
190 | struct bt_ctf_stream_class *stream_class = NULL; |
191 | struct bt_ctf_clock_value *clock_value = NULL; | |
55595636 | 192 | bool lazy_update = false; |
19ce87a4 JD |
193 | struct bt_notification *new_notification = NULL; |
194 | struct bt_clock_class_priority_map *cc_prio_map; | |
44d3cbf0 | 195 | |
72208f03 JG |
196 | event = bt_notification_event_get_event(notification); |
197 | assert(event); | |
19ce87a4 JD |
198 | cc_prio_map = bt_notification_event_get_clock_class_priority_map( |
199 | notification); | |
200 | assert(cc_prio_map); | |
201 | writer_event = trimmer_output_event(trim_it, event); | |
202 | assert(writer_event); | |
203 | new_notification = bt_notification_event_create(writer_event, cc_prio_map); | |
204 | assert(new_notification); | |
205 | bt_put(cc_prio_map); | |
44d3cbf0 | 206 | |
72208f03 JG |
207 | stream = bt_ctf_event_get_stream(event); |
208 | assert(stream); | |
44d3cbf0 | 209 | |
72208f03 JG |
210 | stream_class = bt_ctf_stream_get_class(stream); |
211 | assert(stream_class); | |
212 | ||
213 | trace = bt_ctf_stream_class_get_trace(stream_class); | |
214 | assert(trace); | |
215 | ||
216 | /* FIXME multi-clock? */ | |
9ac68eb1 | 217 | clock_class = bt_ctf_trace_get_clock_class_by_index(trace, 0); |
ac0c6bdd | 218 | if (!clock_class) { |
72208f03 | 219 | goto end; |
44d3cbf0 | 220 | } |
44d3cbf0 | 221 | |
ac0c6bdd | 222 | clock_value = bt_ctf_event_get_clock_value(event, clock_class); |
72208f03 | 223 | if (!clock_value) { |
55595636 | 224 | printf_error("Failed to retrieve clock value"); |
19ce87a4 | 225 | goto error; |
44d3cbf0 | 226 | } |
72208f03 JG |
227 | |
228 | clock_ret = bt_ctf_clock_value_get_value_ns_from_epoch( | |
229 | clock_value, &ts); | |
230 | if (clock_ret) { | |
55595636 | 231 | printf_error("Failed to retrieve clock value timestamp"); |
19ce87a4 | 232 | goto error; |
44d3cbf0 | 233 | } |
55595636 | 234 | if (update_lazy_bound(begin, "begin", ts, &lazy_update)) { |
528debdf MD |
235 | goto end; |
236 | } | |
55595636 | 237 | if (update_lazy_bound(end, "end", ts, &lazy_update)) { |
528debdf MD |
238 | goto end; |
239 | } | |
55595636 MD |
240 | if (lazy_update && begin->set && end->set) { |
241 | if (begin->value > end->value) { | |
242 | printf_error("Unexpected: time range begin value is above end value"); | |
19ce87a4 | 243 | goto error; |
55595636 MD |
244 | } |
245 | } | |
72208f03 JG |
246 | if (begin->set && ts < begin->value) { |
247 | in_range = false; | |
248 | } | |
249 | if (end->set && ts > end->value) { | |
250 | in_range = false; | |
251 | } | |
19ce87a4 JD |
252 | |
253 | goto end; | |
254 | ||
255 | error: | |
256 | BT_PUT(new_notification); | |
44d3cbf0 | 257 | end: |
72208f03 | 258 | bt_put(event); |
19ce87a4 | 259 | bt_put(writer_event); |
ac0c6bdd | 260 | bt_put(clock_class); |
72208f03 JG |
261 | bt_put(trace); |
262 | bt_put(stream); | |
263 | bt_put(stream_class); | |
264 | bt_put(clock_value); | |
55595636 | 265 | *_event_in_range = in_range; |
19ce87a4 | 266 | return new_notification; |
44d3cbf0 JG |
267 | } |
268 | ||
44d3cbf0 | 269 | static |
72208f03 | 270 | int ns_from_integer_field(struct bt_ctf_field *integer, int64_t *ns) |
44d3cbf0 | 271 | { |
72208f03 JG |
272 | int ret = 0; |
273 | int is_signed; | |
274 | uint64_t raw_clock_value; | |
275 | struct bt_ctf_field_type *integer_type = NULL; | |
ac0c6bdd | 276 | struct bt_ctf_clock_class *clock_class = NULL; |
44d3cbf0 JG |
277 | struct bt_ctf_clock_value *clock_value = NULL; |
278 | ||
72208f03 JG |
279 | integer_type = bt_ctf_field_get_type(integer); |
280 | assert(integer_type); | |
ac0c6bdd PP |
281 | clock_class = bt_ctf_field_type_integer_get_mapped_clock_class( |
282 | integer_type); | |
283 | if (!clock_class) { | |
72208f03 | 284 | ret = -1; |
44d3cbf0 JG |
285 | goto end; |
286 | } | |
287 | ||
72208f03 JG |
288 | is_signed = bt_ctf_field_type_integer_get_signed(integer_type); |
289 | if (!is_signed) { | |
290 | ret = bt_ctf_field_unsigned_integer_get_value(integer, | |
291 | &raw_clock_value); | |
292 | if (ret) { | |
44d3cbf0 JG |
293 | goto end; |
294 | } | |
72208f03 JG |
295 | } else { |
296 | /* Signed clock values are unsupported. */ | |
297 | goto end; | |
298 | } | |
44d3cbf0 | 299 | |
ac0c6bdd | 300 | clock_value = bt_ctf_clock_value_create(clock_class, raw_clock_value); |
72208f03 JG |
301 | if (!clock_value) { |
302 | goto end; | |
303 | } | |
44d3cbf0 | 304 | |
72208f03 JG |
305 | ret = bt_ctf_clock_value_get_value_ns_from_epoch(clock_value, ns); |
306 | end: | |
307 | bt_put(integer_type); | |
ac0c6bdd | 308 | bt_put(clock_class); |
72208f03 JG |
309 | bt_put(clock_value); |
310 | return ret; | |
311 | } | |
44d3cbf0 | 312 | |
19ce87a4 JD |
313 | static uint64_t ns_from_value(uint64_t frequency, uint64_t value) |
314 | { | |
315 | uint64_t ns; | |
316 | ||
317 | if (frequency == NSEC_PER_SEC) { | |
318 | ns = value; | |
319 | } else { | |
320 | ns = (uint64_t) ((1e9 * (double) value) / (double) frequency); | |
321 | } | |
322 | ||
323 | return ns; | |
324 | } | |
325 | ||
326 | /* | |
327 | * timestamp minus the offset. | |
328 | */ | |
72208f03 | 329 | static |
19ce87a4 JD |
330 | int64_t get_raw_timestamp(struct bt_ctf_packet *writer_packet, |
331 | int64_t timestamp) | |
332 | { | |
333 | struct bt_ctf_clock_class *writer_clock_class; | |
334 | int64_t sec_offset, cycles_offset, ns; | |
335 | struct bt_ctf_trace *writer_trace; | |
336 | struct bt_ctf_stream *writer_stream; | |
337 | struct bt_ctf_stream_class *writer_stream_class; | |
338 | int ret; | |
339 | uint64_t freq; | |
340 | ||
341 | writer_stream = bt_ctf_packet_get_stream(writer_packet); | |
342 | assert(writer_stream); | |
343 | ||
344 | writer_stream_class = bt_ctf_stream_get_class(writer_stream); | |
345 | assert(writer_stream_class); | |
346 | ||
347 | writer_trace = bt_ctf_stream_class_get_trace(writer_stream_class); | |
348 | assert(writer_trace); | |
349 | ||
350 | /* FIXME multi-clock? */ | |
9ac68eb1 PP |
351 | writer_clock_class = bt_ctf_trace_get_clock_class_by_index( |
352 | writer_trace, 0); | |
19ce87a4 JD |
353 | assert(writer_clock_class); |
354 | ||
355 | ret = bt_ctf_clock_class_get_offset_s(writer_clock_class, &sec_offset); | |
356 | assert(!ret); | |
357 | ns = sec_offset * NSEC_PER_SEC; | |
358 | ||
359 | freq = bt_ctf_clock_class_get_frequency(writer_clock_class); | |
360 | assert(freq != -1ULL); | |
361 | ||
362 | ret = bt_ctf_clock_class_get_offset_cycles(writer_clock_class, &cycles_offset); | |
363 | assert(!ret); | |
364 | ||
365 | ns += ns_from_value(freq, cycles_offset); | |
366 | ||
367 | bt_put(writer_clock_class); | |
368 | bt_put(writer_trace); | |
369 | bt_put(writer_stream_class); | |
370 | bt_put(writer_stream); | |
371 | ||
372 | return timestamp - ns; | |
373 | } | |
374 | ||
375 | static | |
376 | struct bt_notification *evaluate_packet_notification( | |
55595636 | 377 | struct bt_notification *notification, |
19ce87a4 | 378 | struct trimmer_iterator *trim_it, |
55595636 MD |
379 | struct trimmer_bound *begin, struct trimmer_bound *end, |
380 | bool *_packet_in_range) | |
72208f03 | 381 | { |
72208f03 JG |
382 | int64_t begin_ns, pkt_begin_ns, end_ns, pkt_end_ns; |
383 | bool in_range = true; | |
19ce87a4 | 384 | struct bt_ctf_packet *packet = NULL, *writer_packet = NULL; |
72208f03 JG |
385 | struct bt_ctf_field *packet_context = NULL, |
386 | *timestamp_begin = NULL, | |
387 | *timestamp_end = NULL; | |
19ce87a4 JD |
388 | struct bt_notification *new_notification = NULL; |
389 | enum bt_component_status ret; | |
390 | bool lazy_update = false; | |
72208f03 JG |
391 | |
392 | switch (bt_notification_get_type(notification)) { | |
393 | case BT_NOTIFICATION_TYPE_PACKET_BEGIN: | |
394 | packet = bt_notification_packet_begin_get_packet(notification); | |
19ce87a4 JD |
395 | assert(packet); |
396 | writer_packet = trimmer_new_packet(trim_it, packet); | |
397 | assert(writer_packet); | |
44d3cbf0 | 398 | break; |
72208f03 JG |
399 | case BT_NOTIFICATION_TYPE_PACKET_END: |
400 | packet = bt_notification_packet_end_get_packet(notification); | |
19ce87a4 JD |
401 | assert(packet); |
402 | writer_packet = trimmer_close_packet(trim_it, packet); | |
403 | assert(writer_packet); | |
72208f03 JG |
404 | break; |
405 | default: | |
19ce87a4 | 406 | goto end; |
44d3cbf0 | 407 | } |
72208f03 | 408 | |
19ce87a4 | 409 | packet_context = bt_ctf_packet_get_context(writer_packet); |
72208f03 | 410 | if (!packet_context) { |
19ce87a4 | 411 | goto end_no_notif; |
72208f03 JG |
412 | } |
413 | ||
414 | if (!bt_ctf_field_is_structure(packet_context)) { | |
19ce87a4 | 415 | goto end_no_notif; |
72208f03 JG |
416 | } |
417 | ||
418 | timestamp_begin = bt_ctf_field_structure_get_field( | |
419 | packet_context, "timestamp_begin"); | |
420 | if (!timestamp_begin || !bt_ctf_field_is_integer(timestamp_begin)) { | |
19ce87a4 | 421 | goto end_no_notif; |
72208f03 JG |
422 | } |
423 | timestamp_end = bt_ctf_field_structure_get_field( | |
424 | packet_context, "timestamp_end"); | |
425 | if (!timestamp_end || !bt_ctf_field_is_integer(timestamp_end)) { | |
19ce87a4 | 426 | goto end_no_notif; |
72208f03 JG |
427 | } |
428 | ||
55595636 | 429 | if (ns_from_integer_field(timestamp_begin, &pkt_begin_ns)) { |
19ce87a4 | 430 | goto end_no_notif; |
72208f03 | 431 | } |
55595636 | 432 | if (ns_from_integer_field(timestamp_end, &pkt_end_ns)) { |
19ce87a4 JD |
433 | goto end_no_notif; |
434 | } | |
435 | ||
436 | if (update_lazy_bound(begin, "begin", pkt_begin_ns, &lazy_update)) { | |
437 | goto end_no_notif; | |
438 | } | |
439 | if (update_lazy_bound(end, "end", pkt_end_ns, &lazy_update)) { | |
440 | goto end_no_notif; | |
441 | } | |
442 | if (lazy_update && begin->set && end->set) { | |
443 | if (begin->value > end->value) { | |
444 | printf_error("Unexpected: time range begin value is above end value"); | |
445 | goto end_no_notif; | |
446 | } | |
72208f03 JG |
447 | } |
448 | ||
449 | begin_ns = begin->set ? begin->value : INT64_MIN; | |
450 | end_ns = end->set ? end->value : INT64_MAX; | |
451 | ||
452 | /* | |
453 | * Accept if there is any overlap between the selected region and the | |
454 | * packet. | |
455 | */ | |
456 | in_range = (pkt_end_ns >= begin_ns) && (pkt_begin_ns <= end_ns); | |
19ce87a4 JD |
457 | if (!in_range) { |
458 | goto end_no_notif; | |
459 | } | |
460 | ||
461 | if (begin_ns > pkt_begin_ns) { | |
462 | ret = update_packet_context_field(trim_it->err, writer_packet, | |
463 | "timestamp_begin", | |
464 | get_raw_timestamp(writer_packet, begin_ns)); | |
465 | assert(!ret); | |
466 | } | |
467 | ||
468 | if (end_ns < pkt_end_ns) { | |
469 | ret = update_packet_context_field(trim_it->err, writer_packet, | |
470 | "timestamp_end", | |
471 | get_raw_timestamp(writer_packet, end_ns)); | |
472 | assert(!ret); | |
473 | } | |
474 | ||
72208f03 | 475 | end: |
19ce87a4 JD |
476 | switch (bt_notification_get_type(notification)) { |
477 | case BT_NOTIFICATION_TYPE_PACKET_BEGIN: | |
478 | new_notification = bt_notification_packet_begin_create(writer_packet); | |
479 | assert(new_notification); | |
480 | break; | |
481 | case BT_NOTIFICATION_TYPE_PACKET_END: | |
482 | new_notification = bt_notification_packet_end_create(writer_packet); | |
483 | assert(new_notification); | |
484 | break; | |
485 | default: | |
486 | break; | |
487 | } | |
488 | end_no_notif: | |
55595636 | 489 | *_packet_in_range = in_range; |
72208f03 | 490 | bt_put(packet); |
19ce87a4 | 491 | bt_put(writer_packet); |
72208f03 JG |
492 | bt_put(packet_context); |
493 | bt_put(timestamp_begin); | |
494 | bt_put(timestamp_end); | |
19ce87a4 JD |
495 | return new_notification; |
496 | } | |
497 | ||
498 | static | |
499 | struct bt_notification *evaluate_stream_notification( | |
500 | struct bt_notification *notification, | |
501 | struct trimmer_iterator *trim_it) | |
502 | { | |
503 | struct bt_ctf_stream *stream; | |
504 | ||
505 | stream = bt_notification_stream_end_get_stream(notification); | |
506 | assert(stream); | |
507 | ||
508 | /* FIXME: useless copy */ | |
509 | return bt_notification_stream_end_create(stream); | |
72208f03 JG |
510 | } |
511 | ||
512 | /* Return true if the notification should be forwarded. */ | |
513 | static | |
55595636 | 514 | enum bt_notification_iterator_status evaluate_notification( |
19ce87a4 JD |
515 | struct bt_notification **notification, |
516 | struct trimmer_iterator *trim_it, | |
55595636 MD |
517 | struct trimmer_bound *begin, struct trimmer_bound *end, |
518 | bool *in_range) | |
72208f03 | 519 | { |
72208f03 | 520 | enum bt_notification_type type; |
19ce87a4 | 521 | struct bt_notification *new_notification = NULL; |
72208f03 | 522 | |
b61397c4 | 523 | *in_range = true; |
19ce87a4 | 524 | type = bt_notification_get_type(*notification); |
72208f03 JG |
525 | switch (type) { |
526 | case BT_NOTIFICATION_TYPE_EVENT: | |
19ce87a4 JD |
527 | new_notification = evaluate_event_notification(*notification, |
528 | trim_it, begin, end, in_range); | |
72208f03 JG |
529 | break; |
530 | case BT_NOTIFICATION_TYPE_PACKET_BEGIN: | |
531 | case BT_NOTIFICATION_TYPE_PACKET_END: | |
19ce87a4 JD |
532 | new_notification = evaluate_packet_notification(*notification, |
533 | trim_it, begin, end, in_range); | |
534 | break; | |
535 | case BT_NOTIFICATION_TYPE_STREAM_END: | |
536 | new_notification = evaluate_stream_notification(*notification, | |
537 | trim_it); | |
72208f03 | 538 | break; |
44d3cbf0 | 539 | default: |
72208f03 | 540 | /* Accept all other notifications. */ |
44d3cbf0 JG |
541 | break; |
542 | } | |
19ce87a4 JD |
543 | BT_PUT(*notification); |
544 | *notification = new_notification; | |
545 | ||
546 | return BT_NOTIFICATION_ITERATOR_STATUS_OK; | |
cab3f160 JG |
547 | } |
548 | ||
549 | BT_HIDDEN | |
41a2b7ae | 550 | struct bt_notification_iterator_next_return trimmer_iterator_next( |
890882ef | 551 | struct bt_private_notification_iterator *iterator) |
cab3f160 | 552 | { |
44d3cbf0 | 553 | struct trimmer_iterator *trim_it = NULL; |
890882ef | 554 | struct bt_private_component *component = NULL; |
44d3cbf0 JG |
555 | struct trimmer *trimmer = NULL; |
556 | struct bt_notification_iterator *source_it = NULL; | |
41a2b7ae PP |
557 | struct bt_notification_iterator_next_return ret = { |
558 | .status = BT_NOTIFICATION_ITERATOR_STATUS_OK, | |
559 | .notification = NULL, | |
560 | }; | |
72208f03 | 561 | bool notification_in_range = false; |
cab3f160 | 562 | |
890882ef | 563 | trim_it = bt_private_notification_iterator_get_user_data(iterator); |
44d3cbf0 JG |
564 | assert(trim_it); |
565 | ||
890882ef PP |
566 | component = bt_private_notification_iterator_get_private_component( |
567 | iterator); | |
44d3cbf0 | 568 | assert(component); |
890882ef | 569 | trimmer = bt_private_component_get_user_data(component); |
44d3cbf0 JG |
570 | assert(trimmer); |
571 | ||
99cdb69e JG |
572 | source_it = trim_it->input_iterator; |
573 | assert(source_it); | |
44d3cbf0 | 574 | |
72208f03 | 575 | while (!notification_in_range) { |
41a2b7ae PP |
576 | ret.status = bt_notification_iterator_next(source_it); |
577 | if (ret.status != BT_NOTIFICATION_ITERATOR_STATUS_OK) { | |
44d3cbf0 JG |
578 | goto end; |
579 | } | |
580 | ||
41a2b7ae | 581 | ret.notification = bt_notification_iterator_get_notification( |
44d3cbf0 | 582 | source_it); |
41a2b7ae PP |
583 | if (!ret.notification) { |
584 | ret.status = BT_NOTIFICATION_ITERATOR_STATUS_ERROR; | |
44d3cbf0 JG |
585 | goto end; |
586 | } | |
587 | ||
19ce87a4 | 588 | ret.status = evaluate_notification(&ret.notification, trim_it, |
55595636 MD |
589 | &trimmer->begin, &trimmer->end, |
590 | ¬ification_in_range); | |
41a2b7ae | 591 | if (!notification_in_range) { |
19ce87a4 | 592 | BT_PUT(ret.notification); |
44d3cbf0 | 593 | } |
6d5f6792 | 594 | |
41a2b7ae | 595 | if (ret.status != BT_NOTIFICATION_ITERATOR_STATUS_OK) { |
6d5f6792 JG |
596 | break; |
597 | } | |
44d3cbf0 | 598 | } |
cab3f160 | 599 | end: |
44d3cbf0 | 600 | bt_put(component); |
cab3f160 JG |
601 | return ret; |
602 | } | |
603 | ||
604 | BT_HIDDEN | |
605 | enum bt_notification_iterator_status trimmer_iterator_seek_time( | |
890882ef PP |
606 | struct bt_private_notification_iterator *iterator, |
607 | int64_t time) | |
cab3f160 | 608 | { |
72b913fb | 609 | return BT_NOTIFICATION_ITERATOR_STATUS_OK; |
cab3f160 | 610 | } |