Rename bt_X_from_private_X() -> bt_X_from_private()
[babeltrace.git] / lib / graph / filter.c
index 4e6db19fd5d59508f9182443a10b7cfe01b2affe..8914e1ef876477dd2135a1ea285a5e13b564bd48 100644 (file)
@@ -36,6 +36,7 @@
 #include <babeltrace/graph/component-class-internal.h>
 #include <babeltrace/graph/notification.h>
 #include <babeltrace/graph/notification-iterator-internal.h>
+#include <babeltrace/graph/graph.h>
 
 BT_HIDDEN
 void bt_component_filter_destroy(struct bt_component *component)
@@ -44,7 +45,7 @@ void bt_component_filter_destroy(struct bt_component *component)
 
 BT_HIDDEN
 struct bt_component *bt_component_filter_create(
-               struct bt_component_class *class, struct bt_value *params)
+               struct bt_component_class *class)
 {
        struct bt_component_filter *filter = NULL;
 
@@ -228,7 +229,7 @@ bt_private_component_filter_get_input_private_port_by_index(
        /* bt_component_filter_get_input_port_by_index() logs details/errors */
        return bt_private_port_from_port(
                bt_component_filter_get_input_port_by_index(
-                       bt_component_from_private(private_component), index));
+                       bt_component_borrow_from_private(private_component), index));
 }
 
 struct bt_private_port *
@@ -239,7 +240,7 @@ bt_private_component_filter_get_input_private_port_by_name(
        /* bt_component_filter_get_input_port_by_name() logs details/errors */
        return bt_private_port_from_port(
                bt_component_filter_get_input_port_by_name(
-                       bt_component_from_private(private_component), name));
+                       bt_component_borrow_from_private(private_component), name));
 }
 
 enum bt_component_status bt_private_component_filter_add_input_private_port(
@@ -250,7 +251,8 @@ enum bt_component_status bt_private_component_filter_add_input_private_port(
        enum bt_component_status status = BT_COMPONENT_STATUS_OK;
        struct bt_port *port = NULL;
        struct bt_component *component =
-               bt_component_from_private(private_component);
+               bt_component_borrow_from_private(private_component);
+       struct bt_graph *graph;
 
        if (!component) {
                BT_LOGW_STR("Invalid parameter: component is NULL.");
@@ -267,6 +269,17 @@ enum bt_component_status bt_private_component_filter_add_input_private_port(
                goto end;
        }
 
+       graph = bt_component_borrow_graph(component);
+
+       if (graph && bt_graph_is_canceled(graph)) {
+               BT_LOGW("Cannot add input port to filter component: graph is canceled: "
+                       "comp-addr=%p, comp-name=\"%s\", graph-addr=%p",
+                       component, bt_component_get_name(component),
+                       bt_component_borrow_graph(component));
+               status = BT_COMPONENT_STATUS_GRAPH_IS_CANCELED;
+               goto end;
+       }
+
        /* bt_component_add_input_port() logs details/errors */
        port = bt_component_add_input_port(component, name, user_data);
        if (!port) {
@@ -292,7 +305,7 @@ bt_private_component_filter_get_output_private_port_by_index(
        /* bt_component_filter_get_output_port_by_index() logs details/errors */
        return bt_private_port_from_port(
                bt_component_filter_get_output_port_by_index(
-                       bt_component_from_private(private_component), index));
+                       bt_component_borrow_from_private(private_component), index));
 }
 
 struct bt_private_port *
@@ -303,7 +316,7 @@ bt_private_component_filter_get_output_private_port_by_name(
        /* bt_component_filter_get_output_port_by_name() logs details/errors */
        return bt_private_port_from_port(
                bt_component_filter_get_output_port_by_name(
-                       bt_component_from_private(private_component), name));
+                       bt_component_borrow_from_private(private_component), name));
 }
 
 enum bt_component_status bt_private_component_filter_add_output_private_port(
@@ -314,7 +327,8 @@ enum bt_component_status bt_private_component_filter_add_output_private_port(
        enum bt_component_status status = BT_COMPONENT_STATUS_OK;
        struct bt_port *port = NULL;
        struct bt_component *component =
-               bt_component_from_private(private_component);
+               bt_component_borrow_from_private(private_component);
+       struct bt_graph *graph;
 
        if (!component) {
                BT_LOGW_STR("Invalid parameter: component is NULL.");
@@ -331,6 +345,17 @@ enum bt_component_status bt_private_component_filter_add_output_private_port(
                goto end;
        }
 
+       graph = bt_component_borrow_graph(component);
+
+       if (graph && bt_graph_is_canceled(graph)) {
+               BT_LOGW("Cannot add output port to filter component: graph is canceled: "
+                       "comp-addr=%p, comp-name=\"%s\", graph-addr=%p",
+                       component, bt_component_get_name(component),
+                       bt_component_borrow_graph(component));
+               status = BT_COMPONENT_STATUS_GRAPH_IS_CANCELED;
+               goto end;
+       }
+
        /* bt_component_add_output_port() logs details/errors */
        port = bt_component_add_output_port(component, name, user_data);
        if (!port) {
This page took 0.029699 seconds and 4 git commands to generate.