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