1mod owner;
13
14pub use crate::error::Error;
17pub use harmos_domain::plugin::*;
18pub use owner::{Owner, Table};
19
20use std::future::Future;
24use std::pin::Pin;
25use std::sync::Arc;
26
27use serde::de::DeserializeOwned;
29
30use crate::operations::{ServingError, WireTable, lifecycle};
32
33pub trait Context: Clone + Send + Sync + 'static {
46 fn with_generation(&self, token: [u8; 32]) -> Self;
47}
48
49pub trait Plugin: lifecycle::Policy + Send + Sync + Sized + 'static {
50 fn register(_registrar: &mut crate::Registrar) -> Result<(), crate::RegistrationError> {
51 Ok(())
52 }
53
54 type Config: DeserializeOwned + Default + Send + 'static;
55 type Error: std::error::Error + Send + Sync + 'static;
56 type Context: Context;
57 type Resources: Send + Sync + 'static;
58
59 fn resources(&self) -> Arc<Self::Resources>;
60
61 fn prepare(config: Self::Config) -> Result<Self, Self::Error>;
62
63 fn initialize(&mut self, context: &Self::Context) -> impl Future<Output = Result<(), Self::Error>> + Send;
64
65 fn bind_operations(&self, table: &mut WireTable<Self::Context>) -> Result<(), ServingError>;
66
67 fn stop(&mut self, context: &Self::Context) -> impl Future<Output = Result<(), Self::Error>> + Send;
68
69 fn cleanup(&mut self) -> impl Future<Output = Result<(), Self::Error>> + Send;
70
71 fn attachment(&self) -> Option<Arc<dyn Attachment<Self::Context>>> {
72 None
73 }
74}
75
76pub trait Attachment<C>: Send + Sync + 'static {
77 fn observers(&self) -> Vec<crate::inventory::observers::Declaration>;
78 fn resources(&self) -> Arc<dyn std::any::Any + Send + Sync>;
79 fn quiesce(&self) -> Pin<Box<dyn Future<Output = Result<(), ServingError>> + Send + '_>>;
80}
81
82impl Context for () {
85 fn with_generation(&self, _: [u8; 32]) -> Self {}
86}
87
88