nullnet_libconfmon/lib.rs
1pub use detector::{Detector, State};
2pub use error::{Error, ErrorKind};
3pub use interface_snapshot::InterfaceSnapshot;
4pub use platform::Platform;
5pub use watcher::{
6 r#impl::{Watcher, WatcherHandler},
7 types::{FileData, Snapshot},
8};
9
10mod detector;
11mod error;
12mod interface_snapshot;
13mod platform;
14mod watcher;
15
16/// Creates and initializes a new `Watcher` to monitor file changes on a specified platform.
17///
18/// # Parameters
19/// - `platform`: A string representing the target platform for the watcher (e.g., `"pfsense"` or `"opnsense"`).
20/// - `poll_interval`: The polling interval in milliseconds to check for file changes.
21/// - `handler`: A user-defined function or closure that gets executed when a change is detected.
22/// This function must implement the `WatcherHandler` trait.
23///
24/// # Returns
25/// - `Ok(Watcher<T>)`: A successfully initialized `Watcher` instance configured for the given platform.
26/// - `Err(Error)`: Returns an error if initialization fails.
27///
28/// # Errors
29/// - Returns `ErrorKind::ErrorUnsupportedPlatform` if the specified platform is not recognized.
30/// - Returns `ErrorKind::ErrorInitializingWatcher` if the watcher fails to initialize.
31pub async fn make_watcher<T>(
32 platform: &str,
33 poll_interval: u64,
34 handler: T,
35) -> Result<Watcher<T>, Error>
36where
37 T: WatcherHandler,
38{
39 let pval = Platform::from_string(platform)?;
40 let retval = Watcher::new(pval, poll_interval, handler).await?;
41
42 Ok(retval)
43}