1use async_trait::async_trait;
4use clasp_core::Message;
5use tokio::sync::mpsc;
6
7use crate::Result;
8
9#[derive(Debug, Clone)]
11pub enum BridgeEvent {
12 ToClasp(Box<Message>),
14 Connected,
16 Disconnected { reason: Option<String> },
18 Error(String),
20}
21
22#[derive(Debug, Clone)]
24pub struct BridgeConfig {
25 pub name: String,
27 pub protocol: String,
29 pub bidirectional: bool,
31 pub options: std::collections::HashMap<String, String>,
33}
34
35impl Default for BridgeConfig {
36 fn default() -> Self {
37 Self {
38 name: "Bridge".to_string(),
39 protocol: "unknown".to_string(),
40 bidirectional: true,
41 options: std::collections::HashMap::new(),
42 }
43 }
44}
45
46#[async_trait]
48pub trait Bridge: Send + Sync {
49 fn config(&self) -> &BridgeConfig;
51
52 async fn start(&mut self) -> Result<mpsc::Receiver<BridgeEvent>>;
54
55 async fn stop(&mut self) -> Result<()>;
57
58 async fn send(&self, message: Message) -> Result<()>;
60
61 fn is_running(&self) -> bool;
63
64 fn namespace(&self) -> &str;
66}