extern "C" {
#endif
+typedef enum bt_self_component_port_input_message_iterator_create_from_message_iterator_status {
+ BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_CREATE_FROM_MESSAGE_ITERATOR_STATUS_OK = __BT_FUNC_STATUS_OK,
+ BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_CREATE_FROM_MESSAGE_ITERATOR_STATUS_ERROR = __BT_FUNC_STATUS_ERROR,
+ BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_CREATE_FROM_MESSAGE_ITERATOR_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR,
+} bt_self_component_port_input_message_iterator_create_from_message_iterator_status;
+
+typedef enum bt_self_component_port_input_message_iterator_create_from_sink_component_status {
+ BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_CREATE_FROM_SINK_COMPONENT_STATUS_OK = __BT_FUNC_STATUS_OK,
+ BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_CREATE_FROM_SINK_COMPONENT_STATUS_ERROR = __BT_FUNC_STATUS_ERROR,
+ BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_CREATE_FROM_SINK_COMPONENT_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR,
+} bt_self_component_port_input_message_iterator_create_from_sink_component_status;
+
static inline
bt_message_iterator *
bt_self_component_port_input_message_iterator_as_message_iterator(
return __BT_UPCAST(bt_message_iterator, iterator);
}
-extern bt_self_component_port_input_message_iterator *
+extern bt_self_component_port_input_message_iterator_create_from_message_iterator_status
bt_self_component_port_input_message_iterator_create_from_message_iterator(
bt_self_message_iterator *self_msg_iter,
- bt_self_component_port_input *input_port);
+ bt_self_component_port_input *input_port,
+ bt_self_component_port_input_message_iterator **message_iterator);
-extern bt_self_component_port_input_message_iterator *
+extern bt_self_component_port_input_message_iterator_create_from_sink_component_status
bt_self_component_port_input_message_iterator_create_from_sink_component(
bt_self_component_sink *self_comp,
- bt_self_component_port_input *input_port);
+ bt_self_component_port_input *input_port,
+ bt_self_component_port_input_message_iterator **message_iterator);
extern bt_component *
bt_self_component_port_input_message_iterator_borrow_component(
def _create_input_port_message_iterator(self, input_port):
utils._check_type(input_port, bt2_port._UserComponentInputPort)
- msg_iter_ptr = native_bt.self_component_port_input_message_iterator_create_from_sink_component(
+ status, msg_iter_ptr = native_bt.bt2_self_component_port_input_message_iterator_create_from_sink_component(
self._bt_ptr, input_port._ptr
)
-
- if msg_iter_ptr is None:
- raise bt2._MemoryError('cannot create message iterator object')
+ utils._handle_func_status(status, 'cannot create message iterator object')
+ assert msg_iter_ptr is not None
return bt2_message_iterator._UserComponentInputPortMessageIterator(msg_iter_ptr)
def _create_input_port_message_iterator(self, input_port):
utils._check_type(input_port, bt2_port._UserComponentInputPort)
- msg_iter_ptr = native_bt.self_component_port_input_message_iterator_create_from_message_iterator(
+ status, msg_iter_ptr = native_bt.bt2_self_component_port_input_message_iterator_create_from_message_iterator(
self._bt_ptr, input_port._ptr
)
-
- if msg_iter_ptr is None:
- raise bt2._MemoryError('cannot create message iterator object')
+ utils._handle_func_status(status, 'cannot create message iterator object')
+ assert msg_iter_ptr is not None
return _UserComponentInputPortMessageIterator(msg_iter_ptr)
* THE SOFTWARE.
*/
+/* Output argument typemap for message_iterator (always appends) */
+%typemap(in, numinputs=0)
+ (bt_self_component_port_input_message_iterator **)
+ (bt_self_component_port_input_message_iterator *temp_msg_iter = NULL) {
+ $1 = &temp_msg_iter;
+}
+
+%typemap(argout)
+ (bt_self_component_port_input_message_iterator **) {
+ if (*$1) {
+ /* SWIG_Python_AppendOutput() steals the created object */
+ $result = SWIG_Python_AppendOutput($result,
+ SWIG_NewPointerObj(SWIG_as_voidptr(*$1),
+ SWIGTYPE_p_bt_self_component_port_input_message_iterator, 0));
+ } else {
+ /* SWIG_Python_AppendOutput() steals Py_None */
+ Py_INCREF(Py_None);
+ $result = SWIG_Python_AppendOutput($result, Py_None);
+ }
+}
+
%include <babeltrace2/graph/message-iterator.h>
%include <babeltrace2/graph/self-component-port-input-message-iterator.h>
%include <babeltrace2/graph/self-message-iterator.h>
#include "native_bt_message_iterator.i.h"
%}
+bt_self_component_port_input_message_iterator_create_from_message_iterator_status
+bt_bt2_self_component_port_input_message_iterator_create_from_message_iterator(
+ bt_self_message_iterator *self_msg_iter,
+ bt_self_component_port_input *input_port,
+ bt_self_component_port_input_message_iterator **message_iterator);
+bt_self_component_port_input_message_iterator_create_from_sink_component_status
+bt_bt2_self_component_port_input_message_iterator_create_from_sink_component(
+ bt_self_component_sink *self_comp,
+ bt_self_component_port_input *input_port,
+ bt_self_component_port_input_message_iterator **message_iterator);
PyObject *bt_bt2_get_user_component_from_user_msg_iter(
bt_self_message_iterator *self_message_iterator);
PyObject *bt_bt2_self_component_port_input_get_msg_range(
* THE SOFTWARE.
*/
+bt_self_component_port_input_message_iterator_create_from_message_iterator_status
+bt_bt2_self_component_port_input_message_iterator_create_from_message_iterator(
+ bt_self_message_iterator *self_msg_iter,
+ bt_self_component_port_input *input_port,
+ bt_self_component_port_input_message_iterator **message_iterator)
+{
+ bt_self_component_port_input_message_iterator_create_from_message_iterator_status
+ status;
+
+ status = bt_self_component_port_input_message_iterator_create_from_message_iterator(
+ self_msg_iter, input_port, message_iterator);
+
+ if (status != BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_CREATE_FROM_MESSAGE_ITERATOR_STATUS_OK) {
+ *message_iterator = NULL;
+ }
+
+ return status;
+}
+
+bt_self_component_port_input_message_iterator_create_from_sink_component_status
+bt_bt2_self_component_port_input_message_iterator_create_from_sink_component(
+ bt_self_component_sink *self_comp,
+ bt_self_component_port_input *input_port,
+ bt_self_component_port_input_message_iterator **message_iterator)
+{
+ bt_self_component_port_input_message_iterator_create_from_sink_component_status
+ status;
+
+ status = bt_self_component_port_input_message_iterator_create_from_sink_component(
+ self_comp, input_port, message_iterator);
+
+ if (status != BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_CREATE_FROM_SINK_COMPONENT_STATUS_OK) {
+ *message_iterator = NULL;
+ }
+
+ return status;
+}
+
static PyObject *bt_bt2_get_user_component_from_user_msg_iter(
bt_self_message_iterator *self_message_iterator)
{
simple_sink_graph_is_configured(
bt_self_component_sink *self_comp)
{
- int status = BT_FUNC_STATUS_OK;
+ bt_component_class_sink_graph_is_configured_method_status status;
+ bt_self_component_port_input_message_iterator_create_from_sink_component_status
+ msg_iter_status;
struct simple_sink_data *data = bt_self_component_get_data(
bt_self_component_sink_as_self_component(self_comp));
BT_LIB_LOGE_APPEND_CAUSE(
"Simple sink component's input port is not connected: "
"%![comp-]+c, %![port-]+p", self_comp, self_port);
- status = BT_FUNC_STATUS_ERROR;
+ status = BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_ERROR;
goto end;
}
BT_ASSERT(data);
- data->msg_iter =
- bt_self_component_port_input_message_iterator_create_from_sink_component(
- self_comp, self_port);
- if (!data->msg_iter) {
+ msg_iter_status = bt_self_component_port_input_message_iterator_create_from_sink_component(
+ self_comp, self_port, &data->msg_iter);
+ if (msg_iter_status != BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_CREATE_FROM_SINK_COMPONENT_STATUS_OK) {
BT_LIB_LOGE_APPEND_CAUSE(
"Cannot create input port message iterator: "
"%![comp-]+c, %![port-]+p", self_comp, self_port);
- status = BT_FUNC_STATUS_MEMORY_ERROR;
+ status = (int) msg_iter_status;
goto end;
}
if (data->init_method_data.init_func) {
+ bt_graph_simple_sink_component_init_func_status init_status;
+
/* Call user's initialization function */
- status = data->init_method_data.init_func(data->msg_iter,
+ init_status = data->init_method_data.init_func(data->msg_iter,
data->init_method_data.user_data);
- if (status != BT_FUNC_STATUS_OK) {
+ if (init_status != BT_GRAPH_SIMPLE_SINK_COMPONENT_INIT_FUNC_STATUS_OK) {
BT_LIB_LOGW_APPEND_CAUSE(
"Simple sink component's user's initialization function failed: "
"status=%s, %![comp-]+c, %![port-]+p",
- bt_common_func_status_string(status),
+ bt_common_func_status_string(init_status),
self_comp, self_port);
+ status = (int) init_status;
goto end;
}
}
+ status = BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_OK;
+
end:
return status;
}
}
static
-struct bt_self_component_port_input_message_iterator *
-create_self_component_input_port_message_iterator(
+int create_self_component_input_port_message_iterator(
struct bt_self_message_iterator *self_downstream_msg_iter,
- struct bt_self_component_port_input *self_port)
+ struct bt_self_component_port_input *self_port,
+ 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 *);
struct bt_component *comp;
struct bt_component *upstream_comp;
struct bt_component_class *upstream_comp_cls;
+ int status;
+ BT_ASSERT_PRE_NON_NULL(message_iterator, "Created message iterator");
BT_ASSERT_PRE_NON_NULL(port, "Input port");
comp = bt_port_borrow_component_inline(port);
BT_ASSERT_PRE(bt_port_is_connected(port),
BT_LIB_LOGE_APPEND_CAUSE(
"Failed to allocate one self component input port "
"message iterator.");
+ status = BT_FUNC_STATUS_MEMORY_ERROR;
goto error;
}
iterator->msgs = g_ptr_array_new();
if (!iterator->msgs) {
BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
+ status = BT_FUNC_STATUS_MEMORY_ERROR;
goto error;
}
iterator->auto_seek.msgs = g_queue_new();
if (!iterator->auto_seek.msgs) {
BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GQueue.");
+ status = BT_FUNC_STATUS_MEMORY_ERROR;
goto error;
}
iterator->upstream_msg_iters = g_ptr_array_new();
if (!iterator->upstream_msg_iters) {
BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
+ status = BT_FUNC_STATUS_MEMORY_ERROR;
goto error;
}
"%![iter-]+i, status=%s",
iterator,
bt_common_func_status_string(iter_status));
+ status = iter_status;
goto error;
}
}
BT_LIB_LOGI("Created message iterator on self component input port: "
"%![up-port-]+p, %![up-comp-]+c, %![iter-]+i",
upstream_port, upstream_comp, iterator);
+
+ *message_iterator = iterator;
+ status = BT_FUNC_STATUS_OK;
goto end;
error:
BT_OBJECT_PUT_REF_AND_RESET(iterator);
end:
- return iterator;
+ return status;
}
-struct bt_self_component_port_input_message_iterator *
+bt_self_component_port_input_message_iterator_create_from_message_iterator_status
bt_self_component_port_input_message_iterator_create_from_message_iterator(
struct bt_self_message_iterator *self_msg_iter,
- struct bt_self_component_port_input *input_port)
+ struct bt_self_component_port_input *input_port,
+ struct bt_self_component_port_input_message_iterator **message_iterator)
{
BT_ASSERT_PRE_NON_NULL(self_msg_iter, "Message iterator");
return create_self_component_input_port_message_iterator(self_msg_iter,
- input_port);
+ input_port, message_iterator);
}
-struct bt_self_component_port_input_message_iterator *
+bt_self_component_port_input_message_iterator_create_from_sink_component_status
bt_self_component_port_input_message_iterator_create_from_sink_component(
struct bt_self_component_sink *self_comp,
- struct bt_self_component_port_input *input_port)
+ struct bt_self_component_port_input *input_port,
+ struct bt_self_component_port_input_message_iterator **message_iterator)
{
BT_ASSERT_PRE_NON_NULL(self_comp, "Sink component");
return create_self_component_input_port_message_iterator(NULL,
- input_port);
+ input_port, message_iterator);
}
void *bt_self_message_iterator_get_data(
}
BT_HIDDEN
-bt_component_class_sink_graph_is_configured_method_status ctf_fs_sink_graph_is_configured(
+bt_component_class_sink_graph_is_configured_method_status
+ctf_fs_sink_graph_is_configured(
bt_self_component_sink *self_comp)
{
- bt_component_class_sink_graph_is_configured_method_status status =
- BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_OK;
+ bt_component_class_sink_graph_is_configured_method_status status;
+ bt_self_component_port_input_message_iterator_create_from_sink_component_status
+ msg_iter_status;
struct fs_sink_comp *fs_sink = bt_self_component_get_data(
bt_self_component_sink_as_self_component(self_comp));
- fs_sink->upstream_iter =
+ msg_iter_status =
bt_self_component_port_input_message_iterator_create_from_sink_component(
self_comp,
bt_self_component_sink_borrow_input_port_by_name(
- self_comp, in_port_name));
- if (!fs_sink->upstream_iter) {
- status = BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_ERROR;
+ self_comp, in_port_name), &fs_sink->upstream_iter);
+ if (msg_iter_status != BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_CREATE_FROM_SINK_COMPONENT_STATUS_OK) {
+ status = (int) msg_iter_status;
goto end;
}
+ status = BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_OK;
end:
return status;
}
bt_self_component_filter *self_comp_flt,
bt_self_component_port_output *self_port)
{
- bt_component_class_message_iterator_init_method_status status =
- BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_OK;
+ bt_component_class_message_iterator_init_method_status status;
+ bt_self_component_port_input_message_iterator_create_from_message_iterator_status
+ msg_iter_status;
struct bt_self_component_port_input *input_port = NULL;
bt_self_component_port_input_message_iterator *upstream_iterator = NULL;
struct debug_info_msg_iter *debug_info_msg_iter = NULL;
debug_info_msg_iter->self_comp = self_comp;
/* Create an iterator on the upstream component. */
- upstream_iterator = bt_self_component_port_input_message_iterator_create_from_message_iterator(
- self_msg_iter, input_port);
- if (!upstream_iterator) {
- status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_MEMORY_ERROR;
+ msg_iter_status = bt_self_component_port_input_message_iterator_create_from_message_iterator(
+ self_msg_iter, input_port, &upstream_iterator);
+ if (msg_iter_status != BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_CREATE_FROM_MESSAGE_ITERATOR_STATUS_OK) {
+ status = (int) msg_iter_status;
goto error;
}
bt_self_message_iterator_set_data(self_msg_iter, debug_info_msg_iter);
debug_info_msg_iter->input_iterator = self_msg_iter;
+ status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_OK;
goto end;
error:
bt_component_class_sink_graph_is_configured_method_status
details_graph_is_configured(bt_self_component_sink *comp)
{
- bt_component_class_sink_graph_is_configured_method_status status =
- BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_OK;
+ bt_component_class_sink_graph_is_configured_method_status status;
+ bt_self_component_port_input_message_iterator_create_from_sink_component_status
+ msg_iter_status;
bt_self_component_port_input_message_iterator *iterator;
struct details_comp *details_comp;
bt_self_component_port_input *in_port;
goto end;
}
- iterator = bt_self_component_port_input_message_iterator_create_from_sink_component(
+ msg_iter_status = bt_self_component_port_input_message_iterator_create_from_sink_component(
comp, bt_self_component_sink_borrow_input_port_by_name(comp,
- in_port_name));
- if (!iterator) {
- status = BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_MEMORY_ERROR;
+ in_port_name), &iterator);
+ if (msg_iter_status != BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_CREATE_FROM_SINK_COMPONENT_STATUS_OK) {
+ status = (int) msg_iter_status;
goto end;
}
BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_MOVE_REF(
details_comp->msg_iter, iterator);
+ status = BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_OK;
+
end:
return status;
}
bt_component_class_sink_graph_is_configured_method_status
pretty_graph_is_configured(bt_self_component_sink *comp)
{
- bt_component_class_sink_graph_is_configured_method_status status =
- BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_OK;
+ bt_component_class_sink_graph_is_configured_method_status status;
+ bt_self_component_port_input_message_iterator_create_from_sink_component_status
+ msg_iter_status;
struct pretty_component *pretty;
pretty = bt_self_component_get_data(
bt_self_component_sink_as_self_component(comp));
BT_ASSERT(pretty);
BT_ASSERT(!pretty->iterator);
- pretty->iterator = bt_self_component_port_input_message_iterator_create_from_sink_component(
+ msg_iter_status = bt_self_component_port_input_message_iterator_create_from_sink_component(
comp, bt_self_component_sink_borrow_input_port_by_name(comp,
- in_port_name));
- if (!pretty->iterator) {
- status = BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_ERROR;
+ in_port_name), &pretty->iterator);
+ if (msg_iter_status != BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_CREATE_FROM_SINK_COMPONENT_STATUS_OK) {
+ status = (int) msg_iter_status;
+ goto end;
}
+ status = BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_OK;
+
+end:
return status;
}
counter_graph_is_configured(
bt_self_component_sink *comp)
{
- bt_component_class_sink_graph_is_configured_method_status status =
- BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_OK;
+ bt_component_class_sink_graph_is_configured_method_status status;
+ bt_self_component_port_input_message_iterator_create_from_sink_component_status
+ msg_iter_status;
struct counter *counter;
bt_self_component_port_input_message_iterator *iterator;
counter = bt_self_component_get_data(
bt_self_component_sink_as_self_component(comp));
BT_ASSERT(counter);
- iterator = bt_self_component_port_input_message_iterator_create_from_sink_component(
+
+ msg_iter_status = bt_self_component_port_input_message_iterator_create_from_sink_component(
comp, bt_self_component_sink_borrow_input_port_by_name(comp,
- in_port_name));
- if (!iterator) {
- status = BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_MEMORY_ERROR;
+ in_port_name), &iterator);
+ if (msg_iter_status != BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_CREATE_FROM_SINK_COMPONENT_STATUS_OK) {
+ status = (int) msg_iter_status;
goto end;
}
BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_MOVE_REF(
counter->msg_iter, iterator);
+ status = BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_OK;
end:
return status;
}
bt_component_class_sink_graph_is_configured_method_status dummy_graph_is_configured(
bt_self_component_sink *comp)
{
- bt_component_class_sink_graph_is_configured_method_status status =
- BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_OK;
+ bt_component_class_sink_graph_is_configured_method_status status;
+ bt_self_component_port_input_message_iterator_create_from_sink_component_status
+ msg_iter_status;
struct dummy *dummy;
bt_self_component_port_input_message_iterator *iterator;
dummy = bt_self_component_get_data(
bt_self_component_sink_as_self_component(comp));
BT_ASSERT(dummy);
- iterator = bt_self_component_port_input_message_iterator_create_from_sink_component(
+ msg_iter_status = bt_self_component_port_input_message_iterator_create_from_sink_component(
comp, bt_self_component_sink_borrow_input_port_by_name(comp,
- in_port_name));
- if (!iterator) {
- status = BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_MEMORY_ERROR;
+ in_port_name), &iterator);
+ if (msg_iter_status != BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_CREATE_FROM_SINK_COMPONENT_STATUS_OK) {
+ status = (int) msg_iter_status;
goto end;
}
BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_MOVE_REF(
dummy->msg_iter, iterator);
+ status = BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_OK;
+
end:
return status;
}
}
static
-bt_self_component_port_input_message_iterator *
+bt_self_component_port_input_message_iterator_create_from_message_iterator_status
create_msg_iter_on_input_port(struct muxer_comp *muxer_comp,
struct muxer_msg_iter *muxer_msg_iter,
- bt_self_component_port_input *self_port)
+ bt_self_component_port_input *self_port,
+ bt_self_component_port_input_message_iterator **msg_iter)
{
const bt_port *port = bt_self_component_port_as_port(
bt_self_component_port_input_as_self_component_port(
self_port));
- bt_self_component_port_input_message_iterator *msg_iter =
- NULL;
+ bt_self_component_port_input_message_iterator_create_from_message_iterator_status
+ status;
BT_ASSERT(port);
BT_ASSERT(bt_port_is_connected(port));
// TODO: Advance the iterator to >= the time of the latest
// returned message by the muxer message
// iterator which creates it.
- msg_iter = bt_self_component_port_input_message_iterator_create_from_message_iterator(
- muxer_msg_iter->self_msg_iter, self_port);
- if (!msg_iter) {
+ status = bt_self_component_port_input_message_iterator_create_from_message_iterator(
+ muxer_msg_iter->self_msg_iter, self_port, msg_iter);
+ if (status != BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_CREATE_FROM_MESSAGE_ITERATOR_STATUS_OK) {
BT_COMP_LOGE("Cannot create upstream message iterator on input port: "
"port-addr=%p, port-name=\"%s\"",
port, bt_port_get_name(port));
port, bt_port_get_name(port), msg_iter);
end:
- return msg_iter;
+ return status;
}
static
}
static
-int muxer_msg_iter_init_upstream_iterators(struct muxer_comp *muxer_comp,
+bt_component_class_message_iterator_init_method_status
+muxer_msg_iter_init_upstream_iterators(struct muxer_comp *muxer_comp,
struct muxer_msg_iter *muxer_msg_iter)
{
int64_t count;
int64_t i;
- int ret = 0;
+ bt_component_class_message_iterator_init_method_status status;
count = bt_component_filter_get_input_port_count(
bt_self_component_filter_as_component_filter(
BT_COMP_LOGD("No input port to initialize for muxer component's message iterator: "
"muxer-comp-addr=%p, muxer-msg-iter-addr=%p",
muxer_comp, muxer_msg_iter);
+ status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_OK;
goto end;
}
bt_self_component_filter_borrow_input_port_by_index(
muxer_comp->self_comp_flt, i);
const bt_port *port;
+ bt_self_component_port_input_message_iterator_create_from_message_iterator_status
+ msg_iter_status;
+ int int_status;
BT_ASSERT(self_port);
port = bt_self_component_port_as_port(
continue;
}
- upstream_msg_iter = create_msg_iter_on_input_port(muxer_comp,
- muxer_msg_iter, self_port);
- if (!upstream_msg_iter) {
+ msg_iter_status = create_msg_iter_on_input_port(muxer_comp,
+ muxer_msg_iter, self_port, &upstream_msg_iter);
+ if (msg_iter_status != BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_CREATE_FROM_MESSAGE_ITERATOR_STATUS_OK) {
/* create_msg_iter_on_input_port() logs errors */
- BT_ASSERT(!upstream_msg_iter);
- ret = -1;
+ status = (int) msg_iter_status;
goto end;
}
- ret = muxer_msg_iter_add_upstream_msg_iter(muxer_msg_iter,
+ int_status = muxer_msg_iter_add_upstream_msg_iter(muxer_msg_iter,
upstream_msg_iter);
bt_self_component_port_input_message_iterator_put_ref(
upstream_msg_iter);
- if (ret) {
+ if (int_status) {
+ status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_ERROR;
/* muxer_msg_iter_add_upstream_msg_iter() logs errors */
goto end;
}
}
+ status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_OK;
+
end:
- return ret;
+ return status;
}
BT_HIDDEN
{
struct muxer_comp *muxer_comp = NULL;
struct muxer_msg_iter *muxer_msg_iter = NULL;
- bt_component_class_message_iterator_init_method_status status =
- BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_OK;
- int ret;
+ bt_component_class_message_iterator_init_method_status status;
muxer_comp = bt_self_component_get_data(
bt_self_component_filter_as_self_component(self_comp));
BT_COMP_LOGE("Recursive initialization of muxer component's message iterator: "
"comp-addr=%p, muxer-comp-addr=%p, msg-iter-addr=%p",
self_comp, muxer_comp, self_msg_iter);
+ status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_ERROR;
goto error;
}
muxer_msg_iter = g_new0(struct muxer_msg_iter, 1);
if (!muxer_msg_iter) {
BT_COMP_LOGE_STR("Failed to allocate one muxer component's message iterator.");
+ status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_MEMORY_ERROR;
goto error;
}
(GDestroyNotify) destroy_muxer_upstream_msg_iter);
if (!muxer_msg_iter->active_muxer_upstream_msg_iters) {
BT_COMP_LOGE_STR("Failed to allocate a GPtrArray.");
+ status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_MEMORY_ERROR;
goto error;
}
(GDestroyNotify) destroy_muxer_upstream_msg_iter);
if (!muxer_msg_iter->ended_muxer_upstream_msg_iters) {
BT_COMP_LOGE_STR("Failed to allocate a GPtrArray.");
+ status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_MEMORY_ERROR;
goto error;
}
- ret = muxer_msg_iter_init_upstream_iterators(muxer_comp,
+ status = muxer_msg_iter_init_upstream_iterators(muxer_comp,
muxer_msg_iter);
- if (ret) {
+ if (status) {
BT_COMP_LOGE("Cannot initialize connected input ports for muxer component's message iterator: "
"comp-addr=%p, muxer-comp-addr=%p, "
"muxer-msg-iter-addr=%p, msg-iter-addr=%p, ret=%d",
self_comp, muxer_comp, muxer_msg_iter,
- self_msg_iter, ret);
+ self_msg_iter, status);
goto error;
}
error:
destroy_muxer_msg_iter(muxer_msg_iter);
bt_self_message_iterator_set_data(self_msg_iter, NULL);
- status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_ERROR;
end:
muxer_comp->initializing_muxer_msg_iter = false;
static
void destroy_trimmer_iterator(struct trimmer_iterator *trimmer_it)
{
- BT_ASSERT(trimmer_it);
+ if (!trimmer_it) {
+ goto end;
+ }
+
bt_self_component_port_input_message_iterator_put_ref(
trimmer_it->upstream_iter);
}
g_free(trimmer_it);
+end:
+ return;
}
static
bt_self_component_filter *self_comp,
bt_self_component_port_output *port)
{
- bt_component_class_message_iterator_init_method_status status =
- BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_OK;
+ bt_component_class_message_iterator_init_method_status status;
+ bt_self_component_port_input_message_iterator_create_from_message_iterator_status
+ msg_iter_status;
struct trimmer_iterator *trimmer_it;
trimmer_it = g_new0(struct trimmer_iterator, 1);
if (!trimmer_it) {
status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_MEMORY_ERROR;
- goto end;
+ goto error;
}
trimmer_it->trimmer_comp = bt_self_component_get_data(
trimmer_it->begin = trimmer_it->trimmer_comp->begin;
trimmer_it->end = trimmer_it->trimmer_comp->end;
- trimmer_it->upstream_iter =
+ msg_iter_status =
bt_self_component_port_input_message_iterator_create_from_message_iterator(
self_msg_iter,
bt_self_component_filter_borrow_input_port_by_name(
- self_comp, in_port_name));
- if (!trimmer_it->upstream_iter) {
- status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_ERROR;
- goto end;
+ self_comp, in_port_name), &trimmer_it->upstream_iter);
+ if (msg_iter_status != BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_CREATE_FROM_MESSAGE_ITERATOR_STATUS_OK) {
+ status = (int) msg_iter_status;
+ goto error;
}
trimmer_it->output_messages = g_queue_new();
if (!trimmer_it->output_messages) {
status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_MEMORY_ERROR;
- goto end;
+ goto error;
}
trimmer_it->stream_states = g_hash_table_new_full(g_direct_hash,
(GDestroyNotify) destroy_trimmer_iterator_stream_state);
if (!trimmer_it->stream_states) {
status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_MEMORY_ERROR;
- goto end;
+ goto error;
}
trimmer_it->self_msg_iter = self_msg_iter;
bt_self_message_iterator_set_data(self_msg_iter, trimmer_it);
-end:
- if (status != BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_OK && trimmer_it) {
- destroy_trimmer_iterator(trimmer_it);
- }
+ status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_OK;
+ goto end;
+error:
+ destroy_trimmer_iterator(trimmer_it);
+
+end:
return status;
}
self.assertTrue(src_iter_initialized)
self.assertTrue(flt_iter_initialized)
+ def test_create_user_error(self):
+ # This tests both error handling by
+ # _UserSinkComponent._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):
+ raise ValueError('Very bad error')
+
+ class MySource(bt2._UserSourceComponent, message_iterator_class=MySourceIter):
+ def __init__(self, params, obj):
+ self._add_output_port('out')
+
+ class MyFilterIter(bt2._UserMessageIterator):
+ def __init__(self, self_port_output):
+ # This is expected to raise because of the error in
+ # MySourceIter.__init__.
+ self._create_input_port_message_iterator(
+ self._component._input_ports['in']
+ )
+
+ class MyFilter(bt2._UserFilterComponent, message_iterator_class=MyFilterIter):
+ def __init__(self, params, obj):
+ self._add_input_port('in')
+ self._add_output_port('out')
+
+ graph = self._create_graph(MySource, MyFilter)
+
+ with self.assertRaises(bt2._Error) as ctx:
+ graph.run()
+
+ exc = ctx.exception
+ cause = exc[0]
+
+ self.assertIsInstance(cause, bt2._MessageIteratorErrorCause)
+ self.assertEqual(cause.component_name, 'src')
+ self.assertEqual(cause.component_output_port_name, 'out')
+ self.assertIn('ValueError: Very bad error', cause.message)
+
def test_finalize(self):
class MyIter(bt2._UserMessageIterator):
def _user_finalize(self):