trimmer: remove unused function
[babeltrace.git] / src / plugins / utils / trimmer / trimmer.c
CommitLineData
cab3f160 1/*
cab3f160 2 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
7de0e49a 3 * Copyright 2019 Philippe Proulx <pproulx@efficios.com>
cab3f160
JG
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 */
23
ec4ae660 24#define BT_COMP_LOG_SELF_COMP (trimmer_comp->self_comp)
0d9a3d3e 25#define BT_LOG_OUTPUT_LEVEL (trimmer_comp->log_level)
350ad6c1 26#define BT_LOG_TAG "PLUGIN/FLT.UTILS.TRIMMER"
ec4ae660 27#include "plugins/comp-logging.h"
b4565e8b 28
578e048b
MJ
29#include "compat/utc.h"
30#include "compat/time.h"
3fadfbc0 31#include <babeltrace2/babeltrace.h>
578e048b 32#include "common/common.h"
578e048b 33#include "common/assert.h"
7de0e49a
PP
34#include <stdint.h>
35#include <inttypes.h>
36#include <glib.h>
37
38#include "trimmer.h"
39
40#define NS_PER_S INT64_C(1000000000)
41
42static const char * const in_port_name = "in";
43
44struct trimmer_time {
45 unsigned int hour, minute, second, ns;
46};
47
48struct trimmer_bound {
49 /*
50 * Nanoseconds from origin, valid if `is_set` is set and
51 * `is_infinite` is false.
52 */
53 int64_t ns_from_origin;
54
55 /* True if this bound's full time (`ns_from_origin`) is set */
56 bool is_set;
57
58 /*
59 * True if this bound represents the infinity (negative or
60 * positive depending on which bound it is). If this is true,
61 * then we don't care about `ns_from_origin` above.
62 */
63 bool is_infinite;
64
65 /*
66 * This bound's time without the date; this time is used to set
67 * `ns_from_origin` once we know the date.
68 */
69 struct trimmer_time time;
70};
71
72struct trimmer_comp {
73 struct trimmer_bound begin, end;
74 bool is_gmt;
0d9a3d3e 75 bt_logging_level log_level;
ec4ae660 76 bt_self_component *self_comp;
7de0e49a
PP
77};
78
79enum trimmer_iterator_state {
80 /*
81 * Find the first message's date and set the bounds's times
82 * accordingly.
83 */
84 TRIMMER_ITERATOR_STATE_SET_BOUNDS_NS_FROM_ORIGIN,
85
86 /*
87 * Initially seek to the trimming range's beginning time.
88 */
89 TRIMMER_ITERATOR_STATE_SEEK_INITIALLY,
90
91 /*
92 * Fill the output message queue for as long as received input
93 * messages are within the trimming time range.
94 */
95 TRIMMER_ITERATOR_STATE_TRIM,
96
97 /* Flush the remaining messages in the output message queue */
98 TRIMMER_ITERATOR_STATE_ENDING,
99
100 /* Trimming operation and message iterator is ended */
101 TRIMMER_ITERATOR_STATE_ENDED,
102};
103
104struct trimmer_iterator {
105 /* Weak */
106 struct trimmer_comp *trimmer_comp;
107
108 /* Weak */
109 bt_self_message_iterator *self_msg_iter;
110
111 enum trimmer_iterator_state state;
112
113 /* Owned by this */
114 bt_self_component_port_input_message_iterator *upstream_iter;
115 struct trimmer_bound begin, end;
116
117 /*
118 * Queue of `const bt_message *` (owned by the queue).
119 *
120 * This is where the trimming operation pushes the messages to
121 * output by this message iterator.
122 */
123 GQueue *output_messages;
124
125 /*
126 * Hash table of `bt_stream *` (weak) to
127 * `struct trimmer_iterator_stream_state *` (owned by the HT).
128 */
129 GHashTable *stream_states;
130};
131
132struct trimmer_iterator_stream_state {
7de0e49a
PP
133 /*
134 * True if the last pushed message for this stream was a stream
135 * activity end message.
136 */
137 bool last_msg_is_stream_activity_end;
138
139 /*
140 * Time to use for a generated stream end activity message when
141 * ending the stream.
142 */
143 int64_t stream_act_end_ns_from_origin;
144
145 /* Weak */
146 const bt_stream *stream;
147
148 /* Owned by this (`NULL` initially and between packets) */
149 const bt_packet *cur_packet;
7de0e49a 150};
cab3f160
JG
151
152static
7de0e49a 153void destroy_trimmer_comp(struct trimmer_comp *trimmer_comp)
cab3f160 154{
7de0e49a
PP
155 BT_ASSERT(trimmer_comp);
156 g_free(trimmer_comp);
cab3f160
JG
157}
158
159static
7de0e49a
PP
160struct trimmer_comp *create_trimmer_comp(void)
161{
162 return g_new0(struct trimmer_comp, 1);
163}
164
165BT_HIDDEN
166void trimmer_finalize(bt_self_component_filter *self_comp)
cab3f160 167{
7de0e49a
PP
168 struct trimmer_comp *trimmer_comp =
169 bt_self_component_get_data(
170 bt_self_component_filter_as_self_component(self_comp));
171
172 if (trimmer_comp) {
173 destroy_trimmer_comp(trimmer_comp);
174 }
cab3f160
JG
175}
176
7de0e49a
PP
177/*
178 * Sets the time (in ns from origin) of a trimmer bound from date and
179 * time components.
180 *
181 * Returns a negative value if anything goes wrong.
182 */
183static
184int set_bound_ns_from_origin(struct trimmer_bound *bound,
185 unsigned int year, unsigned int month, unsigned int day,
186 unsigned int hour, unsigned int minute, unsigned int second,
187 unsigned int ns, bool is_gmt)
cab3f160 188{
7de0e49a
PP
189 int ret = 0;
190 time_t result;
191 struct tm tm = {
192 .tm_sec = second,
193 .tm_min = minute,
194 .tm_hour = hour,
195 .tm_mday = day,
196 .tm_mon = month - 1,
197 .tm_year = year - 1900,
198 .tm_isdst = -1,
199 };
200
201 if (is_gmt) {
202 result = bt_timegm(&tm);
203 } else {
204 result = mktime(&tm);
205 }
206
207 if (result < 0) {
208 ret = -1;
209 goto end;
210 }
cab3f160 211
7de0e49a
PP
212 BT_ASSERT(bound);
213 bound->ns_from_origin = (int64_t) result;
214 bound->ns_from_origin *= NS_PER_S;
215 bound->ns_from_origin += ns;
216 bound->is_set = true;
217
218end:
219 return ret;
cab3f160
JG
220}
221
528debdf
MD
222/*
223 * Parses a timestamp, figuring out its format.
224 *
225 * Returns a negative value if anything goes wrong.
226 *
227 * Expected formats:
228 *
7de0e49a
PP
229 * YYYY-MM-DD hh:mm[:ss[.ns]]
230 * [hh:mm:]ss[.ns]
231 * [-]s[.ns]
232 *
233 * TODO: Check overflows.
234 */
235static
0d9a3d3e
PP
236int set_bound_from_str(struct trimmer_comp *trimmer_comp,
237 const char *str, struct trimmer_bound *bound, bool is_gmt)
7de0e49a
PP
238{
239 int ret = 0;
240 int s_ret;
241 unsigned int year, month, day, hour, minute, second, ns;
242 char dummy;
243
244 /* Try `YYYY-MM-DD hh:mm:ss.ns` format */
245 s_ret = sscanf(str, "%u-%u-%u %u:%u:%u.%u%c", &year, &month, &day,
246 &hour, &minute, &second, &ns, &dummy);
247 if (s_ret == 7) {
248 ret = set_bound_ns_from_origin(bound, year, month, day,
249 hour, minute, second, ns, is_gmt);
250 goto end;
251 }
252
253 /* Try `YYYY-MM-DD hh:mm:ss` format */
254 s_ret = sscanf(str, "%u-%u-%u %u:%u:%u%c", &year, &month, &day,
255 &hour, &minute, &second, &dummy);
256 if (s_ret == 6) {
257 ret = set_bound_ns_from_origin(bound, year, month, day,
258 hour, minute, second, 0, is_gmt);
259 goto end;
260 }
261
262 /* Try `YYYY-MM-DD hh:mm` format */
263 s_ret = sscanf(str, "%u-%u-%u %u:%u%c", &year, &month, &day,
264 &hour, &minute, &dummy);
265 if (s_ret == 5) {
266 ret = set_bound_ns_from_origin(bound, year, month, day,
267 hour, minute, 0, 0, is_gmt);
268 goto end;
269 }
270
271 /* Try `YYYY-MM-DD` format */
272 s_ret = sscanf(str, "%u-%u-%u%c", &year, &month, &day, &dummy);
273 if (s_ret == 3) {
274 ret = set_bound_ns_from_origin(bound, year, month, day,
275 0, 0, 0, 0, is_gmt);
276 goto end;
277 }
278
279 /* Try `hh:mm:ss.ns` format */
280 s_ret = sscanf(str, "%u:%u:%u.%u%c", &hour, &minute, &second, &ns,
281 &dummy);
282 if (s_ret == 4) {
283 bound->time.hour = hour;
284 bound->time.minute = minute;
285 bound->time.second = second;
286 bound->time.ns = ns;
287 goto end;
288 }
289
290 /* Try `hh:mm:ss` format */
291 s_ret = sscanf(str, "%u:%u:%u%c", &hour, &minute, &second, &dummy);
292 if (s_ret == 3) {
293 bound->time.hour = hour;
294 bound->time.minute = minute;
295 bound->time.second = second;
296 bound->time.ns = 0;
297 goto end;
298 }
299
300 /* Try `-s.ns` format */
301 s_ret = sscanf(str, "-%u.%u%c", &second, &ns, &dummy);
302 if (s_ret == 2) {
303 bound->ns_from_origin = -((int64_t) second) * NS_PER_S;
304 bound->ns_from_origin -= (int64_t) ns;
305 bound->is_set = true;
306 goto end;
307 }
308
309 /* Try `s.ns` format */
310 s_ret = sscanf(str, "%u.%u%c", &second, &ns, &dummy);
311 if (s_ret == 2) {
312 bound->ns_from_origin = ((int64_t) second) * NS_PER_S;
313 bound->ns_from_origin += (int64_t) ns;
314 bound->is_set = true;
315 goto end;
316 }
317
318 /* Try `-s` format */
319 s_ret = sscanf(str, "-%u%c", &second, &dummy);
320 if (s_ret == 1) {
321 bound->ns_from_origin = -((int64_t) second) * NS_PER_S;
322 bound->is_set = true;
323 goto end;
324 }
325
326 /* Try `s` format */
327 s_ret = sscanf(str, "%u%c", &second, &dummy);
328 if (s_ret == 1) {
329 bound->ns_from_origin = (int64_t) second * NS_PER_S;
330 bound->is_set = true;
331 goto end;
332 }
333
ec4ae660 334 BT_COMP_LOGE("Invalid date/time format: param=\"%s\"", str);
7de0e49a
PP
335 ret = -1;
336
337end:
338 return ret;
339}
340
341/*
342 * Sets a trimmer bound's properties from a parameter string/integer
343 * value.
344 *
345 * Returns a negative value if anything goes wrong.
528debdf 346 */
44d3cbf0 347static
0d9a3d3e
PP
348int set_bound_from_param(struct trimmer_comp *trimmer_comp,
349 const char *param_name, const bt_value *param,
7de0e49a 350 struct trimmer_bound *bound, bool is_gmt)
528debdf
MD
351{
352 int ret;
268fae9a 353 const char *arg;
7de0e49a 354 char tmp_arg[64];
268fae9a 355
fdd3a2da
PP
356 if (bt_value_is_signed_integer(param)) {
357 int64_t value = bt_value_signed_integer_get(param);
7de0e49a
PP
358
359 /*
360 * Just convert it to a temporary string to handle
361 * everything the same way.
362 */
363 sprintf(tmp_arg, "%" PRId64, value);
364 arg = tmp_arg;
365 } else if (bt_value_is_string(param)) {
366 arg = bt_value_string_get(param);
367 } else {
ec4ae660 368 BT_COMP_LOGE("`%s` parameter must be an integer or a string value.",
268fae9a 369 param_name);
7de0e49a
PP
370 ret = -1;
371 goto end;
268fae9a
PP
372 }
373
0d9a3d3e 374 ret = set_bound_from_str(trimmer_comp, arg, bound, is_gmt);
7de0e49a
PP
375
376end:
377 return ret;
378}
379
380static
0d9a3d3e
PP
381int validate_trimmer_bounds(struct trimmer_comp *trimmer_comp,
382 struct trimmer_bound *begin, struct trimmer_bound *end)
7de0e49a
PP
383{
384 int ret = 0;
385
386 BT_ASSERT(begin->is_set);
387 BT_ASSERT(end->is_set);
388
389 if (!begin->is_infinite && !end->is_infinite &&
390 begin->ns_from_origin > end->ns_from_origin) {
ec4ae660 391 BT_COMP_LOGE("Trimming time range's beginning time is greater than end time: "
7de0e49a
PP
392 "begin-ns-from-origin=%" PRId64 ", "
393 "end-ns-from-origin=%" PRId64,
394 begin->ns_from_origin,
395 end->ns_from_origin);
396 ret = -1;
397 goto end;
528debdf
MD
398 }
399
7de0e49a 400 if (!begin->is_infinite && begin->ns_from_origin == INT64_MIN) {
ec4ae660 401 BT_COMP_LOGE("Invalid trimming time range's beginning time: "
7de0e49a
PP
402 "ns-from-origin=%" PRId64,
403 begin->ns_from_origin);
404 ret = -1;
405 goto end;
406 }
528debdf 407
7de0e49a 408 if (!end->is_infinite && end->ns_from_origin == INT64_MIN) {
ec4ae660 409 BT_COMP_LOGE("Invalid trimming time range's end time: "
7de0e49a
PP
410 "ns-from-origin=%" PRId64,
411 end->ns_from_origin);
412 ret = -1;
413 goto end;
414 }
528debdf 415
7de0e49a
PP
416end:
417 return ret;
528debdf
MD
418}
419
420static
7de0e49a
PP
421int init_trimmer_comp_from_params(struct trimmer_comp *trimmer_comp,
422 const bt_value *params)
44d3cbf0 423{
7de0e49a
PP
424 const bt_value *value;
425 int ret = 0;
44d3cbf0 426
f6ccaed9 427 BT_ASSERT(params);
7de0e49a 428 value = bt_value_map_borrow_entry_value_const(params, "gmt");
528debdf 429 if (value) {
7de0e49a 430 trimmer_comp->is_gmt = (bool) bt_value_bool_get(value);
528debdf
MD
431 }
432
7de0e49a 433 value = bt_value_map_borrow_entry_value_const(params, "begin");
528debdf 434 if (value) {
0d9a3d3e 435 if (set_bound_from_param(trimmer_comp, "begin", value,
7de0e49a
PP
436 &trimmer_comp->begin, trimmer_comp->is_gmt)) {
437 /* set_bound_from_param() logs errors */
d24d5663 438 ret = -1;
268fae9a 439 goto end;
44d3cbf0 440 }
7de0e49a
PP
441 } else {
442 trimmer_comp->begin.is_infinite = true;
443 trimmer_comp->begin.is_set = true;
44d3cbf0 444 }
528debdf 445
7de0e49a 446 value = bt_value_map_borrow_entry_value_const(params, "end");
528debdf 447 if (value) {
0d9a3d3e 448 if (set_bound_from_param(trimmer_comp, "end", value,
7de0e49a
PP
449 &trimmer_comp->end, trimmer_comp->is_gmt)) {
450 /* set_bound_from_param() logs errors */
d24d5663 451 ret = -1;
268fae9a 452 goto end;
528debdf 453 }
7de0e49a
PP
454 } else {
455 trimmer_comp->end.is_infinite = true;
456 trimmer_comp->end.is_set = true;
528debdf 457 }
268fae9a 458
528debdf 459end:
7de0e49a
PP
460 if (trimmer_comp->begin.is_set && trimmer_comp->end.is_set) {
461 /* validate_trimmer_bounds() logs errors */
0d9a3d3e
PP
462 ret = validate_trimmer_bounds(trimmer_comp,
463 &trimmer_comp->begin, &trimmer_comp->end);
55595636 464 }
7de0e49a 465
528debdf 466 return ret;
44d3cbf0
JG
467}
468
d24d5663
PP
469bt_component_class_init_method_status trimmer_init(
470 bt_self_component_filter *self_comp_flt,
7de0e49a 471 const bt_value *params, void *init_data)
cab3f160 472{
7de0e49a 473 int ret;
d24d5663
PP
474 bt_component_class_init_method_status status =
475 BT_COMPONENT_CLASS_INIT_METHOD_STATUS_OK;
476 bt_self_component_add_port_status add_port_status;
7de0e49a 477 struct trimmer_comp *trimmer_comp = create_trimmer_comp();
ec4ae660
PP
478 bt_self_component *self_comp =
479 bt_self_component_filter_as_self_component(self_comp_flt);
7de0e49a 480 if (!trimmer_comp) {
d24d5663 481 status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_MEMORY_ERROR;
7de0e49a 482 goto error;
cab3f160
JG
483 }
484
0d9a3d3e 485 trimmer_comp->log_level = bt_component_get_logging_level(
ec4ae660
PP
486 bt_self_component_as_component(self_comp));
487 trimmer_comp->self_comp = self_comp;
d24d5663 488 add_port_status = bt_self_component_filter_add_input_port(
ec4ae660 489 self_comp_flt, in_port_name, NULL, NULL);
d24d5663
PP
490 switch (add_port_status) {
491 case BT_SELF_COMPONENT_ADD_PORT_STATUS_ERROR:
492 status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_ERROR;
b9d103be 493 goto error;
d24d5663
PP
494 case BT_SELF_COMPONENT_ADD_PORT_STATUS_MEMORY_ERROR:
495 status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_MEMORY_ERROR;
496 goto error;
497 default:
498 break;
b9d103be
PP
499 }
500
d24d5663 501 add_port_status = bt_self_component_filter_add_output_port(
ec4ae660 502 self_comp_flt, "out", NULL, NULL);
d24d5663
PP
503 switch (add_port_status) {
504 case BT_SELF_COMPONENT_ADD_PORT_STATUS_ERROR:
505 status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_ERROR;
b9d103be 506 goto error;
d24d5663
PP
507 case BT_SELF_COMPONENT_ADD_PORT_STATUS_MEMORY_ERROR:
508 status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_MEMORY_ERROR;
509 goto error;
510 default:
511 break;
b9d103be
PP
512 }
513
7de0e49a
PP
514 ret = init_trimmer_comp_from_params(trimmer_comp, params);
515 if (ret) {
d24d5663 516 status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_ERROR;
cab3f160
JG
517 goto error;
518 }
519
ec4ae660 520 bt_self_component_set_data(self_comp, trimmer_comp);
7de0e49a
PP
521 goto end;
522
523error:
d24d5663
PP
524 if (status == BT_COMPONENT_CLASS_INIT_METHOD_STATUS_OK) {
525 status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_ERROR;
7de0e49a
PP
526 }
527
528 if (trimmer_comp) {
529 destroy_trimmer_comp(trimmer_comp);
530 }
531
cab3f160 532end:
8dad9b32 533 return status;
7de0e49a
PP
534}
535
536static
537void destroy_trimmer_iterator(struct trimmer_iterator *trimmer_it)
538{
539 BT_ASSERT(trimmer_it);
540 bt_self_component_port_input_message_iterator_put_ref(
541 trimmer_it->upstream_iter);
542
543 if (trimmer_it->output_messages) {
544 g_queue_free(trimmer_it->output_messages);
545 }
546
547 if (trimmer_it->stream_states) {
548 g_hash_table_destroy(trimmer_it->stream_states);
549 }
550
551 g_free(trimmer_it);
552}
553
554static
555void destroy_trimmer_iterator_stream_state(
556 struct trimmer_iterator_stream_state *sstate)
557{
558 BT_ASSERT(sstate);
559 BT_PACKET_PUT_REF_AND_RESET(sstate->cur_packet);
7de0e49a
PP
560 g_free(sstate);
561}
562
563BT_HIDDEN
d24d5663 564bt_component_class_message_iterator_init_method_status trimmer_msg_iter_init(
7de0e49a
PP
565 bt_self_message_iterator *self_msg_iter,
566 bt_self_component_filter *self_comp,
567 bt_self_component_port_output *port)
568{
d24d5663
PP
569 bt_component_class_message_iterator_init_method_status status =
570 BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_OK;
7de0e49a
PP
571 struct trimmer_iterator *trimmer_it;
572
573 trimmer_it = g_new0(struct trimmer_iterator, 1);
574 if (!trimmer_it) {
d24d5663 575 status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_MEMORY_ERROR;
7de0e49a
PP
576 goto end;
577 }
578
579 trimmer_it->trimmer_comp = bt_self_component_get_data(
580 bt_self_component_filter_as_self_component(self_comp));
581 BT_ASSERT(trimmer_it->trimmer_comp);
582
583 if (trimmer_it->trimmer_comp->begin.is_set &&
584 trimmer_it->trimmer_comp->end.is_set) {
585 /*
586 * Both trimming time range's bounds are set, so skip
587 * the
588 * `TRIMMER_ITERATOR_STATE_SET_BOUNDS_NS_FROM_ORIGIN`
589 * phase.
590 */
591 trimmer_it->state = TRIMMER_ITERATOR_STATE_SEEK_INITIALLY;
592 }
593
594 trimmer_it->begin = trimmer_it->trimmer_comp->begin;
595 trimmer_it->end = trimmer_it->trimmer_comp->end;
596 trimmer_it->upstream_iter =
597 bt_self_component_port_input_message_iterator_create(
598 bt_self_component_filter_borrow_input_port_by_name(
599 self_comp, in_port_name));
600 if (!trimmer_it->upstream_iter) {
d24d5663 601 status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_ERROR;
7de0e49a
PP
602 goto end;
603 }
604
605 trimmer_it->output_messages = g_queue_new();
606 if (!trimmer_it->output_messages) {
d24d5663 607 status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_MEMORY_ERROR;
7de0e49a
PP
608 goto end;
609 }
610
611 trimmer_it->stream_states = g_hash_table_new_full(g_direct_hash,
612 g_direct_equal, NULL,
613 (GDestroyNotify) destroy_trimmer_iterator_stream_state);
614 if (!trimmer_it->stream_states) {
d24d5663 615 status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_MEMORY_ERROR;
7de0e49a
PP
616 goto end;
617 }
618
619 trimmer_it->self_msg_iter = self_msg_iter;
620 bt_self_message_iterator_set_data(self_msg_iter, trimmer_it);
621
622end:
d24d5663 623 if (status != BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_OK && trimmer_it) {
7de0e49a
PP
624 destroy_trimmer_iterator(trimmer_it);
625 }
626
627 return status;
628}
629
630static inline
631int get_msg_ns_from_origin(const bt_message *msg, int64_t *ns_from_origin,
632 bool *skip)
633{
634 const bt_clock_class *clock_class = NULL;
635 const bt_clock_snapshot *clock_snapshot = NULL;
7de0e49a
PP
636 bt_message_stream_activity_clock_snapshot_state sa_cs_state;
637 int ret = 0;
638
639 BT_ASSERT(msg);
640 BT_ASSERT(ns_from_origin);
641 BT_ASSERT(skip);
642
643 switch (bt_message_get_type(msg)) {
644 case BT_MESSAGE_TYPE_EVENT:
645 clock_class =
646 bt_message_event_borrow_stream_class_default_clock_class_const(
647 msg);
91d81473 648 if (G_UNLIKELY(!clock_class)) {
7de0e49a
PP
649 goto error;
650 }
651
0cbc2c33
PP
652 clock_snapshot = bt_message_event_borrow_default_clock_snapshot_const(
653 msg);
7de0e49a
PP
654 break;
655 case BT_MESSAGE_TYPE_PACKET_BEGINNING:
656 clock_class =
657 bt_message_packet_beginning_borrow_stream_class_default_clock_class_const(
658 msg);
91d81473 659 if (G_UNLIKELY(!clock_class)) {
7de0e49a
PP
660 goto error;
661 }
662
0cbc2c33
PP
663 clock_snapshot = bt_message_packet_beginning_borrow_default_clock_snapshot_const(
664 msg);
7de0e49a
PP
665 break;
666 case BT_MESSAGE_TYPE_PACKET_END:
667 clock_class =
668 bt_message_packet_end_borrow_stream_class_default_clock_class_const(
669 msg);
91d81473 670 if (G_UNLIKELY(!clock_class)) {
7de0e49a
PP
671 goto error;
672 }
673
0cbc2c33
PP
674 clock_snapshot = bt_message_packet_end_borrow_default_clock_snapshot_const(
675 msg);
7de0e49a
PP
676 break;
677 case BT_MESSAGE_TYPE_DISCARDED_EVENTS:
678 clock_class =
679 bt_message_discarded_events_borrow_stream_class_default_clock_class_const(
680 msg);
91d81473 681 if (G_UNLIKELY(!clock_class)) {
7de0e49a
PP
682 goto error;
683 }
684
9b24b6aa 685 clock_snapshot = bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const(
0cbc2c33 686 msg);
7de0e49a
PP
687 break;
688 case BT_MESSAGE_TYPE_DISCARDED_PACKETS:
689 clock_class =
690 bt_message_discarded_packets_borrow_stream_class_default_clock_class_const(
691 msg);
91d81473 692 if (G_UNLIKELY(!clock_class)) {
7de0e49a
PP
693 goto error;
694 }
695
9b24b6aa 696 clock_snapshot = bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
0cbc2c33 697 msg);
7de0e49a
PP
698 break;
699 case BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING:
700 clock_class =
701 bt_message_stream_activity_beginning_borrow_stream_class_default_clock_class_const(
702 msg);
91d81473 703 if (G_UNLIKELY(!clock_class)) {
7de0e49a
PP
704 goto error;
705 }
706
707 sa_cs_state = bt_message_stream_activity_beginning_borrow_default_clock_snapshot_const(
708 msg, &clock_snapshot);
709 if (sa_cs_state == BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_UNKNOWN ||
710 sa_cs_state == BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_INFINITE) {
711 /* Lowest possible time to always include them */
712 *ns_from_origin = INT64_MIN;
713 goto no_clock_snapshot;
714 }
715
716 break;
717 case BT_MESSAGE_TYPE_STREAM_ACTIVITY_END:
718 clock_class =
719 bt_message_stream_activity_end_borrow_stream_class_default_clock_class_const(
720 msg);
91d81473 721 if (G_UNLIKELY(!clock_class)) {
7de0e49a
PP
722 goto error;
723 }
724
725 sa_cs_state = bt_message_stream_activity_end_borrow_default_clock_snapshot_const(
726 msg, &clock_snapshot);
727 if (sa_cs_state == BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_UNKNOWN) {
728 /* Lowest time to always include it */
729 *ns_from_origin = INT64_MIN;
730 goto no_clock_snapshot;
731 } else if (sa_cs_state == BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_INFINITE) {
732 /* Greatest time to always exclude it */
733 *ns_from_origin = INT64_MAX;
734 goto no_clock_snapshot;
735 }
736
737 break;
738 case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY:
0cbc2c33 739 clock_snapshot =
7de0e49a 740 bt_message_message_iterator_inactivity_borrow_default_clock_snapshot_const(
0cbc2c33 741 msg);
7de0e49a
PP
742 break;
743 default:
744 goto no_clock_snapshot;
745 }
746
7de0e49a
PP
747 ret = bt_clock_snapshot_get_ns_from_origin(clock_snapshot,
748 ns_from_origin);
91d81473 749 if (G_UNLIKELY(ret)) {
7de0e49a
PP
750 goto error;
751 }
752
753 goto end;
754
755no_clock_snapshot:
756 *skip = true;
757 goto end;
758
cab3f160 759error:
7de0e49a
PP
760 ret = -1;
761
762end:
763 return ret;
764}
765
766static inline
767void put_messages(bt_message_array_const msgs, uint64_t count)
768{
769 uint64_t i;
770
771 for (i = 0; i < count; i++) {
772 BT_MESSAGE_PUT_REF_AND_RESET(msgs[i]);
773 }
774}
775
776static inline
0d9a3d3e
PP
777int set_trimmer_iterator_bound(struct trimmer_iterator *trimmer_it,
778 struct trimmer_bound *bound, int64_t ns_from_origin,
779 bool is_gmt)
7de0e49a 780{
0d9a3d3e 781 struct trimmer_comp *trimmer_comp = trimmer_it->trimmer_comp;
7de0e49a
PP
782 struct tm tm;
783 time_t time_seconds = (time_t) (ns_from_origin / NS_PER_S);
784 int ret = 0;
785
786 BT_ASSERT(!bound->is_set);
787 errno = 0;
788
789 /* We only need to extract the date from this time */
790 if (is_gmt) {
791 bt_gmtime_r(&time_seconds, &tm);
792 } else {
793 bt_localtime_r(&time_seconds, &tm);
794 }
795
796 if (errno) {
ec4ae660 797 BT_COMP_LOGE_ERRNO("Cannot convert timestamp to date and time",
7de0e49a
PP
798 "ts=%" PRId64, (int64_t) time_seconds);
799 ret = -1;
800 goto end;
801 }
802
803 ret = set_bound_ns_from_origin(bound, tm.tm_year + 1900, tm.tm_mon + 1,
804 tm.tm_mday, bound->time.hour, bound->time.minute,
805 bound->time.second, bound->time.ns, is_gmt);
806
807end:
cab3f160
JG
808 return ret;
809}
7de0e49a
PP
810
811static
d24d5663
PP
812bt_component_class_message_iterator_next_method_status
813state_set_trimmer_iterator_bounds(
7de0e49a
PP
814 struct trimmer_iterator *trimmer_it)
815{
d24d5663
PP
816 bt_message_iterator_next_status upstream_iter_status =
817 BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK;
7de0e49a
PP
818 struct trimmer_comp *trimmer_comp = trimmer_it->trimmer_comp;
819 bt_message_array_const msgs;
820 uint64_t count = 0;
821 int64_t ns_from_origin = INT64_MIN;
822 uint64_t i;
823 int ret;
824
825 BT_ASSERT(!trimmer_it->begin.is_set ||
826 !trimmer_it->end.is_set);
827
828 while (true) {
829 upstream_iter_status =
830 bt_self_component_port_input_message_iterator_next(
831 trimmer_it->upstream_iter, &msgs, &count);
d24d5663 832 if (upstream_iter_status != BT_MESSAGE_ITERATOR_NEXT_STATUS_OK) {
7de0e49a
PP
833 goto end;
834 }
835
836 for (i = 0; i < count; i++) {
837 const bt_message *msg = msgs[i];
838 bool skip = false;
839 int ret;
840
841 ret = get_msg_ns_from_origin(msg, &ns_from_origin,
842 &skip);
843 if (ret) {
844 goto error;
845 }
846
847 if (skip) {
848 continue;
849 }
850
851 BT_ASSERT(ns_from_origin != INT64_MIN &&
852 ns_from_origin != INT64_MAX);
853 put_messages(msgs, count);
854 goto found;
855 }
856
857 put_messages(msgs, count);
858 }
859
860found:
861 if (!trimmer_it->begin.is_set) {
862 BT_ASSERT(!trimmer_it->begin.is_infinite);
0d9a3d3e 863 ret = set_trimmer_iterator_bound(trimmer_it, &trimmer_it->begin,
7de0e49a
PP
864 ns_from_origin, trimmer_comp->is_gmt);
865 if (ret) {
866 goto error;
867 }
868 }
869
870 if (!trimmer_it->end.is_set) {
871 BT_ASSERT(!trimmer_it->end.is_infinite);
0d9a3d3e 872 ret = set_trimmer_iterator_bound(trimmer_it, &trimmer_it->end,
7de0e49a
PP
873 ns_from_origin, trimmer_comp->is_gmt);
874 if (ret) {
875 goto error;
876 }
877 }
878
0d9a3d3e
PP
879 ret = validate_trimmer_bounds(trimmer_it->trimmer_comp,
880 &trimmer_it->begin, &trimmer_it->end);
7de0e49a
PP
881 if (ret) {
882 goto error;
883 }
884
885 goto end;
886
887error:
888 put_messages(msgs, count);
d24d5663
PP
889 upstream_iter_status =
890 BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR;
7de0e49a
PP
891
892end:
893 return (int) upstream_iter_status;
894}
895
896static
d24d5663 897bt_component_class_message_iterator_next_method_status state_seek_initially(
7de0e49a
PP
898 struct trimmer_iterator *trimmer_it)
899{
0d9a3d3e 900 struct trimmer_comp *trimmer_comp = trimmer_it->trimmer_comp;
d24d5663
PP
901 bt_component_class_message_iterator_next_method_status status =
902 BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK;
7de0e49a
PP
903
904 BT_ASSERT(trimmer_it->begin.is_set);
905
906 if (trimmer_it->begin.is_infinite) {
907 if (!bt_self_component_port_input_message_iterator_can_seek_beginning(
908 trimmer_it->upstream_iter)) {
ec4ae660 909 BT_COMP_LOGE_STR("Cannot make upstream message iterator initially seek its beginning.");
d24d5663 910 status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR;
7de0e49a
PP
911 goto end;
912 }
913
914 status = (int) bt_self_component_port_input_message_iterator_seek_beginning(
915 trimmer_it->upstream_iter);
916 } else {
917 if (!bt_self_component_port_input_message_iterator_can_seek_ns_from_origin(
918 trimmer_it->upstream_iter,
919 trimmer_it->begin.ns_from_origin)) {
ec4ae660 920 BT_COMP_LOGE("Cannot make upstream message iterator initially seek: "
7de0e49a
PP
921 "seek-ns-from-origin=%" PRId64,
922 trimmer_it->begin.ns_from_origin);
d24d5663 923 status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR;
7de0e49a
PP
924 goto end;
925 }
926
927 status = (int) bt_self_component_port_input_message_iterator_seek_ns_from_origin(
928 trimmer_it->upstream_iter, trimmer_it->begin.ns_from_origin);
929 }
930
d24d5663 931 if (status == BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK) {
7de0e49a
PP
932 trimmer_it->state = TRIMMER_ITERATOR_STATE_TRIM;
933 }
934
935end:
936 return status;
937}
938
939static inline
940void push_message(struct trimmer_iterator *trimmer_it, const bt_message *msg)
941{
942 g_queue_push_head(trimmer_it->output_messages, (void *) msg);
943}
944
945static inline
946const bt_message *pop_message(struct trimmer_iterator *trimmer_it)
947{
948 return g_queue_pop_tail(trimmer_it->output_messages);
949}
950
951static inline
952int clock_raw_value_from_ns_from_origin(const bt_clock_class *clock_class,
953 int64_t ns_from_origin, uint64_t *raw_value)
954{
955
956 int64_t cc_offset_s;
957 uint64_t cc_offset_cycles;
958 uint64_t cc_freq;
959
960 bt_clock_class_get_offset(clock_class, &cc_offset_s, &cc_offset_cycles);
961 cc_freq = bt_clock_class_get_frequency(clock_class);
962 return bt_common_clock_value_from_ns_from_origin(cc_offset_s,
963 cc_offset_cycles, cc_freq, ns_from_origin, raw_value);
964}
965
966static inline
d24d5663
PP
967bt_component_class_message_iterator_next_method_status
968end_stream(struct trimmer_iterator *trimmer_it,
7de0e49a
PP
969 struct trimmer_iterator_stream_state *sstate)
970{
d24d5663
PP
971 bt_component_class_message_iterator_next_method_status status =
972 BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK;
7de0e49a
PP
973 uint64_t raw_value;
974 const bt_clock_class *clock_class;
975 int ret;
976 bt_message *msg = NULL;
977
978 BT_ASSERT(!trimmer_it->end.is_infinite);
979
980 if (!sstate->stream) {
981 goto end;
982 }
983
984 if (sstate->cur_packet) {
985 /*
986 * The last message could not have been a stream
987 * activity end message if we have a current packet.
988 */
989 BT_ASSERT(!sstate->last_msg_is_stream_activity_end);
990
991 /*
992 * Create and push a packet end message, making its time
993 * the trimming range's end time.
994 */
995 clock_class = bt_stream_class_borrow_default_clock_class_const(
996 bt_stream_borrow_class_const(sstate->stream));
997 BT_ASSERT(clock_class);
998 ret = clock_raw_value_from_ns_from_origin(clock_class,
999 trimmer_it->end.ns_from_origin, &raw_value);
1000 if (ret) {
d24d5663 1001 status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR;
7de0e49a
PP
1002 goto end;
1003 }
1004
1005 msg = bt_message_packet_end_create_with_default_clock_snapshot(
1006 trimmer_it->self_msg_iter, sstate->cur_packet,
1007 raw_value);
1008 if (!msg) {
d24d5663 1009 status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_MEMORY_ERROR;
7de0e49a
PP
1010 goto end;
1011 }
1012
1013 push_message(trimmer_it, msg);
1014 msg = NULL;
1015 BT_PACKET_PUT_REF_AND_RESET(sstate->cur_packet);
1016
1017 /*
1018 * Because we generated a packet end message, set the
1019 * stream activity end message's time to use to the
1020 * trimming range's end time (this packet end message's
1021 * time).
1022 */
1023 sstate->stream_act_end_ns_from_origin =
1024 trimmer_it->end.ns_from_origin;
1025 }
1026
1027 if (!sstate->last_msg_is_stream_activity_end) {
1028 /* Create and push a stream activity end message */
1029 msg = bt_message_stream_activity_end_create(
1030 trimmer_it->self_msg_iter, sstate->stream);
1031 if (!msg) {
d24d5663 1032 status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_MEMORY_ERROR;
7de0e49a
PP
1033 goto end;
1034 }
1035
1036 clock_class = bt_stream_class_borrow_default_clock_class_const(
1037 bt_stream_borrow_class_const(sstate->stream));
1038 BT_ASSERT(clock_class);
cb179cb6
PP
1039
1040 if (sstate->stream_act_end_ns_from_origin == INT64_MIN) {
1041 /*
1042 * We received at least what is necessary to
1043 * have a stream state (stream beginning and
1044 * stream activity beginning messages), but
1045 * nothing else: use the trimmer range's end
1046 * time.
1047 */
1048 sstate->stream_act_end_ns_from_origin =
1049 trimmer_it->end.ns_from_origin;
1050 }
1051
7de0e49a
PP
1052 ret = clock_raw_value_from_ns_from_origin(clock_class,
1053 sstate->stream_act_end_ns_from_origin, &raw_value);
1054 if (ret) {
d24d5663 1055 status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR;
7de0e49a
PP
1056 goto end;
1057 }
1058
1059 bt_message_stream_activity_end_set_default_clock_snapshot(
1060 msg, raw_value);
1061 push_message(trimmer_it, msg);
1062 msg = NULL;
1063 }
1064
1065 /* Create and push a stream end message */
1066 msg = bt_message_stream_end_create(trimmer_it->self_msg_iter,
1067 sstate->stream);
1068 if (!msg) {
d24d5663 1069 status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_MEMORY_ERROR;
7de0e49a
PP
1070 goto end;
1071 }
1072
1073 push_message(trimmer_it, msg);
1074 msg = NULL;
1075
1076 /*
1077 * Just to make sure that we don't use this stream state again
1078 * in the future without an obvious error.
1079 */
1080 sstate->stream = NULL;
1081
1082end:
1083 bt_message_put_ref(msg);
1084 return status;
1085}
1086
1087static inline
d24d5663 1088bt_component_class_message_iterator_next_method_status end_iterator_streams(
7de0e49a
PP
1089 struct trimmer_iterator *trimmer_it)
1090{
d24d5663
PP
1091 bt_component_class_message_iterator_next_method_status status =
1092 BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK;
7de0e49a
PP
1093 GHashTableIter iter;
1094 gpointer key, sstate;
1095
1096 if (trimmer_it->end.is_infinite) {
1097 /*
1098 * An infinite trimming range's end time guarantees that
1099 * we received (and pushed) all the appropriate end
1100 * messages.
1101 */
1102 goto remove_all;
1103 }
1104
1105 /*
1106 * End each stream and then remove them from the hash table of
1107 * stream states to release unneeded references.
1108 */
1109 g_hash_table_iter_init(&iter, trimmer_it->stream_states);
1110
1111 while (g_hash_table_iter_next(&iter, &key, &sstate)) {
1112 status = end_stream(trimmer_it, sstate);
1113 if (status) {
1114 goto end;
1115 }
1116 }
1117
1118remove_all:
1119 g_hash_table_remove_all(trimmer_it->stream_states);
1120
1121end:
1122 return status;
1123}
1124
7de0e49a
PP
1125/*
1126 * Handles a message which is associated to a given stream state. This
1127 * _could_ make the iterator's output message queue grow; this could
1128 * also consume the message without pushing anything to this queue, only
1129 * modifying the stream state.
1130 *
1131 * This function consumes the `msg` reference, _whatever the outcome_.
1132 *
1133 * `ns_from_origin` is the message's time, as given by
1134 * get_msg_ns_from_origin().
1135 *
1136 * This function sets `reached_end` if handling this message made the
1137 * iterator reach the end of the trimming range. Note that the output
1138 * message queue could contain messages even if this function sets
1139 * `reached_end`.
1140 */
1141static inline
d24d5663
PP
1142bt_component_class_message_iterator_next_method_status
1143handle_message_with_stream_state(
7de0e49a
PP
1144 struct trimmer_iterator *trimmer_it, const bt_message *msg,
1145 struct trimmer_iterator_stream_state *sstate,
1146 int64_t ns_from_origin, bool *reached_end)
1147{
d24d5663
PP
1148 bt_component_class_message_iterator_next_method_status status =
1149 BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK;
7de0e49a
PP
1150 bt_message_type msg_type = bt_message_get_type(msg);
1151 int ret;
1152
1153 switch (msg_type) {
1154 case BT_MESSAGE_TYPE_EVENT:
91d81473 1155 if (G_UNLIKELY(!trimmer_it->end.is_infinite &&
7de0e49a
PP
1156 ns_from_origin > trimmer_it->end.ns_from_origin)) {
1157 status = end_iterator_streams(trimmer_it);
1158 *reached_end = true;
1159 break;
1160 }
1161
7de0e49a
PP
1162 BT_ASSERT(sstate->cur_packet);
1163 push_message(trimmer_it, msg);
1164 msg = NULL;
1165 break;
1166 case BT_MESSAGE_TYPE_PACKET_BEGINNING:
91d81473 1167 if (G_UNLIKELY(!trimmer_it->end.is_infinite &&
7de0e49a
PP
1168 ns_from_origin > trimmer_it->end.ns_from_origin)) {
1169 status = end_iterator_streams(trimmer_it);
1170 *reached_end = true;
1171 break;
1172 }
1173
7de0e49a
PP
1174 BT_ASSERT(!sstate->cur_packet);
1175 sstate->cur_packet =
1176 bt_message_packet_beginning_borrow_packet_const(msg);
1177 bt_packet_get_ref(sstate->cur_packet);
1178 push_message(trimmer_it, msg);
1179 msg = NULL;
1180 break;
1181 case BT_MESSAGE_TYPE_PACKET_END:
1182 sstate->stream_act_end_ns_from_origin = ns_from_origin;
1183
91d81473 1184 if (G_UNLIKELY(!trimmer_it->end.is_infinite &&
7de0e49a
PP
1185 ns_from_origin > trimmer_it->end.ns_from_origin)) {
1186 status = end_iterator_streams(trimmer_it);
1187 *reached_end = true;
1188 break;
1189 }
1190
7de0e49a
PP
1191 BT_ASSERT(sstate->cur_packet);
1192 BT_PACKET_PUT_REF_AND_RESET(sstate->cur_packet);
1193 push_message(trimmer_it, msg);
1194 msg = NULL;
1195 break;
1196 case BT_MESSAGE_TYPE_DISCARDED_EVENTS:
1197 case BT_MESSAGE_TYPE_DISCARDED_PACKETS:
1198 {
1199 /*
1200 * `ns_from_origin` is the message's time range's
1201 * beginning time here.
1202 */
1203 int64_t end_ns_from_origin;
1204 const bt_clock_snapshot *end_cs;
1205
1206 if (bt_message_get_type(msg) ==
1207 BT_MESSAGE_TYPE_DISCARDED_EVENTS) {
1208 /*
1209 * Safe to ignore the return value because we
1210 * know there's a default clock and it's always
1211 * known.
1212 */
9b24b6aa 1213 end_cs = bt_message_discarded_events_borrow_end_default_clock_snapshot_const(
0cbc2c33 1214 msg);
7de0e49a
PP
1215 } else {
1216 /*
1217 * Safe to ignore the return value because we
1218 * know there's a default clock and it's always
1219 * known.
1220 */
9b24b6aa 1221 end_cs = bt_message_discarded_packets_borrow_end_default_clock_snapshot_const(
0cbc2c33 1222 msg);
7de0e49a
PP
1223 }
1224
1225 if (bt_clock_snapshot_get_ns_from_origin(end_cs,
1226 &end_ns_from_origin)) {
d24d5663 1227 status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR;
7de0e49a
PP
1228 goto end;
1229 }
1230
1231 sstate->stream_act_end_ns_from_origin = end_ns_from_origin;
1232
1233 if (!trimmer_it->end.is_infinite &&
1234 ns_from_origin > trimmer_it->end.ns_from_origin) {
1235 status = end_iterator_streams(trimmer_it);
1236 *reached_end = true;
1237 break;
1238 }
1239
1240 if (!trimmer_it->end.is_infinite &&
1241 end_ns_from_origin > trimmer_it->end.ns_from_origin) {
1242 /*
1243 * This message's end time is outside the
1244 * trimming time range: replace it with a new
1245 * message having an end time equal to the
1246 * trimming time range's end and without a
1247 * count.
1248 */
1249 const bt_clock_class *clock_class =
1250 bt_clock_snapshot_borrow_clock_class_const(
1251 end_cs);
1252 const bt_clock_snapshot *begin_cs;
1253 bt_message *new_msg;
1254 uint64_t end_raw_value;
1255
1256 ret = clock_raw_value_from_ns_from_origin(clock_class,
1257 trimmer_it->end.ns_from_origin, &end_raw_value);
1258 if (ret) {
d24d5663 1259 status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR;
7de0e49a
PP
1260 goto end;
1261 }
1262
1263 if (msg_type == BT_MESSAGE_TYPE_DISCARDED_EVENTS) {
9b24b6aa 1264 begin_cs = bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const(
0cbc2c33 1265 msg);
7de0e49a
PP
1266 new_msg = bt_message_discarded_events_create_with_default_clock_snapshots(
1267 trimmer_it->self_msg_iter,
1268 sstate->stream,
1269 bt_clock_snapshot_get_value(begin_cs),
1270 end_raw_value);
1271 } else {
9b24b6aa 1272 begin_cs = bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
0cbc2c33 1273 msg);
7de0e49a
PP
1274 new_msg = bt_message_discarded_packets_create_with_default_clock_snapshots(
1275 trimmer_it->self_msg_iter,
1276 sstate->stream,
1277 bt_clock_snapshot_get_value(begin_cs),
1278 end_raw_value);
1279 }
1280
1281 if (!new_msg) {
d24d5663 1282 status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_MEMORY_ERROR;
7de0e49a
PP
1283 goto end;
1284 }
1285
1286 /* Replace the original message */
1287 BT_MESSAGE_MOVE_REF(msg, new_msg);
1288 }
1289
7de0e49a
PP
1290 push_message(trimmer_it, msg);
1291 msg = NULL;
1292 break;
1293 }
1294 case BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING:
1295 if (!trimmer_it->end.is_infinite &&
1296 ns_from_origin > trimmer_it->end.ns_from_origin) {
1297 /*
1298 * This only happens when the message's time is
1299 * known and is greater than the trimming
1300 * range's end time. Unknown and -inf times are
1301 * always less than
1302 * `trimmer_it->end.ns_from_origin`.
1303 */
1304 status = end_iterator_streams(trimmer_it);
1305 *reached_end = true;
1306 break;
1307 }
1308
5b7b55be
SM
1309 push_message(trimmer_it, msg);
1310 msg = NULL;
7de0e49a
PP
1311 break;
1312 case BT_MESSAGE_TYPE_STREAM_ACTIVITY_END:
1313 if (trimmer_it->end.is_infinite) {
1314 push_message(trimmer_it, msg);
1315 msg = NULL;
1316 break;
1317 }
1318
1319 if (ns_from_origin == INT64_MIN) {
5b7b55be
SM
1320 /* Unknown: consider it to be in the trimmer window. */
1321 push_message(trimmer_it, msg);
1322 msg = NULL;
1323 sstate->last_msg_is_stream_activity_end = true;
7de0e49a
PP
1324 } else if (ns_from_origin == INT64_MAX) {
1325 /* Infinite: use trimming range's end time */
1326 sstate->stream_act_end_ns_from_origin =
1327 trimmer_it->end.ns_from_origin;
1328 } else {
1329 /* Known: check if outside of trimming range */
1330 if (ns_from_origin > trimmer_it->end.ns_from_origin) {
1331 sstate->stream_act_end_ns_from_origin =
1332 trimmer_it->end.ns_from_origin;
1333 status = end_iterator_streams(trimmer_it);
1334 *reached_end = true;
1335 break;
1336 }
1337
7de0e49a
PP
1338 push_message(trimmer_it, msg);
1339 msg = NULL;
1340 sstate->last_msg_is_stream_activity_end = true;
1341 sstate->stream_act_end_ns_from_origin = ns_from_origin;
1342 }
1343
1344 break;
1345 case BT_MESSAGE_TYPE_STREAM_BEGINNING:
5b7b55be
SM
1346 push_message(trimmer_it, msg);
1347 msg = NULL;
7de0e49a
PP
1348 break;
1349 case BT_MESSAGE_TYPE_STREAM_END:
5b7b55be
SM
1350 /*
1351 * This is the end of a stream: end this
1352 * stream if its stream activity end message
1353 * time is not the trimming range's end time
1354 * (which means the final stream activity end
1355 * message had an infinite time). end_stream()
1356 * will generate its own stream end message.
1357 */
1358 if (trimmer_it->end.is_infinite) {
1359 push_message(trimmer_it, msg);
1360 msg = NULL;
1361
1362 /* We won't need this stream state again */
1363 g_hash_table_remove(trimmer_it->stream_states, sstate->stream);
1364 } else if (sstate->stream_act_end_ns_from_origin <
1365 trimmer_it->end.ns_from_origin) {
1366 status = end_stream(trimmer_it, sstate);
d24d5663 1367 if (status != BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK) {
5b7b55be 1368 goto end;
7de0e49a 1369 }
5b7b55be
SM
1370
1371 /* We won't need this stream state again */
7de0e49a
PP
1372 g_hash_table_remove(trimmer_it->stream_states, sstate->stream);
1373 }
7de0e49a
PP
1374 break;
1375 default:
1376 break;
1377 }
1378
1379end:
1380 /* We release the message's reference whatever the outcome */
1381 bt_message_put_ref(msg);
d24d5663 1382 return BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK;
7de0e49a
PP
1383}
1384
1385/*
1386 * Handles an input message. This _could_ make the iterator's output
1387 * message queue grow; this could also consume the message without
1388 * pushing anything to this queue, only modifying the stream state.
1389 *
1390 * This function consumes the `msg` reference, _whatever the outcome_.
1391 *
1392 * This function sets `reached_end` if handling this message made the
1393 * iterator reach the end of the trimming range. Note that the output
1394 * message queue could contain messages even if this function sets
1395 * `reached_end`.
1396 */
1397static inline
d24d5663 1398bt_component_class_message_iterator_next_method_status handle_message(
7de0e49a
PP
1399 struct trimmer_iterator *trimmer_it, const bt_message *msg,
1400 bool *reached_end)
1401{
d24d5663 1402 bt_component_class_message_iterator_next_method_status status;
7de0e49a
PP
1403 const bt_stream *stream = NULL;
1404 int64_t ns_from_origin = INT64_MIN;
1405 bool skip;
1406 int ret;
1407 struct trimmer_iterator_stream_state *sstate = NULL;
0d9a3d3e 1408 struct trimmer_comp *trimmer_comp = trimmer_it->trimmer_comp;
7de0e49a
PP
1409
1410 /* Find message's associated stream */
1411 switch (bt_message_get_type(msg)) {
1412 case BT_MESSAGE_TYPE_EVENT:
1413 stream = bt_event_borrow_stream_const(
1414 bt_message_event_borrow_event_const(msg));
1415 break;
1416 case BT_MESSAGE_TYPE_PACKET_BEGINNING:
1417 stream = bt_packet_borrow_stream_const(
1418 bt_message_packet_beginning_borrow_packet_const(msg));
1419 break;
1420 case BT_MESSAGE_TYPE_PACKET_END:
1421 stream = bt_packet_borrow_stream_const(
1422 bt_message_packet_end_borrow_packet_const(msg));
1423 break;
1424 case BT_MESSAGE_TYPE_DISCARDED_EVENTS:
1425 stream = bt_message_discarded_events_borrow_stream_const(msg);
1426 break;
1427 case BT_MESSAGE_TYPE_DISCARDED_PACKETS:
1428 stream = bt_message_discarded_packets_borrow_stream_const(msg);
1429 break;
1430 case BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING:
1431 stream = bt_message_stream_activity_beginning_borrow_stream_const(msg);
1432 break;
1433 case BT_MESSAGE_TYPE_STREAM_ACTIVITY_END:
1434 stream = bt_message_stream_activity_end_borrow_stream_const(msg);
1435 break;
1436 case BT_MESSAGE_TYPE_STREAM_BEGINNING:
1437 stream = bt_message_stream_beginning_borrow_stream_const(msg);
1438 break;
1439 case BT_MESSAGE_TYPE_STREAM_END:
1440 stream = bt_message_stream_end_borrow_stream_const(msg);
1441 break;
1442 default:
1443 break;
1444 }
1445
91d81473 1446 if (G_LIKELY(stream)) {
7de0e49a
PP
1447 /* Find stream state */
1448 sstate = g_hash_table_lookup(trimmer_it->stream_states,
1449 stream);
91d81473 1450 if (G_UNLIKELY(!sstate)) {
7de0e49a
PP
1451 /* No stream state yet: create one now */
1452 const bt_stream_class *sc;
1453
1454 /*
1455 * Validate right now that the stream's class
1456 * has a registered default clock class so that
1457 * an existing stream state guarantees existing
1458 * default clock snapshots for its associated
1459 * messages.
1460 *
1461 * Also check that clock snapshots are always
1462 * known.
1463 */
1464 sc = bt_stream_borrow_class_const(stream);
1465 if (!bt_stream_class_borrow_default_clock_class_const(sc)) {
ec4ae660 1466 BT_COMP_LOGE("Unsupported stream: stream class does "
7de0e49a
PP
1467 "not have a default clock class: "
1468 "stream-addr=%p, "
1469 "stream-id=%" PRIu64 ", "
1470 "stream-name=\"%s\"",
1471 stream, bt_stream_get_id(stream),
1472 bt_stream_get_name(stream));
d24d5663 1473 status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR;
7de0e49a
PP
1474 goto end;
1475 }
1476
649934d2 1477 /*
2e90378a
PP
1478 * Temporary: make sure packet beginning, packet
1479 * end, discarded events, and discarded packets
649934d2
PP
1480 * messages have default clock snapshots until
1481 * the support for not having them is
1482 * implemented.
1483 */
9b24b6aa 1484 if (!bt_stream_class_packets_have_beginning_default_clock_snapshot(
649934d2 1485 sc)) {
ec4ae660 1486 BT_COMP_LOGE("Unsupported stream: packets have "
649934d2
PP
1487 "no beginning clock snapshot: "
1488 "stream-addr=%p, "
1489 "stream-id=%" PRIu64 ", "
1490 "stream-name=\"%s\"",
1491 stream, bt_stream_get_id(stream),
1492 bt_stream_get_name(stream));
d24d5663 1493 status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR;
649934d2
PP
1494 goto end;
1495 }
1496
9b24b6aa 1497 if (!bt_stream_class_packets_have_end_default_clock_snapshot(
649934d2 1498 sc)) {
ec4ae660 1499 BT_COMP_LOGE("Unsupported stream: packets have "
649934d2
PP
1500 "no end clock snapshot: "
1501 "stream-addr=%p, "
1502 "stream-id=%" PRIu64 ", "
1503 "stream-name=\"%s\"",
1504 stream, bt_stream_get_id(stream),
1505 bt_stream_get_name(stream));
d24d5663 1506 status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR;
649934d2
PP
1507 goto end;
1508 }
1509
2e90378a
PP
1510 if (bt_stream_class_supports_discarded_events(sc) &&
1511 !bt_stream_class_discarded_events_have_default_clock_snapshots(sc)) {
ec4ae660 1512 BT_COMP_LOGE("Unsupported stream: discarded events "
2e90378a
PP
1513 "have no clock snapshots: "
1514 "stream-addr=%p, "
1515 "stream-id=%" PRIu64 ", "
1516 "stream-name=\"%s\"",
1517 stream, bt_stream_get_id(stream),
1518 bt_stream_get_name(stream));
d24d5663 1519 status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR;
2e90378a
PP
1520 goto end;
1521 }
1522
1523 if (bt_stream_class_supports_discarded_packets(sc) &&
1524 !bt_stream_class_discarded_packets_have_default_clock_snapshots(sc)) {
ec4ae660 1525 BT_COMP_LOGE("Unsupported stream: discarded packets "
2e90378a
PP
1526 "have no clock snapshots: "
1527 "stream-addr=%p, "
1528 "stream-id=%" PRIu64 ", "
1529 "stream-name=\"%s\"",
1530 stream, bt_stream_get_id(stream),
1531 bt_stream_get_name(stream));
d24d5663 1532 status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR;
2e90378a
PP
1533 goto end;
1534 }
1535
7de0e49a
PP
1536 sstate = g_new0(struct trimmer_iterator_stream_state,
1537 1);
1538 if (!sstate) {
d24d5663 1539 status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_MEMORY_ERROR;
7de0e49a
PP
1540 goto end;
1541 }
1542
1543 sstate->stream = stream;
1544 sstate->stream_act_end_ns_from_origin = INT64_MIN;
1545 g_hash_table_insert(trimmer_it->stream_states,
1546 (void *) stream, sstate);
1547 }
1548 }
1549
1550 /* Retrieve the message's time */
1551 ret = get_msg_ns_from_origin(msg, &ns_from_origin, &skip);
91d81473 1552 if (G_UNLIKELY(ret)) {
d24d5663 1553 status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR;
7de0e49a
PP
1554 goto end;
1555 }
1556
91d81473 1557 if (G_LIKELY(sstate)) {
7de0e49a
PP
1558 /* Message associated to a stream */
1559 status = handle_message_with_stream_state(trimmer_it, msg,
1560 sstate, ns_from_origin, reached_end);
1561
1562 /*
1563 * handle_message_with_stream_state() unconditionally
1564 * consumes `msg`.
1565 */
1566 msg = NULL;
1567 } else {
1568 /*
1569 * Message not associated to a stream (message iterator
1570 * inactivity).
1571 */
91d81473 1572 if (G_UNLIKELY(ns_from_origin > trimmer_it->end.ns_from_origin)) {
7de0e49a
PP
1573 BT_MESSAGE_PUT_REF_AND_RESET(msg);
1574 status = end_iterator_streams(trimmer_it);
1575 *reached_end = true;
1576 } else {
1577 push_message(trimmer_it, msg);
d24d5663 1578 status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK;
7de0e49a
PP
1579 msg = NULL;
1580 }
1581 }
1582
1583end:
1584 /* We release the message's reference whatever the outcome */
1585 bt_message_put_ref(msg);
1586 return status;
1587}
1588
1589static inline
1590void fill_message_array_from_output_messages(
1591 struct trimmer_iterator *trimmer_it,
1592 bt_message_array_const msgs, uint64_t capacity, uint64_t *count)
1593{
1594 *count = 0;
1595
1596 /*
1597 * Move auto-seek messages to the output array (which is this
1598 * iterator's base message array).
1599 */
1600 while (capacity > 0 && !g_queue_is_empty(trimmer_it->output_messages)) {
1601 msgs[*count] = pop_message(trimmer_it);
1602 capacity--;
1603 (*count)++;
1604 }
1605
1606 BT_ASSERT(*count > 0);
1607}
1608
1609static inline
d24d5663 1610bt_component_class_message_iterator_next_method_status state_ending(
7de0e49a
PP
1611 struct trimmer_iterator *trimmer_it,
1612 bt_message_array_const msgs, uint64_t capacity,
1613 uint64_t *count)
1614{
d24d5663
PP
1615 bt_component_class_message_iterator_next_method_status status =
1616 BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK;
7de0e49a
PP
1617
1618 if (g_queue_is_empty(trimmer_it->output_messages)) {
1619 trimmer_it->state = TRIMMER_ITERATOR_STATE_ENDED;
d24d5663 1620 status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_END;
7de0e49a
PP
1621 goto end;
1622 }
1623
1624 fill_message_array_from_output_messages(trimmer_it, msgs,
1625 capacity, count);
1626
1627end:
1628 return status;
1629}
1630
1631static inline
d24d5663
PP
1632bt_component_class_message_iterator_next_method_status
1633state_trim(struct trimmer_iterator *trimmer_it,
7de0e49a
PP
1634 bt_message_array_const msgs, uint64_t capacity,
1635 uint64_t *count)
1636{
d24d5663
PP
1637 bt_component_class_message_iterator_next_method_status status =
1638 BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK;
7de0e49a
PP
1639 bt_message_array_const my_msgs;
1640 uint64_t my_count;
1641 uint64_t i;
1642 bool reached_end = false;
1643
1644 while (g_queue_is_empty(trimmer_it->output_messages)) {
1645 status = (int) bt_self_component_port_input_message_iterator_next(
1646 trimmer_it->upstream_iter, &my_msgs, &my_count);
d24d5663
PP
1647 if (G_UNLIKELY(status != BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK)) {
1648 if (status == BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_END) {
7de0e49a 1649 status = end_iterator_streams(trimmer_it);
d24d5663 1650 if (status != BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK) {
7de0e49a
PP
1651 goto end;
1652 }
1653
1654 trimmer_it->state =
1655 TRIMMER_ITERATOR_STATE_ENDING;
1656 status = state_ending(trimmer_it, msgs,
1657 capacity, count);
1658 }
1659
1660 goto end;
1661 }
1662
1663 BT_ASSERT(my_count > 0);
1664
1665 for (i = 0; i < my_count; i++) {
1666 status = handle_message(trimmer_it, my_msgs[i],
1667 &reached_end);
1668
1669 /*
1670 * handle_message() unconditionally consumes the
1671 * message reference.
1672 */
1673 my_msgs[i] = NULL;
1674
91d81473 1675 if (G_UNLIKELY(status !=
d24d5663 1676 BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK)) {
7de0e49a
PP
1677 put_messages(my_msgs, my_count);
1678 goto end;
1679 }
1680
91d81473 1681 if (G_UNLIKELY(reached_end)) {
7de0e49a
PP
1682 /*
1683 * This message's time was passed the
1684 * trimming time range's end time: we
1685 * are done. Their might still be
1686 * messages in the output message queue,
1687 * so move to the "ending" state and
1688 * apply it immediately since
1689 * state_trim() is called within the
1690 * "next" method.
1691 */
1692 put_messages(my_msgs, my_count);
1693 trimmer_it->state =
1694 TRIMMER_ITERATOR_STATE_ENDING;
1695 status = state_ending(trimmer_it, msgs,
1696 capacity, count);
1697 goto end;
1698 }
1699 }
1700 }
1701
1702 /*
1703 * There's at least one message in the output message queue:
1704 * move the messages to the output message array.
1705 */
1706 BT_ASSERT(!g_queue_is_empty(trimmer_it->output_messages));
1707 fill_message_array_from_output_messages(trimmer_it, msgs,
1708 capacity, count);
1709
1710end:
1711 return status;
1712}
1713
1714BT_HIDDEN
d24d5663 1715bt_component_class_message_iterator_next_method_status trimmer_msg_iter_next(
7de0e49a
PP
1716 bt_self_message_iterator *self_msg_iter,
1717 bt_message_array_const msgs, uint64_t capacity,
1718 uint64_t *count)
1719{
1720 struct trimmer_iterator *trimmer_it =
1721 bt_self_message_iterator_get_data(self_msg_iter);
d24d5663
PP
1722 bt_component_class_message_iterator_next_method_status status =
1723 BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK;
7de0e49a
PP
1724
1725 BT_ASSERT(trimmer_it);
1726
91d81473 1727 if (G_LIKELY(trimmer_it->state == TRIMMER_ITERATOR_STATE_TRIM)) {
7de0e49a 1728 status = state_trim(trimmer_it, msgs, capacity, count);
d24d5663 1729 if (status != BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK) {
7de0e49a
PP
1730 goto end;
1731 }
1732 } else {
1733 switch (trimmer_it->state) {
1734 case TRIMMER_ITERATOR_STATE_SET_BOUNDS_NS_FROM_ORIGIN:
1735 status = state_set_trimmer_iterator_bounds(trimmer_it);
d24d5663 1736 if (status != BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK) {
7de0e49a
PP
1737 goto end;
1738 }
1739
1740 status = state_seek_initially(trimmer_it);
d24d5663 1741 if (status != BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK) {
7de0e49a
PP
1742 goto end;
1743 }
1744
1745 status = state_trim(trimmer_it, msgs, capacity, count);
d24d5663 1746 if (status != BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK) {
7de0e49a
PP
1747 goto end;
1748 }
1749
1750 break;
1751 case TRIMMER_ITERATOR_STATE_SEEK_INITIALLY:
1752 status = state_seek_initially(trimmer_it);
d24d5663 1753 if (status != BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK) {
7de0e49a
PP
1754 goto end;
1755 }
1756
1757 status = state_trim(trimmer_it, msgs, capacity, count);
d24d5663 1758 if (status != BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK) {
7de0e49a
PP
1759 goto end;
1760 }
1761
1762 break;
1763 case TRIMMER_ITERATOR_STATE_ENDING:
1764 status = state_ending(trimmer_it, msgs, capacity,
1765 count);
d24d5663 1766 if (status != BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK) {
7de0e49a
PP
1767 goto end;
1768 }
1769
1770 break;
1771 case TRIMMER_ITERATOR_STATE_ENDED:
d24d5663 1772 status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_END;
7de0e49a
PP
1773 break;
1774 default:
1775 abort();
1776 }
1777 }
1778
1779end:
1780 return status;
1781}
1782
1783BT_HIDDEN
1784void trimmer_msg_iter_finalize(bt_self_message_iterator *self_msg_iter)
1785{
1786 struct trimmer_iterator *trimmer_it =
1787 bt_self_message_iterator_get_data(self_msg_iter);
1788
1789 BT_ASSERT(trimmer_it);
1790 destroy_trimmer_iterator(trimmer_it);
1791}
This page took 0.126508 seconds and 4 git commands to generate.