1use fuchsia_component::server::ServiceFs;
9use fuchsia_inspect::component;
10use futures::channel::mpsc::unbounded;
11use futures::{FutureExt as _, StreamExt as _};
12use log::info;
13use reachability_core::{Monitor, NetworkCheckAction, NetworkCheckCookie};
14use reachability_handler::ReachabilityHandler;
15use std::pin::pin;
16
17mod eventloop;
18
19use crate::eventloop::EventLoop;
20
21#[fuchsia::main(logging_tags = ["reachability"])]
22pub fn main() {
23 info!("Starting reachability monitor!");
26 let mut executor = fuchsia_async::LocalExecutor::new();
27
28 let mut fs = ServiceFs::new_local();
29
30 let mut handler = ReachabilityHandler::new();
31 handler.publish_service(fs.dir("svc"));
32
33 let inspector = component::inspector();
34 component::serve_inspect_stats();
37
38 let _inspect_server_task =
39 inspect_runtime::publish(inspector, inspect_runtime::PublishOptions::default())
40 .expect("publish Inspect task");
41
42 let fs = fs.take_and_serve_directory_handle().expect("failed to serve ServiceFS directory");
43
44 let (sender, receiver) = unbounded::<(NetworkCheckAction, NetworkCheckCookie)>();
45 let mut monitor = Monitor::new(sender).expect("failed to create reachability monitor");
46 let () = monitor.set_inspector(inspector);
47
48 info!("monitoring");
49 let mut eventloop = EventLoop::new(monitor, handler, receiver, inspector);
50 let mut eventloop_fut = pin!(eventloop.run().fuse());
51 let mut serve_fut = pin!(fs.fuse().collect());
52
53 executor.run_singlethreaded(async {
54 futures::select! {
55 r = eventloop_fut => {
56 let r: Result<(), anyhow::Error> = r;
57 panic!("unexpectedly exited event loop with result {:?}", r);
58 },
59 () = serve_fut => {
60 panic!("unexpectedly stopped serving ServiceFS");
61 },
62 }
63 })
64}