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