X-Git-Url: https://code.octet-stream.net/netwatcher/blobdiff_plain/846b618fe219c44dfc7b3a13aadace2198442c9c..1c34fe3947aaf8af2d773d59bdebf19e17d78527:/src/lib.rs diff --git a/src/lib.rs b/src/lib.rs index 9f82092..61e4940 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,9 +3,14 @@ use std::{ net::{IpAddr, Ipv4Addr, Ipv6Addr}, }; -#[cfg_attr(windows, path = "imp_win.rs")] -#[cfg_attr(target_vendor = "apple", path = "imp_mac.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; @@ -40,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, @@ -56,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 -}