use crate::error::{Error, Result};
use parking_lot::RwLock;
use std::sync::Arc;
use tracing::{debug, info};
pub struct Zenoh {
_config: ZenohConfig,
_inner: Arc<RwLock<()>>, }
#[derive(Debug, Clone)]
pub struct ZenohConfig {
pub mode: String,
pub connect: Vec<String>,
pub listen: Vec<String>,
}
impl Default for ZenohConfig {
fn default() -> Self {
Self {
mode: "peer".to_string(),
connect: vec![],
listen: vec!["tcp/0.0.0.0:7447".to_string()],
}
}
}
impl Zenoh {
pub async fn new(config: ZenohConfig) -> Result<Self> {
info!("Initializing Zenoh middleware in {} mode", config.mode);
Ok(Self {
_config: config,
_inner: Arc::new(RwLock::new(())),
})
}
pub async fn open() -> Result<Self> {
Self::new(ZenohConfig::default()).await
}
pub fn config(&self) -> &ZenohConfig {
&self._config
}
}
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn test_zenoh_creation() {
let zenoh = Zenoh::open().await;
assert!(zenoh.is_ok());
}
}