]> code.octet-stream.net Git - netwatcher/blob - src/watch_mac.rs
ed2879c6feff85a0c57c5fb9c08c3f2e48068df3
[netwatcher] / src / watch_mac.rs
1 use crate::Update;
2
3 // The "objc2" project aims to provide bindings for all frameworks but Network.framework
4 // isn't ready yet so let's kick it old-school
5
6 struct nw_path_monitor;
7 type nw_path_monitor_t = *mut nw_path_monitor;
8 struct nw_path;
9 type nw_path_t = *mut nw_path;
10 struct dispatch_queue;
11 type dispatch_queue_t = *mut dispatch_queue;
12 const QOS_CLASS_BACKGROUND: usize = 0x09;
13
14 #[link(name = "Network", kind = "framework")]
15 extern "C" {
16 fn nw_path_monitor_create() -> nw_path_monitor_t;
17 fn nw_path_monitor_set_update_handler(
18 monitor: nw_path_monitor_t,
19 update_handler: &Block<dyn Fn(nw_path_t)>,
20 );
21 fn nw_path_monitor_set_queue(monitor: nw_path_monitor_t, queue: dispatch_queue_t);
22 fn nw_path_monitor_start(monitor: nw_path_monitor_t);
23 fn nw_path_monitor_cancel(monitor: nw_path_monitor_t);
24
25 fn dispatch_get_global_queue(identifier: usize, flag: usize) -> dispatch_queue_t;
26 }
27
28 #[cfg(test)]
29 mod test {
30 use super::list_interfaces;
31
32 #[test]
33 fn list() {
34 let ifaces = list_interfaces().unwrap();
35 println!("{:?}", ifaces);
36 }
37 }
38
39 pub(crate) struct WatchHandle;
40
41 pub(crate) fn watch_interfaces<F: FnMut(Update) + 'static>(
42 callback: F,
43 ) -> Result<WatchHandle, Error> {
44 // stop current worker thread
45 // post this into a thread that will use it
46 drop(callback);
47 Ok(WatchHandle)
48 }