use std::sync::Arc;
use crate::ndarray_pool::NDArrayPool;
use crate::plugin::channel::{NDArrayOutput, NDArraySender};
use crate::plugin::wiring::WiringRegistry;
pub trait DriverContext: Send + Sync {
fn pool(&self) -> Arc<NDArrayPool>;
fn connect_downstream(&self, sender: NDArraySender);
}
pub struct GenericDriverContext {
pool: Arc<NDArrayPool>,
output: Arc<parking_lot::Mutex<NDArrayOutput>>,
}
impl GenericDriverContext {
pub fn new(
pool: Arc<NDArrayPool>,
output: Arc<parking_lot::Mutex<NDArrayOutput>>,
port_name: &str,
wiring: &WiringRegistry,
) -> Self {
wiring.register_output(port_name, output.clone());
Self { pool, output }
}
}
impl DriverContext for GenericDriverContext {
fn pool(&self) -> Arc<NDArrayPool> {
self.pool.clone()
}
fn connect_downstream(&self, sender: NDArraySender) {
self.output.lock().add(sender);
}
}