Files
oxydsp/oxydsp-flowgraph/src/edge.rs
2026-03-11 21:49:02 +01:00

66 lines
1.3 KiB
Rust

use std::sync::Arc;
use std::sync::Mutex;
use crate::stream::StreamConsumer;
use crate::stream::StreamProducer;
pub struct Edge
{
// Represents the index of the block owning the Out end in the graph
// And the the output index within that block
pub from: Option<BlockIOIndex>,
// Represents the index of the block owning the In end in the graph
// And the the input index within that block
pub to: Option<BlockIOIndex>,
}
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub struct BlockIOIndex
{
pub block_index: usize,
pub port_index: usize,
}
pub struct In<T>
{
stream: Option<StreamProducer<T>>,
// Will rarely be accessed
edge: Arc<Mutex<Edge>>,
}
pub struct Out<T>
{
stream: Option<StreamConsumer<T>>,
// Will rarely be accessed
edge: Arc<Mutex<Edge>>,
}
impl<T> In<T>
{
pub fn set_block_index(&self, index: BlockIOIndex)
{
self.edge.lock().unwrap().to = Some(index);
}
pub fn get_producer_block(&self) -> Option<BlockIOIndex>
{
self.edge.lock().unwrap().from
}
}
impl<T> Out<T>
{
pub fn set_block_index(&self, index: BlockIOIndex)
{
self.edge.lock().unwrap().from = Some(index);
}
pub fn get_consumer_block(&self) -> Option<BlockIOIndex>
{
self.edge.lock().unwrap().to
}
}