2 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
3 * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
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:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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
24 #define BT_LOG_TAG "LIB/MSG-ITER"
25 #include "lib/logging.h"
27 #include "compat/compiler.h"
28 #include "compat/glib.h"
29 #include "lib/trace-ir/clock-class.h"
30 #include "lib/trace-ir/clock-snapshot.h"
31 #include <babeltrace2/trace-ir/field.h>
32 #include <babeltrace2/trace-ir/event-const.h>
33 #include "lib/trace-ir/event.h"
34 #include <babeltrace2/trace-ir/packet-const.h>
35 #include "lib/trace-ir/packet.h"
36 #include "lib/trace-ir/stream.h"
37 #include <babeltrace2/trace-ir/clock-class-const.h>
38 #include <babeltrace2/trace-ir/stream-class-const.h>
39 #include <babeltrace2/trace-ir/stream-const.h>
40 #include <babeltrace2/graph/connection-const.h>
41 #include <babeltrace2/graph/component-const.h>
42 #include <babeltrace2/graph/component-sink-const.h>
43 #include <babeltrace2/graph/message-const.h>
44 #include <babeltrace2/graph/message-iterator.h>
45 #include <babeltrace2/graph/self-component-port-input-message-iterator.h>
46 #include <babeltrace2/graph/port-output-message-iterator.h>
47 #include <babeltrace2/graph/message-event-const.h>
48 #include <babeltrace2/graph/message-message-iterator-inactivity-const.h>
49 #include <babeltrace2/graph/message-packet-beginning.h>
50 #include <babeltrace2/graph/message-packet-beginning-const.h>
51 #include <babeltrace2/graph/message-packet-end-const.h>
52 #include <babeltrace2/graph/message-stream-activity-beginning.h>
53 #include <babeltrace2/graph/message-stream-activity-beginning-const.h>
54 #include <babeltrace2/graph/message-stream-activity-end-const.h>
55 #include <babeltrace2/graph/message-stream-beginning.h>
56 #include <babeltrace2/graph/message-stream-beginning-const.h>
57 #include <babeltrace2/graph/message-stream-end-const.h>
58 #include <babeltrace2/graph/port-const.h>
59 #include <babeltrace2/graph/graph.h>
60 #include <babeltrace2/graph/graph-const.h>
61 #include <babeltrace2/types.h>
62 #include "common/assert.h"
63 #include "lib/assert-pre.h"
64 #include "lib/assert-post.h"
69 #include "component-class.h"
70 #include "component-class-sink-colander.h"
71 #include "component.h"
72 #include "component-sink.h"
73 #include "component-source.h"
74 #include "connection.h"
76 #include "message/discarded-items.h"
77 #include "message/event.h"
78 #include "message/iterator.h"
79 #include "message/message.h"
80 #include "message/message-iterator-inactivity.h"
81 #include "message/stream.h"
82 #include "message/packet.h"
83 #include "message/stream-activity.h"
84 #include "lib/func-status.h"
87 * TODO: Use graph's state (number of active iterators, etc.) and
88 * possibly system specifications to make a better guess than this.
90 #define MSG_BATCH_SIZE 15
92 #define BT_ASSERT_PRE_ITER_HAS_STATE_TO_SEEK(_iter) \
93 BT_ASSERT_PRE((_iter)->state == BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE || \
94 (_iter)->state == BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ENDED || \
95 (_iter)->state == BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_AGAIN || \
96 (_iter)->state == BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_ERROR, \
97 "Message iterator is in the wrong state: %!+i", _iter)
100 void set_self_comp_port_input_msg_iterator_state(
101 struct bt_self_component_port_input_message_iterator
*iterator
,
102 enum bt_self_component_port_input_message_iterator_state state
)
105 BT_LIB_LOGD("Updating message iterator's state: new-state=%s",
106 bt_self_component_port_input_message_iterator_state_string(state
));
107 iterator
->state
= state
;
111 void destroy_base_message_iterator(struct bt_object
*obj
)
113 struct bt_message_iterator
*iterator
= (void *) obj
;
117 if (iterator
->msgs
) {
118 g_ptr_array_free(iterator
->msgs
, TRUE
);
119 iterator
->msgs
= NULL
;
126 void bt_self_component_port_input_message_iterator_destroy(struct bt_object
*obj
)
128 struct bt_self_component_port_input_message_iterator
*iterator
;
133 * The message iterator's reference count is 0 if we're
134 * here. Increment it to avoid a double-destroy (possibly
135 * infinitely recursive). This could happen for example if the
136 * message iterator's finalization function does
137 * bt_object_get_ref() (or anything that causes
138 * bt_object_get_ref() to be called) on itself (ref. count goes
139 * from 0 to 1), and then bt_object_put_ref(): the reference
140 * count would go from 1 to 0 again and this function would be
144 iterator
= (void *) obj
;
145 BT_LIB_LOGI("Destroying self component input port message iterator object: "
147 bt_self_component_port_input_message_iterator_try_finalize(iterator
);
149 if (iterator
->connection
) {
151 * Remove ourself from the originating connection so
152 * that it does not try to finalize a dangling pointer
155 bt_connection_remove_iterator(iterator
->connection
, iterator
);
156 iterator
->connection
= NULL
;
159 if (iterator
->auto_seek
.msgs
) {
160 while (!g_queue_is_empty(iterator
->auto_seek
.msgs
)) {
161 bt_object_put_no_null_check(
162 g_queue_pop_tail(iterator
->auto_seek
.msgs
));
165 g_queue_free(iterator
->auto_seek
.msgs
);
166 iterator
->auto_seek
.msgs
= NULL
;
169 destroy_base_message_iterator(obj
);
173 void bt_self_component_port_input_message_iterator_try_finalize(
174 struct bt_self_component_port_input_message_iterator
*iterator
)
176 typedef void (*method_t
)(void *);
178 struct bt_component_class
*comp_class
= NULL
;
179 method_t method
= NULL
;
183 switch (iterator
->state
) {
184 case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_NON_INITIALIZED
:
185 /* Skip user finalization if user initialization failed */
186 BT_LIB_LOGD("Not finalizing non-initialized message iterator: "
189 case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZED
:
190 /* Already finalized */
191 BT_LIB_LOGD("Not finalizing message iterator: already finalized: "
194 case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZING
:
196 BT_LIB_LOGF("Message iterator is already being finalized: "
203 BT_LIB_LOGD("Finalizing message iterator: %!+i", iterator
);
204 set_self_comp_port_input_msg_iterator_state(iterator
,
205 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZING
);
206 BT_ASSERT(iterator
->upstream_component
);
207 comp_class
= iterator
->upstream_component
->class;
209 /* Call user-defined destroy method */
210 switch (comp_class
->type
) {
211 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
213 struct bt_component_class_source
*src_comp_cls
=
216 method
= (method_t
) src_comp_cls
->methods
.msg_iter_finalize
;
219 case BT_COMPONENT_CLASS_TYPE_FILTER
:
221 struct bt_component_class_filter
*flt_comp_cls
=
224 method
= (method_t
) flt_comp_cls
->methods
.msg_iter_finalize
;
233 BT_LIB_LOGD("Calling user's finalization method: %!+i",
238 iterator
->upstream_component
= NULL
;
239 iterator
->upstream_port
= NULL
;
240 set_self_comp_port_input_msg_iterator_state(iterator
,
241 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZED
);
242 BT_LIB_LOGD("Finalized message iterator: %!+i", iterator
);
249 void bt_self_component_port_input_message_iterator_set_connection(
250 struct bt_self_component_port_input_message_iterator
*iterator
,
251 struct bt_connection
*connection
)
254 iterator
->connection
= connection
;
255 BT_LIB_LOGI("Set message iterator's connection: "
256 "%![iter-]+i, %![conn-]+x", iterator
, connection
);
260 int init_message_iterator(struct bt_message_iterator
*iterator
,
261 enum bt_message_iterator_type type
,
262 bt_object_release_func destroy
)
266 bt_object_init_shared(&iterator
->base
, destroy
);
267 iterator
->type
= type
;
268 iterator
->msgs
= g_ptr_array_new();
269 if (!iterator
->msgs
) {
270 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
275 g_ptr_array_set_size(iterator
->msgs
, MSG_BATCH_SIZE
);
282 bt_bool
can_seek_ns_from_origin_true(
283 struct bt_self_component_port_input_message_iterator
*iterator
,
284 int64_t ns_from_origin
)
290 bt_bool
can_seek_beginning_true(
291 struct bt_self_component_port_input_message_iterator
*iterator
)
297 struct bt_self_component_port_input_message_iterator
*
298 bt_self_component_port_input_message_iterator_create_initial(
299 struct bt_component
*upstream_comp
,
300 struct bt_port
*upstream_port
)
303 struct bt_self_component_port_input_message_iterator
*iterator
= NULL
;
305 BT_ASSERT(upstream_comp
);
306 BT_ASSERT(upstream_port
);
307 BT_ASSERT(bt_port_is_connected(upstream_port
));
308 BT_LIB_LOGI("Creating initial message iterator on self component input port: "
309 "%![up-comp-]+c, %![up-port-]+p", upstream_comp
, upstream_port
);
310 BT_ASSERT(bt_component_get_class_type(upstream_comp
) ==
311 BT_COMPONENT_CLASS_TYPE_SOURCE
||
312 bt_component_get_class_type(upstream_comp
) ==
313 BT_COMPONENT_CLASS_TYPE_FILTER
);
315 struct bt_self_component_port_input_message_iterator
, 1);
317 BT_LIB_LOGE_APPEND_CAUSE(
318 "Failed to allocate one self component input port "
319 "message iterator.");
323 ret
= init_message_iterator((void *) iterator
,
324 BT_MESSAGE_ITERATOR_TYPE_SELF_COMPONENT_PORT_INPUT
,
325 bt_self_component_port_input_message_iterator_destroy
);
327 /* init_message_iterator() logs errors */
331 iterator
->last_ns_from_origin
= INT64_MIN
;
333 iterator
->auto_seek
.msgs
= g_queue_new();
334 if (!iterator
->auto_seek
.msgs
) {
335 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GQueue.");
340 iterator
->upstream_component
= upstream_comp
;
341 iterator
->upstream_port
= upstream_port
;
342 iterator
->connection
= iterator
->upstream_port
->connection
;
343 iterator
->graph
= bt_component_borrow_graph(upstream_comp
);
344 set_self_comp_port_input_msg_iterator_state(iterator
,
345 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_NON_INITIALIZED
);
347 switch (iterator
->upstream_component
->class->type
) {
348 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
350 struct bt_component_class_source
*src_comp_cls
=
351 (void *) iterator
->upstream_component
->class;
353 iterator
->methods
.next
=
354 (bt_self_component_port_input_message_iterator_next_method
)
355 src_comp_cls
->methods
.msg_iter_next
;
356 iterator
->methods
.seek_ns_from_origin
=
357 (bt_self_component_port_input_message_iterator_seek_ns_from_origin_method
)
358 src_comp_cls
->methods
.msg_iter_seek_ns_from_origin
;
359 iterator
->methods
.seek_beginning
=
360 (bt_self_component_port_input_message_iterator_seek_beginning_method
)
361 src_comp_cls
->methods
.msg_iter_seek_beginning
;
362 iterator
->methods
.can_seek_ns_from_origin
=
363 (bt_self_component_port_input_message_iterator_can_seek_ns_from_origin_method
)
364 src_comp_cls
->methods
.msg_iter_can_seek_ns_from_origin
;
365 iterator
->methods
.can_seek_beginning
=
366 (bt_self_component_port_input_message_iterator_can_seek_beginning_method
)
367 src_comp_cls
->methods
.msg_iter_can_seek_beginning
;
370 case BT_COMPONENT_CLASS_TYPE_FILTER
:
372 struct bt_component_class_filter
*flt_comp_cls
=
373 (void *) iterator
->upstream_component
->class;
375 iterator
->methods
.next
=
376 (bt_self_component_port_input_message_iterator_next_method
)
377 flt_comp_cls
->methods
.msg_iter_next
;
378 iterator
->methods
.seek_ns_from_origin
=
379 (bt_self_component_port_input_message_iterator_seek_ns_from_origin_method
)
380 flt_comp_cls
->methods
.msg_iter_seek_ns_from_origin
;
381 iterator
->methods
.seek_beginning
=
382 (bt_self_component_port_input_message_iterator_seek_beginning_method
)
383 flt_comp_cls
->methods
.msg_iter_seek_beginning
;
384 iterator
->methods
.can_seek_ns_from_origin
=
385 (bt_self_component_port_input_message_iterator_can_seek_ns_from_origin_method
)
386 flt_comp_cls
->methods
.msg_iter_can_seek_ns_from_origin
;
387 iterator
->methods
.can_seek_beginning
=
388 (bt_self_component_port_input_message_iterator_can_seek_beginning_method
)
389 flt_comp_cls
->methods
.msg_iter_can_seek_beginning
;
396 if (iterator
->methods
.seek_ns_from_origin
&&
397 !iterator
->methods
.can_seek_ns_from_origin
) {
398 iterator
->methods
.can_seek_ns_from_origin
=
399 (bt_self_component_port_input_message_iterator_can_seek_ns_from_origin_method
)
400 can_seek_ns_from_origin_true
;
403 if (iterator
->methods
.seek_beginning
&&
404 !iterator
->methods
.can_seek_beginning
) {
405 iterator
->methods
.can_seek_beginning
=
406 (bt_self_component_port_input_message_iterator_seek_beginning_method
)
407 can_seek_beginning_true
;
410 BT_LIB_LOGI("Created initial message iterator on self component input port: "
411 "%![up-port-]+p, %![up-comp-]+c, %![iter-]+i",
412 upstream_port
, upstream_comp
, iterator
);
416 BT_OBJECT_PUT_REF_AND_RESET(iterator
);
422 struct bt_self_component_port_input_message_iterator
*
423 bt_self_component_port_input_message_iterator_create(
424 struct bt_self_component_port_input
*self_port
)
426 typedef enum bt_component_class_message_iterator_init_method_status (*init_method_t
)(
427 void *, void *, void *);
429 init_method_t init_method
= NULL
;
430 struct bt_self_component_port_input_message_iterator
*iterator
=
432 struct bt_port
*port
= (void *) self_port
;
433 struct bt_port
*upstream_port
;
434 struct bt_component
*comp
;
435 struct bt_component
*upstream_comp
;
436 struct bt_component_class
*upstream_comp_cls
;
438 BT_ASSERT_PRE_NON_NULL(port
, "Port");
439 comp
= bt_port_borrow_component_inline(port
);
440 BT_ASSERT_PRE(bt_port_is_connected(port
),
441 "Port is not connected: %![port-]+p", port
);
442 BT_ASSERT_PRE(comp
, "Port is not part of a component: %![port-]+p",
444 BT_ASSERT_PRE(!bt_component_graph_is_canceled(comp
),
445 "Port's component's graph is canceled: "
446 "%![port-]+p, %![comp-]+c", port
, comp
);
447 BT_ASSERT(port
->connection
);
448 upstream_port
= port
->connection
->upstream_port
;
449 BT_ASSERT(upstream_port
);
450 upstream_comp
= bt_port_borrow_component_inline(upstream_port
);
451 BT_ASSERT(upstream_comp
);
453 bt_component_borrow_graph(upstream_comp
)->config_state
!=
454 BT_GRAPH_CONFIGURATION_STATE_CONFIGURING
,
455 "Graph is not configured: %!+g",
456 bt_component_borrow_graph(upstream_comp
));
457 upstream_comp_cls
= upstream_comp
->class;
458 BT_ASSERT(upstream_comp
->class->type
==
459 BT_COMPONENT_CLASS_TYPE_SOURCE
||
460 upstream_comp
->class->type
==
461 BT_COMPONENT_CLASS_TYPE_FILTER
);
462 iterator
= bt_self_component_port_input_message_iterator_create_initial(
463 upstream_comp
, upstream_port
);
465 BT_LIB_LOGE_APPEND_CAUSE(
466 "Cannot create self component input port message iterator.");
470 switch (upstream_comp_cls
->type
) {
471 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
473 struct bt_component_class_source
*src_comp_cls
=
474 (void *) upstream_comp_cls
;
477 (init_method_t
) src_comp_cls
->methods
.msg_iter_init
;
480 case BT_COMPONENT_CLASS_TYPE_FILTER
:
482 struct bt_component_class_filter
*flt_comp_cls
=
483 (void *) upstream_comp_cls
;
486 (init_method_t
) flt_comp_cls
->methods
.msg_iter_init
;
495 enum bt_component_class_message_iterator_init_method_status iter_status
;
497 BT_LIB_LOGD("Calling user's initialization method: %!+i", iterator
);
498 iter_status
= init_method(iterator
, upstream_comp
,
500 BT_LOGD("User method returned: status=%s",
501 bt_common_func_status_string(iter_status
));
502 if (iter_status
!= BT_FUNC_STATUS_OK
) {
503 BT_LIB_LOGW_APPEND_CAUSE(
504 "Component input port message iterator initialization method failed: "
505 "%![iter-]+i, status=%s",
507 bt_common_func_status_string(iter_status
));
512 set_self_comp_port_input_msg_iterator_state(iterator
,
513 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE
);
514 g_ptr_array_add(port
->connection
->iterators
, iterator
);
515 BT_LIB_LOGI("Created message iterator on self component input port: "
516 "%![up-port-]+p, %![up-comp-]+c, %![iter-]+i",
517 upstream_port
, upstream_comp
, iterator
);
521 BT_OBJECT_PUT_REF_AND_RESET(iterator
);
527 void *bt_self_message_iterator_get_data(
528 const struct bt_self_message_iterator
*self_iterator
)
530 struct bt_self_component_port_input_message_iterator
*iterator
=
531 (void *) self_iterator
;
533 BT_ASSERT_PRE_NON_NULL(iterator
, "Message iterator");
534 return iterator
->user_data
;
537 void bt_self_message_iterator_set_data(
538 struct bt_self_message_iterator
*self_iterator
, void *data
)
540 struct bt_self_component_port_input_message_iterator
*iterator
=
541 (void *) self_iterator
;
543 BT_ASSERT_PRE_NON_NULL(iterator
, "Message iterator");
544 iterator
->user_data
= data
;
545 BT_LIB_LOGD("Set message iterator's user data: "
546 "%!+i, user-data-addr=%p", iterator
, data
);
550 * Validate that the default clock snapshot in `msg` doesn't make us go back in
556 bool clock_snapshots_are_monotonic_one(
557 struct bt_self_component_port_input_message_iterator
*iterator
,
558 const bt_message
*msg
)
560 const struct bt_clock_snapshot
*clock_snapshot
= NULL
;
561 bt_message_type message_type
= bt_message_get_type(msg
);
562 int64_t ns_from_origin
;
563 enum bt_clock_snapshot_get_ns_from_origin_status clock_snapshot_status
;
566 * The default is true: if we can't figure out the clock snapshot
567 * (or there is none), assume it is fine.
571 switch (message_type
) {
572 case BT_MESSAGE_TYPE_EVENT
:
574 struct bt_message_event
*event_msg
= (struct bt_message_event
*) msg
;
575 clock_snapshot
= event_msg
->default_cs
;
578 case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY
:
580 struct bt_message_message_iterator_inactivity
*inactivity_msg
=
581 (struct bt_message_message_iterator_inactivity
*) msg
;
582 clock_snapshot
= inactivity_msg
->default_cs
;
585 case BT_MESSAGE_TYPE_PACKET_BEGINNING
:
586 case BT_MESSAGE_TYPE_PACKET_END
:
588 struct bt_message_packet
*packet_msg
= (struct bt_message_packet
*) msg
;
589 clock_snapshot
= packet_msg
->default_cs
;
592 case BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING
:
593 case BT_MESSAGE_TYPE_STREAM_ACTIVITY_END
:
595 struct bt_message_stream_activity
*str_act_msg
=
596 (struct bt_message_stream_activity
*) msg
;
598 if (str_act_msg
->default_cs_state
== BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_KNOWN
) {
599 clock_snapshot
= str_act_msg
->default_cs
;
603 case BT_MESSAGE_TYPE_STREAM_BEGINNING
:
604 case BT_MESSAGE_TYPE_STREAM_END
:
605 /* These messages don't have clock snapshots. */
607 case BT_MESSAGE_TYPE_DISCARDED_EVENTS
:
608 case BT_MESSAGE_TYPE_DISCARDED_PACKETS
:
610 struct bt_message_discarded_items
*discarded_msg
=
611 (struct bt_message_discarded_items
*) msg
;
613 clock_snapshot
= discarded_msg
->default_begin_cs
;
618 if (!clock_snapshot
) {
622 clock_snapshot_status
= bt_clock_snapshot_get_ns_from_origin(clock_snapshot
, &ns_from_origin
);
623 if (clock_snapshot_status
!= BT_FUNC_STATUS_OK
) {
627 result
= ns_from_origin
>= iterator
->last_ns_from_origin
;
628 iterator
->last_ns_from_origin
= ns_from_origin
;
635 bool clock_snapshots_are_monotonic(
636 struct bt_self_component_port_input_message_iterator
*iterator
,
637 bt_message_array_const msgs
, uint64_t msg_count
)
642 for (i
= 0; i
< msg_count
; i
++) {
643 if (!clock_snapshots_are_monotonic_one(iterator
, msgs
[i
])) {
656 * When a new stream begins, verify that the clock class tied to this
657 * stream is compatible with what we've seen before.
662 bool clock_classes_are_compatible_one(struct bt_self_component_port_input_message_iterator
*iterator
,
663 const struct bt_message
*msg
)
665 enum bt_message_type message_type
= bt_message_get_type(msg
);
668 if (message_type
== BT_MESSAGE_TYPE_STREAM_BEGINNING
) {
669 const struct bt_message_stream
*stream_msg
= (struct bt_message_stream
*) msg
;
670 const struct bt_clock_class
*clock_class
= stream_msg
->stream
->class->default_clock_class
;
671 bt_uuid clock_class_uuid
= NULL
;
674 clock_class_uuid
= bt_clock_class_get_uuid(clock_class
);
677 switch (iterator
->clock_expectation
.type
) {
678 case CLOCK_EXPECTATION_UNSET
:
680 * This is the first time we see a message with a clock
681 * snapshot: record the properties of that clock, against
682 * which we'll compare the clock properties of the following
687 iterator
->clock_expectation
.type
= CLOCK_EXPECTATION_NONE
;
688 } else if (bt_clock_class_origin_is_unix_epoch(clock_class
)) {
689 iterator
->clock_expectation
.type
= CLOCK_EXPECTATION_ORIGIN_UNIX
;
690 } else if (clock_class_uuid
) {
691 iterator
->clock_expectation
.type
= CLOCK_EXPECTATION_ORIGIN_OTHER_UUID
;
692 memcpy(iterator
->clock_expectation
.uuid
, clock_class_uuid
, BABELTRACE_UUID_LEN
);
694 iterator
->clock_expectation
.type
= CLOCK_EXPECTATION_ORIGIN_OTHER_NO_UUID
;
698 case CLOCK_EXPECTATION_NONE
:
700 BT_ASSERT_POST_MSG("Expecting no clock class, got one: %![cc-]+K",
708 case CLOCK_EXPECTATION_ORIGIN_UNIX
:
710 BT_ASSERT_POST_MSG("Expecting a clock class, got none.");
715 if (!bt_clock_class_origin_is_unix_epoch(clock_class
)) {
716 BT_ASSERT_POST_MSG("Expecting a clock class with Unix epoch origin: %![cc-]+K",
723 case CLOCK_EXPECTATION_ORIGIN_OTHER_UUID
:
725 BT_ASSERT_POST_MSG("Expecting a clock class, got none.");
730 if (bt_clock_class_origin_is_unix_epoch(clock_class
)) {
731 BT_ASSERT_POST_MSG("Expecting a clock class without Unix epoch origin: %![cc-]+K",
737 if (!clock_class_uuid
) {
738 BT_ASSERT_POST_MSG("Expecting a clock class with UUID: %![cc-]+K",
744 if (bt_uuid_compare(iterator
->clock_expectation
.uuid
, clock_class_uuid
)) {
745 BT_ASSERT_POST_MSG("Expecting a clock class with UUID, got one "
746 "with a different UUID: %![cc-]+K, expected-uuid=%!u",
747 clock_class
, iterator
->clock_expectation
.uuid
);
753 case CLOCK_EXPECTATION_ORIGIN_OTHER_NO_UUID
:
755 BT_ASSERT_POST_MSG("Expecting a clock class, got none.");
760 if (bt_clock_class_origin_is_unix_epoch(clock_class
)) {
761 BT_ASSERT_POST_MSG("Expecting a clock class without Unix epoch origin: %![cc-]+K",
767 if (clock_class_uuid
) {
768 BT_ASSERT_POST_MSG("Expecting a clock class without UUID: %![cc-]+K",
785 bool clock_classes_are_compatible(
786 struct bt_self_component_port_input_message_iterator
*iterator
,
787 bt_message_array_const msgs
, uint64_t msg_count
)
792 for (i
= 0; i
< msg_count
; i
++) {
793 if (!clock_classes_are_compatible_one(iterator
, msgs
[i
])) {
806 * Call the `next` method of the iterator. Do some validation on the returned
811 enum bt_component_class_message_iterator_next_method_status
812 call_iterator_next_method(
813 struct bt_self_component_port_input_message_iterator
*iterator
,
814 bt_message_array_const msgs
, uint64_t capacity
, uint64_t *user_count
)
816 enum bt_component_class_message_iterator_next_method_status status
;
818 BT_ASSERT(iterator
->methods
.next
);
819 BT_LOGD_STR("Calling user's \"next\" method.");
820 status
= iterator
->methods
.next(iterator
, msgs
, capacity
, user_count
);
821 BT_LOGD("User method returned: status=%s, msg-count=%" PRIu64
,
822 bt_common_func_status_string(status
), *user_count
);
824 if (status
== BT_FUNC_STATUS_OK
) {
825 BT_ASSERT_POST(clock_classes_are_compatible(iterator
, msgs
, *user_count
),
826 "Clocks are not compatible");
827 BT_ASSERT_POST(clock_snapshots_are_monotonic(iterator
, msgs
, *user_count
),
828 "Clock snapshots are not monotonic");
834 enum bt_message_iterator_next_status
835 bt_self_component_port_input_message_iterator_next(
836 struct bt_self_component_port_input_message_iterator
*iterator
,
837 bt_message_array_const
*msgs
, uint64_t *user_count
)
839 enum bt_message_iterator_next_status status
= BT_FUNC_STATUS_OK
;
841 BT_ASSERT_PRE_NON_NULL(iterator
, "Message iterator");
842 BT_ASSERT_PRE_NON_NULL(msgs
, "Message array (output)");
843 BT_ASSERT_PRE_NON_NULL(user_count
, "Message count (output)");
844 BT_ASSERT_PRE(iterator
->state
==
845 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE
,
846 "Message iterator's \"next\" called, but "
847 "message iterator is in the wrong state: %!+i", iterator
);
848 BT_ASSERT(iterator
->upstream_component
);
849 BT_ASSERT(iterator
->upstream_component
->class);
851 bt_component_borrow_graph(iterator
->upstream_component
)->config_state
!=
852 BT_GRAPH_CONFIGURATION_STATE_CONFIGURING
,
853 "Graph is not configured: %!+g",
854 bt_component_borrow_graph(iterator
->upstream_component
));
855 BT_LIB_LOGD("Getting next self component input port "
856 "message iterator's messages: %!+i, batch-size=%u",
857 iterator
, MSG_BATCH_SIZE
);
860 * Call the user's "next" method to get the next messages
864 status
= (int) call_iterator_next_method(iterator
,
865 (void *) iterator
->base
.msgs
->pdata
, MSG_BATCH_SIZE
,
867 BT_LOGD("User method returned: status=%s, msg-count=%" PRIu64
,
868 bt_common_func_status_string(status
), *user_count
);
870 BT_LIB_LOGW_APPEND_CAUSE(
871 "Component input port message iterator's \"next\" method failed: "
872 "%![iter-]+i, status=%s",
873 iterator
, bt_common_func_status_string(status
));
878 * There is no way that this iterator could have been finalized
879 * during its "next" method, as the only way to do this is to
880 * put the last iterator's reference, and this can only be done
881 * by its downstream owner.
883 * For the same reason, there is no way that this iterator could
884 * have seeked (cannot seek a self message iterator).
886 BT_ASSERT(iterator
->state
==
887 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE
);
890 case BT_FUNC_STATUS_OK
:
891 BT_ASSERT_POST(*user_count
<= MSG_BATCH_SIZE
,
892 "Invalid returned message count: greater than "
893 "batch size: count=%" PRIu64
", batch-size=%u",
894 *user_count
, MSG_BATCH_SIZE
);
895 *msgs
= (void *) iterator
->base
.msgs
->pdata
;
897 case BT_FUNC_STATUS_AGAIN
:
899 case BT_FUNC_STATUS_END
:
900 set_self_comp_port_input_msg_iterator_state(iterator
,
901 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ENDED
);
904 /* Unknown non-error status */
912 enum bt_message_iterator_next_status
bt_port_output_message_iterator_next(
913 struct bt_port_output_message_iterator
*iterator
,
914 bt_message_array_const
*msgs_to_user
,
915 uint64_t *count_to_user
)
917 enum bt_message_iterator_next_status status
;
920 BT_ASSERT_PRE_NON_NULL(iterator
, "Message iterator");
921 BT_ASSERT_PRE_NON_NULL(msgs_to_user
, "Message array (output)");
922 BT_ASSERT_PRE_NON_NULL(count_to_user
, "Message count (output)");
923 BT_LIB_LOGD("Getting next output port message iterator's messages: "
925 graph_status
= bt_graph_consume_sink_no_check(iterator
->graph
,
927 switch (graph_status
) {
928 case BT_FUNC_STATUS_CANCELED
:
929 case BT_FUNC_STATUS_AGAIN
:
930 case BT_FUNC_STATUS_END
:
931 case BT_FUNC_STATUS_MEMORY_ERROR
:
932 status
= (int) graph_status
;
934 case BT_FUNC_STATUS_OK
:
935 status
= BT_FUNC_STATUS_OK
;
938 * On success, the colander sink moves the messages
939 * to this iterator's array and sets this iterator's
940 * message count: move them to the user.
942 *msgs_to_user
= (void *) iterator
->base
.msgs
->pdata
;
943 *count_to_user
= iterator
->count
;
947 status
= BT_FUNC_STATUS_ERROR
;
953 struct bt_component
*
954 bt_self_component_port_input_message_iterator_borrow_component(
955 struct bt_self_component_port_input_message_iterator
*iterator
)
957 BT_ASSERT_PRE_NON_NULL(iterator
, "Message iterator");
958 return iterator
->upstream_component
;
961 const struct bt_component
*
962 bt_self_component_port_input_message_iterator_borrow_component_const(
963 const struct bt_self_component_port_input_message_iterator
*iterator
)
965 BT_ASSERT_PRE_NON_NULL(iterator
, "Message iterator");
966 return iterator
->upstream_component
;
969 struct bt_self_component
*bt_self_message_iterator_borrow_component(
970 struct bt_self_message_iterator
*self_iterator
)
972 struct bt_self_component_port_input_message_iterator
*iterator
=
973 (void *) self_iterator
;
975 BT_ASSERT_PRE_NON_NULL(iterator
, "Message iterator");
976 return (void *) iterator
->upstream_component
;
979 struct bt_self_port_output
*bt_self_message_iterator_borrow_port(
980 struct bt_self_message_iterator
*self_iterator
)
982 struct bt_self_component_port_input_message_iterator
*iterator
=
983 (void *) self_iterator
;
985 BT_ASSERT_PRE_NON_NULL(iterator
, "Message iterator");
986 return (void *) iterator
->upstream_port
;
990 void bt_port_output_message_iterator_destroy(struct bt_object
*obj
)
992 struct bt_port_output_message_iterator
*iterator
= (void *) obj
;
994 BT_LIB_LOGI("Destroying output port message iterator object: %!+i",
996 BT_LOGD_STR("Putting graph.");
997 BT_OBJECT_PUT_REF_AND_RESET(iterator
->graph
);
998 BT_LOGD_STR("Putting colander sink component.");
999 BT_OBJECT_PUT_REF_AND_RESET(iterator
->colander
);
1000 destroy_base_message_iterator(obj
);
1003 struct bt_port_output_message_iterator
*
1004 bt_port_output_message_iterator_create(struct bt_graph
*graph
,
1005 const struct bt_port_output
*output_port
)
1007 struct bt_port_output_message_iterator
*iterator
= NULL
;
1008 struct bt_component_class_sink
*colander_comp_cls
= NULL
;
1009 struct bt_component
*output_port_comp
= NULL
;
1010 struct bt_component_sink
*colander_comp
;
1012 struct bt_port_input
*colander_in_port
= NULL
;
1013 struct bt_component_class_sink_colander_data colander_data
;
1016 BT_ASSERT_PRE_NON_NULL(graph
, "Graph");
1017 BT_ASSERT_PRE_NON_NULL(output_port
, "Output port");
1018 output_port_comp
= bt_port_borrow_component_inline(
1019 (const void *) output_port
);
1020 BT_ASSERT_PRE(output_port_comp
,
1021 "Output port has no component: %!+p", output_port
);
1022 BT_ASSERT_PRE(bt_component_borrow_graph(output_port_comp
) ==
1024 "Output port is not part of graph: %![graph-]+g, %![port-]+p",
1025 graph
, output_port
);
1026 BT_ASSERT_PRE(!graph
->has_sink
,
1027 "Graph already has a sink component: %![graph-]+g");
1029 /* Create message iterator */
1030 BT_LIB_LOGI("Creating message iterator on output port: "
1031 "%![port-]+p, %![comp-]+c", output_port
, output_port_comp
);
1032 iterator
= g_new0(struct bt_port_output_message_iterator
, 1);
1034 BT_LIB_LOGE_APPEND_CAUSE(
1035 "Failed to allocate one output port message iterator.");
1039 ret
= init_message_iterator((void *) iterator
,
1040 BT_MESSAGE_ITERATOR_TYPE_PORT_OUTPUT
,
1041 bt_port_output_message_iterator_destroy
);
1043 /* init_message_iterator() logs errors */
1044 BT_OBJECT_PUT_REF_AND_RESET(iterator
);
1048 /* Create colander component */
1049 colander_comp_cls
= bt_component_class_sink_colander_get();
1050 if (!colander_comp_cls
) {
1051 /* bt_component_class_sink_colander_get() logs errors */
1052 BT_LIB_LOGE_APPEND_CAUSE(
1053 "Cannot get colander sink component class.");
1057 iterator
->graph
= graph
;
1058 bt_object_get_no_null_check(iterator
->graph
);
1059 colander_data
.msgs
= (void *) iterator
->base
.msgs
->pdata
;
1060 colander_data
.count_addr
= &iterator
->count
;
1063 * Hope that nobody uses this very unique name.
1065 * We pass `BT_LOGGING_LEVEL_NONE` but the colander component
1066 * class module does not use this level anyway since it belongs
1069 graph_status
= bt_graph_add_sink_component_with_init_method_data(
1070 (void *) graph
, colander_comp_cls
,
1071 "colander-36ac3409-b1a8-4d60-ab1f-4fdf341a8fb1",
1072 NULL
, &colander_data
, BT_LOGGING_LEVEL_NONE
,
1073 (void *) &iterator
->colander
);
1074 if (graph_status
!= BT_FUNC_STATUS_OK
) {
1075 BT_LIB_LOGE_APPEND_CAUSE(
1076 "Cannot add colander sink component to graph: "
1077 "%![graph-]+g, status=%s", graph
,
1078 bt_common_func_status_string(graph_status
));
1083 * Connect provided output port to the colander component's
1087 (void *) bt_component_sink_borrow_input_port_by_index_const(
1088 (void *) iterator
->colander
, 0);
1089 BT_ASSERT(colander_in_port
);
1090 graph_status
= bt_graph_connect_ports(graph
,
1091 output_port
, colander_in_port
, NULL
);
1092 if (graph_status
!= BT_FUNC_STATUS_OK
) {
1093 BT_LIB_LOGW_APPEND_CAUSE(
1094 "Cannot connect colander sink's port: "
1095 "%![graph-]+g, %![comp-]+c, status=%s", graph
,
1097 bt_common_func_status_string(graph_status
));
1102 * At this point everything went fine. Make the graph
1103 * nonconsumable forever so that only this message iterator
1104 * can consume (thanks to bt_graph_consume_sink_no_check()).
1105 * This avoids leaking the message created by the colander
1106 * sink and moved to the message iterator's message
1109 bt_graph_set_can_consume(iterator
->graph
, false);
1111 /* Also set the graph as being configured. */
1112 graph_status
= bt_graph_configure(graph
);
1113 if (graph_status
!= BT_FUNC_STATUS_OK
) {
1114 BT_LIB_LOGW_APPEND_CAUSE(
1115 "Cannot configure graph after having "
1116 "added and connected colander sink: "
1117 "%![graph-]+g, %![comp-]+c, status=%s", graph
,
1119 bt_common_func_status_string(graph_status
));
1125 if (iterator
&& iterator
->graph
&& iterator
->colander
) {
1128 /* Remove created colander component from graph if any */
1129 colander_comp
= iterator
->colander
;
1130 BT_OBJECT_PUT_REF_AND_RESET(iterator
->colander
);
1133 * At this point the colander component's reference
1134 * count is 0 because iterator->colander was the only
1135 * owner. We also know that it is not connected because
1136 * this is the last operation before this function
1139 * Since we honor the preconditions here,
1140 * bt_graph_remove_unconnected_component() always
1143 ret
= bt_graph_remove_unconnected_component(iterator
->graph
,
1144 (void *) colander_comp
);
1145 BT_ASSERT(ret
== 0);
1148 BT_OBJECT_PUT_REF_AND_RESET(iterator
);
1151 bt_object_put_ref(colander_comp_cls
);
1152 return (void *) iterator
;
1155 bt_bool
bt_self_component_port_input_message_iterator_can_seek_ns_from_origin(
1156 struct bt_self_component_port_input_message_iterator
*iterator
,
1157 int64_t ns_from_origin
)
1159 bt_bool can
= BT_FALSE
;
1161 BT_ASSERT_PRE_NON_NULL(iterator
, "Message iterator");
1162 BT_ASSERT_PRE_ITER_HAS_STATE_TO_SEEK(iterator
);
1164 bt_component_borrow_graph(iterator
->upstream_component
)->config_state
!=
1165 BT_GRAPH_CONFIGURATION_STATE_CONFIGURING
,
1166 "Graph is not configured: %!+g",
1167 bt_component_borrow_graph(iterator
->upstream_component
));
1169 if (iterator
->methods
.can_seek_ns_from_origin
) {
1170 can
= iterator
->methods
.can_seek_ns_from_origin(iterator
,
1176 * Automatic seeking fall back: if we can seek to the beginning,
1177 * then we can automatically seek to any message.
1179 if (iterator
->methods
.can_seek_beginning
) {
1180 can
= iterator
->methods
.can_seek_beginning(iterator
);
1187 bt_bool
bt_self_component_port_input_message_iterator_can_seek_beginning(
1188 struct bt_self_component_port_input_message_iterator
*iterator
)
1190 bt_bool can
= BT_FALSE
;
1192 BT_ASSERT_PRE_NON_NULL(iterator
, "Message iterator");
1193 BT_ASSERT_PRE_ITER_HAS_STATE_TO_SEEK(iterator
);
1195 bt_component_borrow_graph(iterator
->upstream_component
)->config_state
!=
1196 BT_GRAPH_CONFIGURATION_STATE_CONFIGURING
,
1197 "Graph is not configured: %!+g",
1198 bt_component_borrow_graph(iterator
->upstream_component
));
1200 if (iterator
->methods
.can_seek_beginning
) {
1201 can
= iterator
->methods
.can_seek_beginning(iterator
);
1208 void set_iterator_state_after_seeking(
1209 struct bt_self_component_port_input_message_iterator
*iterator
,
1212 enum bt_self_component_port_input_message_iterator_state new_state
= 0;
1214 /* Set iterator's state depending on seeking status */
1216 case BT_FUNC_STATUS_OK
:
1217 new_state
= BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE
;
1219 case BT_FUNC_STATUS_AGAIN
:
1220 new_state
= BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_AGAIN
;
1222 case BT_FUNC_STATUS_ERROR
:
1223 case BT_FUNC_STATUS_MEMORY_ERROR
:
1224 new_state
= BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_ERROR
;
1226 case BT_FUNC_STATUS_END
:
1227 new_state
= BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ENDED
;
1233 set_self_comp_port_input_msg_iterator_state(iterator
, new_state
);
1237 void reset_iterator_expectations(
1238 struct bt_self_component_port_input_message_iterator
*iterator
)
1240 iterator
->last_ns_from_origin
= INT64_MIN
;
1241 iterator
->clock_expectation
.type
= CLOCK_EXPECTATION_UNSET
;
1244 enum bt_message_iterator_seek_beginning_status
1245 bt_self_component_port_input_message_iterator_seek_beginning(
1246 struct bt_self_component_port_input_message_iterator
*iterator
)
1250 BT_ASSERT_PRE_NON_NULL(iterator
, "Message iterator");
1251 BT_ASSERT_PRE_ITER_HAS_STATE_TO_SEEK(iterator
);
1253 bt_component_borrow_graph(iterator
->upstream_component
)->config_state
!=
1254 BT_GRAPH_CONFIGURATION_STATE_CONFIGURING
,
1255 "Graph is not configured: %!+g",
1256 bt_component_borrow_graph(iterator
->upstream_component
));
1258 bt_self_component_port_input_message_iterator_can_seek_beginning(
1260 "Message iterator cannot seek beginning: %!+i", iterator
);
1263 * We are seeking, reset our expectations about how the following
1264 * messages should look like.
1266 reset_iterator_expectations(iterator
);
1268 BT_LIB_LOGD("Calling user's \"seek beginning\" method: %!+i", iterator
);
1269 set_self_comp_port_input_msg_iterator_state(iterator
,
1270 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_SEEKING
);
1271 status
= iterator
->methods
.seek_beginning(iterator
);
1272 BT_LOGD("User method returned: status=%s",
1273 bt_common_func_status_string(status
));
1274 BT_ASSERT_POST(status
== BT_FUNC_STATUS_OK
||
1275 status
== BT_FUNC_STATUS_ERROR
||
1276 status
== BT_FUNC_STATUS_MEMORY_ERROR
||
1277 status
== BT_FUNC_STATUS_AGAIN
,
1278 "Unexpected status: %![iter-]+i, status=%s",
1279 iterator
, bt_common_func_status_string(status
));
1281 BT_LIB_LOGW_APPEND_CAUSE(
1282 "Component input port message iterator's \"seek beginning\" method failed: "
1283 "%![iter-]+i, status=%s",
1284 iterator
, bt_common_func_status_string(status
));
1287 set_iterator_state_after_seeking(iterator
, status
);
1292 * Structure used to record the state of a given stream during the fast-forward
1293 * phase of an auto-seek.
1295 struct auto_seek_stream_state
{
1297 * Value representing which step of this timeline we are at.
1300 * [SB] 1 [SAB] 2 [PB] 3 [PE] 2 [SAE] 1 [SE]
1302 * At each point in the timeline, the messages we need to replicate are:
1304 * 1: Stream beginning
1305 * 2: Stream beginning, stream activity beginning
1306 * 3: Stream beginning, stream activity beginning, packet beginning
1308 * Before "Stream beginning" and after "Stream end", we don't need to
1309 * replicate anything as the stream doesn't exist.
1312 AUTO_SEEK_STREAM_STATE_STREAM_BEGAN
,
1313 AUTO_SEEK_STREAM_STATE_STREAM_ACTIVITY_BEGAN
,
1314 AUTO_SEEK_STREAM_STATE_PACKET_BEGAN
,
1318 * If `state` is AUTO_SEEK_STREAM_STATE_PACKET_BEGAN, the packet we are
1319 * in. This is a weak reference, since the packet will always be
1320 * alive by the time we use it.
1322 struct bt_packet
*packet
;
1326 struct auto_seek_stream_state
*create_auto_seek_stream_state(void)
1328 return g_new0(struct auto_seek_stream_state
, 1);
1332 void destroy_auto_seek_stream_state(void *ptr
)
1338 GHashTable
*create_auto_seek_stream_states(void)
1340 return g_hash_table_new_full(g_direct_hash
, g_direct_equal
, NULL
,
1341 destroy_auto_seek_stream_state
);
1345 void destroy_auto_seek_stream_states(GHashTable
*stream_states
)
1347 g_hash_table_destroy(stream_states
);
1351 * Handle one message while we are in the fast-forward phase of an auto-seek.
1353 * Sets `*got_first` to true if the message's timestamp is greater or equal to
1354 * `ns_from_origin`. In other words, if this is the first message after our
1357 * `stream_states` is an hash table of `bt_stream *` (weak reference) to
1358 * `struct auto_seek_stream_state` used to keep the state of each stream
1359 * during the fast-forward.
1363 int auto_seek_handle_message(
1364 struct bt_self_component_port_input_message_iterator
*iterator
,
1365 int64_t ns_from_origin
, const struct bt_message
*msg
,
1366 bool *got_first
, GHashTable
*stream_states
)
1368 int status
= BT_FUNC_STATUS_OK
;
1369 int64_t msg_ns_from_origin
;
1370 const struct bt_clock_snapshot
*clk_snapshot
= NULL
;
1374 BT_ASSERT(got_first
);
1376 switch (msg
->type
) {
1377 case BT_MESSAGE_TYPE_EVENT
:
1379 const struct bt_message_event
*event_msg
=
1382 clk_snapshot
= event_msg
->default_cs
;
1383 BT_ASSERT_POST(clk_snapshot
,
1384 "Event message has no default clock snapshot: %!+n",
1388 case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY
:
1390 const struct bt_message_message_iterator_inactivity
*inactivity_msg
=
1393 clk_snapshot
= inactivity_msg
->default_cs
;
1394 BT_ASSERT(clk_snapshot
);
1397 case BT_MESSAGE_TYPE_PACKET_BEGINNING
:
1398 case BT_MESSAGE_TYPE_PACKET_END
:
1400 const struct bt_message_packet
*packet_msg
=
1403 clk_snapshot
= packet_msg
->default_cs
;
1404 BT_ASSERT_POST(clk_snapshot
,
1405 "Packet message has no default clock snapshot: %!+n",
1409 case BT_MESSAGE_TYPE_DISCARDED_EVENTS
:
1410 case BT_MESSAGE_TYPE_DISCARDED_PACKETS
:
1412 struct bt_message_discarded_items
*msg_disc_items
=
1415 BT_ASSERT_POST(msg_disc_items
->default_begin_cs
&&
1416 msg_disc_items
->default_end_cs
,
1417 "Discarded events/packets message has no default clock snapshots: %!+n",
1419 ret
= bt_clock_snapshot_get_ns_from_origin(
1420 msg_disc_items
->default_begin_cs
,
1421 &msg_ns_from_origin
);
1423 status
= BT_FUNC_STATUS_ERROR
;
1427 if (msg_ns_from_origin
>= ns_from_origin
) {
1432 ret
= bt_clock_snapshot_get_ns_from_origin(
1433 msg_disc_items
->default_end_cs
,
1434 &msg_ns_from_origin
);
1436 status
= BT_FUNC_STATUS_ERROR
;
1440 if (msg_ns_from_origin
>= ns_from_origin
) {
1442 * The discarded items message's beginning time
1443 * is before the requested seeking time, but its
1444 * end time is after. Modify the message so as
1445 * to set its beginning time to the requested
1446 * seeking time, and make its item count unknown
1447 * as we don't know if items were really
1448 * discarded within the new time range.
1450 uint64_t new_begin_raw_value
;
1452 ret
= bt_clock_class_clock_value_from_ns_from_origin(
1453 msg_disc_items
->default_end_cs
->clock_class
,
1454 ns_from_origin
, &new_begin_raw_value
);
1456 status
= BT_FUNC_STATUS_ERROR
;
1460 bt_clock_snapshot_set_raw_value(
1461 msg_disc_items
->default_begin_cs
,
1462 new_begin_raw_value
);
1463 msg_disc_items
->count
.base
.avail
=
1464 BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE
;
1467 * It is safe to push it because its beginning
1468 * time is exactly the requested seeking time.
1475 case BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING
:
1477 const struct bt_message_stream_activity
*stream_act_msg
=
1480 switch (stream_act_msg
->default_cs_state
) {
1481 case BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_UNKNOWN
:
1482 case BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_INFINITE
:
1484 * -inf is always less than any requested time,
1485 * and we can't assume any specific time for an
1486 * unknown clock snapshot, so skip this.
1489 case BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_KNOWN
:
1490 clk_snapshot
= stream_act_msg
->default_cs
;
1491 BT_ASSERT(clk_snapshot
);
1499 case BT_MESSAGE_TYPE_STREAM_ACTIVITY_END
:
1501 const struct bt_message_stream_activity
*stream_act_msg
=
1504 switch (stream_act_msg
->default_cs_state
) {
1505 case BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_UNKNOWN
:
1507 * We can't assume any specific time for an
1508 * unknown clock snapshot, so skip this.
1511 case BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_INFINITE
:
1513 * +inf is always greater than any requested
1518 case BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_KNOWN
:
1519 clk_snapshot
= stream_act_msg
->default_cs
;
1520 BT_ASSERT(clk_snapshot
);
1528 case BT_MESSAGE_TYPE_STREAM_BEGINNING
:
1529 case BT_MESSAGE_TYPE_STREAM_END
:
1536 BT_ASSERT(clk_snapshot
);
1537 ret
= bt_clock_snapshot_get_ns_from_origin(clk_snapshot
,
1538 &msg_ns_from_origin
);
1540 status
= BT_FUNC_STATUS_ERROR
;
1544 if (msg_ns_from_origin
>= ns_from_origin
) {
1550 /* This message won't be sent downstream. */
1551 switch (msg
->type
) {
1552 case BT_MESSAGE_TYPE_STREAM_BEGINNING
:
1554 const struct bt_message_stream
*stream_msg
= (const void *) msg
;
1555 struct auto_seek_stream_state
*stream_state
;
1557 /* Update stream's state: stream began. */
1558 stream_state
= create_auto_seek_stream_state();
1559 if (!stream_state
) {
1560 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1564 stream_state
->state
= AUTO_SEEK_STREAM_STATE_STREAM_BEGAN
;
1566 BT_ASSERT(!bt_g_hash_table_contains(stream_states
, stream_msg
->stream
));
1567 g_hash_table_insert(stream_states
, stream_msg
->stream
, stream_state
);
1570 case BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING
:
1572 const struct bt_message_stream_activity
*stream_act_msg
=
1574 struct auto_seek_stream_state
*stream_state
;
1576 /* Update stream's state: stream activity began. */
1577 stream_state
= g_hash_table_lookup(stream_states
, stream_act_msg
->stream
);
1578 BT_ASSERT(stream_state
);
1580 BT_ASSERT(stream_state
->state
== AUTO_SEEK_STREAM_STATE_STREAM_BEGAN
);
1581 stream_state
->state
= AUTO_SEEK_STREAM_STATE_STREAM_ACTIVITY_BEGAN
;
1582 BT_ASSERT(!stream_state
->packet
);
1585 case BT_MESSAGE_TYPE_PACKET_BEGINNING
:
1587 const struct bt_message_packet
*packet_msg
=
1589 struct auto_seek_stream_state
*stream_state
;
1591 /* Update stream's state: packet began. */
1592 stream_state
= g_hash_table_lookup(stream_states
, packet_msg
->packet
->stream
);
1593 BT_ASSERT(stream_state
);
1595 BT_ASSERT(stream_state
->state
== AUTO_SEEK_STREAM_STATE_STREAM_ACTIVITY_BEGAN
);
1596 stream_state
->state
= AUTO_SEEK_STREAM_STATE_PACKET_BEGAN
;
1597 BT_ASSERT(!stream_state
->packet
);
1598 stream_state
->packet
= packet_msg
->packet
;
1601 case BT_MESSAGE_TYPE_PACKET_END
:
1603 const struct bt_message_packet
*packet_msg
=
1605 struct auto_seek_stream_state
*stream_state
;
1607 /* Update stream's state: packet ended. */
1608 stream_state
= g_hash_table_lookup(stream_states
, packet_msg
->packet
->stream
);
1609 BT_ASSERT(stream_state
);
1611 BT_ASSERT(stream_state
->state
== AUTO_SEEK_STREAM_STATE_PACKET_BEGAN
);
1612 stream_state
->state
= AUTO_SEEK_STREAM_STATE_STREAM_ACTIVITY_BEGAN
;
1613 BT_ASSERT(stream_state
->packet
);
1614 stream_state
->packet
= NULL
;
1617 case BT_MESSAGE_TYPE_STREAM_ACTIVITY_END
:
1619 const struct bt_message_stream_activity
*stream_act_msg
=
1621 struct auto_seek_stream_state
*stream_state
;
1623 /* Update stream's state: stream activity ended. */
1624 stream_state
= g_hash_table_lookup(stream_states
, stream_act_msg
->stream
);
1625 BT_ASSERT(stream_state
);
1627 BT_ASSERT(stream_state
->state
== AUTO_SEEK_STREAM_STATE_STREAM_ACTIVITY_BEGAN
);
1628 stream_state
->state
= AUTO_SEEK_STREAM_STATE_STREAM_BEGAN
;
1629 BT_ASSERT(!stream_state
->packet
);
1632 case BT_MESSAGE_TYPE_STREAM_END
:
1634 const struct bt_message_stream
*stream_msg
= (const void *) msg
;
1635 struct auto_seek_stream_state
*stream_state
;
1637 stream_state
= g_hash_table_lookup(stream_states
, stream_msg
->stream
);
1638 BT_ASSERT(stream_state
);
1639 BT_ASSERT(stream_state
->state
== AUTO_SEEK_STREAM_STATE_STREAM_BEGAN
);
1640 BT_ASSERT(!stream_state
->packet
);
1642 /* Update stream's state: this stream doesn't exist anymore. */
1643 g_hash_table_remove(stream_states
, stream_msg
->stream
);
1650 bt_object_put_no_null_check(msg
);
1655 g_queue_push_tail(iterator
->auto_seek
.msgs
, (void *) msg
);
1659 BT_ASSERT(!msg
|| status
!= BT_FUNC_STATUS_OK
);
1664 int find_message_ge_ns_from_origin(
1665 struct bt_self_component_port_input_message_iterator
*iterator
,
1666 int64_t ns_from_origin
, GHashTable
*stream_states
)
1669 enum bt_self_component_port_input_message_iterator_state init_state
=
1671 const struct bt_message
*messages
[MSG_BATCH_SIZE
];
1672 uint64_t user_count
= 0;
1674 bool got_first
= false;
1676 BT_ASSERT(iterator
);
1677 memset(&messages
[0], 0, sizeof(messages
[0]) * MSG_BATCH_SIZE
);
1680 * Make this iterator temporarily active (not seeking) to call
1681 * the "next" method.
1683 set_self_comp_port_input_msg_iterator_state(iterator
,
1684 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE
);
1686 BT_ASSERT(iterator
->methods
.next
);
1688 while (!got_first
) {
1690 * Call the user's "next" method to get the next
1691 * messages and status.
1693 status
= call_iterator_next_method(iterator
,
1694 &messages
[0], MSG_BATCH_SIZE
, &user_count
);
1695 BT_LOGD("User method returned: status=%s",
1696 bt_common_func_status_string(status
));
1698 BT_LIB_LOGW_APPEND_CAUSE(
1699 "Component input port message iterator's \"next\" method failed: "
1700 "%![iter-]+i, status=%s",
1701 iterator
, bt_common_func_status_string(status
));
1705 * The user's "next" method must not do any action which
1706 * would change the iterator's state.
1708 BT_ASSERT(iterator
->state
==
1709 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE
);
1712 case BT_FUNC_STATUS_OK
:
1713 BT_ASSERT_POST(user_count
<= MSG_BATCH_SIZE
,
1714 "Invalid returned message count: greater than "
1715 "batch size: count=%" PRIu64
", batch-size=%u",
1716 user_count
, MSG_BATCH_SIZE
);
1718 case BT_FUNC_STATUS_AGAIN
:
1719 case BT_FUNC_STATUS_ERROR
:
1720 case BT_FUNC_STATUS_MEMORY_ERROR
:
1721 case BT_FUNC_STATUS_END
:
1727 for (i
= 0; i
< user_count
; i
++) {
1729 g_queue_push_tail(iterator
->auto_seek
.msgs
,
1730 (void *) messages
[i
]);
1735 status
= auto_seek_handle_message(iterator
,
1736 ns_from_origin
, messages
[i
], &got_first
,
1738 if (status
== BT_FUNC_STATUS_OK
) {
1739 /* Message was either pushed or moved */
1748 for (i
= 0; i
< user_count
; i
++) {
1750 bt_object_put_no_null_check(messages
[i
]);
1754 set_self_comp_port_input_msg_iterator_state(iterator
, init_state
);
1759 * This function is installed as the iterator's next callback after we have
1760 * auto-seeked (seeked to the beginning and fast-forwarded) to send the
1761 * messages saved in iterator->auto_seek.msgs. Once this is done, the original
1762 * next callback is put back.
1766 enum bt_component_class_message_iterator_next_method_status
post_auto_seek_next(
1767 struct bt_self_component_port_input_message_iterator
*iterator
,
1768 bt_message_array_const msgs
, uint64_t capacity
,
1771 BT_ASSERT(!g_queue_is_empty(iterator
->auto_seek
.msgs
));
1775 * Move auto-seek messages to the output array (which is this
1776 * iterator's base message array).
1778 while (capacity
> 0 && !g_queue_is_empty(iterator
->auto_seek
.msgs
)) {
1779 msgs
[*count
] = g_queue_pop_head(iterator
->auto_seek
.msgs
);
1784 BT_ASSERT(*count
> 0);
1786 if (g_queue_is_empty(iterator
->auto_seek
.msgs
)) {
1787 /* No more auto-seek messages, restore user's next callback. */
1788 BT_ASSERT(iterator
->auto_seek
.original_next_callback
);
1789 iterator
->methods
.next
= iterator
->auto_seek
.original_next_callback
;
1790 iterator
->auto_seek
.original_next_callback
= NULL
;
1793 return BT_FUNC_STATUS_OK
;
1797 int clock_raw_value_from_ns_from_origin(const bt_clock_class
*clock_class
,
1798 int64_t ns_from_origin
, uint64_t *raw_value
)
1801 int64_t cc_offset_s
= clock_class
->offset_seconds
;
1802 uint64_t cc_offset_cycles
= clock_class
->offset_cycles
;
1803 uint64_t cc_freq
= clock_class
->frequency
;
1805 return bt_common_clock_value_from_ns_from_origin(cc_offset_s
,
1806 cc_offset_cycles
, cc_freq
, ns_from_origin
, raw_value
);
1810 enum bt_message_iterator_seek_ns_from_origin_status
1811 bt_self_component_port_input_message_iterator_seek_ns_from_origin(
1812 struct bt_self_component_port_input_message_iterator
*iterator
,
1813 int64_t ns_from_origin
)
1816 GHashTable
*stream_states
= NULL
;
1818 BT_ASSERT_PRE_NON_NULL(iterator
, "Message iterator");
1819 BT_ASSERT_PRE_ITER_HAS_STATE_TO_SEEK(iterator
);
1821 bt_component_borrow_graph(iterator
->upstream_component
)->config_state
!=
1822 BT_GRAPH_CONFIGURATION_STATE_CONFIGURING
,
1823 "Graph is not configured: %!+g",
1824 bt_component_borrow_graph(iterator
->upstream_component
));
1826 bt_self_component_port_input_message_iterator_can_seek_ns_from_origin(
1827 iterator
, ns_from_origin
),
1828 "Message iterator cannot seek nanoseconds from origin: %!+i, "
1829 "ns-from-origin=%" PRId64
, iterator
, ns_from_origin
);
1830 set_self_comp_port_input_msg_iterator_state(iterator
,
1831 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_SEEKING
);
1834 * We are seeking, reset our expectations about how the following
1835 * messages should look like.
1837 reset_iterator_expectations(iterator
);
1839 if (iterator
->methods
.seek_ns_from_origin
) {
1840 /* The iterator knows how to seek to a particular time, let it handle this. */
1841 BT_LIB_LOGD("Calling user's \"seek nanoseconds from origin\" method: "
1842 "%![iter-]+i, ns=%" PRId64
, iterator
, ns_from_origin
);
1843 status
= iterator
->methods
.seek_ns_from_origin(iterator
,
1845 BT_LOGD("User method returned: status=%s",
1846 bt_common_func_status_string(status
));
1847 BT_ASSERT_POST(status
== BT_FUNC_STATUS_OK
||
1848 status
== BT_FUNC_STATUS_ERROR
||
1849 status
== BT_FUNC_STATUS_MEMORY_ERROR
||
1850 status
== BT_FUNC_STATUS_AGAIN
,
1851 "Unexpected status: %![iter-]+i, status=%s",
1852 iterator
, bt_common_func_status_string(status
));
1854 BT_LIB_LOGW_APPEND_CAUSE(
1855 "Component input port message iterator's \"seek nanoseconds from origin\" method failed: "
1856 "%![iter-]+i, status=%s",
1857 iterator
, bt_common_func_status_string(status
));
1861 * The iterator doesn't know how to seek to a particular time. We will
1862 * seek to the beginning and fast forward to the right place.
1864 BT_ASSERT(iterator
->methods
.can_seek_beginning(iterator
));
1865 BT_ASSERT(iterator
->methods
.seek_beginning
);
1866 BT_LIB_LOGD("Calling user's \"seek beginning\" method: %!+i",
1868 status
= iterator
->methods
.seek_beginning(iterator
);
1869 BT_LOGD("User method returned: status=%s",
1870 bt_common_func_status_string(status
));
1871 BT_ASSERT_POST(status
== BT_FUNC_STATUS_OK
||
1872 status
== BT_FUNC_STATUS_ERROR
||
1873 status
== BT_FUNC_STATUS_MEMORY_ERROR
||
1874 status
== BT_FUNC_STATUS_AGAIN
,
1875 "Unexpected status: %![iter-]+i, status=%s",
1876 iterator
, bt_common_func_status_string(status
));
1878 BT_LIB_LOGW_APPEND_CAUSE(
1879 "Component input port message iterator's \"seek beginning\" method failed: "
1880 "%![iter-]+i, status=%s",
1881 iterator
, bt_common_func_status_string(status
));
1885 case BT_FUNC_STATUS_OK
:
1887 case BT_FUNC_STATUS_ERROR
:
1888 case BT_FUNC_STATUS_MEMORY_ERROR
:
1889 case BT_FUNC_STATUS_AGAIN
:
1896 * Find the first message which has a default clock
1897 * snapshot greater than or equal to the requested
1898 * seeking time, and move the received messages from
1899 * this point in the batch to this iterator's auto-seek
1902 while (!g_queue_is_empty(iterator
->auto_seek
.msgs
)) {
1903 bt_object_put_no_null_check(
1904 g_queue_pop_tail(iterator
->auto_seek
.msgs
));
1907 stream_states
= create_auto_seek_stream_states();
1908 if (!stream_states
) {
1909 BT_LIB_LOGE_APPEND_CAUSE(
1910 "Failed to allocate one GHashTable.");
1911 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1915 status
= find_message_ge_ns_from_origin(iterator
,
1916 ns_from_origin
, stream_states
);
1918 case BT_FUNC_STATUS_OK
:
1919 case BT_FUNC_STATUS_END
:
1921 GHashTableIter iter
;
1922 gpointer key
, value
;
1925 * If some streams exist at the seek time, prepend the
1926 * required messages to put those streams in the right
1929 g_hash_table_iter_init(&iter
, stream_states
);
1930 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
1931 const bt_stream
*stream
= key
;
1932 struct auto_seek_stream_state
*stream_state
=
1933 (struct auto_seek_stream_state
*) value
;
1935 const bt_clock_class
*clock_class
= bt_stream_class_borrow_default_clock_class_const(
1936 bt_stream_borrow_class_const(stream
));
1939 if (clock_raw_value_from_ns_from_origin(clock_class
, ns_from_origin
, &raw_value
) != 0) {
1940 BT_LIB_LOGW_APPEND_CAUSE(
1941 "Could not convert nanoseconds from origin to clock value: "
1942 "ns-from-origin=%" PRId64
", %![cc-]+K",
1943 ns_from_origin
, clock_class
);
1944 status
= BT_FUNC_STATUS_ERROR
;
1948 switch (stream_state
->state
) {
1949 case AUTO_SEEK_STREAM_STATE_PACKET_BEGAN
:
1950 BT_ASSERT(stream_state
->packet
);
1951 BT_LIB_LOGD("Creating packet message: %![packet-]+a", stream_state
->packet
);
1952 msg
= bt_message_packet_beginning_create_with_default_clock_snapshot(
1953 (bt_self_message_iterator
*) iterator
, stream_state
->packet
, raw_value
);
1955 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1959 g_queue_push_head(iterator
->auto_seek
.msgs
, msg
);
1962 case AUTO_SEEK_STREAM_STATE_STREAM_ACTIVITY_BEGAN
:
1963 msg
= bt_message_stream_activity_beginning_create(
1964 (bt_self_message_iterator
*) iterator
, stream
);
1966 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1970 bt_message_stream_activity_beginning_set_default_clock_snapshot(msg
, raw_value
);
1972 g_queue_push_head(iterator
->auto_seek
.msgs
, msg
);
1975 case AUTO_SEEK_STREAM_STATE_STREAM_BEGAN
:
1976 msg
= bt_message_stream_beginning_create(
1977 (bt_self_message_iterator
*) iterator
, stream
);
1979 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1983 g_queue_push_head(iterator
->auto_seek
.msgs
, msg
);
1990 * If there are messages in the auto-seek
1991 * message queue, replace the user's "next"
1992 * method with a custom, temporary "next" method
1993 * which returns them.
1995 if (!g_queue_is_empty(iterator
->auto_seek
.msgs
)) {
1996 BT_ASSERT(!iterator
->auto_seek
.original_next_callback
);
1997 iterator
->auto_seek
.original_next_callback
= iterator
->methods
.next
;
1999 iterator
->methods
.next
=
2000 (bt_self_component_port_input_message_iterator_next_method
)
2001 post_auto_seek_next
;
2005 * `BT_FUNC_STATUS_END` becomes
2006 * `BT_FUNC_STATUS_OK`: the next
2007 * time this iterator's "next" method is called,
2009 * `BT_FUNC_STATUS_END`.
2011 status
= BT_FUNC_STATUS_OK
;
2014 case BT_FUNC_STATUS_ERROR
:
2015 case BT_FUNC_STATUS_MEMORY_ERROR
:
2016 case BT_FUNC_STATUS_AGAIN
:
2024 * The following messages returned by the next method (including
2025 * post_auto_seek_next) must be after (or at) `ns_from_origin`.
2027 iterator
->last_ns_from_origin
= ns_from_origin
;
2030 if (stream_states
) {
2031 destroy_auto_seek_stream_states(stream_states
);
2032 stream_states
= NULL
;
2035 set_iterator_state_after_seeking(iterator
, status
);
2040 bt_self_component_port_input_message_iterator
*
2041 borrow_output_port_message_iterator_upstream_iterator(
2042 struct bt_port_output_message_iterator
*iterator
)
2044 struct bt_component_class_sink_colander_priv_data
*colander_data
;
2046 BT_ASSERT(iterator
);
2047 colander_data
= (void *) iterator
->colander
->parent
.user_data
;
2048 BT_ASSERT(colander_data
);
2049 BT_ASSERT(colander_data
->msg_iter
);
2050 return colander_data
->msg_iter
;
2053 bt_bool
bt_port_output_message_iterator_can_seek_ns_from_origin(
2054 struct bt_port_output_message_iterator
*iterator
,
2055 int64_t ns_from_origin
)
2057 BT_ASSERT_PRE_NON_NULL(iterator
, "Message iterator");
2058 return bt_self_component_port_input_message_iterator_can_seek_ns_from_origin(
2059 borrow_output_port_message_iterator_upstream_iterator(
2060 iterator
), ns_from_origin
);
2063 bt_bool
bt_port_output_message_iterator_can_seek_beginning(
2064 struct bt_port_output_message_iterator
*iterator
)
2066 BT_ASSERT_PRE_NON_NULL(iterator
, "Message iterator");
2067 return bt_self_component_port_input_message_iterator_can_seek_beginning(
2068 borrow_output_port_message_iterator_upstream_iterator(
2072 enum bt_message_iterator_seek_ns_from_origin_status
2073 bt_port_output_message_iterator_seek_ns_from_origin(
2074 struct bt_port_output_message_iterator
*iterator
,
2075 int64_t ns_from_origin
)
2077 BT_ASSERT_PRE_NON_NULL(iterator
, "Message iterator");
2078 return bt_self_component_port_input_message_iterator_seek_ns_from_origin(
2079 borrow_output_port_message_iterator_upstream_iterator(iterator
),
2083 enum bt_message_iterator_seek_beginning_status
2084 bt_port_output_message_iterator_seek_beginning(
2085 struct bt_port_output_message_iterator
*iterator
)
2087 BT_ASSERT_PRE_NON_NULL(iterator
, "Message iterator");
2088 return bt_self_component_port_input_message_iterator_seek_beginning(
2089 borrow_output_port_message_iterator_upstream_iterator(
2093 void bt_port_output_message_iterator_get_ref(
2094 const struct bt_port_output_message_iterator
*iterator
)
2096 bt_object_get_ref(iterator
);
2099 void bt_port_output_message_iterator_put_ref(
2100 const struct bt_port_output_message_iterator
*iterator
)
2102 bt_object_put_ref(iterator
);
2105 void bt_self_component_port_input_message_iterator_get_ref(
2106 const struct bt_self_component_port_input_message_iterator
*iterator
)
2108 bt_object_get_ref(iterator
);
2111 void bt_self_component_port_input_message_iterator_put_ref(
2112 const struct bt_self_component_port_input_message_iterator
*iterator
)
2114 bt_object_put_ref(iterator
);