use std::collections::HashMap;
use std::sync::{Arc, RwLock};
use crate::adapter::PairingChannelAdapter;
#[derive(Clone, Default)]
pub struct PairingAdapterRegistry {
inner: Arc<RwLock<HashMap<&'static str, Arc<dyn PairingChannelAdapter>>>>,
}
impl PairingAdapterRegistry {
pub fn new() -> Self {
Self::default()
}
pub fn register(&self, adapter: Arc<dyn PairingChannelAdapter>) {
let id = adapter.channel_id();
self.inner.write().unwrap().insert(id, adapter);
}
pub fn get(&self, channel_id: &str) -> Option<Arc<dyn PairingChannelAdapter>> {
self.inner.read().unwrap().get(channel_id).cloned()
}
pub fn is_empty(&self) -> bool {
self.inner.read().unwrap().is_empty()
}
}