From 572075a867d130d6f997188a8c01aff6337f0bd7 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Mon, 17 Jun 2019 13:01:03 -0400 Subject: [PATCH] iterator: save original next callback in iterator struct When we restore the iterator's next method (after we overrode it with post_auto_seek_next), we inspect the upstream component class to find out what was the original method. It seems simpler to save and restore the function pointer. This is what this patch does. No user-visible changes intended. Change-Id: If5eb7df692d2aa745f7f19e22c8046afb5b8d1d2 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/1485 Tested-by: jenkins Reviewed-by: Philippe Proulx --- src/lib/graph/iterator.c | 32 +++++++------------------------- src/lib/graph/message/iterator.h | 8 ++++++++ 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/src/lib/graph/iterator.c b/src/lib/graph/iterator.c index 6fd22af0..aac7bfc1 100644 --- a/src/lib/graph/iterator.c +++ b/src/lib/graph/iterator.c @@ -1260,31 +1260,10 @@ enum bt_self_message_iterator_status post_auto_seek_next( BT_ASSERT(*count > 0); if (g_queue_is_empty(iterator->auto_seek.msgs)) { - /* No more auto-seek messages */ - switch (iterator->upstream_component->class->type) { - case BT_COMPONENT_CLASS_TYPE_SOURCE: - { - struct bt_component_class_source *src_comp_cls = - (void *) iterator->upstream_component->class; - - iterator->methods.next = - (bt_self_component_port_input_message_iterator_next_method) - src_comp_cls->methods.msg_iter_next; - break; - } - case BT_COMPONENT_CLASS_TYPE_FILTER: - { - struct bt_component_class_filter *flt_comp_cls = - (void *) iterator->upstream_component->class; - - iterator->methods.next = - (bt_self_component_port_input_message_iterator_next_method) - flt_comp_cls->methods.msg_iter_next; - break; - } - default: - abort(); - } + /* No more auto-seek messages, restore user's next callback. */ + BT_ASSERT(iterator->auto_seek.original_next_callback); + iterator->methods.next = iterator->auto_seek.original_next_callback; + iterator->auto_seek.original_next_callback = NULL; } return BT_SELF_MESSAGE_ITERATOR_STATUS_OK; @@ -1377,6 +1356,9 @@ bt_self_component_port_input_message_iterator_seek_ns_from_origin( * which returns them. */ if (!g_queue_is_empty(iterator->auto_seek.msgs)) { + BT_ASSERT(!iterator->auto_seek.original_next_callback); + iterator->auto_seek.original_next_callback = iterator->methods.next; + iterator->methods.next = (bt_self_component_port_input_message_iterator_next_method) post_auto_seek_next; diff --git a/src/lib/graph/message/iterator.h b/src/lib/graph/message/iterator.h index 1ecaa95a..a174f3e9 100644 --- a/src/lib/graph/message/iterator.h +++ b/src/lib/graph/message/iterator.h @@ -131,6 +131,14 @@ struct bt_self_component_port_input_message_iterator { * send is the first of the queue). */ GQueue *msgs; + + /* + * After auto-seeking, we replace the iterator's `next` callback + * with our own, which returns the contents of the `msgs` queue. + * This field is where we save the original callback, so we can + * restore it. + */ + void *original_next_callback; } auto_seek; void *user_data; -- 2.34.1