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};
32use harmos_domain::model::operations::lifecycle;
33
34pub trait Context: Clone + Send + Sync + 'static {
47 fn assign_operations(&self, bytes: &[u8]) -> Result<(), ServingError>;
48 fn with_generation(&self, token: [u8; 32]) -> Self;
49}
50
51pub trait Plugin: lifecycle::Policy + Send + Sync + Sized + 'static {
52 fn register(_registrar: &mut crate::Registrar) -> Result<(), crate::RegistrationError> {
53 Ok(())
54 }
55
56 type Config: DeserializeOwned + Default + Send + 'static;
57 type Error: std::error::Error + Send + Sync + 'static;
58 type Context: Context;
59 type Resources: Send + Sync + 'static;
60
61 fn resources(&self) -> Arc<Self::Resources>;
62
63 fn prepare(config: Self::Config) -> Result<Self, Self::Error>;
64
65 fn initialize(&mut self, context: &Self::Context) -> impl Future<Output = Result<(), Self::Error>> + Send;
66
67 fn bind_operations(&self, table: &mut WireTable) -> Result<(), ServingError>;
68
69 fn stop(&mut self, context: &Self::Context) -> impl Future<Output = Result<(), Self::Error>> + Send;
70
71 fn cleanup(&mut self) -> impl Future<Output = Result<(), Self::Error>> + Send;
72
73 fn attachment(&self) -> Option<Arc<dyn Attachment<Self::Context>>> {
74 None
75 }
76}
77
78pub trait Attachment<C>: Send + Sync + 'static {
79 fn observers(&self) -> Vec<crate::inventory::observers::Declaration>;
80 fn resources(&self) -> Arc<dyn std::any::Any + Send + Sync>;
81 fn quiesce(&self) -> Pin<Box<dyn Future<Output = Result<(), ServingError>> + Send + '_>>;
82}
83
84impl Context for () {
87 fn assign_operations(&self, bytes: &[u8]) -> Result<(), ServingError> {
88 if bytes.is_empty() { Ok(()) } else { Err(ServingError::Catalog) }
89 }
90 fn with_generation(&self, _: [u8; 32]) -> Self {}
91}
92
93