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