Move to kernel style SPDX license identifiers
[babeltrace.git] / src / lib / graph / message / iterator.h
CommitLineData
d6e69534 1/*
0235b0db
MJ
2 * SPDX-License-Identifier: MIT
3 *
d6e69534
PP
4 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
5 * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
d6e69534
PP
6 */
7
0235b0db
MJ
8#ifndef BABELTRACE_GRAPH_MESSAGE_ITERATOR_INTERNAL_H
9#define BABELTRACE_GRAPH_MESSAGE_ITERATOR_INTERNAL_H
10
91d81473 11#include "common/macros.h"
578e048b 12#include "lib/object.h"
43c59509
PP
13#include <babeltrace2/graph/connection.h>
14#include <babeltrace2/graph/message.h>
3fadfbc0 15#include <babeltrace2/types.h>
578e048b 16#include "common/assert.h"
d6e69534 17#include <stdbool.h>
6162e6b7 18#include "common/uuid.h"
d6e69534
PP
19
20struct bt_port;
21struct bt_graph;
22
9a2c8b8e 23enum bt_message_iterator_state {
7474e7d3 24 /* Iterator is not initialized */
9a2c8b8e 25 BT_MESSAGE_ITERATOR_STATE_NON_INITIALIZED,
d6e69534 26
7474e7d3 27 /* Iterator is active, not at the end yet, and not finalized */
9a2c8b8e 28 BT_MESSAGE_ITERATOR_STATE_ACTIVE,
d6e69534
PP
29
30 /*
31 * Iterator is ended, not finalized yet: the "next" method
32 * returns BT_MESSAGE_ITERATOR_STATUS_END.
33 */
9a2c8b8e 34 BT_MESSAGE_ITERATOR_STATE_ENDED,
d6e69534 35
7474e7d3 36 /* Iterator is currently being finalized */
9a2c8b8e 37 BT_MESSAGE_ITERATOR_STATE_FINALIZING,
d6e69534 38
7474e7d3 39 /* Iterator is finalized */
9a2c8b8e 40 BT_MESSAGE_ITERATOR_STATE_FINALIZED,
7474e7d3
PP
41
42 /* Iterator is seeking */
9a2c8b8e 43 BT_MESSAGE_ITERATOR_STATE_SEEKING,
7474e7d3
PP
44
45 /* Iterator did seek, but returned `BT_MESSAGE_ITERATOR_STATUS_AGAIN` */
9a2c8b8e 46 BT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_AGAIN,
7474e7d3
PP
47
48 /* Iterator did seek, but returned error status */
9a2c8b8e 49 BT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_ERROR,
d6e69534
PP
50};
51
a3f0c7db 52typedef enum bt_message_iterator_class_next_method_status
9a2c8b8e 53(*bt_message_iterator_next_method)(
7474e7d3
PP
54 void *, bt_message_array_const, uint64_t, uint64_t *);
55
a3f0c7db 56typedef enum bt_message_iterator_class_seek_ns_from_origin_method_status
9a2c8b8e 57(*bt_message_iterator_seek_ns_from_origin_method)(
7474e7d3
PP
58 void *, int64_t);
59
a3f0c7db 60typedef enum bt_message_iterator_class_seek_beginning_method_status
9a2c8b8e 61(*bt_message_iterator_seek_beginning_method)(
7474e7d3
PP
62 void *);
63
a3f0c7db 64typedef enum bt_message_iterator_class_can_seek_ns_from_origin_method_status
9a2c8b8e 65(*bt_message_iterator_can_seek_ns_from_origin_method)(
f2fb1b32 66 void *, int64_t, bt_bool *);
7474e7d3 67
a3f0c7db 68typedef enum bt_message_iterator_class_can_seek_beginning_method_status
9a2c8b8e 69(*bt_message_iterator_can_seek_beginning_method)(
f2fb1b32 70 void *, bt_bool *);
7474e7d3 71
8d8b141d
SM
72struct bt_self_message_iterator_configuration {
73 bool frozen;
74 bool can_seek_forward;
75};
76
9a2c8b8e 77struct bt_message_iterator {
6c373cc9
PP
78 struct bt_object base;
79 GPtrArray *msgs;
d6e69534
PP
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 */
8d8b141d 84 struct bt_self_message_iterator_configuration config;
d6e69534 85
ca02df0a
PP
86 /*
87 * Array of
9a2c8b8e 88 * `struct bt_message_iterator *`
ca02df0a
PP
89 * (weak).
90 *
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.
95 */
96 GPtrArray *upstream_msg_iters;
97
98 /*
99 * Downstream message iterator which depends on this message
100 * iterator (weak).
101 *
102 * This can be `NULL` if this message iterator's owner is a sink
103 * component.
104 */
9a2c8b8e 105 struct bt_message_iterator *downstream_msg_iter;
ca02df0a 106
7474e7d3 107 struct {
9a2c8b8e 108 bt_message_iterator_next_method next;
2e1b5615
SM
109
110 /* These two are always both set or both unset. */
9a2c8b8e
PP
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;
2e1b5615
SM
113
114 /* These two are always both set or both unset. */
9a2c8b8e
PP
115 bt_message_iterator_seek_beginning_method seek_beginning;
116 bt_message_iterator_can_seek_beginning_method can_seek_beginning;
7474e7d3 117 } methods;
d6e69534 118
9a2c8b8e 119 enum bt_message_iterator_state state;
da9c4c52 120
54b135a0
SM
121 /*
122 * Timestamp of the last received message (or INT64_MIN in the
123 * beginning, or after a seek to beginning).
124 */
125 int64_t last_ns_from_origin;
126
127 struct {
128 enum {
129 /* We haven't recorded clock properties yet. */
130 CLOCK_EXPECTATION_UNSET,
131
132 /* Expect to have no clock. */
133 CLOCK_EXPECTATION_NONE,
134
135 /* Clock with origin_is_unix_epoch true.*/
136 CLOCK_EXPECTATION_ORIGIN_UNIX,
137
138 /* Clock with origin_is_unix_epoch false, with a UUID.*/
139 CLOCK_EXPECTATION_ORIGIN_OTHER_UUID,
140
141 /* Clock with origin_is_unix_epoch false, without a UUID.*/
142 CLOCK_EXPECTATION_ORIGIN_OTHER_NO_UUID,
143 } type;
144
145 /*
146 * Expected UUID of the clock, if `type`is CLOCK_EXPECTATION_ORIGIN_OTHER_UUID.
147 *
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).
151 */
6162e6b7 152 bt_uuid_t uuid;
54b135a0
SM
153 } clock_expectation;
154
da9c4c52
SM
155 /*
156 * Data necessary for auto seek (the seek-to-beginning then fast-forward
157 * seek strategy).
158 */
159 struct {
160 /*
161 * Queue of `const bt_message *` (owned by this queue).
162 *
163 * When fast-forwarding, we get the messages from upstream in
164 * batches. Once we have found the first message with timestamp
165 * greater or equal to the seek time, we put it and all of the
166 * following message of the batch in this queue. They will be
167 * sent on the next "next" call on this iterator.
168 *
169 * The messages are in chronological order (i.e. the first to
170 * send is the first of the queue).
171 */
172 GQueue *msgs;
572075a8
SM
173
174 /*
175 * After auto-seeking, we replace the iterator's `next` callback
176 * with our own, which returns the contents of the `msgs` queue.
177 * This field is where we save the original callback, so we can
178 * restore it.
179 */
180 void *original_next_callback;
da9c4c52
SM
181 } auto_seek;
182
d6e69534
PP
183 void *user_data;
184};
185
d6e69534 186BT_HIDDEN
9a2c8b8e
PP
187void bt_message_iterator_try_finalize(
188 struct bt_message_iterator *iterator);
d6e69534
PP
189
190BT_HIDDEN
9a2c8b8e
PP
191void bt_message_iterator_set_connection(
192 struct bt_message_iterator *iterator,
d6e69534
PP
193 struct bt_connection *connection);
194
d6e69534 195static inline
9a2c8b8e
PP
196const char *bt_message_iterator_state_string(
197 enum bt_message_iterator_state state)
d6e69534
PP
198{
199 switch (state) {
9a2c8b8e 200 case BT_MESSAGE_ITERATOR_STATE_ACTIVE:
8a432889 201 return "ACTIVE";
9a2c8b8e 202 case BT_MESSAGE_ITERATOR_STATE_ENDED:
8a432889 203 return "ENDED";
9a2c8b8e 204 case BT_MESSAGE_ITERATOR_STATE_FINALIZING:
8a432889 205 return "FINALIZING";
9a2c8b8e 206 case BT_MESSAGE_ITERATOR_STATE_FINALIZED:
8a432889 207 return "FINALIZED";
9a2c8b8e 208 case BT_MESSAGE_ITERATOR_STATE_SEEKING:
8a432889 209 return "SEEKING";
9a2c8b8e 210 case BT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_AGAIN:
8a432889 211 return "LAST_SEEKING_RETURNED_AGAIN";
9a2c8b8e 212 case BT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_ERROR:
8a432889 213 return "LAST_SEEKING_RETURNED_ERROR";
d6e69534
PP
214 default:
215 return "(unknown)";
216 }
217};
218
219#endif /* BABELTRACE_GRAPH_MESSAGE_ITERATOR_INTERNAL_H */
This page took 0.072323 seconds and 4 git commands to generate.