Refuse to add port to component when parent graph is canceled
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 7 Jun 2017 20:24:13 +0000 (16:24 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 9 Jun 2017 21:03:27 +0000 (17:03 -0400)
The objects owned by a graph should not be able to perform any useless
action. Having those constraints promise that certain contained objects
remain within certain states when the graph is canceled.

In this case, it is useless for a component to add a port, since this
port cannot be connected to another one within the same graph because
bt_graph_connect_ports() is not permitted when the graph is canceled.

We still allow ports to be removed when the graph is canceled for
symetric teardowns, for example.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
include/babeltrace/graph/component-internal.h
include/babeltrace/graph/component-status.h
lib/graph/filter.c
lib/graph/sink.c
lib/graph/source.c

index d67dd54f0dd930a79b3330ec2951a7015fe3cf33..f78c468b079ff69d3e5aea0522449e8565ffca42 100644 (file)
@@ -170,6 +170,8 @@ const char *bt_component_status_string(enum bt_component_status status)
                return "BT_COMPONENT_STATUS_NOMEM";
        case BT_COMPONENT_STATUS_NOT_FOUND:
                return "BT_COMPONENT_STATUS_NOT_FOUND";
+       case BT_COMPONENT_STATUS_GRAPH_IS_CANCELED:
+               return "BT_COMPONENT_STATUS_GRAPH_IS_CANCELED";
        default:
                return "(unknown)";
        }
index 2425c5ee6f67d8386a334d02d130716065bb1012..fe1d59ab2d84d899ee379d52bf3e0e517d1064a5 100644 (file)
@@ -56,6 +56,7 @@ enum bt_component_status {
        BT_COMPONENT_STATUS_NOMEM                       = -12,
        /** Element not found. */
        BT_COMPONENT_STATUS_NOT_FOUND                   = -19,
+       BT_COMPONENT_STATUS_GRAPH_IS_CANCELED           = 125,
 };
 
 #ifdef __cplusplus
index 4e6db19fd5d59508f9182443a10b7cfe01b2affe..6cae9b3b76da2e163f94bd1ccc49fbe44e91fe51 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)
@@ -251,6 +252,7 @@ enum bt_component_status bt_private_component_filter_add_input_private_port(
        struct bt_port *port = NULL;
        struct bt_component *component =
                bt_component_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 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_input_port() logs details/errors */
        port = bt_component_add_input_port(component, name, user_data);
        if (!port) {
@@ -315,6 +328,7 @@ enum bt_component_status bt_private_component_filter_add_output_private_port(
        struct bt_port *port = NULL;
        struct bt_component *component =
                bt_component_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) {
index b2088139f080bfe7bccb89ea43666bcd8dedac5c..063539f2acd3c0fd24d02acb5ab7385d40066e50 100644 (file)
@@ -34,6 +34,7 @@
 #include <babeltrace/graph/component-sink-internal.h>
 #include <babeltrace/graph/component-internal.h>
 #include <babeltrace/graph/notification.h>
+#include <babeltrace/graph/graph.h>
 
 BT_HIDDEN
 void bt_component_sink_destroy(struct bt_component *component)
@@ -205,6 +206,7 @@ enum bt_component_status bt_private_component_sink_add_input_private_port(
        struct bt_port *port = NULL;
        struct bt_component *component =
                bt_component_from_private(private_component);
+       struct bt_graph *graph;
 
        if (!component) {
                BT_LOGW_STR("Invalid parameter: component is NULL.");
@@ -221,6 +223,17 @@ enum bt_component_status bt_private_component_sink_add_input_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_input_port() logs details/errors */
        port = bt_component_add_input_port(component, name, user_data);
        if (!port) {
index 57244c062584e14d978c40640ae79a015e23300a..b09494f25e6aa384cdffa3c6e816e98da683157a 100644 (file)
@@ -36,6 +36,7 @@
 #include <babeltrace/graph/port-internal.h>
 #include <babeltrace/graph/notification-iterator.h>
 #include <babeltrace/graph/notification-iterator-internal.h>
+#include <babeltrace/graph/graph.h>
 
 BT_HIDDEN
 void bt_component_source_destroy(struct bt_component *component)
@@ -170,6 +171,7 @@ enum bt_component_status bt_private_component_source_add_output_private_port(
        struct bt_port *port = NULL;
        struct bt_component *component =
                bt_component_from_private(private_component);
+       struct bt_graph *graph;
 
        if (!component) {
                BT_LOGW_STR("Invalid parameter: component is NULL.");
@@ -186,6 +188,17 @@ enum bt_component_status bt_private_component_source_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 and errors */
        port = bt_component_add_output_port(component, name, user_data);
        if (!port) {
This page took 0.02739 seconds and 4 git commands to generate.