melodium_common/executive/
world.rs1use crate::{
2 descriptor::Collection,
3 executive::{
4 Context, ContinuousFuture, Input, Level, Log, ModelId, Output, Outputs, TrackFuture, Value,
5 },
6};
7use async_trait::async_trait;
8use core::fmt::Debug;
9use std::{collections::HashMap, sync::Arc};
10use uuid::Uuid;
11
12pub type TrackId = usize;
13pub type TrackCreationCallback = Box<dyn FnOnce(Box<dyn Outputs>) -> Vec<TrackFuture> + Send>;
14pub type DirectCreationCallback = Box<
15 dyn FnOnce(
16 HashMap<String, Box<dyn Output>>,
17 HashMap<String, Box<dyn Input>>,
18 ) -> Vec<TrackFuture>
19 + Send,
20>;
21
22#[async_trait]
23pub trait World: Debug + Send + Sync {
24 fn collection(&self) -> Arc<Collection>;
25 fn add_continuous_task(&self, task: ContinuousFuture);
26 async fn create_track(
27 &self,
28 id: ModelId,
29 source: &str,
30 params: &HashMap<String, Value>,
31 contexts: Vec<Arc<dyn Context>>,
32 parent_track: Option<TrackId>,
33 callback: Option<TrackCreationCallback>,
34 );
35 async fn log(&self, level: Level, label: String, message: String, track_id: Option<TrackId>);
36 async fn inject_log(&self, log: Log) -> Result<(), ()>;
37 async fn inject_debug(&self, run_id: Uuid, data: String) -> Result<(), ()>;
38 async fn wait_no_more_tracks(&self);
46}