+
+BT_HIDDEN
+void bt_ctf_stream_map_component_to_port(struct bt_ctf_stream *stream,
+ struct bt_component *comp,
+ struct bt_port *port)
+{
+ assert(stream);
+ assert(comp);
+ assert(port);
+ assert(stream->comp_cur_port);
+
+ /*
+ * Do not take a reference to the component here because we
+ * don't want the component to exist as long as this stream
+ * exists. Instead, keep a weak reference, but add a destroy
+ * listener so that we remove this hash table entry when we know
+ * the component is destroyed.
+ */
+ bt_component_add_destroy_listener(comp, component_destroy_listener,
+ stream);
+ g_hash_table_insert(stream->comp_cur_port, comp, port);
+}
+
+BT_HIDDEN
+struct bt_port *bt_ctf_stream_port_for_component(struct bt_ctf_stream *stream,
+ struct bt_component *comp)
+{
+ assert(stream);
+ assert(comp);
+ assert(stream->comp_cur_port);
+ return g_hash_table_lookup(stream->comp_cur_port, comp);
+}
+
+BT_HIDDEN
+void bt_ctf_stream_add_destroy_listener(struct bt_ctf_stream *stream,
+ bt_ctf_stream_destroy_listener_func func, void *data)
+{
+ struct bt_ctf_stream_destroy_listener listener;
+
+ assert(stream);
+ assert(func);
+ listener.func = func;
+ listener.data = data;
+ g_array_append_val(stream->destroy_listeners, listener);
+}
+
+BT_HIDDEN
+void bt_ctf_stream_remove_destroy_listener(struct bt_ctf_stream *stream,
+ bt_ctf_stream_destroy_listener_func func, void *data)
+{
+ size_t i;
+
+ assert(stream);
+ assert(func);
+
+ for (i = 0; i < stream->destroy_listeners->len; i++) {
+ struct bt_ctf_stream_destroy_listener *listener =
+ &g_array_index(stream->destroy_listeners,
+ struct bt_ctf_stream_destroy_listener, i);
+
+ if (listener->func == func && listener->data == data) {
+ g_array_remove_index(stream->destroy_listeners, i);
+ i--;
+ }
+ }
+}