oxios_gateway/plugin.rs
1//! Channel plugin system.
2//!
3//! Provides a factory pattern for channels. Each channel (web, cli, telegram)
4//! implements ChannelPlugin so the main binary can activate channels from
5//! configuration without importing concrete types.
6
7use anyhow::Result;
8use async_trait::async_trait;
9use std::path::PathBuf;
10use std::sync::Arc;
11use tokio::task::JoinHandle;
12
13use crate::Channel;
14
15/// Shared context provided to channel plugins during setup.
16pub struct ChannelContext {
17 /// Kernel subsystem handle (supervisor, state store, etc.).
18 pub kernel: Arc<oxios_kernel::KernelHandle>,
19 /// Hot-reloadable configuration.
20 pub config: Arc<parking_lot::RwLock<oxios_kernel::OxiosConfig>>,
21 /// Path to the config file.
22 pub config_path: PathBuf,
23}
24
25/// Result of channel plugin setup.
26pub struct ChannelBundle {
27 /// The channel to register with the gateway.
28 pub channel: Box<dyn Channel>,
29 /// Background task handles (servers, event loops).
30 pub tasks: Vec<JoinHandle<()>>,
31}
32
33/// Factory for creating and setting up a channel.
34///
35/// Implementors are compiled into the binary based on feature flags.
36/// The main binary discovers plugins via the channel registry and calls
37/// `setup()` for each enabled channel.
38#[async_trait]
39pub trait ChannelPlugin: Send + Sync {
40 /// Unique name for this channel type (e.g., "web", "cli", "telegram").
41 fn name(&self) -> &str;
42
43 /// Create and set up the channel.
44 ///
45 /// Returns a bundle with the channel (for gateway registration)
46 /// and optional background tasks (e.g., axum server, interactive loop).
47 async fn setup(&self, ctx: ChannelContext) -> Result<ChannelBundle>;
48}