- ret = init_message_iterator((void *) iterator,
- BT_MESSAGE_ITERATOR_TYPE_PORT_OUTPUT,
- bt_port_output_message_iterator_destroy);
- if (ret) {
- /* init_message_iterator() logs errors */
- BT_OBJECT_PUT_REF_AND_RESET(iterator);
- goto end;
- }
-
- /* Create colander component */
- colander_comp_cls = bt_component_class_sink_colander_get();
- if (!colander_comp_cls) {
- /* bt_component_class_sink_colander_get() logs errors */
- BT_LIB_LOGE_APPEND_CAUSE(
- "Cannot get colander sink component class.");
- goto error;
- }
-
- iterator->graph = graph;
- bt_object_get_no_null_check(iterator->graph);
- colander_data.msgs = (void *) iterator->base.msgs->pdata;
- colander_data.count_addr = &iterator->count;
-
- /*
- * Hope that nobody uses this very unique name.
- *
- * We pass `BT_LOGGING_LEVEL_NONE` but the colander component
- * class module does not use this level anyway since it belongs
- * to the library.
- */
- graph_status = bt_graph_add_sink_component_with_init_method_data(
- (void *) graph, colander_comp_cls,
- "colander-36ac3409-b1a8-4d60-ab1f-4fdf341a8fb1",
- NULL, &colander_data, BT_LOGGING_LEVEL_NONE,
- (void *) &iterator->colander);
- if (graph_status != BT_FUNC_STATUS_OK) {
- BT_LIB_LOGE_APPEND_CAUSE(
- "Cannot add colander sink component to graph: "
- "%![graph-]+g, status=%s", graph,
- bt_common_func_status_string(graph_status));
- goto error;
- }
-
- /*
- * Connect provided output port to the colander component's
- * input port.
- */
- colander_in_port =
- (void *) bt_component_sink_borrow_input_port_by_index_const(
- (void *) iterator->colander, 0);
- BT_ASSERT(colander_in_port);
- graph_status = bt_graph_connect_ports(graph,
- output_port, colander_in_port, NULL);
- if (graph_status != BT_FUNC_STATUS_OK) {
- BT_LIB_LOGW_APPEND_CAUSE(
- "Cannot connect colander sink's port: "
- "%![graph-]+g, %![comp-]+c, status=%s", graph,
- iterator->colander,
- bt_common_func_status_string(graph_status));
- goto error;
- }
-
- /*
- * At this point everything went fine. Make the graph
- * nonconsumable forever so that only this message iterator
- * can consume (thanks to bt_graph_consume_sink_no_check()).
- * This avoids leaking the message created by the colander
- * sink and moved to the message iterator's message
- * member.
- */
- bt_graph_set_can_consume(iterator->graph, false);
-
- /* Also set the graph as being configured. */
- graph_status = bt_graph_configure(graph);
- if (graph_status != BT_FUNC_STATUS_OK) {
- BT_LIB_LOGW_APPEND_CAUSE(
- "Cannot configure graph after having "
- "added and connected colander sink: "
- "%![graph-]+g, %![comp-]+c, status=%s", graph,
- iterator->colander,
- bt_common_func_status_string(graph_status));
- goto error;
- }
- goto end;
-
-error:
- if (iterator && iterator->graph && iterator->colander) {
- int ret;
-
- /* Remove created colander component from graph if any */
- colander_comp = iterator->colander;
- BT_OBJECT_PUT_REF_AND_RESET(iterator->colander);