X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=lib%2Fgraph%2Fconnection.c;h=d490c5dcf5f61b3ef14d7b4f8ea7fb5b89516ed6;hb=44b2734f713bf5ff42c0f6ee819d4d3ec29a1bb9;hp=655b36c9f6ab632b5f2af2b3c0a6f62fc6042f60;hpb=d27a81b29c34b4855f02b31f291d8c885760b3a2;p=deliverable%2Fbabeltrace.git diff --git a/lib/graph/connection.c b/lib/graph/connection.c index 655b36c9f..d490c5dcf 100644 --- a/lib/graph/connection.c +++ b/lib/graph/connection.c @@ -1,8 +1,7 @@ /* + * Copyright 2017-2018 Philippe Proulx * Copyright 2017 Jérémie Galarneau * - * Author: Jérémie Galarneau - * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights @@ -25,16 +24,16 @@ #define BT_LOG_TAG "CONNECTION" #include -#include +#include +#include +#include #include #include +#include #include #include #include #include -#include -#include -#include #include #include @@ -47,13 +46,13 @@ void destroy_connection(struct bt_object *obj) BT_LIB_LOGD("Destroying connection: %!+x", connection); /* - * Make sure that each notification iterator which was created - * for this connection is finalized before we destroy it. Once a - * notification iterator is finalized, all its method return - * NULL or the BT_NOTIFICATION_ITERATOR_STATUS_CANCELED status. + * Make sure that each message iterator which was created for + * this connection is finalized before we destroy it. Once a + * message iterator is finalized, all its method return NULL or + * the BT_MESSAGE_ITERATOR_STATUS_CANCELED status. * * Because connections are destroyed before components within a - * graph, this ensures that notification iterators are always + * graph, this ensures that message iterators are always * finalized before their upstream component. * * Ending the connection does exactly this. We pass `false` to @@ -88,7 +87,7 @@ void try_remove_connection_from_graph(struct bt_connection *connection) * At this point we know that: * * 1. The connection is ended (ports were disconnected). - * 2. All the notification iterators that this connection + * 2. All the message iterators that this connection * created, if any, are finalized. * 3. The connection's reference count is 0, so only the * parent (graph) owns this connection after this call. @@ -169,7 +168,7 @@ void bt_connection_end(struct bt_connection *conn, bool try_remove_from_graph) conn, try_remove_from_graph); /* - * Any of the following notification callback functions could + * Any of the following message callback functions could * remove one of the connection's ports from its component. To * make sure that at least logging in called functions works * with existing objects, get a local reference on both ports. @@ -180,7 +179,8 @@ void bt_connection_end(struct bt_connection *conn, bool try_remove_from_graph) if (downstream_port) { BT_LIB_LOGD("Disconnecting connection's downstream port: %!+p", downstream_port); - downstream_comp = bt_port_borrow_component(downstream_port); + downstream_comp = bt_port_borrow_component_inline( + downstream_port); bt_port_set_connection(downstream_port, NULL); conn->downstream_port = NULL; } @@ -188,7 +188,8 @@ void bt_connection_end(struct bt_connection *conn, bool try_remove_from_graph) if (upstream_port) { BT_LIB_LOGD("Disconnecting connection's upstream port: %!+p", upstream_port); - upstream_comp = bt_port_borrow_component(upstream_port); + upstream_comp = bt_port_borrow_component_inline( + upstream_port); bt_port_set_connection(upstream_port, NULL); conn->upstream_port = NULL; } @@ -226,16 +227,20 @@ void bt_connection_end(struct bt_connection *conn, bool try_remove_from_graph) bt_object_put_ref(upstream_port); /* - * Because this connection is ended, finalize (cancel) each - * notification iterator created from it. + * Because this connection is ended, finalize each message + * iterator created from it. + * + * In practice, this only happens when the connection is + * destroyed and not all its message iterators were finalized, + * which is on graph destruction. */ for (i = 0; i < conn->iterators->len; i++) { - struct bt_self_component_port_input_notification_iterator *iterator = + struct bt_self_component_port_input_message_iterator *iterator = g_ptr_array_index(conn->iterators, i); - BT_LIB_LOGD("Finalizing notification iterator created by " + BT_LIB_LOGD("Finalizing message iterator created by " "this ended connection: %![iter-]+i", iterator); - bt_self_component_port_input_notification_iterator_finalize( + bt_self_component_port_input_message_iterator_try_finalize( iterator); /* @@ -243,7 +248,7 @@ void bt_connection_end(struct bt_connection *conn, bool try_remove_from_graph) * from this connection's iterators on destruction * because this connection won't exist anymore. */ - bt_self_component_port_input_notification_iterator_set_connection( + bt_self_component_port_input_message_iterator_set_connection( iterator, NULL); } @@ -254,15 +259,15 @@ void bt_connection_end(struct bt_connection *conn, bool try_remove_from_graph) } } -struct bt_port_output *bt_connection_borrow_upstream_port( - struct bt_connection *connection) +const struct bt_port_output *bt_connection_borrow_upstream_port_const( + const struct bt_connection *connection) { BT_ASSERT_PRE_NON_NULL(connection, "Connection"); return (void *) connection->upstream_port; } -struct bt_port_input *bt_connection_borrow_downstream_port( - struct bt_connection *connection) +const struct bt_port_input *bt_connection_borrow_downstream_port_const( + const struct bt_connection *connection) { BT_ASSERT_PRE_NON_NULL(connection, "Connection"); return (void *) connection->downstream_port; @@ -270,15 +275,25 @@ struct bt_port_input *bt_connection_borrow_downstream_port( BT_HIDDEN void bt_connection_remove_iterator(struct bt_connection *conn, - struct bt_self_component_port_input_notification_iterator *iterator) + struct bt_self_component_port_input_message_iterator *iterator) { g_ptr_array_remove(conn->iterators, iterator); - BT_LIB_LOGV("Removed notification iterator from connection: " + BT_LIB_LOGV("Removed message iterator from connection: " "%![conn-]+x, %![iter-]+i", conn, iterator); try_remove_connection_from_graph(conn); } -bt_bool bt_connection_is_ended(struct bt_connection *connection) +bt_bool bt_connection_is_ended(const struct bt_connection *connection) { return !connection->downstream_port && !connection->upstream_port; } + +void bt_connection_get_ref(const struct bt_connection *connection) +{ + bt_object_get_ref(connection); +} + +void bt_connection_put_ref(const struct bt_connection *connection) +{ + bt_object_put_ref(connection); +}