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);
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);
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);
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
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;
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
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
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)
{
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;
/*
* 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);
}
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:");
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
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 =
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));
status = iter_status;
goto error;
}
+
+ iterator->config.frozen = true;
}
if (downstream_msg_iter) {
"%!+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.
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.
(*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;
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
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)
{
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);
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)
{
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);
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)
{
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);
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)
{
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);
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)
{
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);
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)
{
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);
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):
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)]
)
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)
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)])
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)])
class _MyIter(bt2._UserMessageIterator):
- def __init__(self, self_output_port):
+ def __init__(self, config, self_output_port):
self._build_meta()
self._at = 0
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
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):
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
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
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(
# 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):
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(
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
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
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
# 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)
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)
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']
)
_msgs = None
class MyIter(bt2._UserMessageIterator):
- def __init__(self, self_output_port):
+ def __init__(self, config, self_output_port):
nonlocal _msgs
self._at = 0
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
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']
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:])
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)
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)
{
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)
{