1use auria_core::AuriaResult;
2use async_trait::async_trait;
3
4#[async_trait]
5pub trait Plugin: Send + Sync {
6 fn name(&self) -> &str;
7 fn version(&self) -> &str;
8 async fn initialize(&self) -> AuriaResult<()>;
9 async fn shutdown(&self) -> AuriaResult<()>;
10}
11
12pub struct PluginRegistry {
13 plugins: Vec<Box<dyn Plugin>>,
14}
15
16impl PluginRegistry {
17 pub fn new() -> Self {
18 Self {
19 plugins: Vec::new(),
20 }
21 }
22
23 pub fn register(&mut self, plugin: Box<dyn Plugin>) {
24 self.plugins.push(plugin);
25 }
26
27 pub async fn initialize_all(&self) -> AuriaResult<()> {
28 for plugin in &self.plugins {
29 plugin.initialize().await?;
30 }
31 Ok(())
32 }
33
34 pub async fn shutdown_all(&self) -> AuriaResult<()> {
35 for plugin in &self.plugins {
36 plugin.shutdown().await?;
37 }
38 Ok(())
39 }
40}