Add bt_graph_add_component(), make bt_component_create() internal
[babeltrace.git] / lib / graph / sink.c
index 78dc97f93fc542f778b6c5111ab7037612a00d02..455ed4ef1dc5cc26738cbe697b46c37c43aff739 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)
@@ -42,7 +43,7 @@ void bt_component_sink_destroy(struct bt_component *component)
 
 BT_HIDDEN
 struct bt_component *bt_component_sink_create(
-               struct bt_component_class *class, struct bt_value *params)
+               struct bt_component_class *class)
 {
        struct bt_component_sink *sink = NULL;
 
@@ -196,16 +197,20 @@ bt_private_component_sink_get_input_private_port_by_name(
                        bt_component_from_private(private_component), name));
 }
 
-struct bt_private_port *bt_private_component_sink_add_input_private_port(
+enum bt_component_status bt_private_component_sink_add_input_private_port(
                struct bt_private_component *private_component,
-               const char *name, void *user_data)
+               const char *name, void *user_data,
+               struct bt_private_port **user_priv_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);
+       struct bt_graph *graph;
 
        if (!component) {
                BT_LOGW_STR("Invalid parameter: component is NULL.");
+               status = BT_COMPONENT_STATUS_INVALID;
                goto end;
        }
 
@@ -214,12 +219,35 @@ struct bt_private_port *bt_private_component_sink_add_input_private_port(
                        "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s",
                        component, bt_component_get_name(component),
                        bt_component_class_type_string(component->class->type));
+               status = BT_COMPONENT_STATUS_INVALID;
+               goto end;
+       }
+
+       graph = bt_component_borrow_graph(component);
+
+       if (graph && bt_graph_is_canceled(graph)) {
+               BT_LOGW("Cannot add input port to sink 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) {
+               status = BT_COMPONENT_STATUS_NOMEM;
+               goto end;
+       }
+
+       if (user_priv_port) {
+               /* Move reference to user */
+               *user_priv_port = bt_private_port_from_port(port);
+               port = NULL;
+       }
 
 end:
-       return bt_private_port_from_port(port);
+       bt_put(port);
+       return status;
 }
This page took 0.023966 seconds and 4 git commands to generate.