Skip to main content

melodium_engine/
engine.rs

1use crate::{
2    debug::{DebugLevel, Event},
3    error::{LogicErrors, LogicResult},
4};
5use async_channel::Sender;
6use async_trait::async_trait;
7use melodium_common::{
8    descriptor::{Collection, Identifier},
9    executive::{
10        DirectCreationCallback, Level as LogLevel, Log, Secret, SecretsAccess, TrackId, Value,
11    },
12};
13use std::{collections::HashMap, sync::Arc};
14
15#[async_trait]
16pub trait Engine: Send + Sync {
17    fn collection(&self) -> Arc<Collection>;
18    fn genesis(&self, entry: &Identifier, params: HashMap<String, Value>) -> LogicResult<()>;
19    fn errors(&self) -> LogicErrors;
20    fn set_auto_end(&self, auto_end: bool);
21    fn auto_end(&self) -> bool;
22    fn log_level(&self) -> LogLevel;
23    fn add_logs_listener(&self, sender: Sender<Log>);
24    fn debug_level(&self) -> DebugLevel;
25    fn add_debug_listener(&self, sender: Sender<Event>);
26    async fn live(&self);
27    async fn instanciate(&self, callback: Option<DirectCreationCallback>) -> LogicResult<()>;
28    async fn end(&self);
29    /// Stops every running track and continuous task, after ending as `end` does: their
30    /// futures are dropped at their next await point, and `live` then ends.
31    async fn stop(&self);
32    /// Resolves the secrets given for each parameter and drops their values right away,
33    /// to check that they can be resolved.
34    async fn check_secrets(&self, secrets: Vec<(String, Secret)>) -> LogicResult<()>;
35    /// Logs a message from the engine itself.
36    async fn log(&self, level: LogLevel, label: String, message: String);
37    /// Gives an access to secrets on behalf of `element`, for code driving the engine
38    /// from outside, such as distribution.
39    fn secrets_access(
40        &self,
41        element: Identifier,
42        label: Option<String>,
43        track_id: Option<TrackId>,
44    ) -> SecretsAccess;
45}