X-Git-Url: https://code.octet-stream.net/netwatcher/blobdiff_plain/0ecc1ee8ddfdf50d813fe18794eb27ac4ec0cf56..1c34fe3947aaf8af2d773d59bdebf19e17d78527:/src/lib.rs?ds=sidebyside diff --git a/src/lib.rs b/src/lib.rs index af5b7af..61e4940 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,8 +3,15 @@ use std::{ net::{IpAddr, Ipv4Addr, Ipv6Addr}, }; -#[cfg_attr(windows, path = "imp_win.rs")] -mod imp; +#[cfg_attr(windows, path = "list_win.rs")] +#[cfg_attr(target_vendor = "apple", path = "list_mac.rs")] +mod list; + +#[cfg_attr(windows, path = "watch_win.rs")] +#[cfg_attr(target_vendor = "apple", path = "watch_mac.rs")] +mod watch; + +mod util; type IfIndex = u32; @@ -38,14 +45,21 @@ pub struct Update { pub diff: UpdateDiff, } -#[derive(Debug, Clone, PartialEq, Eq)] +impl Update { + pub fn diff_from_previous(_prev: &Update) -> UpdateDiff { + // TODO: real calculation + UpdateDiff::default() + } +} + +#[derive(Debug, Clone, PartialEq, Eq, Default)] pub struct UpdateDiff { pub added: Vec, pub removed: Vec, pub modified: HashMap, } -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Default)] pub struct InterfaceDiff { pub hw_addr_changed: bool, pub addrs_added: Vec, @@ -54,18 +68,10 @@ pub struct InterfaceDiff { #[derive(Debug, Clone, PartialEq, Eq)] pub enum Error { + // TODO: handle all cases with proper sources Internal, } -pub fn list_interfaces() -> Result, Error> { - imp::list_interfaces() -} +pub use list::list_interfaces; +pub use watch::{watch_interfaces, WatchHandle}; -pub struct WatchHandle; - -pub fn watch_interfaces(callback: F) -> WatchHandle { - // stop current worker thread - // post this into a thread that will use it - drop(callback); - WatchHandle -}