tap-driver.sh: flush stdout after each test result
[babeltrace.git] / lib / graph / graph.c
index 49933d54931588dbd88ad7f6eddbc8f35bd6c38f..f7b02a10bece15a7914d8612e362f058328bcc6e 100644 (file)
  */
 
 #define BT_LOG_TAG "GRAPH"
-#include <babeltrace/lib-logging-internal.h>
-
-#include <babeltrace/assert-internal.h>
-#include <babeltrace/assert-pre-internal.h>
-#include <babeltrace/graph/component-internal.h>
-#include <babeltrace/graph/graph.h>
-#include <babeltrace/graph/graph-const.h>
-#include <babeltrace/graph/graph-internal.h>
-#include <babeltrace/graph/connection-internal.h>
-#include <babeltrace/graph/component-sink-internal.h>
-#include <babeltrace/graph/component-source-const.h>
-#include <babeltrace/graph/component-filter-const.h>
-#include <babeltrace/graph/port-const.h>
-#include <babeltrace/graph/message-internal.h>
-#include <babeltrace/graph/message-event-internal.h>
-#include <babeltrace/graph/message-packet-internal.h>
-#include <babeltrace/compiler-internal.h>
-#include <babeltrace/common-internal.h>
-#include <babeltrace/types.h>
-#include <babeltrace/value.h>
-#include <babeltrace/value-const.h>
-#include <babeltrace/value-internal.h>
+#include <babeltrace2/lib-logging-internal.h>
+
+#include <babeltrace2/assert-internal.h>
+#include <babeltrace2/assert-pre-internal.h>
+#include <babeltrace2/graph/component-internal.h>
+#include <babeltrace2/graph/graph.h>
+#include <babeltrace2/graph/graph-const.h>
+#include <babeltrace2/graph/graph-internal.h>
+#include <babeltrace2/graph/connection-internal.h>
+#include <babeltrace2/graph/component-sink-internal.h>
+#include <babeltrace2/graph/component-source-const.h>
+#include <babeltrace2/graph/component-filter-const.h>
+#include <babeltrace2/graph/port-const.h>
+#include <babeltrace2/graph/message-internal.h>
+#include <babeltrace2/graph/message-event-internal.h>
+#include <babeltrace2/graph/message-packet-internal.h>
+#include <babeltrace2/compiler-internal.h>
+#include <babeltrace2/common-internal.h>
+#include <babeltrace2/types.h>
+#include <babeltrace2/value.h>
+#include <babeltrace2/value-const.h>
+#include <babeltrace2/value-internal.h>
 #include <unistd.h>
 #include <glib.h>
 
-typedef void (*port_added_func_t)(const void *, const void *, void *);
+typedef enum bt_graph_listener_status (*port_added_func_t)(
+               const void *, const void *, void *);
 
-typedef void (*ports_connected_func_t)(const void *, const void *, const void *,
-               const void *, void *);
+typedef enum bt_graph_listener_status (*ports_connected_func_t)(
+               const void *, const void *, const void *, const void *, void *);
 
 typedef enum bt_self_component_status (*comp_init_method_t)(const void *,
                const void *, void *);
