iterator: save original next callback in iterator struct
authorSimon Marchi <simon.marchi@efficios.com>
Mon, 17 Jun 2019 17:01:03 +0000 (13:01 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 27 Jun 2019 17:58:21 +0000 (13:58 -0400)
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 <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1485
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
src/lib/graph/iterator.c
src/lib/graph/message/iterator.h

index 6fd22af01d5695219493c218a85e4760ee4838ab..aac7bfc197872f737b7e3b32af5f94a8e615a451 100644 (file)
@@ -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;
index 1ecaa95a991d29329a2816d1ffcc6dd0ca160bca..a174f3e9c17f99c4fb879c7db4c067c314250f5a 100644 (file)
@@ -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;
This page took 0.027061 seconds and 4 git commands to generate.