2 * SPDX-License-Identifier: MIT
4 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
5 * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 #ifndef BABELTRACE_GRAPH_MESSAGE_ITERATOR_INTERNAL_H
9 #define BABELTRACE_GRAPH_MESSAGE_ITERATOR_INTERNAL_H
11 #include "common/macros.h"
12 #include "lib/object.h"
13 #include <babeltrace2/graph/connection.h>
14 #include <babeltrace2/graph/message.h>
15 #include <babeltrace2/types.h>
16 #include "common/assert.h"
18 #include "common/uuid.h"
23 enum bt_message_iterator_state
{
24 /* Iterator is not initialized */
25 BT_MESSAGE_ITERATOR_STATE_NON_INITIALIZED
,
27 /* Iterator is active, not at the end yet, and not finalized */
28 BT_MESSAGE_ITERATOR_STATE_ACTIVE
,
31 * Iterator is ended, not finalized yet: the "next" method
32 * returns BT_MESSAGE_ITERATOR_STATUS_END.
34 BT_MESSAGE_ITERATOR_STATE_ENDED
,
36 /* Iterator is currently being finalized */
37 BT_MESSAGE_ITERATOR_STATE_FINALIZING
,
39 /* Iterator is finalized */
40 BT_MESSAGE_ITERATOR_STATE_FINALIZED
,
42 /* Iterator is seeking */
43 BT_MESSAGE_ITERATOR_STATE_SEEKING
,
45 /* Iterator did seek, but returned `BT_MESSAGE_ITERATOR_STATUS_AGAIN` */
46 BT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_AGAIN
,
48 /* Iterator did seek, but returned error status */
49 BT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_ERROR
,
52 typedef enum bt_message_iterator_class_next_method_status
53 (*bt_message_iterator_next_method
)(
54 void *, bt_message_array_const
, uint64_t, uint64_t *);
56 typedef enum bt_message_iterator_class_seek_ns_from_origin_method_status
57 (*bt_message_iterator_seek_ns_from_origin_method
)(
60 typedef enum bt_message_iterator_class_seek_beginning_method_status
61 (*bt_message_iterator_seek_beginning_method
)(
64 typedef enum bt_message_iterator_class_can_seek_ns_from_origin_method_status
65 (*bt_message_iterator_can_seek_ns_from_origin_method
)(
66 void *, int64_t, bt_bool
*);
68 typedef enum bt_message_iterator_class_can_seek_beginning_method_status
69 (*bt_message_iterator_can_seek_beginning_method
)(
72 struct bt_self_message_iterator_configuration
{
74 bool can_seek_forward
;
77 struct bt_message_iterator
{
78 struct bt_object base
;
80 struct bt_component
*upstream_component
; /* Weak */
81 struct bt_port
*upstream_port
; /* Weak */
82 struct bt_connection
*connection
; /* Weak */
83 struct bt_graph
*graph
; /* Weak */
84 struct bt_self_message_iterator_configuration config
;
88 * `struct bt_message_iterator *`
91 * This is an array of upstream message iterators on which this
92 * iterator depends. The references are weak: an upstream
93 * message iterator is responsible for removing its entry within
94 * this array on finalization/destruction.
96 GPtrArray
*upstream_msg_iters
;
99 * Downstream message iterator which depends on this message
102 * This can be `NULL` if this message iterator's owner is a sink
105 struct bt_message_iterator
*downstream_msg_iter
;
108 bt_message_iterator_next_method next
;
110 /* These two are always both set or both unset. */
111 bt_message_iterator_seek_ns_from_origin_method seek_ns_from_origin
;
112 bt_message_iterator_can_seek_ns_from_origin_method can_seek_ns_from_origin
;
114 /* These two are always both set or both unset. */
115 bt_message_iterator_seek_beginning_method seek_beginning
;
116 bt_message_iterator_can_seek_beginning_method can_seek_beginning
;
119 enum bt_message_iterator_state state
;
122 * Timestamp of the last received message (or INT64_MIN in the
123 * beginning, or after a seek to beginning).
125 int64_t last_ns_from_origin
;
129 /* We haven't recorded clock properties yet. */
130 CLOCK_EXPECTATION_UNSET
,
132 /* Expect to have no clock. */
133 CLOCK_EXPECTATION_NONE
,
135 /* Clock with origin_is_unix_epoch true.*/
136 CLOCK_EXPECTATION_ORIGIN_UNIX
,
138 /* Clock with origin_is_unix_epoch false, with a UUID.*/
139 CLOCK_EXPECTATION_ORIGIN_OTHER_UUID
,
141 /* Clock with origin_is_unix_epoch false, without a UUID.*/
142 CLOCK_EXPECTATION_ORIGIN_OTHER_NO_UUID
,
146 * Expected UUID of the clock, if `type`is CLOCK_EXPECTATION_ORIGIN_OTHER_UUID.
148 * If the clock's origin is the unix epoch, the UUID is
149 * irrelevant (as the clock will be correlatable with other
150 * clocks having the same origin).
155 BT_IF_DEV_MODE(GHashTable
*per_stream_state
);
158 * Data necessary for auto seek (the seek-to-beginning then fast-forward
163 * Queue of `const bt_message *` (owned by this queue).
165 * When fast-forwarding, we get the messages from upstream in
166 * batches. Once we have found the first message with timestamp
167 * greater or equal to the seek time, we put it and all of the
168 * following message of the batch in this queue. They will be
169 * sent on the next "next" call on this iterator.
171 * The messages are in chronological order (i.e. the first to
172 * send is the first of the queue).
177 * After auto-seeking, we replace the iterator's `next` callback
178 * with our own, which returns the contents of the `msgs` queue.
179 * This field is where we save the original callback, so we can
182 void *original_next_callback
;
188 void bt_message_iterator_try_finalize(
189 struct bt_message_iterator
*iterator
);
191 void bt_message_iterator_set_connection(
192 struct bt_message_iterator
*iterator
,
193 struct bt_connection
*connection
);
196 const char *bt_message_iterator_state_string(
197 enum bt_message_iterator_state state
)
200 case BT_MESSAGE_ITERATOR_STATE_ACTIVE
:
202 case BT_MESSAGE_ITERATOR_STATE_ENDED
:
204 case BT_MESSAGE_ITERATOR_STATE_FINALIZING
:
206 case BT_MESSAGE_ITERATOR_STATE_FINALIZED
:
208 case BT_MESSAGE_ITERATOR_STATE_SEEKING
:
210 case BT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_AGAIN
:
211 return "LAST_SEEKING_RETURNED_AGAIN";
212 case BT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_ERROR
:
213 return "LAST_SEEKING_RETURNED_ERROR";
219 #endif /* BABELTRACE_GRAPH_MESSAGE_ITERATOR_INTERNAL_H */