1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use {
anyhow::Error,
fidl_test_policy::{ExitControllerRequest, ExitControllerRequestStream},
fuchsia_async as fasync,
fuchsia_component::server::ServiceFs,
futures::prelude::*,
std::process,
};
#[fasync::run_singlethreaded]
async fn main() {
let mut fs = ServiceFs::new_local();
fs.dir("svc").add_fidl_service(move |stream| {
fasync::Task::local(
run_service(stream).unwrap_or_else(|e| panic!("error running service: {:?}", e)),
)
.detach();
});
fs.take_and_serve_directory_handle().expect("failed to serve outgoing dir");
fs.collect::<()>().await;
}
async fn run_service(mut stream: ExitControllerRequestStream) -> Result<(), Error> {
while let Some(request) = stream.try_next().await? {
match request {
ExitControllerRequest::Exit { code, control_handle: _ } => {
process::exit(code);
}
}
}
Ok(())
}