1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (c) 2022-2023, Radu Racariu.
//!
//! Defines the block execution engine
//!
use anyhow::Result;
use super::{block::Block, program::Program};
pub mod messages;
/// Specifies the interface for an engine
/// that implements the block execution logic.
pub trait Engine {
/// The transmission type of the blocks
type Writer;
/// The reception type of the blocks
type Reader;
/// The type used to send messages to/from this engine.
type Channel: Send + Sync + Clone;
/// Schedule a block to be executed by this engine.
/// This operation can be performed while the engine is running.
fn schedule<B: Block<Writer = Self::Writer, Reader = Self::Reader> + 'static>(
&mut self,
block: B,
);
/// Synchronously schedule the blocks and validate-and-queue the links
/// from a [`Program`]. This is the pre-run setup half of program
/// loading; it does NOT push input/output constant values (which
/// requires the actor loop to be running — see `load_program` on the
/// inherent engine impls for the full async path).
fn schedule_program_blocks(&mut self, program: &Program) -> Result<()>;
/// Runs the event loop of this engine
/// an execute the blocks that where scheduled
#[allow(async_fn_in_trait)]
async fn run(&mut self);
/// Get a handle to this engines messaging system so external
/// systems can communicate with this engine once the engine will run.
///
/// # Arguments
/// - sender_id The sender unique id.
/// - sender_channel The sender chanel to send notifications from the engine.
///
/// # Returns
/// A sender chanel that is used to send messages to the engine.
///
fn create_message_channel(
&mut self,
sender_id: uuid::Uuid,
sender_channel: Self::Channel,
) -> Self::Channel;
}