futuresdr 0.0.41

An Experimental Async SDR Runtime for Heterogeneous Architectures.
Documentation
use std::future::Future;

use crate::runtime::BlockId;
use crate::runtime::Error;
use crate::runtime::Pmt;
use crate::runtime::PortId;
use crate::runtime::Result;
use crate::runtime::buffer::BufferReader;
use crate::runtime::dev::BlockInbox;
use crate::runtime::dev::BlockMeta;
use crate::runtime::dev::MessageOutputs;
use crate::runtime::dev::WorkIo;

/// Send-capable proof for the generated block interface.
///
/// This keeps return-type-notation bounds for generated async handlers in one
/// place. Block authors should implement [`crate::runtime::dev::Kernel`], not
/// this trait.
#[doc(hidden)]
pub trait SendKernelInterface: KernelInterface + Send
where
    Self: KernelInterface<stream_ports_notify_finished(..): Send, call_handler(..): Send>,
{
}

impl<T> SendKernelInterface for T where
    T: KernelInterface<stream_ports_notify_finished(..): Send, call_handler(..): Send> + Send
{
}

/// Internal block interface generated by `#[derive(Block)]`.
#[doc(hidden)]
pub trait KernelInterface {
    /// Whether this block should run in a separate thread instead of on
    /// a normal scheduler worker.
    fn is_blocking() -> bool;
    /// Static block type name.
    fn type_name() -> &'static str;
    /// Stream input port names.
    fn stream_inputs(&self) -> Vec<String>;
    /// Stream output port names.
    fn stream_outputs(&self) -> Vec<String>;
    /// Bind stream ports to their owning block id, port ids, and inbox.
    fn stream_ports_init(&mut self, block_id: BlockId, inbox: BlockInbox);
    /// Validate that all stream ports are connected and ready to run.
    fn stream_ports_validate(&self) -> Result<(), Error>;
    /// Mark one stream input as finished because the upstream writer is done.
    fn stream_input_finish(&mut self, port_id: PortId) -> Result<(), Error>;
    /// Notify adjacent stream peers that this block is done.
    fn stream_ports_notify_finished(&mut self) -> impl Future<Output = ()>;
    /// Get a type-erased stream input by port id.
    fn stream_input(&mut self, id: &PortId) -> Result<&mut dyn BufferReader, Error>;
    /// Connect a type-erased destination reader to one stream output.
    fn connect_stream_output(
        &mut self,
        id: &PortId,
        reader: &mut dyn BufferReader,
    ) -> Result<(), Error>;

    /// Message input port names.
    fn message_inputs() -> &'static [&'static str];
    /// Message output port names.
    fn message_outputs() -> &'static [&'static str];
    /// Call a message handler.
    fn call_handler(
        &mut self,
        _io: &mut WorkIo,
        _mo: &mut MessageOutputs,
        _meta: &mut BlockMeta,
        id: PortId,
        _p: Pmt,
    ) -> impl Future<Output = Result<Pmt, Error>>;
}