lib: pass config object to message iterator init method, add can seek forward property
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 18 Sep 2019 20:12:00 +0000 (16:12 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Thu, 26 Sep 2019 01:43:52 +0000 (21:43 -0400)
This patch introduces a new bt_self_message_iterator_configuration
object that is passed to message iterator init methods.  The purpose of
this object is to hold options the message iterator can set at init time
but not later.

To verify that the user does not save a pointer to this object and try
to use it later, the object is frozen right after the init method
returns.

The object contains one option that we know we'll need,
`can_seek_forward`.  The corresponding functions to set it (on the
config object) and read it (from the self component port input message
iterator object) are also provided.  But because this patch already
contains a lot of boilerplate, the code that actually uses that option
will come in a following patch.

The Python bindings provide a simple wrapper around this new object.

Change-Id: Ibcd0df842fd154d3bafe3869b56f70aa3a72ceab
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2064
Tested-by: jenkins <jenkins@lttng.org>
35 files changed:
include/babeltrace2/graph/component-class-filter.h
include/babeltrace2/graph/component-class-source.h
include/babeltrace2/graph/self-component-port-input-message-iterator.h
include/babeltrace2/graph/self-message-iterator.h
include/babeltrace2/types.h
src/bindings/python/bt2/bt2/message_iterator.py
src/bindings/python/bt2/bt2/native_bt_component_class.i.h
src/lib/graph/iterator.c
src/lib/graph/message/iterator.h
src/plugins/ctf/fs-src/fs.c
src/plugins/ctf/fs-src/fs.h
src/plugins/ctf/lttng-live/lttng-live.c
src/plugins/ctf/lttng-live/lttng-live.h
src/plugins/lttng-utils/debug-info/debug-info.c
src/plugins/lttng-utils/debug-info/debug-info.h
src/plugins/text/dmesg/dmesg.c
src/plugins/text/dmesg/dmesg.h
src/plugins/utils/muxer/muxer.c
src/plugins/utils/muxer/muxer.h
src/plugins/utils/trimmer/trimmer.c
src/plugins/utils/trimmer/trimmer.h
tests/bindings/python/bt2/test_clock_class.py
tests/bindings/python/bt2/test_event.py
tests/bindings/python/bt2/test_event_class.py
tests/bindings/python/bt2/test_field.py
tests/bindings/python/bt2/test_field_class.py
tests/bindings/python/bt2/test_graph.py
tests/bindings/python/bt2/test_message.py
tests/bindings/python/bt2/test_message_iterator.py
tests/bindings/python/bt2/utils.py
tests/data/auto-source-discovery/grouping/bt_plugin_test.py
tests/data/auto-source-discovery/params-log-level/bt_plugin_test.py
tests/data/plugins/flt.utils.muxer/bt_plugin_muxer_test.py
tests/data/plugins/flt.utils.trimmer/bt_plugin_trimmer_test.py
tests/lib/test-plugin-plugins/sfs.c

index b95e18fc50f0b8e76ce9a4c606c1c83ae9f74dfd..1907fc0f292f52533bb497a06d169b73c20e053c 100644 (file)
@@ -56,6 +56,7 @@ typedef void (*bt_component_class_filter_finalize_method)(
 typedef bt_component_class_message_iterator_init_method_status
 (*bt_component_class_filter_message_iterator_init_method)(
                bt_self_message_iterator *message_iterator,
+               bt_self_message_iterator_configuration *config,
                bt_self_component_filter *self_component,
                bt_self_component_port_output *port);
 
index e523440313b36611d9026d7658b149f1d0b8edea..5d7c41612a04216be089029339696d6a251c61c9 100644 (file)
@@ -56,6 +56,7 @@ typedef void (*bt_component_class_source_finalize_method)(
 typedef bt_component_class_message_iterator_init_method_status
 (*bt_component_class_source_message_iterator_init_method)(
                bt_self_message_iterator *message_iterator,
+               bt_self_message_iterator_configuration *config,
                bt_self_component_source *self_component,
                bt_self_component_port_output *port);
 
index c83bd8db60cfd42d560f4649619486cc7b917ce9..a0c8c54e47412f84c68550fdd6255a9c71961cbc 100644 (file)
@@ -96,6 +96,10 @@ extern bt_message_iterator_seek_beginning_status
 bt_self_component_port_input_message_iterator_seek_beginning(
                bt_self_component_port_input_message_iterator *iterator);
 
+extern bt_bool
+bt_self_component_port_input_message_iterator_can_seek_forward(
+               bt_self_component_port_input_message_iterator *iterator);
+
 extern void bt_self_component_port_input_message_iterator_get_ref(
                const bt_self_component_port_input_message_iterator *self_component_port_input_message_iterator);
 
index ad528e49ff02f5771947b3012e619bde89fb1702..9aaa2767159918a63a4995e11c684dbd54e880a4 100644 (file)
@@ -51,6 +51,10 @@ extern void bt_self_message_iterator_set_data(
 extern void *bt_self_message_iterator_get_data(
                const bt_self_message_iterator *message_iterator);
 
+extern void bt_self_message_iterator_configuration_set_can_seek_forward(
+               bt_self_message_iterator_configuration *config,
+               bt_bool can_seek_forward);
+
 #ifdef __cplusplus
 }
 #endif
index d9b883ac85d491abd24bddadcf3a909b9b1fcd85..fe74a81a314112bcd2d455c5fd0b30514ca59c3a 100644 (file)
@@ -148,6 +148,7 @@ typedef struct bt_self_component_sink_configuration bt_self_component_sink_confi
 typedef struct bt_self_component_source bt_self_component_source;
 typedef struct bt_self_component_source_configuration bt_self_component_source_configuration;
 typedef struct bt_self_message_iterator bt_self_message_iterator;
+typedef struct bt_self_message_iterator_configuration bt_self_message_iterator_configuration;
 typedef struct bt_self_plugin bt_self_plugin;
 typedef struct bt_stream bt_stream;
 typedef struct bt_stream_class bt_stream_class;
index f57699f6484b523f4c0461f04363a9509ce4065f..3b46c6da5ef4d67071683054f734bb11ef25a931 100644 (file)
@@ -110,6 +110,25 @@ class _UserComponentInputPortMessageIterator(object._SharedObject, _MessageItera
             status, 'message iterator cannot seek given ns from origin'
         )
 
+    @property
+    def can_seek_forward(self):
+        return native_bt.self_component_port_input_message_iterator_can_seek_forward(
+            self._ptr
+        )
+
+
+class _MessageIteratorConfiguration:
+    def __init__(self, ptr):
+        self._ptr = ptr
+
+    def can_seek_forward(self, value):
+        utils._check_bool(value)
+        native_bt.self_message_iterator_configuration_set_can_seek_forward(
+            self._ptr, value
+        )
+
+    can_seek_forward = property(fset=can_seek_forward)
+
 
 # This is extended by the user to implement component classes in Python.  It
 # is created for a given output port when an input port message iterator is
@@ -134,13 +153,14 @@ class _UserMessageIterator(_MessageIterator):
         self._bt_ptr = ptr
         return self
 
-    def _bt_init_from_native(self, self_output_port_ptr):
+    def _bt_init_from_native(self, config_ptr, self_output_port_ptr):
         self_output_port = bt2_port._create_self_from_ptr_and_get_ref(
             self_output_port_ptr, native_bt.PORT_TYPE_OUTPUT
         )
-        self.__init__(self_output_port)
+        config = _MessageIteratorConfiguration(config_ptr)
+        self.__init__(config, self_output_port)
 
-    def __init__(self, output_port):
+    def __init__(self, config, self_output_port):
         pass
 
     @property
index b97193d3ee540202b95a667352acd4a5cc63be86..15ad42900f02402d2a9327b6f7b271f5baba406b 100644 (file)
@@ -935,6 +935,7 @@ static
 bt_component_class_message_iterator_init_method_status
 component_class_message_iterator_init(
                bt_self_message_iterator *self_message_iterator,
+               bt_self_message_iterator_configuration *config,
                bt_self_component *self_component,
                bt_self_component_port_output *self_component_port_output)
 {
@@ -942,6 +943,7 @@ component_class_message_iterator_init(
        PyObject *py_comp_cls = NULL;
        PyObject *py_iter_cls = NULL;
        PyObject *py_iter_ptr = NULL;
+       PyObject *py_config_ptr = NULL;
        PyObject *py_component_port_output_ptr = NULL;
        PyObject *py_init_method_result = NULL;
        PyObject *py_iter = NULL;
@@ -996,15 +998,27 @@ component_class_message_iterator_init(
        /*
         * Initialize object:
         *
-        *     py_iter.__init__(self_output_port)
+        *     py_iter.__init__(config, self_output_port)
         *
-        * through the _init_for_native helper static method.
+        * through the _init_from_native helper static method.
         *
         * At this point, py_iter._ptr is set, so this initialization
         * function has access to self._component (which gives it the
         * user Python component object from which the iterator was
         * created).
         */
+       py_config_ptr = SWIG_NewPointerObj(SWIG_as_voidptr(config),
+               SWIGTYPE_p_bt_self_message_iterator_configuration, 0);
+       if (!py_config_ptr) {
+               const char *err = "Failed to create a SWIG pointer object";
+
+               BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR, log_level, self_component,
+                       "%s", err);
+               BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_MESSAGE_ITERATOR(
+                       self_message_iterator, err);
+               goto error;
+       }
+
        py_component_port_output_ptr = SWIG_NewPointerObj(
                SWIG_as_voidptr(self_component_port_output),
                SWIGTYPE_p_bt_self_component_port_output, 0);
@@ -1019,7 +1033,8 @@ component_class_message_iterator_init(
        }
 
        py_init_method_result = PyObject_CallMethod(py_iter,
-               "_bt_init_from_native", "O", py_component_port_output_ptr);
+               "_bt_init_from_native", "OO", py_config_ptr,
+               py_component_port_output_ptr);
        if (!py_init_method_result) {
                BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR, log_level, self_component,
                        "User's __init__() method failed:");
@@ -1074,24 +1089,30 @@ static
 bt_component_class_message_iterator_init_method_status
 component_class_source_message_iterator_init(
                bt_self_message_iterator *self_message_iterator,
+               bt_self_message_iterator_configuration *config,
                bt_self_component_source *self_component_source,
                bt_self_component_port_output *self_component_port_output)
 {
-       bt_self_component *self_component = bt_self_component_source_as_self_component(self_component_source);
+       bt_self_component *self_component =
+               bt_self_component_source_as_self_component(self_component_source);
 
-       return component_class_message_iterator_init(self_message_iterator, self_component, self_component_port_output);
+       return component_class_message_iterator_init(self_message_iterator,
+               config, self_component, self_component_port_output);
 }
 
 static
 bt_component_class_message_iterator_init_method_status
 component_class_filter_message_iterator_init(
                bt_self_message_iterator *self_message_iterator,
+               bt_self_message_iterator_configuration *config,
                bt_self_component_filter *self_component_filter,
                bt_self_component_port_output *self_component_port_output)
 {
-       bt_self_component *self_component = bt_self_component_filter_as_self_component(self_component_filter);
+       bt_self_component *self_component =
+               bt_self_component_filter_as_self_component(self_component_filter);
 
-       return component_class_message_iterator_init(self_message_iterator, self_component, self_component_port_output);
+       return component_class_message_iterator_init(self_message_iterator,
+               config, self_component, self_component_port_output);
 }
 
 static
index 983f5c100ab5d1a5482742bd080739589f90128c..8af6166a0dd47d5759219c2c4a1d96220a780ffe 100644 (file)
@@ -299,7 +299,7 @@ int create_self_component_input_port_message_iterator(
                struct bt_self_component_port_input_message_iterator **message_iterator)
 {
        typedef enum bt_component_class_message_iterator_init_method_status (*init_method_t)(
-                       void *, void *, void *);
+                       void *, void *, void *, void *);
 
        init_method_t init_method = NULL;
        struct bt_self_component_port_input_message_iterator *iterator =
@@ -472,7 +472,7 @@ int create_self_component_input_port_message_iterator(
                enum bt_component_class_message_iterator_init_method_status iter_status;
 
                BT_LIB_LOGD("Calling user's initialization method: %!+i", iterator);
-               iter_status = init_method(iterator, upstream_comp,
+               iter_status = init_method(iterator, &iterator->config, upstream_comp,
                        upstream_port);
                BT_LOGD("User method returned: status=%s",
                        bt_common_func_status_string(iter_status));
@@ -485,6 +485,8 @@ int create_self_component_input_port_message_iterator(
                        status = iter_status;
                        goto error;
                }
+
+               iterator->config.frozen = true;
        }
 
        if (downstream_msg_iter) {
@@ -561,6 +563,16 @@ void bt_self_message_iterator_set_data(
                "%!+i, user-data-addr=%p", iterator, data);
 }
 
+void bt_self_message_iterator_configuration_set_can_seek_forward(
+               bt_self_message_iterator_configuration *config,
+               bt_bool can_seek_forward)
+{
+       BT_ASSERT_PRE_NON_NULL(config, "Message iterator configuration");
+       BT_ASSERT_PRE_DEV_HOT(config, "Message iterator configuration", "");
+
+       config->can_seek_forward = can_seek_forward;
+}
+
 /*
  * Validate that the default clock snapshot in `msg` doesn't make us go back in
  * time.
@@ -1150,6 +1162,15 @@ bt_self_component_port_input_message_iterator_seek_beginning(
        return status;
 }
 
+bt_bool
+bt_self_component_port_input_message_iterator_can_seek_forward(
+               bt_self_component_port_input_message_iterator *iterator)
+{
+       BT_ASSERT_PRE_NON_NULL(iterator, "Message iterator");
+
+       return iterator->config.can_seek_forward;
+}
+
 /*
  * Structure used to record the state of a given stream during the fast-forward
  * phase of an auto-seek.
index 8014d1fad536c27d8fbd97772a7c014035f17e43..412fe9041046aab97c600eac0b2145970774c25d 100644 (file)
@@ -85,6 +85,11 @@ typedef enum bt_component_class_message_iterator_can_seek_beginning_method_statu
 (*bt_self_component_port_input_message_iterator_can_seek_beginning_method)(
                void *, bt_bool *);
 
+struct bt_self_message_iterator_configuration {
+       bool frozen;
+       bool can_seek_forward;
+};
+
 struct bt_self_component_port_input_message_iterator {
        struct bt_object base;
        GPtrArray *msgs;
@@ -92,6 +97,7 @@ struct bt_self_component_port_input_message_iterator {
        struct bt_port *upstream_port; /* Weak */
        struct bt_connection *connection; /* Weak */
        struct bt_graph *graph; /* Weak */
+       struct bt_self_message_iterator_configuration config;
 
        /*
         * Array of
index 83df6dbed98e06af7cb02e8ecdd73c61b2693163..2149b89c6f0d7d3c9bf6652cb0091004f7e07878 100644 (file)
@@ -250,6 +250,7 @@ void ctf_fs_iterator_finalize(bt_self_message_iterator *it)
 BT_HIDDEN
 bt_component_class_message_iterator_init_method_status ctf_fs_iterator_init(
                bt_self_message_iterator *self_msg_iter,
+               bt_self_message_iterator_configuration *config,
                bt_self_component_source *self_comp_src,
                bt_self_component_port_output *self_port)
 {
index e48c1469a613c4b5cc16e12c3d99c081f040f379..5f8c41285e375b294693a71cff842d80859b5f15 100644 (file)
@@ -215,6 +215,7 @@ bt_component_class_query_method_status ctf_fs_query(
 BT_HIDDEN
 bt_component_class_message_iterator_init_method_status ctf_fs_iterator_init(
                bt_self_message_iterator *self_msg_iter,
+               bt_self_message_iterator_configuration *config,
                bt_self_component_source *self_comp,
                bt_self_component_port_output *self_port);
 
index a79d02b10d3f7abb87c462c2dddf764cb6a04e94..6336ffe5acfc6a1d212e76da721f69f96f8b7286 100644 (file)
@@ -1445,6 +1445,7 @@ no_session:
 BT_HIDDEN
 bt_component_class_message_iterator_init_method_status lttng_live_msg_iter_init(
                bt_self_message_iterator *self_msg_it,
+               bt_self_message_iterator_configuration *config,
                bt_self_component_source *self_comp_src,
                bt_self_component_port_output *self_port)
 {
index 57de598b974473c95e7798b9bc434ff8857d5f23..0c86a687b50c2855f33178a21d63f4829cbbee25 100644 (file)
@@ -280,6 +280,7 @@ bt_component_class_message_iterator_next_method_status lttng_live_msg_iter_next(
 
 bt_component_class_message_iterator_init_method_status lttng_live_msg_iter_init(
                bt_self_message_iterator *self_msg_it,
+               bt_self_message_iterator_configuration *config,
                bt_self_component_source *self_comp,
                bt_self_component_port_output *self_port);
 
index c481f8bf77b5fa930851249ff60c24006968f792..fa2a492e9a8884d435a838112a300fb275cb61f7 100644 (file)
@@ -1958,6 +1958,7 @@ end:
 BT_HIDDEN
 bt_component_class_message_iterator_init_method_status debug_info_msg_iter_init(
                bt_self_message_iterator *self_msg_iter,
+               bt_self_message_iterator_configuration *config,
                bt_self_component_filter *self_comp_flt,
                bt_self_component_port_output *self_port)
 {
index 1c2d106bb27397109af8c59684f6f6324e4fadf2..f39f3bb351125095e075aae1929f9a0ad6be3ab6 100644 (file)
@@ -46,6 +46,7 @@ void debug_info_comp_finalize(bt_self_component_filter *self_comp);
 BT_HIDDEN
 bt_component_class_message_iterator_init_method_status debug_info_msg_iter_init(
                bt_self_message_iterator *self_msg_iter,
+               bt_self_message_iterator_configuration *config,
                bt_self_component_filter *self_comp,
                bt_self_component_port_output *self_port);
 
index 9f22ac868cceb250235267bbd05e41457950ea6f..3ef752c0b58379cdf7b7698d5422c99d57ac9683 100644 (file)
@@ -659,6 +659,7 @@ void destroy_dmesg_msg_iter(struct dmesg_msg_iter *dmesg_msg_iter)
 BT_HIDDEN
 bt_component_class_message_iterator_init_method_status dmesg_msg_iter_init(
                bt_self_message_iterator *self_msg_iter,
+               bt_self_message_iterator_configuration *config,
                bt_self_component_source *self_comp,
                bt_self_component_port_output *self_port)
 {
index f74b3b26b1357077afa3b8e18cdf9a9d42d6cd6b..e997b5e1be5655f2a84d80f8a050490d26a674de 100644 (file)
@@ -39,6 +39,7 @@ void dmesg_finalize(bt_self_component_source *self_comp);
 BT_HIDDEN
 bt_component_class_message_iterator_init_method_status dmesg_msg_iter_init(
                bt_self_message_iterator *self_msg_iter,
+               bt_self_message_iterator_configuration *config,
                bt_self_component_source *self_comp,
                bt_self_component_port_output *self_port);
 
index 7404e1e4ab023a78e9e58ce4b2abfc77c6f88a01..8571b2756944decadf81c0ef52eb819cb9ac8fb0 100644 (file)
@@ -1214,6 +1214,7 @@ end:
 BT_HIDDEN
 bt_component_class_message_iterator_init_method_status muxer_msg_iter_init(
                bt_self_message_iterator *self_msg_iter,
+               bt_self_message_iterator_configuration *config,
                bt_self_component_filter *self_comp,
                bt_self_component_port_output *port)
 {
index 8c3f7f4812a7d61b322ec8c138a5a623fcd3342a..d5eef7ef3c877d6986ff147c4a4032f722de77d0 100644 (file)
@@ -40,6 +40,7 @@ void muxer_finalize(bt_self_component_filter *self_comp);
 BT_HIDDEN
 bt_component_class_message_iterator_init_method_status muxer_msg_iter_init(
                bt_self_message_iterator *self_msg_iter,
+               bt_self_message_iterator_configuration *config,
                bt_self_component_filter *self_comp,
                bt_self_component_port_output *self_port);
 
index 92fad09b6b43c721f67c9d40fa57cbdee43ee42c..4e89581f59838a80fbbbb415825bbc1a6d6a7f4f 100644 (file)
@@ -664,6 +664,7 @@ void destroy_trimmer_iterator_stream_state(
 BT_HIDDEN
 bt_component_class_message_iterator_init_method_status trimmer_msg_iter_init(
                bt_self_message_iterator *self_msg_iter,
+               bt_self_message_iterator_configuration *config,
                bt_self_component_filter *self_comp,
                bt_self_component_port_output *port)
 {
index 34d45efa255c8ec21a13495bfee5e9329a7bec3b..7bf5aaa4e069bbe16a38c330ed48e27baf0ce0df 100644 (file)
@@ -43,6 +43,7 @@ bt_component_class_init_method_status trimmer_init(
 BT_HIDDEN
 bt_component_class_message_iterator_init_method_status trimmer_msg_iter_init(
                bt_self_message_iterator *self_msg_iter,
+               bt_self_message_iterator_configuration *config,
                bt_self_component_filter *self_comp,
                bt_self_component_port_output *port);
 
index 26571bd40bd06b470ee186c4ec79c5cd3d4e116c..c4b34bd29b14110f7674873177600e4db523f085 100644 (file)
@@ -247,7 +247,7 @@ class ClockSnapshotTestCase(unittest.TestCase):
         self._cc = _cc
 
         class MyIter(bt2._UserMessageIterator):
-            def __init__(self, self_port_output):
+            def __init__(self, config, self_port_output):
                 self._at = 0
 
             def __next__(self):
index b6b17ade0c3a7c6c17a801bcbda6b89af73d8553..4288fd91f1471e54bab75be2f3325bc1e5df838b 100644 (file)
@@ -39,7 +39,7 @@ class EventTestCase(unittest.TestCase):
         with_packet=False,
     ):
         class MyIter(bt2._UserMessageIterator):
-            def __init__(self, self_output_port):
+            def __init__(self, config, self_output_port):
                 self._at = 0
                 self._msgs = [self._create_stream_beginning_message(test_obj.stream)]
 
index 6a6eb4cb81308c55300ef07c828fe18bd17520f5..47606b0e2234a193ecc062a02330dc29f804eaab 100644 (file)
@@ -34,7 +34,7 @@ def _create_const_event_class(tc, stream_class):
     )
 
     class MyIter(bt2._UserMessageIterator):
-        def __init__(self, self_port_output):
+        def __init__(self, config, self_port_output):
 
             trace = tc()
             stream = trace.create_stream(stream_class)
index 6271b7706f52803b60a7d7e1ba45542c04431796..47755f2ffdba8d98e9059ba675cb9bde70a50a71 100644 (file)
@@ -73,7 +73,7 @@ def _create_const_field(tc, field_class, field_value_setter_fn):
     field_name = 'const field'
 
     class MyIter(bt2._UserMessageIterator):
-        def __init__(self, self_port_output):
+        def __init__(self, config, self_port_output):
             nonlocal field_class
             nonlocal field_value_setter_fn
             stream = _create_stream(tc, [(field_name, field_class)])
index 3a383fddd7ff911c92035562754b3e98f7005013..01c1a46ae61cd8440dfaab8522b9781ea105393f 100644 (file)
@@ -41,7 +41,7 @@ def _create_const_field_class(tc, field_class, value_setter_fn):
     field_name = 'const field'
 
     class MyIter(bt2._UserMessageIterator):
-        def __init__(self, self_port_output):
+        def __init__(self, config, self_port_output):
             nonlocal field_class
             nonlocal value_setter_fn
             stream = _create_stream(tc, [(field_name, field_class)])
index 347f8803dba0768e946e9b2de59e81f7fe78958f..744f6429274662c23ae5370cbb075d9ae93b5b04 100644 (file)
@@ -21,7 +21,7 @@ import bt2
 
 
 class _MyIter(bt2._UserMessageIterator):
-    def __init__(self, self_output_port):
+    def __init__(self, config, self_output_port):
         self._build_meta()
         self._at = 0
 
index e58e52451d708648012ab2d514bbaf8a2d178eee..012c851f0ea5e64f95bbb72e47dff9fc5e5b9426 100644 (file)
@@ -34,7 +34,7 @@ from bt2 import trace_class as bt2_trace_class
 class AllMessagesTestCase(unittest.TestCase):
     def setUp(self):
         class MyIter(bt2._UserMessageIterator):
-            def __init__(self, self_port_output):
+            def __init__(self, config, self_port_output):
                 self._at = 0
                 self._with_stream_msgs_clock_snapshots = self_port_output.user_data.get(
                     'with_stream_msgs_clock_snapshots', False
index 39d808887988a6111ea97a78a6c4b957898fcc29..b331e4a40996188dd88cc6f0872d2451370d9549 100644 (file)
@@ -21,6 +21,7 @@ import bt2
 import sys
 from utils import TestOutputPortMessageIterator
 from bt2 import port as bt2_port
+from bt2 import message_iterator as bt2_message_iterator
 
 
 class SimpleSink(bt2._UserSinkComponent):
@@ -61,7 +62,7 @@ class UserMessageIteratorTestCase(unittest.TestCase):
         the_output_port_from_iter = None
 
         class MyIter(bt2._UserMessageIterator):
-            def __init__(self, self_port_output):
+            def __init__(self, config, self_port_output):
                 nonlocal initialized
                 nonlocal the_output_port_from_iter
                 initialized = True
@@ -83,7 +84,7 @@ class UserMessageIteratorTestCase(unittest.TestCase):
 
     def test_create_from_message_iterator(self):
         class MySourceIter(bt2._UserMessageIterator):
-            def __init__(self, self_port_output):
+            def __init__(self, config, self_port_output):
                 nonlocal src_iter_initialized
                 src_iter_initialized = True
 
@@ -92,7 +93,7 @@ class UserMessageIteratorTestCase(unittest.TestCase):
                 self._add_output_port('out')
 
         class MyFilterIter(bt2._UserMessageIterator):
-            def __init__(self, self_port_output):
+            def __init__(self, config, self_port_output):
                 nonlocal flt_iter_initialized
                 flt_iter_initialized = True
                 self._up_iter = self._create_input_port_message_iterator(
@@ -120,7 +121,7 @@ class UserMessageIteratorTestCase(unittest.TestCase):
         # and _UserMessageIterator._create_input_port_message_iterator, as they
         # are both used in the graph.
         class MySourceIter(bt2._UserMessageIterator):
-            def __init__(self, self_port_output):
+            def __init__(self, config, self_port_output):
                 raise ValueError('Very bad error')
 
         class MySource(bt2._UserSourceComponent, message_iterator_class=MySourceIter):
@@ -128,7 +129,7 @@ class UserMessageIteratorTestCase(unittest.TestCase):
                 self._add_output_port('out')
 
         class MyFilterIter(bt2._UserMessageIterator):
-            def __init__(self, self_port_output):
+            def __init__(self, config, self_port_output):
                 # This is expected to raise because of the error in
                 # MySourceIter.__init__.
                 self._create_input_port_message_iterator(
@@ -169,9 +170,74 @@ class UserMessageIteratorTestCase(unittest.TestCase):
         del graph
         self.assertTrue(finalized)
 
+    def test_config_parameter(self):
+        class MyIter(bt2._UserMessageIterator):
+            def __init__(self, config, port):
+                nonlocal config_type
+                config_type = type(config)
+
+        class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter):
+            def __init__(self, config, params, obj):
+                self._add_output_port('out')
+
+        config_type = None
+        graph = _create_graph(MySource, SimpleSink)
+        graph.run()
+        self.assertIs(config_type, bt2_message_iterator._MessageIteratorConfiguration)
+
+    def _test_config_can_seek_forward(self, set_can_seek_forward):
+        class MyIter(bt2._UserMessageIterator):
+            def __init__(self, config, port):
+                if set_can_seek_forward:
+                    config.can_seek_forward = True
+
+        class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter):
+            def __init__(self, config, params, obj):
+                self._add_output_port('out')
+
+        class MySink(bt2._UserSinkComponent):
+            def __init__(self, config, params, obj):
+                self._add_input_port('in')
+
+            def _user_graph_is_configured(self):
+                self._msg_iter = self._create_input_port_message_iterator(
+                    self._input_ports['in']
+                )
+
+            def _user_consume(self):
+                nonlocal can_seek_forward
+                can_seek_forward = self._msg_iter.can_seek_forward
+
+        can_seek_forward = None
+        graph = _create_graph(MySource, MySink)
+        graph.run_once()
+        self.assertIs(can_seek_forward, set_can_seek_forward)
+
+    def test_config_can_seek_forward_default(self):
+        self._test_config_can_seek_forward(False)
+
+    def test_config_can_seek_forward(self):
+        self._test_config_can_seek_forward(True)
+
+    def test_config_can_seek_forward_wrong_type(self):
+        class MyIter(bt2._UserMessageIterator):
+            def __init__(self, config, port):
+                config.can_seek_forward = 1
+
+        class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter):
+            def __init__(self, config, params, obj):
+                self._add_output_port('out')
+
+        graph = _create_graph(MySource, SimpleSink)
+        with self.assertRaises(bt2._Error) as ctx:
+            graph.run()
+
+        root_cause = ctx.exception[0]
+        self.assertIn("TypeError: 'int' is not a 'bool' object", root_cause.message)
+
     def test_component(self):
         class MyIter(bt2._UserMessageIterator):
-            def __init__(self, self_port_output):
+            def __init__(self, config, self_port_output):
                 nonlocal salut
                 salut = self._component._salut
 
@@ -187,7 +253,7 @@ class UserMessageIteratorTestCase(unittest.TestCase):
 
     def test_port(self):
         class MyIter(bt2._UserMessageIterator):
-            def __init__(self_iter, self_port_output):
+            def __init__(self_iter, config, self_port_output):
                 nonlocal called
                 called = True
                 port = self_iter._port
@@ -206,7 +272,7 @@ class UserMessageIteratorTestCase(unittest.TestCase):
 
     def test_addr(self):
         class MyIter(bt2._UserMessageIterator):
-            def __init__(self, self_port_output):
+            def __init__(self, config, self_port_output):
                 nonlocal addr
                 addr = self.addr
 
@@ -224,7 +290,7 @@ class UserMessageIteratorTestCase(unittest.TestCase):
     # and can be re-used.
     def test_reuse_message(self):
         class MyIter(bt2._UserMessageIterator):
-            def __init__(self, port):
+            def __init__(self, config, port):
                 tc, sc, ec = port.user_data
                 trace = tc()
                 stream = trace.create_stream(sc)
@@ -322,7 +388,7 @@ def _setup_seek_test(
     user_can_seek_ns_from_origin=None,
 ):
     class MySourceIter(bt2._UserMessageIterator):
-        def __init__(self, port):
+        def __init__(self, config, port):
             tc, sc, ec = port.user_data
             trace = tc()
             stream = trace.create_stream(sc)
@@ -367,7 +433,7 @@ def _setup_seek_test(
             self._add_output_port('out', (tc, sc, ec))
 
     class MyFilterIter(bt2._UserMessageIterator):
-        def __init__(self, port):
+        def __init__(self, config, port):
             self._upstream_iter = self._create_input_port_message_iterator(
                 self._component._input_ports['in']
             )
index f0ddbff4502cf5ae2a0e1c4ae472bda659e3e7eb..a7ea3cde35155fb8faee61aaa7485ca9cc79bc8a 100644 (file)
@@ -65,7 +65,7 @@ def _get_all_message_types(with_packet=True):
     _msgs = None
 
     class MyIter(bt2._UserMessageIterator):
-        def __init__(self, self_output_port):
+        def __init__(self, config, self_output_port):
 
             nonlocal _msgs
             self._at = 0
index dd4d5a4b73288a629e4276ecf36797976f685661..18c396eb423d2498d97cebbfdd0a68fce0b576b0 100644 (file)
@@ -8,7 +8,7 @@ import os
 
 
 class TestIter(bt2._UserMessageIterator):
-    def __init__(self, output_port):
+    def __init__(self, config, output_port):
         inputs = output_port.user_data['inputs']
         sc = output_port.user_data['sc']
         tc = sc.trace_class
index c39db50ffb95c9a40a65cd54190a60392dd62386..ddbf977160f118aa2323f20cc61d174c28fa509e 100644 (file)
@@ -12,7 +12,7 @@ import os
 
 
 class TestIter(bt2._UserMessageIterator):
-    def __init__(self, output_port):
+    def __init__(self, config, output_port):
         params = output_port.user_data['params']
         obj = output_port.user_data['obj']
 
index b81c26dbfbfba627607cfa43c52db080d58128bf..c263d20396060017deb108d68e85d0bbee8bb406 100644 (file)
@@ -2,7 +2,7 @@ import bt2
 
 
 class TheIteratorOfConfusion(bt2._UserMessageIterator):
-    def __init__(self, port):
+    def __init__(self, config, port):
         self._at = 0
         test_name = port.user_data[0]
         TEST_CASES[test_name].create_msgs(self, port.user_data[1:])
index 3a37b32963fc2444a0a796bca73566f7224288b4..9f337356c8552e644a78833f5a4afe55754faecc 100644 (file)
@@ -2,7 +2,7 @@ import bt2
 
 
 class TheIteratorOfAllEvil(bt2._UserMessageIterator):
-    def __init__(self, port):
+    def __init__(self, config, port):
         tc, sc, ec1, ec2, params = port.user_data
         trace = tc()
         stream = trace.create_stream(sc)
index 93ca71101762b170bec16fc3eb406be56fe9e0b8..229d0ede1e1dc622fb327cbd6cd1228fd273119f 100644 (file)
@@ -27,6 +27,7 @@ static bt_component_class_sink_consume_method_status sink_consume(
 static bt_component_class_message_iterator_init_method_status
 src_dummy_iterator_init_method(
                bt_self_message_iterator *self_msg_iter,
+               bt_self_message_iterator_configuration *config,
                bt_self_component_source *self_comp,
                bt_self_component_port_output *self_port)
 {
@@ -36,6 +37,7 @@ src_dummy_iterator_init_method(
 static bt_component_class_message_iterator_init_method_status
 flt_dummy_iterator_init_method(
                bt_self_message_iterator *self_msg_iter,
+               bt_self_message_iterator_configuration *config,
                bt_self_component_filter *self_comp,
                bt_self_component_port_output *self_port)
 {
This page took 0.040561 seconds and 4 git commands to generate.