use std::future::Future;
use futuresdr::channel::mpsc::Sender;
use futuresdr::runtime::BlockId;
use futuresdr::runtime::BlockMessage;
use futuresdr::runtime::BlockMeta;
use futuresdr::runtime::Error;
use futuresdr::runtime::MessageOutputs;
use futuresdr::runtime::Pmt;
use futuresdr::runtime::PortId;
use futuresdr::runtime::Result;
use futuresdr::runtime::WorkIo;
use futuresdr::runtime::buffer::BufferReader;
#[cfg(not(target_arch = "wasm32"))]
pub trait Kernel: Send {
fn work(
&mut self,
_io: &mut WorkIo,
_m: &mut MessageOutputs,
_b: &mut BlockMeta,
) -> impl Future<Output = Result<()>> + Send {
async { Ok(()) }
}
fn init(
&mut self,
_m: &mut MessageOutputs,
_b: &mut BlockMeta,
) -> impl Future<Output = Result<()>> + Send {
async { Ok(()) }
}
fn deinit(
&mut self,
_m: &mut MessageOutputs,
_b: &mut BlockMeta,
) -> impl Future<Output = Result<()>> + Send {
async { Ok(()) }
}
}
#[cfg(target_arch = "wasm32")]
pub trait Kernel: Send {
fn work(
&mut self,
_io: &mut WorkIo,
_m: &mut MessageOutputs,
_b: &mut BlockMeta,
) -> impl Future<Output = Result<()>> {
async { Ok(()) }
}
fn init(
&mut self,
_m: &mut MessageOutputs,
_b: &mut BlockMeta,
) -> impl Future<Output = Result<()>> {
async { Ok(()) }
}
fn deinit(
&mut self,
_m: &mut MessageOutputs,
_b: &mut BlockMeta,
) -> impl Future<Output = Result<()>> {
async { Ok(()) }
}
}
#[cfg(not(target_arch = "wasm32"))]
pub trait KernelInterface {
fn is_blocking() -> bool;
fn type_name() -> &'static str;
fn stream_inputs(&self) -> Vec<String>;
fn stream_outputs(&self) -> Vec<String>;
fn stream_ports_init(&mut self, block_id: BlockId, inbox: Sender<BlockMessage>);
fn stream_ports_validate(&self) -> Result<(), Error>;
fn stream_input_finish(&mut self, port_id: PortId) -> Result<(), Error>;
fn stream_ports_notify_finished(&mut self) -> impl Future<Output = ()> + Send;
fn stream_input(&mut self, name: &str) -> Option<&mut dyn BufferReader>;
fn connect_stream_output(
&mut self,
name: &str,
reader: &mut dyn BufferReader,
) -> Result<(), Error>;
fn message_inputs() -> &'static [&'static str];
fn message_outputs() -> &'static [&'static str];
fn call_handler(
&mut self,
_io: &mut WorkIo,
_mio: &mut MessageOutputs,
_meta: &mut BlockMeta,
id: PortId,
_p: Pmt,
) -> impl Future<Output = Result<Pmt, Error>> + Send;
}
#[cfg(target_arch = "wasm32")]
pub trait KernelInterface {
fn is_blocking() -> bool;
fn type_name() -> &'static str;
fn stream_inputs(&self) -> Vec<String>;
fn stream_outputs(&self) -> Vec<String>;
fn stream_ports_init(&mut self, block_id: BlockId, inbox: Sender<BlockMessage>);
fn stream_ports_validate(&self) -> Result<(), Error>;
fn stream_input_finish(&mut self, port_id: PortId) -> Result<(), Error>;
fn stream_ports_notify_finished(&mut self) -> impl Future<Output = ()>;
fn stream_input(&mut self, name: &str) -> Option<&mut dyn BufferReader>;
fn connect_stream_output(
&mut self,
name: &str,
reader: &mut dyn BufferReader,
) -> Result<(), Error>;
fn message_inputs() -> &'static [&'static str];
fn message_outputs() -> &'static [&'static str];
fn call_handler(
&mut self,
_io: &mut WorkIo,
_mio: &mut MessageOutputs,
_meta: &mut BlockMeta,
id: PortId,
_p: Pmt,
) -> impl Future<Output = Result<Pmt, Error>>;
}