ndn_ipc/
client.rs

1use std::sync::Arc;
2
3use ndn_packet::Name;
4
5/// High-level NDN IPC client.
6///
7/// Generic over the face type `F` so it can work with any transport:
8/// - `AppFace` for in-process use (library embedding)
9/// - `UnixFace` for cross-process use over a Unix domain socket
10/// - A future `ShmFace` for zero-copy cross-process IPC
11///
12/// The namespace is the root name under which this client operates; it is
13/// prepended to all expressed Interests by convention (not enforced here).
14pub struct IpcClient<F> {
15    face: Arc<F>,
16    namespace: Name,
17}
18
19impl<F> IpcClient<F> {
20    pub fn new(face: Arc<F>, namespace: Name) -> Self {
21        Self { face, namespace }
22    }
23
24    pub fn face(&self) -> &F {
25        &self.face
26    }
27
28    pub fn namespace(&self) -> &Name {
29        &self.namespace
30    }
31}
32
33#[cfg(test)]
34mod tests {
35    use super::*;
36    use ndn_faces::local::InProcFace;
37    use ndn_transport::{Face, FaceId};
38
39    #[test]
40    fn new_and_accessors() {
41        let (face, _rx) = InProcFace::new(FaceId(1), 8);
42        let ns = Name::root();
43        let client = IpcClient::new(Arc::new(face), ns.clone());
44        assert_eq!(client.namespace(), &ns);
45        assert_eq!(client.face().id(), FaceId(1));
46    }
47}