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