lib: Make graph listeners return an error status
[babeltrace.git] / include / babeltrace / graph / graph-internal.h
index 97289cf0f168e4b36d349845a5b0de199e46e34f..fce624fb466fe96a0a6fbe852f8ebee57cd740aa 100644 (file)
@@ -43,6 +43,7 @@ enum bt_graph_configuration_state {
        BT_GRAPH_CONFIGURATION_STATE_CONFIGURING,
        BT_GRAPH_CONFIGURATION_STATE_PARTIALLY_CONFIGURED,
        BT_GRAPH_CONFIGURATION_STATE_CONFIGURED,
+       BT_GRAPH_CONFIGURATION_STATE_FAULTY,
 };
 
 struct bt_graph {
@@ -138,11 +139,13 @@ enum bt_graph_status bt_graph_consume_sink_no_check(struct bt_graph *graph,
                struct bt_component_sink *sink);
 
 BT_HIDDEN
-void bt_graph_notify_port_added(struct bt_graph *graph, struct bt_port *port);
+enum bt_graph_listener_status bt_graph_notify_port_added(struct bt_graph *graph,
+               struct bt_port *port);
 
 BT_HIDDEN
-void bt_graph_notify_ports_connected(struct bt_graph *graph,
-               struct bt_port *upstream_port, struct bt_port *downstream_port);
+enum bt_graph_listener_status bt_graph_notify_ports_connected(
+               struct bt_graph *graph, struct bt_port *upstream_port,
+               struct bt_port *downstream_port);
 
 BT_HIDDEN
 void bt_graph_remove_connection(struct bt_graph *graph,
@@ -176,8 +179,6 @@ const char *bt_graph_status_string(enum bt_graph_status status)
                return "BT_GRAPH_STATUS_END";
        case BT_GRAPH_STATUS_OK:
                return "BT_GRAPH_STATUS_OK";
-       case BT_GRAPH_STATUS_NO_SINK:
-               return "BT_GRAPH_STATUS_NO_SINK";
        case BT_GRAPH_STATUS_ERROR:
                return "BT_GRAPH_STATUS_ERROR";
        case BT_GRAPH_STATUS_COMPONENT_REFUSES_PORT_CONNECTION:
@@ -211,11 +212,17 @@ enum bt_graph_status bt_graph_configure(struct bt_graph *graph)
        enum bt_graph_status status = BT_GRAPH_STATUS_OK;
        uint64_t i;
 
+       BT_ASSERT(graph->config_state != BT_GRAPH_CONFIGURATION_STATE_FAULTY);
+
        if (likely(graph->config_state ==
                        BT_GRAPH_CONFIGURATION_STATE_CONFIGURED)) {
                goto end;
        }
 
+#ifdef BT_ASSERT_PRE
+       BT_ASSERT_PRE(graph->has_sink, "Graph has no sink component: %!+g", graph);
+#endif
+
        graph->config_state = BT_GRAPH_CONFIGURATION_STATE_PARTIALLY_CONFIGURED;
 
        for (i = 0; i < graph->components->len; i++) {
@@ -258,6 +265,7 @@ enum bt_graph_status bt_graph_configure(struct bt_graph *graph)
 #endif
 
                        if (comp_status != BT_SELF_COMPONENT_STATUS_OK) {
+                               status = BT_GRAPH_STATUS_ERROR;
 #ifdef BT_LIB_LOGW
                                BT_LIB_LOGW("User's \"graph is configured\" method failed: "
                                        "%![comp-]+c, status=%s",
@@ -279,4 +287,13 @@ end:
        return status;
 }
 
+static inline
+void bt_graph_make_faulty(struct bt_graph *graph)
+{
+       graph->config_state = BT_GRAPH_CONFIGURATION_STATE_FAULTY;
+#ifdef BT_LIB_LOGD
+       BT_LIB_LOGD("Set graph's state to faulty: %![graph-]+g", graph);
+#endif
+}
+
 #endif /* BABELTRACE_GRAPH_GRAPH_INTERNAL_H */
This page took 0.025917 seconds and 4 git commands to generate.