Skip to main content

harmos_sdk/operations/
lifecycle.rs

1/* ***
2 *
3 * Harmos
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * ***
8 */
9
10/* === Modules === */
11
12/* === Re-Exports === */
13
14/* === Imports === */
15
16use super::{ExecutionContext, access::AccessError};
17use harmos_domain::model::operations::lifecycle::Action;
18use std::{future::Future, pin::Pin, sync::Arc};
19
20/* === Constants === */
21
22/* === Macros === */
23
24/* === Type Aliases === */
25
26pub type Transition<'a> = Pin<Box<dyn Future<Output = Result<(), AccessError>> + Send + 'a>>;
27
28/* === Structs === */
29
30pub struct LifecycleAccess(pub Arc<dyn PluginLifecycle>);
31
32/* === Enums === */
33
34/* === Traits === */
35
36pub trait PluginLifecycle: Send + Sync {
37    fn begin(self: Arc<Self>, action: Action) -> Box<dyn LifecycleInstance>;
38}
39pub trait LifecycleInstance: Send {
40    fn run<'a>(&'a mut self, context: ExecutionContext, config: &'a [u8], generation: &'a [u8], assignments: &'a [u8]) -> Transition<'a>;
41    fn cleanup(&mut self) -> Transition<'_>;
42}
43
44/* === Implementations === */
45
46/* === Public Functions === */
47
48/* === Private Functions === */
49
50/* === Tests === */