@@ -82,6 +83,9 @@ struct bt_graph_listener_ports_connected {
        do {                                                            \
                size_t i;                                               \
                                                                        \
+               if (!_listeners) {                                      \
+                       break;                                          \
+               }                                                       \
                for (i = 0; i < (_listeners)->len; i++) {               \
                        _type *listener =                               \
                                &g_array_index((_listeners), _type, i); \
@@ -394,6 +398,7 @@ enum bt_graph_status bt_graph_connect_ports(
                const struct bt_connection **user_connection)
 {
        enum bt_graph_status status = BT_GRAPH_STATUS_OK;
+       enum bt_graph_listener_status listener_status;
        struct bt_connection *connection = NULL;
        struct bt_port *upstream_port = (void *) upstream_port_out;
        struct bt_port *downstream_port = (void *) downstream_port_in;
@@ -408,7 +413,7 @@ enum bt_graph_status bt_graph_connect_ports(
        BT_ASSERT_PRE(!graph->canceled, "Graph is canceled: %!+g", graph);
        BT_ASSERT_PRE(
                graph->config_state == BT_GRAPH_CONFIGURATION_STATE_CONFIGURING,
-               "Graph is already configured: %!+g", graph);
+               "Graph is not in the \"configuring\" state: %!+g", graph);
        BT_ASSERT_PRE(!bt_port_is_connected(upstream_port),
                "Upstream port is already connected: %!+p", upstream_port);
        BT_ASSERT_PRE(!bt_port_is_connected(downstream_port),
@@ -528,7 +533,12 @@ enum bt_graph_status bt_graph_connect_ports(
         * Notify the graph's creator that both ports are connected.
         */
        BT_LOGD_STR("Notifying graph's user that new component ports are connected.");
-       bt_graph_notify_ports_connected(graph, upstream_port, downstream_port);
+       listener_status = bt_graph_notify_ports_connected(graph, upstream_port, downstream_port);
+       if (listener_status != BT_GRAPH_LISTENER_STATUS_OK) {
+               status = (int) listener_status;
+               goto end;
+       }
+
        connection->notified_graph_ports_connected = true;
        BT_LIB_LOGD("Connected component ports within graph: "
                "%![graph-]+g, %![up-comp-]+c, %![down-comp-]+c, "
@@ -543,6 +553,10 @@ enum bt_graph_status bt_graph_connect_ports(
        }
 
 end:
+       if (status != BT_GRAPH_STATUS_OK) {
+               bt_graph_make_faulty(graph);
+       }
+
        bt_object_put_ref(connection);
        (void) init_can_consume;
        bt_graph_set_can_consume(graph, init_can_consume);
@@ -680,9 +694,11 @@ enum bt_graph_status bt_graph_consume(struct bt_graph *graph)
        BT_ASSERT_PRE(!graph->canceled, "Graph is canceled: %!+g", graph);
        BT_ASSERT_PRE(graph->can_consume,
                "Cannot consume graph in its current state: %!+g", graph);
+       BT_ASSERT_PRE(graph->config_state != BT_GRAPH_CONFIGURATION_STATE_FAULTY,
+               "Graph is in a faulty state: %!+g", graph);
        bt_graph_set_can_consume(graph, false);
        status = bt_graph_configure(graph);
-       if (status) {
+       if (unlikely(status)) {
                /* bt_graph_configure() logs errors */
                goto end;
        }
@@ -702,9 +718,11 @@ enum bt_graph_status bt_graph_run(struct bt_graph *graph)
        BT_ASSERT_PRE(!graph->canceled, "Graph is canceled: %!+g", graph);
        BT_ASSERT_PRE(graph->can_consume,
                "Cannot consume graph in its current state: %!+g", graph);
+       BT_ASSERT_PRE(graph->config_state != BT_GRAPH_CONFIGURATION_STATE_FAULTY,
+               "Graph is in a faulty state: %!+g", graph);
        bt_graph_set_can_consume(graph, false);
        status = bt_graph_configure(graph);
-       if (status) {
+       if (unlikely(status)) {
                /* bt_graph_configure() logs errors */
                goto end;
        }
@@ -741,8 +759,6 @@ enum bt_graph_status bt_graph_run(struct bt_graph *graph)
                        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);
 
@@ -1042,11 +1058,13 @@ bt_graph_add_filter_sink_component_ports_connected_listener(
 }
 
 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)
 {
        uint64_t i;
        GArray *listeners;
        struct bt_component *comp;
+       enum bt_graph_listener_status status = BT_GRAPH_LISTENER_STATUS_OK;
 
        BT_ASSERT(graph);
        BT_ASSERT(port);
@@ -1104,19 +1122,28 @@ void bt_graph_notify_port_added(struct bt_graph *graph, struct bt_port *port)
                        &g_array_index(listeners,
                                struct bt_graph_listener_port_added, i);
 
+
                BT_ASSERT(listener->func);
-               listener->func(comp, port, listener->base.data);
+               status = listener->func(comp, port, listener->base.data);
+               if (status != BT_GRAPH_LISTENER_STATUS_OK) {
+                       goto end;
+               }
        }
+
+end:
+       return status;
 }
 
 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)
 {
        uint64_t i;
        GArray *listeners;
        struct bt_component *upstream_comp;
        struct bt_component *downstream_comp;
+       enum bt_graph_listener_status status = BT_GRAPH_LISTENER_STATUS_OK;
 
        BT_ASSERT(graph);
        BT_ASSERT(upstream_port);
@@ -1174,9 +1201,15 @@ void bt_graph_notify_ports_connected(struct bt_graph *graph,
                                struct bt_graph_listener_ports_connected, i);
 
                BT_ASSERT(listener->func);
-               listener->func(upstream_comp, downstream_comp,
+               status = listener->func(upstream_comp, downstream_comp,
                        upstream_port, downstream_port, listener->base.data);
+               if (status != BT_GRAPH_LISTENER_STATUS_OK) {
+                       goto end;
+               }
        }
+
+end:
+       return status;
 }
 
 enum bt_graph_status bt_graph_cancel(struct bt_graph *graph)
@@ -1249,7 +1282,7 @@ enum bt_graph_status add_component_with_init_method_data(
        BT_ASSERT_PRE(!graph->canceled, "Graph is canceled: %!+g", graph);
        BT_ASSERT_PRE(
                graph->config_state == BT_GRAPH_CONFIGURATION_STATE_CONFIGURING,
-               "Graph is already configured: %!+g", graph);
+               "Graph is not in the \"configuring\" state: %!+g", graph);
        BT_ASSERT_PRE(!component_name_exists(graph, name),
                "Duplicate component name: %!+g, name=\"%s\"", graph, name);
        BT_ASSERT_PRE(!params || bt_value_is_map(params),
@@ -1287,6 +1320,7 @@ enum bt_graph_status add_component_with_init_method_data(
         */
        g_ptr_array_add(graph->components, component);
        bt_component_set_graph(component, graph);
+       bt_value_freeze(params);
 
        if (init_method) {
                BT_LOGD_STR("Calling user's initialization method.");
@@ -1335,6 +1369,10 @@ enum bt_graph_status add_component_with_init_method_data(
        }
 
 end:
+       if (graph_status != BT_GRAPH_STATUS_OK) {
+               bt_graph_make_faulty(graph);
+       }
+
        bt_object_put_ref(component);
        bt_object_put_ref(new_params);
        (void) init_can_consume;
This page took 0.026761 seconds and 4 git commands to generate.