goto error;
}
+ graph->can_consume = BT_TRUE;
ret = init_listeners_array(&graph->listeners.port_added);
if (ret) {
BT_LOGE_STR("Cannot create the \"port added\" listener array.");
struct bt_component *upstream_component = NULL;
struct bt_component *downstream_component = NULL;
enum bt_component_status component_status;
+ const bt_bool init_can_consume = graph->can_consume;
if (!graph) {
BT_LOGW_STR("Invalid parameter: graph is NULL.");
goto end;
}
+ graph->can_consume = BT_FALSE;
+
/* Ensure appropriate types for upstream and downstream ports. */
if (bt_port_get_type(upstream_port) != BT_PORT_TYPE_OUTPUT) {
BT_LOGW_STR("Invalid parameter: upstream port is not an output port.");
bt_put(upstream_component);
bt_put(downstream_component);
bt_put(connection);
+ graph->can_consume = init_can_consume;
return status;
}
BT_LOGV("Making next sink consume: addr=%p", graph);
+ if (!graph->has_sink) {
+ BT_LOGW_STR("Graph has no sink component.");
+ status = BT_GRAPH_STATUS_NO_SINK;
+ goto end;
+ }
+
if (g_queue_is_empty(graph->sinks_to_consume)) {
BT_LOGV_STR("Graph's sink queue is empty: end of graph.");
status = BT_GRAPH_STATUS_END;
goto end;
}
+ if (!graph->can_consume) {
+ BT_LOGW_STR("Cannot consume graph in its current state.");
+ status = BT_GRAPH_STATUS_CANNOT_CONSUME;
+ goto end;
+ }
+
+ graph->can_consume = BT_FALSE;
status = bt_graph_consume_no_check(graph);
+ graph->can_consume = BT_TRUE;
end:
return status;
goto end;
}
+ if (!graph->can_consume) {
+ BT_LOGW_STR("Cannot run graph in its current state.");
+ status = BT_GRAPH_STATUS_CANNOT_CONSUME;
+ goto end;
+ }
+
+ graph->can_consume = BT_FALSE;
BT_LOGV("Running graph: addr=%p", graph);
do {
goto end;
}
- status = bt_graph_consume(graph);
+ status = bt_graph_consume_no_check(graph);
if (status == BT_GRAPH_STATUS_AGAIN) {
/*
* If AGAIN is received and there are multiple
if (graph->sinks_to_consume->length > 1) {
status = BT_GRAPH_STATUS_OK;
}
+ } else if (status == BT_GRAPH_STATUS_NO_SINK) {
+ goto end;
}
} while (status == BT_GRAPH_STATUS_OK);
end:
BT_LOGV("Graph ran: status=%s", bt_graph_status_string(status));
+ graph->can_consume = BT_TRUE;
return status;
}
}
}
-extern enum bt_graph_status bt_graph_cancel(struct bt_graph *graph)
+enum bt_graph_status bt_graph_cancel(struct bt_graph *graph)
{
enum bt_graph_status ret = BT_GRAPH_STATUS_OK;
return ret;
}
-extern bt_bool bt_graph_is_canceled(struct bt_graph *graph)
+bt_bool bt_graph_is_canceled(struct bt_graph *graph)
{
- return graph ? graph->canceled : BT_FALSE;
+ bt_bool canceled = BT_FALSE;
+
+ if (!graph) {
+ BT_LOGW_STR("Invalid parameter: graph is NULL.");
+ goto end;
+ }
+
+ canceled = graph->canceled;
+
+end:
+ return canceled;
}
BT_HIDDEN
struct bt_component *component = NULL;
enum bt_component_class_type type;
size_t i;
+ const bt_bool init_can_consume = graph->can_consume;
bt_get(params);
goto end;
}
+ graph->can_consume = BT_FALSE;
type = bt_component_class_get_type(component_class);
BT_LOGD("Adding component to graph: "
"graph-addr=%p, comp-cls-addr=%p, "
* sink queue to be consumed by bt_graph_consume().
*/
if (bt_component_is_sink(component)) {
+ graph->has_sink = BT_TRUE;
g_queue_push_tail(graph->sinks_to_consume, component);
}
end:
bt_put(component);
bt_put(params);
+ graph->can_consume = init_can_consume;
return graph_status;
}