1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use crate::tracers::tracer::Tracer;
use derive_more::{Deref, DerefMut};
use rill_protocol::flow::meta::path::{PathEvent, PathState};
use rill_protocol::io::provider::{Description, Path};

/// This tracer that informs about entries.
#[derive(Debug, Deref, DerefMut, Clone)]
pub struct PathTracer {
    tracer: Tracer<PathState>,
}

impl PathTracer {
    /// Create a new instance of the `Tracer`.
    pub fn new(path: Path) -> Self {
        let state = PathState::new();
        let tracer = Tracer::new_tracer(state, path, None);
        Self { tracer }
    }

    /// Add an path
    pub fn add(&self, path: Path, description: Description) {
        let data = PathEvent::AddPath { path, description };
        self.tracer.send(data, None);
    }

    /// Remove an path
    pub fn del(&self, path: Path) {
        let data = PathEvent::RemovePath { path };
        self.tracer.send(data, None);
    }
}