agentic_robotics_core/
middleware.rs1use crate::error::{Error, Result};
6use parking_lot::RwLock;
7use std::sync::Arc;
8use tracing::{debug, info};
9
10pub struct Zenoh {
12 _config: ZenohConfig,
13 _inner: Arc<RwLock<()>>, }
15
16#[derive(Debug, Clone)]
17pub struct ZenohConfig {
18 pub mode: String,
19 pub connect: Vec<String>,
20 pub listen: Vec<String>,
21}
22
23impl Default for ZenohConfig {
24 fn default() -> Self {
25 Self {
26 mode: "peer".to_string(),
27 connect: vec![],
28 listen: vec!["tcp/0.0.0.0:7447".to_string()],
29 }
30 }
31}
32
33impl Zenoh {
34 pub async fn new(config: ZenohConfig) -> Result<Self> {
36 info!("Initializing Zenoh middleware in {} mode", config.mode);
37
38 Ok(Self {
41 _config: config,
42 _inner: Arc::new(RwLock::new(())),
43 })
44 }
45
46 pub async fn open() -> Result<Self> {
48 Self::new(ZenohConfig::default()).await
49 }
50
51 pub fn config(&self) -> &ZenohConfig {
53 &self._config
54 }
55}
56
57#[cfg(test)]
58mod tests {
59 use super::*;
60
61 #[tokio::test]
62 async fn test_zenoh_creation() {
63 let zenoh = Zenoh::open().await;
64 assert!(zenoh.is_ok());
65 }
66}