Commit | Line | Data |
---|---|---|
47e5a032 | 1 | /* |
f2b0325d | 2 | * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com> |
47e5a032 | 3 | * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
47e5a032 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 | ||
b03487ab | 24 | #define BT_LOG_TAG "LIB/MSG-ITER" |
1633ef46 | 25 | #include "lib/logging.h" |
5af447e5 | 26 | |
57952005 | 27 | #include "compat/compiler.h" |
c3df794d | 28 | #include "compat/glib.h" |
57952005 MJ |
29 | #include "lib/trace-ir/clock-class.h" |
30 | #include "lib/trace-ir/clock-snapshot.h" | |
71c5da58 MJ |
31 | #include <babeltrace2/trace-ir/field.h> |
32 | #include <babeltrace2/trace-ir/event-const.h> | |
57952005 | 33 | #include "lib/trace-ir/event.h" |
71c5da58 | 34 | #include <babeltrace2/trace-ir/packet-const.h> |
57952005 MJ |
35 | #include "lib/trace-ir/packet.h" |
36 | #include "lib/trace-ir/stream.h" | |
fb25b9e3 PP |
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> | |
71c5da58 | 40 | #include <babeltrace2/graph/connection-const.h> |
71c5da58 | 41 | #include <babeltrace2/graph/component-const.h> |
71c5da58 | 42 | #include <babeltrace2/graph/component-sink-const.h> |
71c5da58 | 43 | #include <babeltrace2/graph/message-const.h> |
fb25b9e3 | 44 | #include <babeltrace2/graph/message-iterator.h> |
71c5da58 | 45 | #include <babeltrace2/graph/self-component-port-input-message-iterator.h> |
71c5da58 | 46 | #include <babeltrace2/graph/message-event-const.h> |
143feff5 SM |
47 | #include <babeltrace2/graph/message-message-iterator-inactivity-const.h> |
48 | #include <babeltrace2/graph/message-packet-beginning.h> | |
71c5da58 MJ |
49 | #include <babeltrace2/graph/message-packet-beginning-const.h> |
50 | #include <babeltrace2/graph/message-packet-end-const.h> | |
143feff5 | 51 | #include <babeltrace2/graph/message-stream-beginning.h> |
71c5da58 MJ |
52 | #include <babeltrace2/graph/message-stream-beginning-const.h> |
53 | #include <babeltrace2/graph/message-stream-end-const.h> | |
71c5da58 MJ |
54 | #include <babeltrace2/graph/port-const.h> |
55 | #include <babeltrace2/graph/graph.h> | |
56 | #include <babeltrace2/graph/graph-const.h> | |
71c5da58 | 57 | #include <babeltrace2/types.h> |
57952005 MJ |
58 | #include "common/assert.h" |
59 | #include "lib/assert-pre.h" | |
3b7d3ccc | 60 | #include "lib/assert-post.h" |
fa054faf | 61 | #include <stdint.h> |
b04a393b | 62 | #include <inttypes.h> |
0fbb9a9f | 63 | #include <stdlib.h> |
3230ee6b | 64 | |
57952005 MJ |
65 | #include "component-class.h" |
66 | #include "component-class-sink-colander.h" | |
67 | #include "component.h" | |
68 | #include "component-sink.h" | |
69 | #include "component-source.h" | |
70 | #include "connection.h" | |
71 | #include "graph.h" | |
72 | #include "message/discarded-items.h" | |
73 | #include "message/event.h" | |
74 | #include "message/iterator.h" | |
75 | #include "message/message.h" | |
76 | #include "message/message-iterator-inactivity.h" | |
77 | #include "message/stream.h" | |
78 | #include "message/packet.h" | |
fb25b9e3 | 79 | #include "lib/func-status.h" |
57952005 | 80 | |
3fd7b79d PP |
81 | /* |
82 | * TODO: Use graph's state (number of active iterators, etc.) and | |
83 | * possibly system specifications to make a better guess than this. | |
84 | */ | |
b09a5592 | 85 | #define MSG_BATCH_SIZE 15 |
3fd7b79d | 86 | |
15a52f66 PP |
87 | #define BT_ASSERT_PRE_ITER_HAS_STATE_TO_SEEK(_iter) \ |
88 | BT_ASSERT_PRE((_iter)->state == BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE || \ | |
89 | (_iter)->state == BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ENDED || \ | |
90 | (_iter)->state == BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_AGAIN || \ | |
91 | (_iter)->state == BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_ERROR, \ | |
92 | "Message iterator is in the wrong state: %!+i", _iter) | |
47e5a032 | 93 | |
904860cb | 94 | static inline |
1d55aa9a | 95 | void set_self_comp_port_input_msg_iterator_state( |
904860cb PP |
96 | struct bt_self_component_port_input_message_iterator *iterator, |
97 | enum bt_self_component_port_input_message_iterator_state state) | |
98 | { | |
99 | BT_ASSERT(iterator); | |
15a52f66 | 100 | BT_LIB_LOGD("Updating message iterator's state: new-state=%s", |
904860cb PP |
101 | bt_self_component_port_input_message_iterator_state_string(state)); |
102 | iterator->state = state; | |
103 | } | |
104 | ||
47e5a032 | 105 | static |
b09a5592 | 106 | void bt_self_component_port_input_message_iterator_destroy(struct bt_object *obj) |
47e5a032 | 107 | { |
b09a5592 | 108 | struct bt_self_component_port_input_message_iterator *iterator; |
8738a040 | 109 | |
8b45963b | 110 | BT_ASSERT(obj); |
d3eb6e8f | 111 | |
bd14d768 | 112 | /* |
b09a5592 | 113 | * The message iterator's reference count is 0 if we're |
bd14d768 PP |
114 | * here. Increment it to avoid a double-destroy (possibly |
115 | * infinitely recursive). This could happen for example if the | |
b09a5592 | 116 | * message iterator's finalization function does |
834e9996 PP |
117 | * bt_object_get_ref() (or anything that causes |
118 | * bt_object_get_ref() to be called) on itself (ref. count goes | |
119 | * from 0 to 1), and then bt_object_put_ref(): the reference | |
120 | * count would go from 1 to 0 again and this function would be | |
121 | * called again. | |
bd14d768 | 122 | */ |
1d7bf349 | 123 | obj->ref_count++; |
94a96686 | 124 | iterator = (void *) obj; |
a684a357 | 125 | BT_LIB_LOGI("Destroying self component input port message iterator object: " |
834e9996 | 126 | "%!+i", iterator); |
904860cb | 127 | bt_self_component_port_input_message_iterator_try_finalize(iterator); |
d3eb6e8f | 128 | |
bd14d768 PP |
129 | if (iterator->connection) { |
130 | /* | |
131 | * Remove ourself from the originating connection so | |
132 | * that it does not try to finalize a dangling pointer | |
133 | * later. | |
134 | */ | |
135 | bt_connection_remove_iterator(iterator->connection, iterator); | |
834e9996 | 136 | iterator->connection = NULL; |
bd14d768 PP |
137 | } |
138 | ||
1b3630b6 SM |
139 | if (iterator->auto_seek.msgs) { |
140 | while (!g_queue_is_empty(iterator->auto_seek.msgs)) { | |
3d902f17 | 141 | bt_object_put_no_null_check( |
1b3630b6 | 142 | g_queue_pop_tail(iterator->auto_seek.msgs)); |
15a52f66 PP |
143 | } |
144 | ||
1b3630b6 SM |
145 | g_queue_free(iterator->auto_seek.msgs); |
146 | iterator->auto_seek.msgs = NULL; | |
15a52f66 PP |
147 | } |
148 | ||
692f1a01 PP |
149 | if (iterator->upstream_msg_iters) { |
150 | /* | |
151 | * At this point the message iterator is finalized, so | |
152 | * it's detached from any upstream message iterator. | |
153 | */ | |
154 | BT_ASSERT(iterator->upstream_msg_iters->len == 0); | |
155 | g_ptr_array_free(iterator->upstream_msg_iters, TRUE); | |
156 | iterator->upstream_msg_iters = NULL; | |
157 | } | |
158 | ||
fac7b25a PP |
159 | if (iterator->msgs) { |
160 | g_ptr_array_free(iterator->msgs, TRUE); | |
161 | iterator->msgs = NULL; | |
162 | } | |
163 | ||
164 | g_free(iterator); | |
47e5a032 JG |
165 | } |
166 | ||
bd14d768 | 167 | BT_HIDDEN |
904860cb | 168 | void bt_self_component_port_input_message_iterator_try_finalize( |
b09a5592 | 169 | struct bt_self_component_port_input_message_iterator *iterator) |
bd14d768 | 170 | { |
692f1a01 | 171 | uint64_t i; |
834e9996 PP |
172 | typedef void (*method_t)(void *); |
173 | ||
bd14d768 | 174 | struct bt_component_class *comp_class = NULL; |
834e9996 | 175 | method_t method = NULL; |
bd14d768 | 176 | |
8b45963b | 177 | BT_ASSERT(iterator); |
bd14d768 PP |
178 | |
179 | switch (iterator->state) { | |
b09a5592 | 180 | case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_NON_INITIALIZED: |
dba1e5d8 | 181 | /* Skip user finalization if user initialization failed */ |
b09a5592 | 182 | BT_LIB_LOGD("Not finalizing non-initialized message iterator: " |
834e9996 | 183 | "%!+i", iterator); |
904860cb | 184 | goto end; |
b09a5592 | 185 | case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZED: |
bd14d768 | 186 | /* Already finalized */ |
b09a5592 | 187 | BT_LIB_LOGD("Not finalizing message iterator: already finalized: " |
834e9996 | 188 | "%!+i", iterator); |
904860cb PP |
189 | goto end; |
190 | case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZING: | |
a8f90e5d | 191 | /* Finalizing */ |
904860cb PP |
192 | BT_LIB_LOGF("Message iterator is already being finalized: " |
193 | "%!+i", iterator); | |
194 | abort(); | |
bd14d768 PP |
195 | default: |
196 | break; | |
197 | } | |
198 | ||
b09a5592 | 199 | BT_LIB_LOGD("Finalizing message iterator: %!+i", iterator); |
904860cb PP |
200 | set_self_comp_port_input_msg_iterator_state(iterator, |
201 | BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZING); | |
8b45963b | 202 | BT_ASSERT(iterator->upstream_component); |
bd14d768 PP |
203 | comp_class = iterator->upstream_component->class; |
204 | ||
205 | /* Call user-defined destroy method */ | |
206 | switch (comp_class->type) { | |
207 | case BT_COMPONENT_CLASS_TYPE_SOURCE: | |
208 | { | |
834e9996 PP |
209 | struct bt_component_class_source *src_comp_cls = |
210 | (void *) comp_class; | |
bd14d768 | 211 | |
b09a5592 | 212 | method = (method_t) src_comp_cls->methods.msg_iter_finalize; |
bd14d768 PP |
213 | break; |
214 | } | |
215 | case BT_COMPONENT_CLASS_TYPE_FILTER: | |
216 | { | |
834e9996 PP |
217 | struct bt_component_class_filter *flt_comp_cls = |
218 | (void *) comp_class; | |
bd14d768 | 219 | |
b09a5592 | 220 | method = (method_t) flt_comp_cls->methods.msg_iter_finalize; |
bd14d768 PP |
221 | break; |
222 | } | |
223 | default: | |
224 | /* Unreachable */ | |
0fbb9a9f | 225 | abort(); |
bd14d768 PP |
226 | } |
227 | ||
834e9996 PP |
228 | if (method) { |
229 | BT_LIB_LOGD("Calling user's finalization method: %!+i", | |
5af447e5 | 230 | iterator); |
834e9996 | 231 | method(iterator); |
bd14d768 PP |
232 | } |
233 | ||
692f1a01 PP |
234 | /* Detach upstream message iterators */ |
235 | for (i = 0; i < iterator->upstream_msg_iters->len; i++) { | |
236 | struct bt_self_component_port_input_message_iterator *upstream_msg_iter = | |
237 | iterator->upstream_msg_iters->pdata[i]; | |
238 | ||
239 | upstream_msg_iter->downstream_msg_iter = NULL; | |
240 | } | |
241 | ||
242 | g_ptr_array_set_size(iterator->upstream_msg_iters, 0); | |
243 | ||
244 | /* Detach downstream message iterator */ | |
245 | if (iterator->downstream_msg_iter) { | |
246 | gboolean existed; | |
247 | ||
248 | BT_ASSERT(iterator->downstream_msg_iter->upstream_msg_iters); | |
249 | existed = g_ptr_array_remove_fast( | |
250 | iterator->downstream_msg_iter->upstream_msg_iters, | |
251 | iterator); | |
252 | BT_ASSERT(existed); | |
253 | } | |
254 | ||
bd14d768 PP |
255 | iterator->upstream_component = NULL; |
256 | iterator->upstream_port = NULL; | |
904860cb PP |
257 | set_self_comp_port_input_msg_iterator_state(iterator, |
258 | BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZED); | |
b09a5592 | 259 | BT_LIB_LOGD("Finalized message iterator: %!+i", iterator); |
904860cb PP |
260 | |
261 | end: | |
262 | return; | |
bd14d768 PP |
263 | } |
264 | ||
265 | BT_HIDDEN | |
b09a5592 PP |
266 | void bt_self_component_port_input_message_iterator_set_connection( |
267 | struct bt_self_component_port_input_message_iterator *iterator, | |
bd14d768 PP |
268 | struct bt_connection *connection) |
269 | { | |
8b45963b | 270 | BT_ASSERT(iterator); |
bd14d768 | 271 | iterator->connection = connection; |
a684a357 | 272 | BT_LIB_LOGI("Set message iterator's connection: " |
834e9996 | 273 | "%![iter-]+i, %![conn-]+x", iterator, connection); |
bd14d768 PP |
274 | } |
275 | ||
15a52f66 PP |
276 | static |
277 | bt_bool can_seek_ns_from_origin_true( | |
278 | struct bt_self_component_port_input_message_iterator *iterator, | |
279 | int64_t ns_from_origin) | |
280 | { | |
281 | return BT_TRUE; | |
282 | } | |
283 | ||
284 | static | |
285 | bt_bool can_seek_beginning_true( | |
286 | struct bt_self_component_port_input_message_iterator *iterator) | |
287 | { | |
288 | return BT_TRUE; | |
289 | } | |
290 | ||
834e9996 | 291 | static |
b09a5592 | 292 | struct bt_self_component_port_input_message_iterator * |
692f1a01 PP |
293 | create_self_component_input_port_message_iterator( |
294 | struct bt_self_message_iterator *self_downstream_msg_iter, | |
295 | struct bt_self_component_port_input *self_port) | |
47e5a032 | 296 | { |
692f1a01 PP |
297 | typedef enum bt_component_class_message_iterator_init_method_status (*init_method_t)( |
298 | void *, void *, void *); | |
299 | ||
692f1a01 PP |
300 | init_method_t init_method = NULL; |
301 | struct bt_self_component_port_input_message_iterator *iterator = | |
302 | NULL; | |
303 | struct bt_self_component_port_input_message_iterator *downstream_msg_iter = | |
304 | (void *) self_downstream_msg_iter; | |
305 | struct bt_port *port = (void *) self_port; | |
306 | struct bt_port *upstream_port; | |
307 | struct bt_component *comp; | |
308 | struct bt_component *upstream_comp; | |
309 | struct bt_component_class *upstream_comp_cls; | |
47e5a032 | 310 | |
692f1a01 PP |
311 | BT_ASSERT_PRE_NON_NULL(port, "Input port"); |
312 | comp = bt_port_borrow_component_inline(port); | |
313 | BT_ASSERT_PRE(bt_port_is_connected(port), | |
314 | "Input port is not connected: %![port-]+p", port); | |
315 | BT_ASSERT_PRE(comp, "Input port is not part of a component: %![port-]+p", | |
316 | port); | |
692f1a01 PP |
317 | BT_ASSERT(port->connection); |
318 | upstream_port = port->connection->upstream_port; | |
8b45963b | 319 | BT_ASSERT(upstream_port); |
692f1a01 PP |
320 | upstream_comp = bt_port_borrow_component_inline(upstream_port); |
321 | BT_ASSERT(upstream_comp); | |
322 | BT_ASSERT_PRE( | |
d73bb381 PP |
323 | bt_component_borrow_graph(upstream_comp)->config_state == |
324 | BT_GRAPH_CONFIGURATION_STATE_PARTIALLY_CONFIGURED || | |
325 | bt_component_borrow_graph(upstream_comp)->config_state == | |
326 | BT_GRAPH_CONFIGURATION_STATE_CONFIGURED, | |
692f1a01 PP |
327 | "Graph is not configured: %!+g", |
328 | bt_component_borrow_graph(upstream_comp)); | |
329 | upstream_comp_cls = upstream_comp->class; | |
330 | BT_ASSERT(upstream_comp->class->type == | |
834e9996 | 331 | BT_COMPONENT_CLASS_TYPE_SOURCE || |
692f1a01 | 332 | upstream_comp->class->type == |
834e9996 | 333 | BT_COMPONENT_CLASS_TYPE_FILTER); |
692f1a01 PP |
334 | BT_LIB_LOGI("Creating message iterator on self component input port: " |
335 | "%![up-comp-]+c, %![up-port-]+p", upstream_comp, upstream_port); | |
834e9996 | 336 | iterator = g_new0( |
b09a5592 | 337 | struct bt_self_component_port_input_message_iterator, 1); |
47e5a032 | 338 | if (!iterator) { |
a8f90e5d PP |
339 | BT_LIB_LOGE_APPEND_CAUSE( |
340 | "Failed to allocate one self component input port " | |
b09a5592 | 341 | "message iterator."); |
a8f90e5d | 342 | goto error; |
47e5a032 JG |
343 | } |
344 | ||
fac7b25a | 345 | bt_object_init_shared(&iterator->base, |
b09a5592 | 346 | bt_self_component_port_input_message_iterator_destroy); |
fac7b25a PP |
347 | iterator->msgs = g_ptr_array_new(); |
348 | if (!iterator->msgs) { | |
349 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray."); | |
a8f90e5d | 350 | goto error; |
3fd7b79d | 351 | } |
3230ee6b | 352 | |
fac7b25a | 353 | g_ptr_array_set_size(iterator->msgs, MSG_BATCH_SIZE); |
e253ad8d | 354 | iterator->last_ns_from_origin = INT64_MIN; |
1b3630b6 SM |
355 | iterator->auto_seek.msgs = g_queue_new(); |
356 | if (!iterator->auto_seek.msgs) { | |
a8f90e5d | 357 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GQueue."); |
692f1a01 PP |
358 | goto error; |
359 | } | |
360 | ||
361 | iterator->upstream_msg_iters = g_ptr_array_new(); | |
362 | if (!iterator->upstream_msg_iters) { | |
363 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray."); | |
364 | goto error; | |
3230ee6b PP |
365 | } |
366 | ||
bd14d768 PP |
367 | iterator->upstream_component = upstream_comp; |
368 | iterator->upstream_port = upstream_port; | |
834e9996 | 369 | iterator->connection = iterator->upstream_port->connection; |
f7c3ac09 | 370 | iterator->graph = bt_component_borrow_graph(upstream_comp); |
904860cb PP |
371 | set_self_comp_port_input_msg_iterator_state(iterator, |
372 | BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_NON_INITIALIZED); | |
15a52f66 PP |
373 | |
374 | switch (iterator->upstream_component->class->type) { | |
375 | case BT_COMPONENT_CLASS_TYPE_SOURCE: | |
376 | { | |
377 | struct bt_component_class_source *src_comp_cls = | |
378 | (void *) iterator->upstream_component->class; | |
379 | ||
380 | iterator->methods.next = | |
381 | (bt_self_component_port_input_message_iterator_next_method) | |
382 | src_comp_cls->methods.msg_iter_next; | |
383 | iterator->methods.seek_ns_from_origin = | |
384 | (bt_self_component_port_input_message_iterator_seek_ns_from_origin_method) | |
385 | src_comp_cls->methods.msg_iter_seek_ns_from_origin; | |
386 | iterator->methods.seek_beginning = | |
387 | (bt_self_component_port_input_message_iterator_seek_beginning_method) | |
388 | src_comp_cls->methods.msg_iter_seek_beginning; | |
389 | iterator->methods.can_seek_ns_from_origin = | |
390 | (bt_self_component_port_input_message_iterator_can_seek_ns_from_origin_method) | |
391 | src_comp_cls->methods.msg_iter_can_seek_ns_from_origin; | |
392 | iterator->methods.can_seek_beginning = | |
393 | (bt_self_component_port_input_message_iterator_can_seek_beginning_method) | |
394 | src_comp_cls->methods.msg_iter_can_seek_beginning; | |
395 | break; | |
396 | } | |
397 | case BT_COMPONENT_CLASS_TYPE_FILTER: | |
398 | { | |
399 | struct bt_component_class_filter *flt_comp_cls = | |
400 | (void *) iterator->upstream_component->class; | |
401 | ||
402 | iterator->methods.next = | |
403 | (bt_self_component_port_input_message_iterator_next_method) | |
404 | flt_comp_cls->methods.msg_iter_next; | |
405 | iterator->methods.seek_ns_from_origin = | |
406 | (bt_self_component_port_input_message_iterator_seek_ns_from_origin_method) | |
407 | flt_comp_cls->methods.msg_iter_seek_ns_from_origin; | |
408 | iterator->methods.seek_beginning = | |
409 | (bt_self_component_port_input_message_iterator_seek_beginning_method) | |
410 | flt_comp_cls->methods.msg_iter_seek_beginning; | |
411 | iterator->methods.can_seek_ns_from_origin = | |
412 | (bt_self_component_port_input_message_iterator_can_seek_ns_from_origin_method) | |
413 | flt_comp_cls->methods.msg_iter_can_seek_ns_from_origin; | |
414 | iterator->methods.can_seek_beginning = | |
415 | (bt_self_component_port_input_message_iterator_can_seek_beginning_method) | |
416 | flt_comp_cls->methods.msg_iter_can_seek_beginning; | |
417 | break; | |
418 | } | |
419 | default: | |
420 | abort(); | |
421 | } | |
422 | ||
423 | if (iterator->methods.seek_ns_from_origin && | |
424 | !iterator->methods.can_seek_ns_from_origin) { | |
425 | iterator->methods.can_seek_ns_from_origin = | |
426 | (bt_self_component_port_input_message_iterator_can_seek_ns_from_origin_method) | |
427 | can_seek_ns_from_origin_true; | |
428 | } | |
429 | ||
430 | if (iterator->methods.seek_beginning && | |
431 | !iterator->methods.can_seek_beginning) { | |
432 | iterator->methods.can_seek_beginning = | |
433 | (bt_self_component_port_input_message_iterator_seek_beginning_method) | |
434 | can_seek_beginning_true; | |
435 | } | |
436 | ||
834e9996 PP |
437 | switch (upstream_comp_cls->type) { |
438 | case BT_COMPONENT_CLASS_TYPE_SOURCE: | |
439 | { | |
440 | struct bt_component_class_source *src_comp_cls = | |
441 | (void *) upstream_comp_cls; | |
442 | ||
443 | init_method = | |
b09a5592 | 444 | (init_method_t) src_comp_cls->methods.msg_iter_init; |
834e9996 PP |
445 | break; |
446 | } | |
447 | case BT_COMPONENT_CLASS_TYPE_FILTER: | |
448 | { | |
449 | struct bt_component_class_filter *flt_comp_cls = | |
450 | (void *) upstream_comp_cls; | |
451 | ||
452 | init_method = | |
b09a5592 | 453 | (init_method_t) flt_comp_cls->methods.msg_iter_init; |
834e9996 PP |
454 | break; |
455 | } | |
456 | default: | |
457 | /* Unreachable */ | |
458 | abort(); | |
459 | } | |
460 | ||
461 | if (init_method) { | |
fb25b9e3 | 462 | enum bt_component_class_message_iterator_init_method_status iter_status; |
834e9996 PP |
463 | |
464 | BT_LIB_LOGD("Calling user's initialization method: %!+i", iterator); | |
465 | iter_status = init_method(iterator, upstream_comp, | |
466 | upstream_port); | |
467 | BT_LOGD("User method returned: status=%s", | |
fb25b9e3 PP |
468 | bt_common_func_status_string(iter_status)); |
469 | if (iter_status != BT_FUNC_STATUS_OK) { | |
a8f90e5d PP |
470 | BT_LIB_LOGW_APPEND_CAUSE( |
471 | "Component input port message iterator initialization method failed: " | |
472 | "%![iter-]+i, status=%s", | |
473 | iterator, | |
474 | bt_common_func_status_string(iter_status)); | |
475 | goto error; | |
834e9996 PP |
476 | } |
477 | } | |
478 | ||
692f1a01 PP |
479 | if (downstream_msg_iter) { |
480 | /* Set this message iterator's downstream message iterator */ | |
481 | iterator->downstream_msg_iter = downstream_msg_iter; | |
482 | ||
483 | /* | |
484 | * Add this message iterator to the downstream message | |
485 | * iterator's array of upstream message iterators. | |
486 | */ | |
487 | g_ptr_array_add(downstream_msg_iter->upstream_msg_iters, | |
488 | iterator); | |
489 | } | |
490 | ||
904860cb PP |
491 | set_self_comp_port_input_msg_iterator_state(iterator, |
492 | BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE); | |
834e9996 | 493 | g_ptr_array_add(port->connection->iterators, iterator); |
a684a357 | 494 | BT_LIB_LOGI("Created message iterator on self component input port: " |
834e9996 PP |
495 | "%![up-port-]+p, %![up-comp-]+c, %![iter-]+i", |
496 | upstream_port, upstream_comp, iterator); | |
a8f90e5d PP |
497 | goto end; |
498 | ||
499 | error: | |
500 | BT_OBJECT_PUT_REF_AND_RESET(iterator); | |
834e9996 PP |
501 | |
502 | end: | |
503 | return iterator; | |
ea8d3e58 JG |
504 | } |
505 | ||
692f1a01 PP |
506 | struct bt_self_component_port_input_message_iterator * |
507 | bt_self_component_port_input_message_iterator_create_from_message_iterator( | |
508 | struct bt_self_message_iterator *self_msg_iter, | |
509 | struct bt_self_component_port_input *input_port) | |
510 | { | |
511 | BT_ASSERT_PRE_NON_NULL(self_msg_iter, "Message iterator"); | |
512 | return create_self_component_input_port_message_iterator(self_msg_iter, | |
513 | input_port); | |
514 | } | |
515 | ||
516 | struct bt_self_component_port_input_message_iterator * | |
517 | bt_self_component_port_input_message_iterator_create_from_sink_component( | |
518 | struct bt_self_component_sink *self_comp, | |
519 | struct bt_self_component_port_input *input_port) | |
520 | { | |
521 | BT_ASSERT_PRE_NON_NULL(self_comp, "Sink component"); | |
522 | return create_self_component_input_port_message_iterator(NULL, | |
523 | input_port); | |
524 | } | |
525 | ||
b09a5592 PP |
526 | void *bt_self_message_iterator_get_data( |
527 | const struct bt_self_message_iterator *self_iterator) | |
ea8d3e58 | 528 | { |
b09a5592 | 529 | struct bt_self_component_port_input_message_iterator *iterator = |
834e9996 | 530 | (void *) self_iterator; |
ea8d3e58 | 531 | |
fa6cfec3 | 532 | BT_ASSERT_PRE_DEV_NON_NULL(iterator, "Message iterator"); |
834e9996 | 533 | return iterator->user_data; |
8738a040 | 534 | } |
413bc2c4 | 535 | |
b09a5592 PP |
536 | void bt_self_message_iterator_set_data( |
537 | struct bt_self_message_iterator *self_iterator, void *data) | |
f7c3ac09 | 538 | { |
b09a5592 | 539 | struct bt_self_component_port_input_message_iterator *iterator = |
834e9996 | 540 | (void *) self_iterator; |
f7c3ac09 | 541 | |
fa6cfec3 | 542 | BT_ASSERT_PRE_DEV_NON_NULL(iterator, "Message iterator"); |
834e9996 | 543 | iterator->user_data = data; |
a684a357 | 544 | BT_LIB_LOGD("Set message iterator's user data: " |
834e9996 | 545 | "%!+i, user-data-addr=%p", iterator, data); |
f7c3ac09 PP |
546 | } |
547 | ||
e253ad8d SM |
548 | /* |
549 | * Validate that the default clock snapshot in `msg` doesn't make us go back in | |
550 | * time. | |
551 | */ | |
552 | ||
fa6cfec3 | 553 | BT_ASSERT_POST_DEV_FUNC |
e253ad8d SM |
554 | static |
555 | bool clock_snapshots_are_monotonic_one( | |
556 | struct bt_self_component_port_input_message_iterator *iterator, | |
557 | const bt_message *msg) | |
558 | { | |
559 | const struct bt_clock_snapshot *clock_snapshot = NULL; | |
560 | bt_message_type message_type = bt_message_get_type(msg); | |
561 | int64_t ns_from_origin; | |
fb25b9e3 | 562 | enum bt_clock_snapshot_get_ns_from_origin_status clock_snapshot_status; |
e253ad8d SM |
563 | |
564 | /* | |
565 | * The default is true: if we can't figure out the clock snapshot | |
566 | * (or there is none), assume it is fine. | |
567 | */ | |
568 | bool result = true; | |
569 | ||
570 | switch (message_type) { | |
571 | case BT_MESSAGE_TYPE_EVENT: | |
572 | { | |
573 | struct bt_message_event *event_msg = (struct bt_message_event *) msg; | |
574 | clock_snapshot = event_msg->default_cs; | |
575 | break; | |
576 | } | |
577 | case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY: | |
578 | { | |
579 | struct bt_message_message_iterator_inactivity *inactivity_msg = | |
580 | (struct bt_message_message_iterator_inactivity *) msg; | |
581 | clock_snapshot = inactivity_msg->default_cs; | |
582 | break; | |
583 | } | |
584 | case BT_MESSAGE_TYPE_PACKET_BEGINNING: | |
585 | case BT_MESSAGE_TYPE_PACKET_END: | |
586 | { | |
587 | struct bt_message_packet *packet_msg = (struct bt_message_packet *) msg; | |
588 | clock_snapshot = packet_msg->default_cs; | |
589 | break; | |
590 | } | |
b7cbc799 SM |
591 | case BT_MESSAGE_TYPE_STREAM_BEGINNING: |
592 | case BT_MESSAGE_TYPE_STREAM_END: | |
e253ad8d | 593 | { |
b7cbc799 SM |
594 | struct bt_message_stream *stream_msg = (struct bt_message_stream *) msg; |
595 | if (stream_msg->default_cs_state != BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) { | |
596 | goto end; | |
e253ad8d | 597 | } |
b7cbc799 SM |
598 | |
599 | clock_snapshot = stream_msg->default_cs; | |
e253ad8d SM |
600 | break; |
601 | } | |
e253ad8d SM |
602 | case BT_MESSAGE_TYPE_DISCARDED_EVENTS: |
603 | case BT_MESSAGE_TYPE_DISCARDED_PACKETS: | |
604 | { | |
605 | struct bt_message_discarded_items *discarded_msg = | |
606 | (struct bt_message_discarded_items *) msg; | |
607 | ||
608 | clock_snapshot = discarded_msg->default_begin_cs; | |
609 | break; | |
610 | } | |
611 | } | |
612 | ||
613 | if (!clock_snapshot) { | |
614 | goto end; | |
615 | } | |
616 | ||
617 | clock_snapshot_status = bt_clock_snapshot_get_ns_from_origin(clock_snapshot, &ns_from_origin); | |
fb25b9e3 | 618 | if (clock_snapshot_status != BT_FUNC_STATUS_OK) { |
e253ad8d SM |
619 | goto end; |
620 | } | |
621 | ||
622 | result = ns_from_origin >= iterator->last_ns_from_origin; | |
623 | iterator->last_ns_from_origin = ns_from_origin; | |
624 | end: | |
625 | return result; | |
626 | } | |
627 | ||
fa6cfec3 | 628 | BT_ASSERT_POST_DEV_FUNC |
e253ad8d SM |
629 | static |
630 | bool clock_snapshots_are_monotonic( | |
631 | struct bt_self_component_port_input_message_iterator *iterator, | |
632 | bt_message_array_const msgs, uint64_t msg_count) | |
633 | { | |
634 | uint64_t i; | |
635 | bool result; | |
636 | ||
637 | for (i = 0; i < msg_count; i++) { | |
638 | if (!clock_snapshots_are_monotonic_one(iterator, msgs[i])) { | |
639 | result = false; | |
640 | goto end; | |
641 | } | |
642 | } | |
643 | ||
644 | result = true; | |
645 | ||
646 | end: | |
647 | return result; | |
648 | } | |
649 | ||
650 | /* | |
651 | * When a new stream begins, verify that the clock class tied to this | |
652 | * stream is compatible with what we've seen before. | |
653 | */ | |
654 | ||
fa6cfec3 | 655 | BT_ASSERT_POST_DEV_FUNC |
e253ad8d SM |
656 | static |
657 | bool clock_classes_are_compatible_one(struct bt_self_component_port_input_message_iterator *iterator, | |
658 | const struct bt_message *msg) | |
659 | { | |
660 | enum bt_message_type message_type = bt_message_get_type(msg); | |
661 | bool result; | |
662 | ||
663 | if (message_type == BT_MESSAGE_TYPE_STREAM_BEGINNING) { | |
664 | const struct bt_message_stream *stream_msg = (struct bt_message_stream *) msg; | |
665 | const struct bt_clock_class *clock_class = stream_msg->stream->class->default_clock_class; | |
666 | bt_uuid clock_class_uuid = NULL; | |
667 | ||
668 | if (clock_class) { | |
669 | clock_class_uuid = bt_clock_class_get_uuid(clock_class); | |
670 | } | |
671 | ||
672 | switch (iterator->clock_expectation.type) { | |
673 | case CLOCK_EXPECTATION_UNSET: | |
674 | /* | |
675 | * This is the first time we see a message with a clock | |
676 | * snapshot: record the properties of that clock, against | |
677 | * which we'll compare the clock properties of the following | |
678 | * messages. | |
679 | */ | |
680 | ||
681 | if (!clock_class) { | |
682 | iterator->clock_expectation.type = CLOCK_EXPECTATION_NONE; | |
683 | } else if (bt_clock_class_origin_is_unix_epoch(clock_class)) { | |
684 | iterator->clock_expectation.type = CLOCK_EXPECTATION_ORIGIN_UNIX; | |
685 | } else if (clock_class_uuid) { | |
686 | iterator->clock_expectation.type = CLOCK_EXPECTATION_ORIGIN_OTHER_UUID; | |
d126826c | 687 | bt_uuid_copy(iterator->clock_expectation.uuid, clock_class_uuid); |
e253ad8d SM |
688 | } else { |
689 | iterator->clock_expectation.type = CLOCK_EXPECTATION_ORIGIN_OTHER_NO_UUID; | |
690 | } | |
691 | break; | |
692 | ||
693 | case CLOCK_EXPECTATION_NONE: | |
694 | if (clock_class) { | |
fa6cfec3 PP |
695 | BT_ASSERT_POST_DEV_MSG( |
696 | "Expecting no clock class, got one: %![cc-]+K", | |
e253ad8d SM |
697 | clock_class); |
698 | result = false; | |
699 | goto end; | |
700 | } | |
701 | ||
702 | break; | |
703 | ||
704 | case CLOCK_EXPECTATION_ORIGIN_UNIX: | |
705 | if (!clock_class) { | |
fa6cfec3 PP |
706 | BT_ASSERT_POST_DEV_MSG( |
707 | "Expecting a clock class, got none."); | |
e253ad8d SM |
708 | result = false; |
709 | goto end; | |
710 | } | |
711 | ||
712 | if (!bt_clock_class_origin_is_unix_epoch(clock_class)) { | |
fa6cfec3 PP |
713 | BT_ASSERT_POST_DEV_MSG( |
714 | "Expecting a clock class with Unix epoch origin: %![cc-]+K", | |
e253ad8d SM |
715 | clock_class); |
716 | result = false; | |
717 | goto end; | |
718 | } | |
719 | break; | |
720 | ||
721 | case CLOCK_EXPECTATION_ORIGIN_OTHER_UUID: | |
722 | if (!clock_class) { | |
fa6cfec3 PP |
723 | BT_ASSERT_POST_DEV_MSG( |
724 | "Expecting a clock class, got none."); | |
e253ad8d SM |
725 | result = false; |
726 | goto end; | |
727 | } | |
728 | ||
729 | if (bt_clock_class_origin_is_unix_epoch(clock_class)) { | |
fa6cfec3 PP |
730 | BT_ASSERT_POST_DEV_MSG( |
731 | "Expecting a clock class without Unix epoch origin: %![cc-]+K", | |
e253ad8d SM |
732 | clock_class); |
733 | result = false; | |
734 | goto end; | |
735 | } | |
736 | ||
737 | if (!clock_class_uuid) { | |
fa6cfec3 PP |
738 | BT_ASSERT_POST_DEV_MSG( |
739 | "Expecting a clock class with UUID: %![cc-]+K", | |
e253ad8d SM |
740 | clock_class); |
741 | result = false; | |
742 | goto end; | |
743 | } | |
744 | ||
745 | if (bt_uuid_compare(iterator->clock_expectation.uuid, clock_class_uuid)) { | |
fa6cfec3 PP |
746 | BT_ASSERT_POST_DEV_MSG( |
747 | "Expecting a clock class with UUID, got one " | |
e253ad8d SM |
748 | "with a different UUID: %![cc-]+K, expected-uuid=%!u", |
749 | clock_class, iterator->clock_expectation.uuid); | |
750 | result = false; | |
751 | goto end; | |
752 | } | |
753 | break; | |
754 | ||
755 | case CLOCK_EXPECTATION_ORIGIN_OTHER_NO_UUID: | |
756 | if (!clock_class) { | |
fa6cfec3 PP |
757 | BT_ASSERT_POST_DEV_MSG( |
758 | "Expecting a clock class, got none."); | |
e253ad8d SM |
759 | result = false; |
760 | goto end; | |
761 | } | |
762 | ||
763 | if (bt_clock_class_origin_is_unix_epoch(clock_class)) { | |
fa6cfec3 PP |
764 | BT_ASSERT_POST_DEV_MSG( |
765 | "Expecting a clock class without Unix epoch origin: %![cc-]+K", | |
e253ad8d SM |
766 | clock_class); |
767 | result = false; | |
768 | goto end; | |
769 | } | |
770 | ||
771 | if (clock_class_uuid) { | |
fa6cfec3 PP |
772 | BT_ASSERT_POST_DEV_MSG( |
773 | "Expecting a clock class without UUID: %![cc-]+K", | |
e253ad8d SM |
774 | clock_class); |
775 | result = false; | |
776 | goto end; | |
777 | } | |
778 | break; | |
779 | } | |
780 | } | |
781 | ||
782 | result = true; | |
783 | ||
784 | end: | |
785 | return result; | |
786 | } | |
787 | ||
fa6cfec3 | 788 | BT_ASSERT_POST_DEV_FUNC |
e253ad8d SM |
789 | static |
790 | bool clock_classes_are_compatible( | |
791 | struct bt_self_component_port_input_message_iterator *iterator, | |
792 | bt_message_array_const msgs, uint64_t msg_count) | |
793 | { | |
794 | uint64_t i; | |
795 | bool result; | |
796 | ||
797 | for (i = 0; i < msg_count; i++) { | |
798 | if (!clock_classes_are_compatible_one(iterator, msgs[i])) { | |
799 | result = false; | |
800 | goto end; | |
801 | } | |
802 | } | |
803 | ||
804 | result = true; | |
805 | ||
806 | end: | |
807 | return result; | |
808 | } | |
809 | ||
810 | /* | |
811 | * Call the `next` method of the iterator. Do some validation on the returned | |
812 | * messages. | |
813 | */ | |
814 | ||
815 | static | |
fb25b9e3 PP |
816 | enum bt_component_class_message_iterator_next_method_status |
817 | call_iterator_next_method( | |
e253ad8d SM |
818 | struct bt_self_component_port_input_message_iterator *iterator, |
819 | bt_message_array_const msgs, uint64_t capacity, uint64_t *user_count) | |
820 | { | |
fb25b9e3 | 821 | enum bt_component_class_message_iterator_next_method_status status; |
e253ad8d SM |
822 | |
823 | BT_ASSERT(iterator->methods.next); | |
824 | BT_LOGD_STR("Calling user's \"next\" method."); | |
e253ad8d | 825 | status = iterator->methods.next(iterator, msgs, capacity, user_count); |
3b7d3ccc | 826 | BT_LOGD("User method returned: status=%s, msg-count=%" PRIu64, |
fb25b9e3 | 827 | bt_common_func_status_string(status), *user_count); |
e253ad8d | 828 | |
fb25b9e3 | 829 | if (status == BT_FUNC_STATUS_OK) { |
fa6cfec3 | 830 | BT_ASSERT_POST_DEV(clock_classes_are_compatible(iterator, msgs, *user_count), |
e253ad8d | 831 | "Clocks are not compatible"); |
fa6cfec3 | 832 | BT_ASSERT_POST_DEV(clock_snapshots_are_monotonic(iterator, msgs, *user_count), |
e253ad8d SM |
833 | "Clock snapshots are not monotonic"); |
834 | } | |
835 | ||
836 | return status; | |
837 | } | |
838 | ||
fb25b9e3 | 839 | enum bt_message_iterator_next_status |
b09a5592 PP |
840 | bt_self_component_port_input_message_iterator_next( |
841 | struct bt_self_component_port_input_message_iterator *iterator, | |
842 | bt_message_array_const *msgs, uint64_t *user_count) | |
3230ee6b | 843 | { |
fb25b9e3 | 844 | enum bt_message_iterator_next_status status = BT_FUNC_STATUS_OK; |
834e9996 | 845 | |
fa6cfec3 PP |
846 | BT_ASSERT_PRE_DEV_NON_NULL(iterator, "Message iterator"); |
847 | BT_ASSERT_PRE_DEV_NON_NULL(msgs, "Message array (output)"); | |
848 | BT_ASSERT_PRE_DEV_NON_NULL(user_count, "Message count (output)"); | |
849 | BT_ASSERT_PRE_DEV(iterator->state == | |
b09a5592 PP |
850 | BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE, |
851 | "Message iterator's \"next\" called, but " | |
15a52f66 | 852 | "message iterator is in the wrong state: %!+i", iterator); |
6ff151ad PP |
853 | BT_ASSERT(iterator->upstream_component); |
854 | BT_ASSERT(iterator->upstream_component->class); | |
fa6cfec3 | 855 | BT_ASSERT_PRE_DEV( |
1043fdea PP |
856 | bt_component_borrow_graph(iterator->upstream_component)->config_state != |
857 | BT_GRAPH_CONFIGURATION_STATE_CONFIGURING, | |
9cce94e4 PP |
858 | "Graph is not configured: %!+g", |
859 | bt_component_borrow_graph(iterator->upstream_component)); | |
834e9996 | 860 | BT_LIB_LOGD("Getting next self component input port " |
a684a357 PP |
861 | "message iterator's messages: %!+i, batch-size=%u", |
862 | iterator, MSG_BATCH_SIZE); | |
d3eb6e8f | 863 | |
3230ee6b | 864 | /* |
b09a5592 | 865 | * Call the user's "next" method to get the next messages |
fa054faf | 866 | * and status. |
3230ee6b | 867 | */ |
a684a357 | 868 | *user_count = 0; |
fb25b9e3 | 869 | status = (int) call_iterator_next_method(iterator, |
fac7b25a | 870 | (void *) iterator->msgs->pdata, MSG_BATCH_SIZE, |
15a52f66 | 871 | user_count); |
a8f90e5d PP |
872 | BT_LOGD("User method returned: status=%s, msg-count=%" PRIu64, |
873 | bt_common_func_status_string(status), *user_count); | |
3fd7b79d | 874 | if (status < 0) { |
a8f90e5d PP |
875 | BT_LIB_LOGW_APPEND_CAUSE( |
876 | "Component input port message iterator's \"next\" method failed: " | |
877 | "%![iter-]+i, status=%s", | |
878 | iterator, bt_common_func_status_string(status)); | |
6ff151ad PP |
879 | goto end; |
880 | } | |
3230ee6b | 881 | |
904860cb PP |
882 | /* |
883 | * There is no way that this iterator could have been finalized | |
884 | * during its "next" method, as the only way to do this is to | |
885 | * put the last iterator's reference, and this can only be done | |
886 | * by its downstream owner. | |
15a52f66 PP |
887 | * |
888 | * For the same reason, there is no way that this iterator could | |
889 | * have seeked (cannot seek a self message iterator). | |
904860cb PP |
890 | */ |
891 | BT_ASSERT(iterator->state == | |
892 | BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE); | |
8cf27cc5 | 893 | |
3fd7b79d | 894 | switch (status) { |
fb25b9e3 | 895 | case BT_FUNC_STATUS_OK: |
fa6cfec3 | 896 | BT_ASSERT_POST_DEV(*user_count <= MSG_BATCH_SIZE, |
15a52f66 PP |
897 | "Invalid returned message count: greater than " |
898 | "batch size: count=%" PRIu64 ", batch-size=%u", | |
899 | *user_count, MSG_BATCH_SIZE); | |
fac7b25a | 900 | *msgs = (void *) iterator->msgs->pdata; |
3fd7b79d | 901 | break; |
fb25b9e3 | 902 | case BT_FUNC_STATUS_AGAIN: |
3fd7b79d | 903 | goto end; |
fb25b9e3 | 904 | case BT_FUNC_STATUS_END: |
904860cb PP |
905 | set_self_comp_port_input_msg_iterator_state(iterator, |
906 | BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ENDED); | |
6ff151ad | 907 | goto end; |
6ff151ad PP |
908 | default: |
909 | /* Unknown non-error status */ | |
910 | abort(); | |
41a2b7ae PP |
911 | } |
912 | ||
913 | end: | |
3230ee6b PP |
914 | return status; |
915 | } | |
916 | ||
15a52f66 PP |
917 | struct bt_component * |
918 | bt_self_component_port_input_message_iterator_borrow_component( | |
b09a5592 | 919 | struct bt_self_component_port_input_message_iterator *iterator) |
834e9996 | 920 | { |
fa6cfec3 | 921 | BT_ASSERT_PRE_DEV_NON_NULL(iterator, "Message iterator"); |
834e9996 PP |
922 | return iterator->upstream_component; |
923 | } | |
924 | ||
15a52f66 PP |
925 | const struct bt_component * |
926 | bt_self_component_port_input_message_iterator_borrow_component_const( | |
927 | const struct bt_self_component_port_input_message_iterator *iterator) | |
928 | { | |
fa6cfec3 | 929 | BT_ASSERT_PRE_DEV_NON_NULL(iterator, "Message iterator"); |
15a52f66 PP |
930 | return iterator->upstream_component; |
931 | } | |
932 | ||
b09a5592 PP |
933 | struct bt_self_component *bt_self_message_iterator_borrow_component( |
934 | struct bt_self_message_iterator *self_iterator) | |
413bc2c4 | 935 | { |
b09a5592 | 936 | struct bt_self_component_port_input_message_iterator *iterator = |
834e9996 | 937 | (void *) self_iterator; |
fe7265b5 | 938 | |
fa6cfec3 | 939 | BT_ASSERT_PRE_DEV_NON_NULL(iterator, "Message iterator"); |
834e9996 | 940 | return (void *) iterator->upstream_component; |
413bc2c4 JG |
941 | } |
942 | ||
b09a5592 PP |
943 | struct bt_self_port_output *bt_self_message_iterator_borrow_port( |
944 | struct bt_self_message_iterator *self_iterator) | |
91457551 | 945 | { |
b09a5592 | 946 | struct bt_self_component_port_input_message_iterator *iterator = |
834e9996 PP |
947 | (void *) self_iterator; |
948 | ||
fa6cfec3 | 949 | BT_ASSERT_PRE_DEV_NON_NULL(iterator, "Message iterator"); |
834e9996 | 950 | return (void *) iterator->upstream_port; |
91457551 | 951 | } |
c3ac0193 | 952 | |
15a52f66 PP |
953 | bt_bool bt_self_component_port_input_message_iterator_can_seek_ns_from_origin( |
954 | struct bt_self_component_port_input_message_iterator *iterator, | |
955 | int64_t ns_from_origin) | |
956 | { | |
957 | bt_bool can = BT_FALSE; | |
958 | ||
959 | BT_ASSERT_PRE_NON_NULL(iterator, "Message iterator"); | |
960 | BT_ASSERT_PRE_ITER_HAS_STATE_TO_SEEK(iterator); | |
1043fdea PP |
961 | BT_ASSERT_PRE( |
962 | bt_component_borrow_graph(iterator->upstream_component)->config_state != | |
963 | BT_GRAPH_CONFIGURATION_STATE_CONFIGURING, | |
15a52f66 PP |
964 | "Graph is not configured: %!+g", |
965 | bt_component_borrow_graph(iterator->upstream_component)); | |
966 | ||
967 | if (iterator->methods.can_seek_ns_from_origin) { | |
968 | can = iterator->methods.can_seek_ns_from_origin(iterator, | |
969 | ns_from_origin); | |
970 | goto end; | |
971 | } | |
972 | ||
973 | /* | |
974 | * Automatic seeking fall back: if we can seek to the beginning, | |
975 | * then we can automatically seek to any message. | |
976 | */ | |
977 | if (iterator->methods.can_seek_beginning) { | |
978 | can = iterator->methods.can_seek_beginning(iterator); | |
979 | } | |
980 | ||
981 | end: | |
982 | return can; | |
983 | } | |
984 | ||
985 | bt_bool bt_self_component_port_input_message_iterator_can_seek_beginning( | |
986 | struct bt_self_component_port_input_message_iterator *iterator) | |
987 | { | |
988 | bt_bool can = BT_FALSE; | |
989 | ||
990 | BT_ASSERT_PRE_NON_NULL(iterator, "Message iterator"); | |
991 | BT_ASSERT_PRE_ITER_HAS_STATE_TO_SEEK(iterator); | |
1043fdea PP |
992 | BT_ASSERT_PRE( |
993 | bt_component_borrow_graph(iterator->upstream_component)->config_state != | |
994 | BT_GRAPH_CONFIGURATION_STATE_CONFIGURING, | |
15a52f66 PP |
995 | "Graph is not configured: %!+g", |
996 | bt_component_borrow_graph(iterator->upstream_component)); | |
997 | ||
998 | if (iterator->methods.can_seek_beginning) { | |
999 | can = iterator->methods.can_seek_beginning(iterator); | |
1000 | } | |
1001 | ||
1002 | return can; | |
1003 | } | |
1004 | ||
1005 | static inline | |
1d55aa9a | 1006 | void set_iterator_state_after_seeking( |
15a52f66 | 1007 | struct bt_self_component_port_input_message_iterator *iterator, |
fb25b9e3 | 1008 | int status) |
15a52f66 PP |
1009 | { |
1010 | enum bt_self_component_port_input_message_iterator_state new_state = 0; | |
1011 | ||
1012 | /* Set iterator's state depending on seeking status */ | |
1013 | switch (status) { | |
fb25b9e3 | 1014 | case BT_FUNC_STATUS_OK: |
15a52f66 PP |
1015 | new_state = BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE; |
1016 | break; | |
fb25b9e3 | 1017 | case BT_FUNC_STATUS_AGAIN: |
15a52f66 PP |
1018 | new_state = BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_AGAIN; |
1019 | break; | |
fb25b9e3 PP |
1020 | case BT_FUNC_STATUS_ERROR: |
1021 | case BT_FUNC_STATUS_MEMORY_ERROR: | |
15a52f66 PP |
1022 | new_state = BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_ERROR; |
1023 | break; | |
fb25b9e3 | 1024 | case BT_FUNC_STATUS_END: |
15a52f66 PP |
1025 | new_state = BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ENDED; |
1026 | break; | |
1027 | default: | |
1028 | abort(); | |
1029 | } | |
1030 | ||
1031 | set_self_comp_port_input_msg_iterator_state(iterator, new_state); | |
1032 | } | |
1033 | ||
e253ad8d SM |
1034 | static |
1035 | void reset_iterator_expectations( | |
1036 | struct bt_self_component_port_input_message_iterator *iterator) | |
1037 | { | |
1038 | iterator->last_ns_from_origin = INT64_MIN; | |
1039 | iterator->clock_expectation.type = CLOCK_EXPECTATION_UNSET; | |
1040 | } | |
1041 | ||
fb25b9e3 | 1042 | enum bt_message_iterator_seek_beginning_status |
15a52f66 PP |
1043 | bt_self_component_port_input_message_iterator_seek_beginning( |
1044 | struct bt_self_component_port_input_message_iterator *iterator) | |
1045 | { | |
621b4e7e | 1046 | int status; |
15a52f66 PP |
1047 | |
1048 | BT_ASSERT_PRE_NON_NULL(iterator, "Message iterator"); | |
1049 | BT_ASSERT_PRE_ITER_HAS_STATE_TO_SEEK(iterator); | |
1043fdea PP |
1050 | BT_ASSERT_PRE( |
1051 | bt_component_borrow_graph(iterator->upstream_component)->config_state != | |
1052 | BT_GRAPH_CONFIGURATION_STATE_CONFIGURING, | |
15a52f66 PP |
1053 | "Graph is not configured: %!+g", |
1054 | bt_component_borrow_graph(iterator->upstream_component)); | |
1055 | BT_ASSERT_PRE( | |
1056 | bt_self_component_port_input_message_iterator_can_seek_beginning( | |
1057 | iterator), | |
1058 | "Message iterator cannot seek beginning: %!+i", iterator); | |
e253ad8d SM |
1059 | |
1060 | /* | |
1061 | * We are seeking, reset our expectations about how the following | |
1062 | * messages should look like. | |
1063 | */ | |
1064 | reset_iterator_expectations(iterator); | |
1065 | ||
15a52f66 PP |
1066 | BT_LIB_LOGD("Calling user's \"seek beginning\" method: %!+i", iterator); |
1067 | set_self_comp_port_input_msg_iterator_state(iterator, | |
1068 | BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_SEEKING); | |
1069 | status = iterator->methods.seek_beginning(iterator); | |
1070 | BT_LOGD("User method returned: status=%s", | |
fb25b9e3 PP |
1071 | bt_common_func_status_string(status)); |
1072 | BT_ASSERT_POST(status == BT_FUNC_STATUS_OK || | |
1073 | status == BT_FUNC_STATUS_ERROR || | |
1074 | status == BT_FUNC_STATUS_MEMORY_ERROR || | |
1075 | status == BT_FUNC_STATUS_AGAIN, | |
15a52f66 | 1076 | "Unexpected status: %![iter-]+i, status=%s", |
fb25b9e3 | 1077 | iterator, bt_common_func_status_string(status)); |
a8f90e5d PP |
1078 | if (status < 0) { |
1079 | BT_LIB_LOGW_APPEND_CAUSE( | |
1080 | "Component input port message iterator's \"seek beginning\" method failed: " | |
1081 | "%![iter-]+i, status=%s", | |
1082 | iterator, bt_common_func_status_string(status)); | |
1083 | } | |
1084 | ||
15a52f66 PP |
1085 | set_iterator_state_after_seeking(iterator, status); |
1086 | return status; | |
1087 | } | |
1088 | ||
143feff5 SM |
1089 | /* |
1090 | * Structure used to record the state of a given stream during the fast-forward | |
1091 | * phase of an auto-seek. | |
1092 | */ | |
1093 | struct auto_seek_stream_state { | |
1094 | /* | |
1095 | * Value representing which step of this timeline we are at. | |
1096 | * | |
1097 | * time ---> | |
b7cbc799 | 1098 | * [SB] 1 [PB] 2 [PE] 1 [SE] |
143feff5 SM |
1099 | * |
1100 | * At each point in the timeline, the messages we need to replicate are: | |
1101 | * | |
1102 | * 1: Stream beginning | |
b7cbc799 | 1103 | * 2: Stream beginning, packet beginning |
143feff5 SM |
1104 | * |
1105 | * Before "Stream beginning" and after "Stream end", we don't need to | |
1106 | * replicate anything as the stream doesn't exist. | |
1107 | */ | |
1108 | enum { | |
1109 | AUTO_SEEK_STREAM_STATE_STREAM_BEGAN, | |
143feff5 SM |
1110 | AUTO_SEEK_STREAM_STATE_PACKET_BEGAN, |
1111 | } state; | |
1112 | ||
1113 | /* | |
1114 | * If `state` is AUTO_SEEK_STREAM_STATE_PACKET_BEGAN, the packet we are | |
1115 | * in. This is a weak reference, since the packet will always be | |
1116 | * alive by the time we use it. | |
1117 | */ | |
1118 | struct bt_packet *packet; | |
b7cbc799 SM |
1119 | |
1120 | /* Have we see a message with a clock snapshot yet? */ | |
1121 | bool seen_clock_snapshot; | |
143feff5 SM |
1122 | }; |
1123 | ||
1124 | static | |
1125 | struct auto_seek_stream_state *create_auto_seek_stream_state(void) | |
1126 | { | |
1127 | return g_new0(struct auto_seek_stream_state, 1); | |
1128 | } | |
1129 | ||
1130 | static | |
1131 | void destroy_auto_seek_stream_state(void *ptr) | |
1132 | { | |
1133 | g_free(ptr); | |
1134 | } | |
1135 | ||
1136 | static | |
1137 | GHashTable *create_auto_seek_stream_states(void) | |
1138 | { | |
1139 | return g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, | |
1140 | destroy_auto_seek_stream_state); | |
1141 | } | |
1142 | ||
1143 | static | |
1144 | void destroy_auto_seek_stream_states(GHashTable *stream_states) | |
1145 | { | |
1146 | g_hash_table_destroy(stream_states); | |
1147 | } | |
1148 | ||
1149 | /* | |
1150 | * Handle one message while we are in the fast-forward phase of an auto-seek. | |
1151 | * | |
1152 | * Sets `*got_first` to true if the message's timestamp is greater or equal to | |
1153 | * `ns_from_origin`. In other words, if this is the first message after our | |
1154 | * seek point. | |
1155 | * | |
1156 | * `stream_states` is an hash table of `bt_stream *` (weak reference) to | |
1157 | * `struct auto_seek_stream_state` used to keep the state of each stream | |
1158 | * during the fast-forward. | |
1159 | */ | |
1160 | ||
15a52f66 | 1161 | static inline |
fb25b9e3 | 1162 | int auto_seek_handle_message( |
3d902f17 PP |
1163 | struct bt_self_component_port_input_message_iterator *iterator, |
1164 | int64_t ns_from_origin, const struct bt_message *msg, | |
143feff5 | 1165 | bool *got_first, GHashTable *stream_states) |
15a52f66 | 1166 | { |
fb25b9e3 | 1167 | int status = BT_FUNC_STATUS_OK; |
3d902f17 | 1168 | int64_t msg_ns_from_origin; |
15a52f66 | 1169 | const struct bt_clock_snapshot *clk_snapshot = NULL; |
3d902f17 PP |
1170 | int ret; |
1171 | ||
1172 | BT_ASSERT(msg); | |
1173 | BT_ASSERT(got_first); | |
15a52f66 PP |
1174 | |
1175 | switch (msg->type) { | |
1176 | case BT_MESSAGE_TYPE_EVENT: | |
1177 | { | |
1178 | const struct bt_message_event *event_msg = | |
1179 | (const void *) msg; | |
1180 | ||
9c04b633 | 1181 | clk_snapshot = event_msg->default_cs; |
fa6cfec3 | 1182 | BT_ASSERT_POST_DEV(clk_snapshot, |
956dcc1e PP |
1183 | "Event message has no default clock snapshot: %!+n", |
1184 | event_msg); | |
15a52f66 PP |
1185 | break; |
1186 | } | |
40bf6fd0 | 1187 | case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY: |
15a52f66 | 1188 | { |
40bf6fd0 | 1189 | const struct bt_message_message_iterator_inactivity *inactivity_msg = |
15a52f66 PP |
1190 | (const void *) msg; |
1191 | ||
15a52f66 | 1192 | clk_snapshot = inactivity_msg->default_cs; |
f629b891 | 1193 | BT_ASSERT(clk_snapshot); |
15a52f66 PP |
1194 | break; |
1195 | } | |
f629b891 PP |
1196 | case BT_MESSAGE_TYPE_PACKET_BEGINNING: |
1197 | case BT_MESSAGE_TYPE_PACKET_END: | |
956dcc1e PP |
1198 | { |
1199 | const struct bt_message_packet *packet_msg = | |
1200 | (const void *) msg; | |
1201 | ||
1202 | clk_snapshot = packet_msg->default_cs; | |
fa6cfec3 | 1203 | BT_ASSERT_POST_DEV(clk_snapshot, |
956dcc1e PP |
1204 | "Packet message has no default clock snapshot: %!+n", |
1205 | packet_msg); | |
1206 | break; | |
1207 | } | |
f629b891 PP |
1208 | case BT_MESSAGE_TYPE_DISCARDED_EVENTS: |
1209 | case BT_MESSAGE_TYPE_DISCARDED_PACKETS: | |
15a52f66 | 1210 | { |
3d902f17 PP |
1211 | struct bt_message_discarded_items *msg_disc_items = |
1212 | (void *) msg; | |
1213 | ||
fa6cfec3 | 1214 | BT_ASSERT_POST_DEV(msg_disc_items->default_begin_cs && |
3d902f17 PP |
1215 | msg_disc_items->default_end_cs, |
1216 | "Discarded events/packets message has no default clock snapshots: %!+n", | |
1217 | msg_disc_items); | |
1218 | ret = bt_clock_snapshot_get_ns_from_origin( | |
1219 | msg_disc_items->default_begin_cs, | |
1220 | &msg_ns_from_origin); | |
1221 | if (ret) { | |
fb25b9e3 | 1222 | status = BT_FUNC_STATUS_ERROR; |
3d902f17 PP |
1223 | goto end; |
1224 | } | |
15a52f66 | 1225 | |
3d902f17 PP |
1226 | if (msg_ns_from_origin >= ns_from_origin) { |
1227 | *got_first = true; | |
1228 | goto push_msg; | |
1229 | } | |
1230 | ||
1231 | ret = bt_clock_snapshot_get_ns_from_origin( | |
1232 | msg_disc_items->default_end_cs, | |
1233 | &msg_ns_from_origin); | |
1234 | if (ret) { | |
fb25b9e3 | 1235 | status = BT_FUNC_STATUS_ERROR; |
3d902f17 PP |
1236 | goto end; |
1237 | } | |
1238 | ||
1239 | if (msg_ns_from_origin >= ns_from_origin) { | |
1240 | /* | |
1241 | * The discarded items message's beginning time | |
1242 | * is before the requested seeking time, but its | |
1243 | * end time is after. Modify the message so as | |
1244 | * to set its beginning time to the requested | |
1245 | * seeking time, and make its item count unknown | |
1246 | * as we don't know if items were really | |
1247 | * discarded within the new time range. | |
1248 | */ | |
1564e3dc | 1249 | uint64_t new_begin_raw_value = 0; |
3d902f17 PP |
1250 | |
1251 | ret = bt_clock_class_clock_value_from_ns_from_origin( | |
1252 | msg_disc_items->default_end_cs->clock_class, | |
1253 | ns_from_origin, &new_begin_raw_value); | |
1254 | if (ret) { | |
fb25b9e3 | 1255 | status = BT_FUNC_STATUS_ERROR; |
3d902f17 PP |
1256 | goto end; |
1257 | } | |
1258 | ||
1259 | bt_clock_snapshot_set_raw_value( | |
1260 | msg_disc_items->default_begin_cs, | |
1261 | new_begin_raw_value); | |
1262 | msg_disc_items->count.base.avail = | |
1263 | BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE; | |
1264 | ||
1265 | /* | |
1266 | * It is safe to push it because its beginning | |
1267 | * time is exactly the requested seeking time. | |
1268 | */ | |
1269 | goto push_msg; | |
1270 | } else { | |
1271 | goto skip_msg; | |
1272 | } | |
15a52f66 | 1273 | } |
b7cbc799 SM |
1274 | case BT_MESSAGE_TYPE_STREAM_BEGINNING: |
1275 | case BT_MESSAGE_TYPE_STREAM_END: | |
15a52f66 | 1276 | { |
b7cbc799 SM |
1277 | struct bt_message_stream *stream_msg = |
1278 | (struct bt_message_stream *) msg; | |
15a52f66 | 1279 | |
b7cbc799 SM |
1280 | if (stream_msg->default_cs_state != BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) { |
1281 | /* Ignore */ | |
3d902f17 | 1282 | goto skip_msg; |
f629b891 PP |
1283 | } |
1284 | ||
b7cbc799 | 1285 | clk_snapshot = stream_msg->default_cs; |
15a52f66 PP |
1286 | break; |
1287 | } | |
1288 | default: | |
1289 | abort(); | |
1290 | } | |
1291 | ||
3d902f17 PP |
1292 | BT_ASSERT(clk_snapshot); |
1293 | ret = bt_clock_snapshot_get_ns_from_origin(clk_snapshot, | |
1294 | &msg_ns_from_origin); | |
1295 | if (ret) { | |
fb25b9e3 | 1296 | status = BT_FUNC_STATUS_ERROR; |
15a52f66 PP |
1297 | goto end; |
1298 | } | |
1299 | ||
3d902f17 PP |
1300 | if (msg_ns_from_origin >= ns_from_origin) { |
1301 | *got_first = true; | |
1302 | goto push_msg; | |
1303 | } | |
1304 | ||
1305 | skip_msg: | |
143feff5 SM |
1306 | /* This message won't be sent downstream. */ |
1307 | switch (msg->type) { | |
1308 | case BT_MESSAGE_TYPE_STREAM_BEGINNING: | |
1309 | { | |
1310 | const struct bt_message_stream *stream_msg = (const void *) msg; | |
1311 | struct auto_seek_stream_state *stream_state; | |
143feff5 SM |
1312 | |
1313 | /* Update stream's state: stream began. */ | |
1314 | stream_state = create_auto_seek_stream_state(); | |
1315 | if (!stream_state) { | |
fb25b9e3 | 1316 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
143feff5 SM |
1317 | goto end; |
1318 | } | |
1319 | ||
1320 | stream_state->state = AUTO_SEEK_STREAM_STATE_STREAM_BEGAN; | |
c3df794d | 1321 | |
b7cbc799 SM |
1322 | if (stream_msg->default_cs_state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) { |
1323 | stream_state->seen_clock_snapshot = true; | |
1324 | } | |
1325 | ||
c3df794d SM |
1326 | BT_ASSERT(!bt_g_hash_table_contains(stream_states, stream_msg->stream)); |
1327 | g_hash_table_insert(stream_states, stream_msg->stream, stream_state); | |
143feff5 SM |
1328 | break; |
1329 | } | |
b7cbc799 | 1330 | case BT_MESSAGE_TYPE_PACKET_BEGINNING: |
143feff5 | 1331 | { |
b7cbc799 | 1332 | const struct bt_message_packet *packet_msg = |
143feff5 SM |
1333 | (const void *) msg; |
1334 | struct auto_seek_stream_state *stream_state; | |
1335 | ||
b7cbc799 SM |
1336 | /* Update stream's state: packet began. */ |
1337 | stream_state = g_hash_table_lookup(stream_states, packet_msg->packet->stream); | |
143feff5 SM |
1338 | BT_ASSERT(stream_state); |
1339 | ||
1340 | BT_ASSERT(stream_state->state == AUTO_SEEK_STREAM_STATE_STREAM_BEGAN); | |
b7cbc799 | 1341 | stream_state->state = AUTO_SEEK_STREAM_STATE_PACKET_BEGAN; |
143feff5 | 1342 | BT_ASSERT(!stream_state->packet); |
b7cbc799 SM |
1343 | stream_state->packet = packet_msg->packet; |
1344 | ||
1345 | if (packet_msg->packet->stream->class->packets_have_beginning_default_clock_snapshot) { | |
1346 | stream_state->seen_clock_snapshot = true; | |
1347 | } | |
1348 | ||
143feff5 SM |
1349 | break; |
1350 | } | |
b7cbc799 | 1351 | case BT_MESSAGE_TYPE_EVENT: |
143feff5 | 1352 | { |
b7cbc799 | 1353 | const struct bt_message_event *event_msg = (const void *) msg; |
143feff5 SM |
1354 | struct auto_seek_stream_state *stream_state; |
1355 | ||
b7cbc799 SM |
1356 | stream_state = g_hash_table_lookup(stream_states, |
1357 | event_msg->event->packet->stream); | |
143feff5 SM |
1358 | BT_ASSERT(stream_state); |
1359 | ||
b7cbc799 SM |
1360 | // HELPME: are we sure that event messages have clock snapshots at this point? |
1361 | stream_state->seen_clock_snapshot = true; | |
1362 | ||
143feff5 SM |
1363 | break; |
1364 | } | |
1365 | case BT_MESSAGE_TYPE_PACKET_END: | |
1366 | { | |
1367 | const struct bt_message_packet *packet_msg = | |
1368 | (const void *) msg; | |
1369 | struct auto_seek_stream_state *stream_state; | |
1370 | ||
1371 | /* Update stream's state: packet ended. */ | |
1372 | stream_state = g_hash_table_lookup(stream_states, packet_msg->packet->stream); | |
1373 | BT_ASSERT(stream_state); | |
1374 | ||
1375 | BT_ASSERT(stream_state->state == AUTO_SEEK_STREAM_STATE_PACKET_BEGAN); | |
b7cbc799 | 1376 | stream_state->state = AUTO_SEEK_STREAM_STATE_STREAM_BEGAN; |
143feff5 SM |
1377 | BT_ASSERT(stream_state->packet); |
1378 | stream_state->packet = NULL; | |
143feff5 | 1379 | |
b7cbc799 SM |
1380 | if (packet_msg->packet->stream->class->packets_have_end_default_clock_snapshot) { |
1381 | stream_state->seen_clock_snapshot = true; | |
1382 | } | |
143feff5 | 1383 | |
143feff5 SM |
1384 | break; |
1385 | } | |
1386 | case BT_MESSAGE_TYPE_STREAM_END: | |
1387 | { | |
1388 | const struct bt_message_stream *stream_msg = (const void *) msg; | |
1389 | struct auto_seek_stream_state *stream_state; | |
1390 | ||
1391 | stream_state = g_hash_table_lookup(stream_states, stream_msg->stream); | |
1392 | BT_ASSERT(stream_state); | |
1393 | BT_ASSERT(stream_state->state == AUTO_SEEK_STREAM_STATE_STREAM_BEGAN); | |
1394 | BT_ASSERT(!stream_state->packet); | |
1395 | ||
1396 | /* Update stream's state: this stream doesn't exist anymore. */ | |
1397 | g_hash_table_remove(stream_states, stream_msg->stream); | |
1398 | break; | |
1399 | } | |
b7cbc799 SM |
1400 | case BT_MESSAGE_TYPE_DISCARDED_EVENTS: |
1401 | case BT_MESSAGE_TYPE_DISCARDED_PACKETS: | |
1402 | { | |
1403 | const struct bt_message_discarded_items *discarded_msg = | |
1404 | (const void *) msg; | |
1405 | struct auto_seek_stream_state *stream_state; | |
1406 | ||
1407 | stream_state = g_hash_table_lookup(stream_states, discarded_msg->stream); | |
1408 | BT_ASSERT(stream_state); | |
1409 | ||
1410 | if ((msg->type == BT_MESSAGE_TYPE_DISCARDED_EVENTS && discarded_msg->stream->class->discarded_events_have_default_clock_snapshots) || | |
1411 | (msg->type == BT_MESSAGE_TYPE_DISCARDED_PACKETS && discarded_msg->stream->class->discarded_packets_have_default_clock_snapshots)) { | |
1412 | stream_state->seen_clock_snapshot = true; | |
1413 | } | |
1414 | ||
1415 | break; | |
1416 | } | |
143feff5 SM |
1417 | default: |
1418 | break; | |
1419 | } | |
1420 | ||
3d902f17 | 1421 | bt_object_put_no_null_check(msg); |
27afdfda | 1422 | msg = NULL; |
3d902f17 PP |
1423 | goto end; |
1424 | ||
1425 | push_msg: | |
1b3630b6 | 1426 | g_queue_push_tail(iterator->auto_seek.msgs, (void *) msg); |
3d902f17 | 1427 | msg = NULL; |
15a52f66 PP |
1428 | |
1429 | end: | |
fb25b9e3 | 1430 | BT_ASSERT(!msg || status != BT_FUNC_STATUS_OK); |
3d902f17 | 1431 | return status; |
15a52f66 PP |
1432 | } |
1433 | ||
1434 | static | |
fb25b9e3 | 1435 | int find_message_ge_ns_from_origin( |
15a52f66 | 1436 | struct bt_self_component_port_input_message_iterator *iterator, |
143feff5 | 1437 | int64_t ns_from_origin, GHashTable *stream_states) |
15a52f66 PP |
1438 | { |
1439 | int status; | |
1440 | enum bt_self_component_port_input_message_iterator_state init_state = | |
1441 | iterator->state; | |
1442 | const struct bt_message *messages[MSG_BATCH_SIZE]; | |
1443 | uint64_t user_count = 0; | |
1444 | uint64_t i; | |
3d902f17 | 1445 | bool got_first = false; |
15a52f66 PP |
1446 | |
1447 | BT_ASSERT(iterator); | |
1448 | memset(&messages[0], 0, sizeof(messages[0]) * MSG_BATCH_SIZE); | |
1449 | ||
1450 | /* | |
1451 | * Make this iterator temporarily active (not seeking) to call | |
1452 | * the "next" method. | |
1453 | */ | |
1454 | set_self_comp_port_input_msg_iterator_state(iterator, | |
1455 | BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE); | |
1456 | ||
1457 | BT_ASSERT(iterator->methods.next); | |
1458 | ||
c980433a | 1459 | while (!got_first) { |
15a52f66 PP |
1460 | /* |
1461 | * Call the user's "next" method to get the next | |
1462 | * messages and status. | |
1463 | */ | |
e253ad8d | 1464 | status = call_iterator_next_method(iterator, |
15a52f66 | 1465 | &messages[0], MSG_BATCH_SIZE, &user_count); |
a8f90e5d PP |
1466 | BT_LOGD("User method returned: status=%s", |
1467 | bt_common_func_status_string(status)); | |
1468 | if (status < 0) { | |
1469 | BT_LIB_LOGW_APPEND_CAUSE( | |
1470 | "Component input port message iterator's \"next\" method failed: " | |
1471 | "%![iter-]+i, status=%s", | |
1472 | iterator, bt_common_func_status_string(status)); | |
1473 | } | |
15a52f66 | 1474 | |
15a52f66 PP |
1475 | /* |
1476 | * The user's "next" method must not do any action which | |
1477 | * would change the iterator's state. | |
1478 | */ | |
1479 | BT_ASSERT(iterator->state == | |
1480 | BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE); | |
15a52f66 PP |
1481 | |
1482 | switch (status) { | |
fb25b9e3 | 1483 | case BT_FUNC_STATUS_OK: |
fa6cfec3 | 1484 | BT_ASSERT_POST_DEV(user_count <= MSG_BATCH_SIZE, |
15a52f66 PP |
1485 | "Invalid returned message count: greater than " |
1486 | "batch size: count=%" PRIu64 ", batch-size=%u", | |
1487 | user_count, MSG_BATCH_SIZE); | |
1488 | break; | |
fb25b9e3 PP |
1489 | case BT_FUNC_STATUS_AGAIN: |
1490 | case BT_FUNC_STATUS_ERROR: | |
1491 | case BT_FUNC_STATUS_MEMORY_ERROR: | |
1492 | case BT_FUNC_STATUS_END: | |
15a52f66 PP |
1493 | goto end; |
1494 | default: | |
1495 | abort(); | |
1496 | } | |
1497 | ||
15a52f66 | 1498 | for (i = 0; i < user_count; i++) { |
3d902f17 | 1499 | if (got_first) { |
1b3630b6 | 1500 | g_queue_push_tail(iterator->auto_seek.msgs, |
3d902f17 PP |
1501 | (void *) messages[i]); |
1502 | messages[i] = NULL; | |
15a52f66 PP |
1503 | continue; |
1504 | } | |
1505 | ||
3d902f17 | 1506 | status = auto_seek_handle_message(iterator, |
143feff5 SM |
1507 | ns_from_origin, messages[i], &got_first, |
1508 | stream_states); | |
fb25b9e3 | 1509 | if (status == BT_FUNC_STATUS_OK) { |
c980433a | 1510 | /* Message was either pushed or moved */ |
3d902f17 PP |
1511 | messages[i] = NULL; |
1512 | } else { | |
15a52f66 PP |
1513 | goto end; |
1514 | } | |
15a52f66 PP |
1515 | } |
1516 | } | |
1517 | ||
1518 | end: | |
1519 | for (i = 0; i < user_count; i++) { | |
1520 | if (messages[i]) { | |
1521 | bt_object_put_no_null_check(messages[i]); | |
1522 | } | |
1523 | } | |
1524 | ||
1525 | set_self_comp_port_input_msg_iterator_state(iterator, init_state); | |
1526 | return status; | |
1527 | } | |
1528 | ||
143feff5 SM |
1529 | /* |
1530 | * This function is installed as the iterator's next callback after we have | |
1531 | * auto-seeked (seeked to the beginning and fast-forwarded) to send the | |
1532 | * messages saved in iterator->auto_seek.msgs. Once this is done, the original | |
1533 | * next callback is put back. | |
1534 | */ | |
1535 | ||
15a52f66 | 1536 | static |
fb25b9e3 | 1537 | enum bt_component_class_message_iterator_next_method_status post_auto_seek_next( |
15a52f66 PP |
1538 | struct bt_self_component_port_input_message_iterator *iterator, |
1539 | bt_message_array_const msgs, uint64_t capacity, | |
1540 | uint64_t *count) | |
1541 | { | |
1b3630b6 | 1542 | BT_ASSERT(!g_queue_is_empty(iterator->auto_seek.msgs)); |
3d902f17 | 1543 | *count = 0; |
15a52f66 PP |
1544 | |
1545 | /* | |
1546 | * Move auto-seek messages to the output array (which is this | |
3d902f17 | 1547 | * iterator's base message array). |
15a52f66 | 1548 | */ |
1b3630b6 SM |
1549 | while (capacity > 0 && !g_queue_is_empty(iterator->auto_seek.msgs)) { |
1550 | msgs[*count] = g_queue_pop_head(iterator->auto_seek.msgs); | |
3d902f17 PP |
1551 | capacity--; |
1552 | (*count)++; | |
15a52f66 | 1553 | } |
15a52f66 | 1554 | |
3d902f17 PP |
1555 | BT_ASSERT(*count > 0); |
1556 | ||
1b3630b6 | 1557 | if (g_queue_is_empty(iterator->auto_seek.msgs)) { |
1d801aab SM |
1558 | /* No more auto-seek messages, restore user's next callback. */ |
1559 | BT_ASSERT(iterator->auto_seek.original_next_callback); | |
1560 | iterator->methods.next = iterator->auto_seek.original_next_callback; | |
1561 | iterator->auto_seek.original_next_callback = NULL; | |
15a52f66 PP |
1562 | } |
1563 | ||
fb25b9e3 | 1564 | return BT_FUNC_STATUS_OK; |
15a52f66 PP |
1565 | } |
1566 | ||
143feff5 SM |
1567 | static inline |
1568 | int clock_raw_value_from_ns_from_origin(const bt_clock_class *clock_class, | |
1569 | int64_t ns_from_origin, uint64_t *raw_value) | |
1570 | { | |
1571 | ||
1572 | int64_t cc_offset_s = clock_class->offset_seconds; | |
1573 | uint64_t cc_offset_cycles = clock_class->offset_cycles; | |
1574 | uint64_t cc_freq = clock_class->frequency; | |
1575 | ||
1576 | return bt_common_clock_value_from_ns_from_origin(cc_offset_s, | |
1577 | cc_offset_cycles, cc_freq, ns_from_origin, raw_value); | |
1578 | } | |
1579 | ||
1580 | ||
fb25b9e3 | 1581 | enum bt_message_iterator_seek_ns_from_origin_status |
15a52f66 PP |
1582 | bt_self_component_port_input_message_iterator_seek_ns_from_origin( |
1583 | struct bt_self_component_port_input_message_iterator *iterator, | |
1584 | int64_t ns_from_origin) | |
1585 | { | |
1586 | int status; | |
143feff5 | 1587 | GHashTable *stream_states = NULL; |
15a52f66 PP |
1588 | |
1589 | BT_ASSERT_PRE_NON_NULL(iterator, "Message iterator"); | |
1590 | BT_ASSERT_PRE_ITER_HAS_STATE_TO_SEEK(iterator); | |
1043fdea PP |
1591 | BT_ASSERT_PRE( |
1592 | bt_component_borrow_graph(iterator->upstream_component)->config_state != | |
1593 | BT_GRAPH_CONFIGURATION_STATE_CONFIGURING, | |
15a52f66 PP |
1594 | "Graph is not configured: %!+g", |
1595 | bt_component_borrow_graph(iterator->upstream_component)); | |
1596 | BT_ASSERT_PRE( | |
1597 | bt_self_component_port_input_message_iterator_can_seek_ns_from_origin( | |
1598 | iterator, ns_from_origin), | |
1599 | "Message iterator cannot seek nanoseconds from origin: %!+i, " | |
1600 | "ns-from-origin=%" PRId64, iterator, ns_from_origin); | |
1601 | set_self_comp_port_input_msg_iterator_state(iterator, | |
1602 | BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_SEEKING); | |
1603 | ||
e253ad8d SM |
1604 | /* |
1605 | * We are seeking, reset our expectations about how the following | |
1606 | * messages should look like. | |
1607 | */ | |
1608 | reset_iterator_expectations(iterator); | |
1609 | ||
15a52f66 | 1610 | if (iterator->methods.seek_ns_from_origin) { |
143feff5 | 1611 | /* The iterator knows how to seek to a particular time, let it handle this. */ |
15a52f66 PP |
1612 | BT_LIB_LOGD("Calling user's \"seek nanoseconds from origin\" method: " |
1613 | "%![iter-]+i, ns=%" PRId64, iterator, ns_from_origin); | |
1614 | status = iterator->methods.seek_ns_from_origin(iterator, | |
1615 | ns_from_origin); | |
1616 | BT_LOGD("User method returned: status=%s", | |
fb25b9e3 PP |
1617 | bt_common_func_status_string(status)); |
1618 | BT_ASSERT_POST(status == BT_FUNC_STATUS_OK || | |
1619 | status == BT_FUNC_STATUS_ERROR || | |
1620 | status == BT_FUNC_STATUS_MEMORY_ERROR || | |
1621 | status == BT_FUNC_STATUS_AGAIN, | |
15a52f66 | 1622 | "Unexpected status: %![iter-]+i, status=%s", |
fb25b9e3 | 1623 | iterator, bt_common_func_status_string(status)); |
a8f90e5d PP |
1624 | if (status < 0) { |
1625 | BT_LIB_LOGW_APPEND_CAUSE( | |
1626 | "Component input port message iterator's \"seek nanoseconds from origin\" method failed: " | |
1627 | "%![iter-]+i, status=%s", | |
1628 | iterator, bt_common_func_status_string(status)); | |
1629 | } | |
15a52f66 | 1630 | } else { |
143feff5 SM |
1631 | /* |
1632 | * The iterator doesn't know how to seek to a particular time. We will | |
1633 | * seek to the beginning and fast forward to the right place. | |
1634 | */ | |
15a52f66 PP |
1635 | BT_ASSERT(iterator->methods.can_seek_beginning(iterator)); |
1636 | BT_ASSERT(iterator->methods.seek_beginning); | |
1637 | BT_LIB_LOGD("Calling user's \"seek beginning\" method: %!+i", | |
1638 | iterator); | |
1639 | status = iterator->methods.seek_beginning(iterator); | |
1640 | BT_LOGD("User method returned: status=%s", | |
fb25b9e3 PP |
1641 | bt_common_func_status_string(status)); |
1642 | BT_ASSERT_POST(status == BT_FUNC_STATUS_OK || | |
1643 | status == BT_FUNC_STATUS_ERROR || | |
1644 | status == BT_FUNC_STATUS_MEMORY_ERROR || | |
1645 | status == BT_FUNC_STATUS_AGAIN, | |
15a52f66 | 1646 | "Unexpected status: %![iter-]+i, status=%s", |
fb25b9e3 | 1647 | iterator, bt_common_func_status_string(status)); |
a8f90e5d PP |
1648 | if (status < 0) { |
1649 | BT_LIB_LOGW_APPEND_CAUSE( | |
1650 | "Component input port message iterator's \"seek beginning\" method failed: " | |
1651 | "%![iter-]+i, status=%s", | |
1652 | iterator, bt_common_func_status_string(status)); | |
1653 | } | |
1654 | ||
15a52f66 | 1655 | switch (status) { |
fb25b9e3 | 1656 | case BT_FUNC_STATUS_OK: |
15a52f66 | 1657 | break; |
fb25b9e3 PP |
1658 | case BT_FUNC_STATUS_ERROR: |
1659 | case BT_FUNC_STATUS_MEMORY_ERROR: | |
1660 | case BT_FUNC_STATUS_AGAIN: | |
15a52f66 PP |
1661 | goto end; |
1662 | default: | |
1663 | abort(); | |
1664 | } | |
1665 | ||
1666 | /* | |
1667 | * Find the first message which has a default clock | |
1668 | * snapshot greater than or equal to the requested | |
3d902f17 PP |
1669 | * seeking time, and move the received messages from |
1670 | * this point in the batch to this iterator's auto-seek | |
1671 | * message queue. | |
15a52f66 | 1672 | */ |
1b3630b6 | 1673 | while (!g_queue_is_empty(iterator->auto_seek.msgs)) { |
3d902f17 | 1674 | bt_object_put_no_null_check( |
1b3630b6 | 1675 | g_queue_pop_tail(iterator->auto_seek.msgs)); |
3d902f17 PP |
1676 | } |
1677 | ||
143feff5 SM |
1678 | stream_states = create_auto_seek_stream_states(); |
1679 | if (!stream_states) { | |
a8f90e5d PP |
1680 | BT_LIB_LOGE_APPEND_CAUSE( |
1681 | "Failed to allocate one GHashTable."); | |
fb25b9e3 | 1682 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
143feff5 SM |
1683 | goto end; |
1684 | } | |
1685 | ||
15a52f66 | 1686 | status = find_message_ge_ns_from_origin(iterator, |
143feff5 | 1687 | ns_from_origin, stream_states); |
15a52f66 | 1688 | switch (status) { |
fb25b9e3 PP |
1689 | case BT_FUNC_STATUS_OK: |
1690 | case BT_FUNC_STATUS_END: | |
143feff5 SM |
1691 | { |
1692 | GHashTableIter iter; | |
1693 | gpointer key, value; | |
1694 | ||
1695 | /* | |
1696 | * If some streams exist at the seek time, prepend the | |
1697 | * required messages to put those streams in the right | |
1698 | * state. | |
1699 | */ | |
1700 | g_hash_table_iter_init(&iter, stream_states); | |
1701 | while (g_hash_table_iter_next (&iter, &key, &value)) { | |
1702 | const bt_stream *stream = key; | |
1703 | struct auto_seek_stream_state *stream_state = | |
1704 | (struct auto_seek_stream_state *) value; | |
1705 | bt_message *msg; | |
1706 | const bt_clock_class *clock_class = bt_stream_class_borrow_default_clock_class_const( | |
1707 | bt_stream_borrow_class_const(stream)); | |
b7cbc799 SM |
1708 | /* Initialize to silence maybe-uninitialized warning. */ |
1709 | uint64_t raw_value = 0; | |
1710 | ||
1711 | /* | |
1712 | * If we haven't seen a message with a clock snapshot, we don't know if our seek time is within | |
1713 | * the clock's range, so it wouldn't be safe to try to convert ns_from_origin to a clock value. | |
1714 | * | |
1715 | * Also, it would be a bit of a lie to generate a stream begin message with the seek time as its | |
1716 | * clock snapshot, because we don't really know if the stream existed at that time. If we have | |
1717 | * seen a message with a clock snapshot in our seeking, then we are sure that the | |
1718 | * seek time is not below the clock range, and we know the stream was active at that | |
1719 | * time (and that we cut it short). | |
1720 | */ | |
1721 | if (stream_state->seen_clock_snapshot) { | |
1722 | if (clock_raw_value_from_ns_from_origin(clock_class, ns_from_origin, &raw_value) != 0) { | |
1723 | BT_LIB_LOGW("Could not convert nanoseconds from origin to clock value: ns-from-origin=%" PRId64 ", %![cc-]+K", | |
1724 | ns_from_origin, clock_class); | |
1725 | status = BT_FUNC_STATUS_ERROR; | |
1726 | goto end; | |
1727 | } | |
143feff5 SM |
1728 | } |
1729 | ||
1730 | switch (stream_state->state) { | |
1731 | case AUTO_SEEK_STREAM_STATE_PACKET_BEGAN: | |
1732 | BT_ASSERT(stream_state->packet); | |
1733 | BT_LIB_LOGD("Creating packet message: %![packet-]+a", stream_state->packet); | |
b7cbc799 SM |
1734 | |
1735 | if (stream->class->packets_have_beginning_default_clock_snapshot) { | |
1736 | /* | |
1737 | * If we are in the PACKET_BEGAN state, it means we have seen a "packet beginning" | |
1738 | * message. If "packet beginning" packets have clock snapshots, then we must have | |
1739 | * seen a clock snapshot. | |
1740 | */ | |
1741 | BT_ASSERT(stream_state->seen_clock_snapshot); | |
1742 | ||
1743 | msg = bt_message_packet_beginning_create_with_default_clock_snapshot( | |
1744 | (bt_self_message_iterator *) iterator, stream_state->packet, raw_value); | |
1745 | } else { | |
1746 | msg = bt_message_packet_beginning_create((bt_self_message_iterator *) iterator, | |
1747 | stream_state->packet); | |
143feff5 SM |
1748 | } |
1749 | ||
143feff5 | 1750 | if (!msg) { |
fb25b9e3 | 1751 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
143feff5 SM |
1752 | goto end; |
1753 | } | |
1754 | ||
143feff5 SM |
1755 | g_queue_push_head(iterator->auto_seek.msgs, msg); |
1756 | msg = NULL; | |
1757 | /* fall-thru */ | |
b7cbc799 | 1758 | |
143feff5 SM |
1759 | case AUTO_SEEK_STREAM_STATE_STREAM_BEGAN: |
1760 | msg = bt_message_stream_beginning_create( | |
1761 | (bt_self_message_iterator *) iterator, stream); | |
1762 | if (!msg) { | |
fb25b9e3 | 1763 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
143feff5 SM |
1764 | goto end; |
1765 | } | |
1766 | ||
b7cbc799 SM |
1767 | if (stream_state->seen_clock_snapshot) { |
1768 | bt_message_stream_beginning_set_default_clock_snapshot(msg, raw_value); | |
1769 | } | |
1770 | ||
143feff5 SM |
1771 | g_queue_push_head(iterator->auto_seek.msgs, msg); |
1772 | msg = NULL; | |
1773 | break; | |
1774 | } | |
1775 | } | |
1776 | ||
15a52f66 | 1777 | /* |
3d902f17 PP |
1778 | * If there are messages in the auto-seek |
1779 | * message queue, replace the user's "next" | |
1780 | * method with a custom, temporary "next" method | |
1781 | * which returns them. | |
15a52f66 | 1782 | */ |
1b3630b6 | 1783 | if (!g_queue_is_empty(iterator->auto_seek.msgs)) { |
1d801aab SM |
1784 | BT_ASSERT(!iterator->auto_seek.original_next_callback); |
1785 | iterator->auto_seek.original_next_callback = iterator->methods.next; | |
1786 | ||
3d902f17 PP |
1787 | iterator->methods.next = |
1788 | (bt_self_component_port_input_message_iterator_next_method) | |
1789 | post_auto_seek_next; | |
1790 | } | |
1791 | ||
1792 | /* | |
fb25b9e3 PP |
1793 | * `BT_FUNC_STATUS_END` becomes |
1794 | * `BT_FUNC_STATUS_OK`: the next | |
3d902f17 PP |
1795 | * time this iterator's "next" method is called, |
1796 | * it will return | |
fb25b9e3 | 1797 | * `BT_FUNC_STATUS_END`. |
3d902f17 | 1798 | */ |
fb25b9e3 | 1799 | status = BT_FUNC_STATUS_OK; |
15a52f66 | 1800 | break; |
143feff5 | 1801 | } |
fb25b9e3 PP |
1802 | case BT_FUNC_STATUS_ERROR: |
1803 | case BT_FUNC_STATUS_MEMORY_ERROR: | |
1804 | case BT_FUNC_STATUS_AGAIN: | |
15a52f66 | 1805 | goto end; |
15a52f66 PP |
1806 | default: |
1807 | abort(); | |
1808 | } | |
1809 | } | |
1810 | ||
e253ad8d SM |
1811 | /* |
1812 | * The following messages returned by the next method (including | |
1813 | * post_auto_seek_next) must be after (or at) `ns_from_origin`. | |
1814 | */ | |
1815 | iterator->last_ns_from_origin = ns_from_origin; | |
1816 | ||
15a52f66 | 1817 | end: |
143feff5 SM |
1818 | if (stream_states) { |
1819 | destroy_auto_seek_stream_states(stream_states); | |
1820 | stream_states = NULL; | |
1821 | } | |
a8f90e5d | 1822 | |
15a52f66 | 1823 | set_iterator_state_after_seeking(iterator, status); |
15a52f66 PP |
1824 | return status; |
1825 | } | |
1826 | ||
d73bb381 PP |
1827 | bt_bool bt_self_message_iterator_is_interrupted( |
1828 | const struct bt_self_message_iterator *self_msg_iter) | |
1829 | { | |
1830 | const struct bt_self_component_port_input_message_iterator *iterator = | |
1831 | (const void *) self_msg_iter; | |
1832 | ||
1833 | BT_ASSERT_PRE_NON_NULL(iterator, "Message iterator"); | |
1834 | return (bt_bool) bt_graph_is_interrupted(iterator->graph); | |
1835 | } | |
1836 | ||
b09a5592 PP |
1837 | void bt_self_component_port_input_message_iterator_get_ref( |
1838 | const struct bt_self_component_port_input_message_iterator *iterator) | |
8c6884d9 PP |
1839 | { |
1840 | bt_object_get_ref(iterator); | |
1841 | } | |
1842 | ||
b09a5592 PP |
1843 | void bt_self_component_port_input_message_iterator_put_ref( |
1844 | const struct bt_self_component_port_input_message_iterator *iterator) | |
8c6884d9 PP |
1845 | { |
1846 | bt_object_put_ref(iterator); | |
1847 | } |