1 #ifndef BABELTRACE_GRAPH_MESSAGE_ITERATOR_INTERNAL_H
2 #define BABELTRACE_GRAPH_MESSAGE_ITERATOR_INTERNAL_H
5 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
6 * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 #include "common/macros.h"
28 #include "lib/object.h"
29 #include <babeltrace2/graph/connection-const.h>
30 #include <babeltrace2/graph/message-const.h>
31 #include <babeltrace2/types.h>
32 #include "common/assert.h"
34 #include "common/uuid.h"
39 enum bt_message_iterator_type
{
40 BT_MESSAGE_ITERATOR_TYPE_SELF_COMPONENT_PORT_INPUT
,
41 BT_MESSAGE_ITERATOR_TYPE_PORT_OUTPUT
,
44 enum bt_self_component_port_input_message_iterator_state
{
45 /* Iterator is not initialized */
46 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_NON_INITIALIZED
,
48 /* Iterator is active, not at the end yet, and not finalized */
49 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE
,
52 * Iterator is ended, not finalized yet: the "next" method
53 * returns BT_MESSAGE_ITERATOR_STATUS_END.
55 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ENDED
,
57 /* Iterator is currently being finalized */
58 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZING
,
60 /* Iterator is finalized */
61 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZED
,
63 /* Iterator is seeking */
64 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_SEEKING
,
66 /* Iterator did seek, but returned `BT_MESSAGE_ITERATOR_STATUS_AGAIN` */
67 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_AGAIN
,
69 /* Iterator did seek, but returned error status */
70 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_ERROR
,
73 struct bt_message_iterator
{
74 struct bt_object base
;
75 enum bt_message_iterator_type type
;
79 typedef enum bt_component_class_message_iterator_next_method_status
80 (*bt_self_component_port_input_message_iterator_next_method
)(
81 void *, bt_message_array_const
, uint64_t, uint64_t *);
83 typedef enum bt_component_class_message_iterator_seek_ns_from_origin_method_status
84 (*bt_self_component_port_input_message_iterator_seek_ns_from_origin_method
)(
87 typedef enum bt_component_class_message_iterator_seek_beginning_method_status
88 (*bt_self_component_port_input_message_iterator_seek_beginning_method
)(
92 (*bt_self_component_port_input_message_iterator_can_seek_ns_from_origin_method
)(
96 (*bt_self_component_port_input_message_iterator_can_seek_beginning_method
)(
99 struct bt_self_component_port_input_message_iterator
{
100 struct bt_message_iterator base
;
101 struct bt_component
*upstream_component
; /* Weak */
102 struct bt_port
*upstream_port
; /* Weak */
103 struct bt_connection
*connection
; /* Weak */
104 struct bt_graph
*graph
; /* Weak */
108 * `struct bt_self_component_port_input_message_iterator *`
111 * This is an array of upstream message iterators on which this
112 * iterator depends. The references are weak: an upstream
113 * message iterator is responsible for removing its entry within
114 * this array on finalization/destruction.
116 GPtrArray
*upstream_msg_iters
;
119 * Downstream message iterator which depends on this message
122 * This can be `NULL` if this message iterator's owner is a sink
125 struct bt_self_component_port_input_message_iterator
*downstream_msg_iter
;
128 bt_self_component_port_input_message_iterator_next_method next
;
129 bt_self_component_port_input_message_iterator_seek_ns_from_origin_method seek_ns_from_origin
;
130 bt_self_component_port_input_message_iterator_seek_beginning_method seek_beginning
;
131 bt_self_component_port_input_message_iterator_can_seek_ns_from_origin_method can_seek_ns_from_origin
;
132 bt_self_component_port_input_message_iterator_can_seek_beginning_method can_seek_beginning
;
135 enum bt_self_component_port_input_message_iterator_state state
;
138 * Timestamp of the last received message (or INT64_MIN in the
139 * beginning, or after a seek to beginning).
141 int64_t last_ns_from_origin
;
145 /* We haven't recorded clock properties yet. */
146 CLOCK_EXPECTATION_UNSET
,
148 /* Expect to have no clock. */
149 CLOCK_EXPECTATION_NONE
,
151 /* Clock with origin_is_unix_epoch true.*/
152 CLOCK_EXPECTATION_ORIGIN_UNIX
,
154 /* Clock with origin_is_unix_epoch false, with a UUID.*/
155 CLOCK_EXPECTATION_ORIGIN_OTHER_UUID
,
157 /* Clock with origin_is_unix_epoch false, without a UUID.*/
158 CLOCK_EXPECTATION_ORIGIN_OTHER_NO_UUID
,
162 * Expected UUID of the clock, if `type`is CLOCK_EXPECTATION_ORIGIN_OTHER_UUID.
164 * If the clock's origin is the unix epoch, the UUID is
165 * irrelevant (as the clock will be correlatable with other
166 * clocks having the same origin).
172 * Data necessary for auto seek (the seek-to-beginning then fast-forward
177 * Queue of `const bt_message *` (owned by this queue).
179 * When fast-forwarding, we get the messages from upstream in
180 * batches. Once we have found the first message with timestamp
181 * greater or equal to the seek time, we put it and all of the
182 * following message of the batch in this queue. They will be
183 * sent on the next "next" call on this iterator.
185 * The messages are in chronological order (i.e. the first to
186 * send is the first of the queue).
191 * After auto-seeking, we replace the iterator's `next` callback
192 * with our own, which returns the contents of the `msgs` queue.
193 * This field is where we save the original callback, so we can
196 void *original_next_callback
;
202 struct bt_port_output_message_iterator
{
203 struct bt_message_iterator base
;
204 struct bt_graph
*graph
; /* Owned by this */
205 struct bt_component_sink
*colander
; /* Owned by this */
208 * Only used temporarily as a bridge between a colander sink and
215 void bt_self_component_port_input_message_iterator_try_finalize(
216 struct bt_self_component_port_input_message_iterator
*iterator
);
219 void bt_self_component_port_input_message_iterator_set_connection(
220 struct bt_self_component_port_input_message_iterator
*iterator
,
221 struct bt_connection
*connection
);
224 const char *bt_self_component_port_input_message_iterator_state_string(
225 enum bt_self_component_port_input_message_iterator_state state
)
228 case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE
:
230 case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ENDED
:
232 case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZING
:
234 case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZED
:
236 case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_SEEKING
:
238 case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_AGAIN
:
239 return "LAST_SEEKING_RETURNED_AGAIN";
240 case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_ERROR
:
241 return "LAST_SEEKING_RETURNED_ERROR";
247 #endif /* BABELTRACE_GRAPH_MESSAGE_ITERATOR_INTERNAL_H */