Blocks and flowgraph: added this time

This commit is contained in:
2026-03-11 19:31:37 +01:00
parent 13d060776f
commit 6d99d54f4a
9 changed files with 181 additions and 78 deletions

View File

@ -0,0 +1,63 @@
use std::sync::{Arc, Mutex};
use crate::stream::{StreamConsumer, 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
}
}