lib: make the "port connected" method return a status
[babeltrace.git] / lib / graph / connection.c
index 32146b132c8f86626958d6ebf03a4d442090ed40..163a760b2d809b03529ca9b8e6adc4bf1fb8304d 100644 (file)
@@ -39,6 +39,7 @@
 #include <babeltrace/graph/port-internal.h>
 #include <babeltrace/object-internal.h>
 #include <babeltrace/compiler-internal.h>
+#include <babeltrace/assert-internal.h>
 #include <stdlib.h>
 #include <glib.h>
 
@@ -78,9 +79,9 @@ void bt_connection_destroy(struct bt_object *obj)
 static
 void bt_connection_try_remove_from_graph(struct bt_connection *connection)
 {
-       void *graph = bt_object_borrow_parent(&connection->base);
+       void *graph = (void *) bt_object_borrow_parent(&connection->base);
 
-       if (connection->base.ref_count.count > 0 ||
+       if (connection->base.ref_count > 0 ||
                        connection->downstream_port ||
                        connection->upstream_port ||
                        connection->iterators->len > 0) {
@@ -116,10 +117,10 @@ void bt_connection_parent_is_owner(struct bt_object *obj)
        bt_connection_try_remove_from_graph(connection);
 }
 
-struct bt_connection *bt_connection_from_private_connection(
+struct bt_connection *bt_connection_borrow_from_private(
                struct bt_private_connection *private_connection)
 {
-       return bt_get(bt_connection_from_private(private_connection));
+       return (void *) private_connection;
 }
 
 BT_HIDDEN
@@ -150,8 +151,9 @@ struct bt_connection *bt_connection_create(
                goto end;
        }
 
-       bt_object_init(connection, bt_connection_destroy);
-       bt_object_set_parent_is_owner_listener(connection,
+       bt_object_init_shared_with_parent(&connection->base,
+               bt_connection_destroy);
+       bt_object_set_parent_is_owner_listener_func(&connection->base,
                bt_connection_parent_is_owner);
        connection->iterators = g_ptr_array_new();
        if (!connection->iterators) {
@@ -167,7 +169,7 @@ struct bt_connection *bt_connection_create(
        bt_port_set_connection(upstream_port, connection);
        BT_LOGD_STR("Setting downstream port's connection.");
        bt_port_set_connection(downstream_port, connection);
-       bt_object_set_parent(connection, &graph->base);
+       bt_object_set_parent(&connection->base, &graph->base);
        BT_LOGD("Created connection: "
                "graph-addr=%p, upstream-port-addr=%p, uptream-port-name=\"%s\", "
                "downstream-port-addr=%p, downstream-port-name=\"%s\", "
@@ -212,21 +214,25 @@ void bt_connection_end(struct bt_connection *conn,
                conn->upstream_port = NULL;
        }
 
-       if (downstream_comp) {
+       if (downstream_comp && conn->notified_downstream_port_connected) {
                /* bt_component_port_disconnected() logs details */
                bt_component_port_disconnected(downstream_comp,
                        downstream_port);
        }
 
-       if (upstream_comp) {
+       if (upstream_comp && conn->notified_upstream_port_connected) {
                /* bt_component_port_disconnected() logs details */
                bt_component_port_disconnected(upstream_comp, upstream_port);
        }
 
-       assert(graph);
-       /* bt_graph_notify_ports_disconnected() logs details */
-       bt_graph_notify_ports_disconnected(graph, upstream_comp,
-               downstream_comp, upstream_port, downstream_port);
+       BT_ASSERT(graph);
+
+       if (conn->notified_graph_ports_connected) {
+               /* bt_graph_notify_ports_disconnected() logs details */
+               bt_graph_notify_ports_disconnected(graph, upstream_comp,
+                       downstream_comp, upstream_port, downstream_port);
+       }
+
        bt_put(downstream_comp);
        bt_put(upstream_comp);
 
@@ -273,7 +279,6 @@ struct bt_port *bt_connection_get_downstream_port(
 enum bt_connection_status
 bt_private_connection_create_notification_iterator(
                struct bt_private_connection *private_connection,
-               const enum bt_notification_type *notification_types,
                struct bt_notification_iterator **user_iterator)
 {
        enum bt_component_class_type upstream_comp_class_type;
@@ -284,10 +289,6 @@ bt_private_connection_create_notification_iterator(
        struct bt_connection *connection = NULL;
        bt_component_class_notification_iterator_init_method init_method = NULL;
        enum bt_connection_status status;
-       static const enum bt_notification_type all_notif_types[] = {
-               BT_NOTIFICATION_TYPE_ALL,
-               BT_NOTIFICATION_TYPE_SENTINEL,
-       };
 
        if (!private_connection) {
                BT_LOGW_STR("Invalid parameter: private connection is NULL.");
@@ -301,7 +302,7 @@ bt_private_connection_create_notification_iterator(
                goto end;
        }
 
-       connection = bt_connection_from_private(private_connection);
+       connection = bt_connection_borrow_from_private(private_connection);
 
        if (bt_graph_is_canceled(bt_connection_borrow_graph(connection))) {
                BT_LOGW("Cannot create notification iterator from connection: "
@@ -325,15 +326,10 @@ bt_private_connection_create_notification_iterator(
                goto end;
        }
 
-       if (!notification_types) {
-               BT_LOGD_STR("No notification types: subscribing to all notifications.");
-               notification_types = all_notif_types;
-       }
-
        upstream_port = connection->upstream_port;
-       assert(upstream_port);
+       BT_ASSERT(upstream_port);
        upstream_component = bt_port_get_component(upstream_port);
-       assert(upstream_component);
+       BT_ASSERT(upstream_component);
        upstream_comp_class = upstream_component->class;
        BT_LOGD("Creating notification iterator from connection: "
                "conn-addr=%p, upstream-port-addr=%p, "
@@ -344,10 +340,10 @@ bt_private_connection_create_notification_iterator(
                upstream_component, bt_component_get_name(upstream_component));
        upstream_comp_class_type =
                bt_component_get_class_type(upstream_component);
-       assert(upstream_comp_class_type == BT_COMPONENT_CLASS_TYPE_SOURCE ||
+       BT_ASSERT(upstream_comp_class_type == BT_COMPONENT_CLASS_TYPE_SOURCE ||
                        upstream_comp_class_type == BT_COMPONENT_CLASS_TYPE_FILTER);
        status = bt_private_connection_notification_iterator_create(upstream_component,
-               upstream_port, notification_types, connection, &iterator);
+               upstream_port, connection, &iterator);
        if (status != BT_CONNECTION_STATUS_OK) {
                BT_LOGW("Cannot create notification iterator from connection.");
                goto end;
This page took 0.025468 seconds and 4 git commands to generate.