driver_tools/subcommands/enable/
mod.rs1pub mod args;
6
7use anyhow::{Result, format_err};
8use args::EnableCommand;
9use flex_fuchsia_driver_development as fdd;
10use std::io::Write;
11use zx_status::Status;
12
13pub async fn enable(
14 cmd: EnableCommand,
15 writer: &mut dyn Write,
16 driver_development_proxy: fdd::ManagerProxy,
17) -> Result<()> {
18 writeln!(writer, "Enabling {}.", cmd.url)?;
19
20 let result = driver_development_proxy.enable_driver(&cmd.url, None).await?;
21 match result {
22 Ok(_) => {
23 writeln!(writer, "Enabled driver successfully.")?;
24 }
25 Err(e) => {
26 if e == Status::NOT_FOUND.into_raw() {
27 writeln!(writer, "No drivers affected in this enable operation.")?;
28 } else {
29 writeln!(writer, "Unexpected error from enable: {}", e)?;
30 }
31 }
32 }
33
34 let rebind_result = driver_development_proxy.rebind_composites_with_driver(&cmd.url).await?;
35 match rebind_result {
36 Ok(count) => {
37 if count > 0 {
38 writeln!(writer, "Rebound {count} composites successfully.")?;
39 } else {
40 writeln!(writer, "No composites affected in this operation.")?;
41 }
42 }
43 Err(e) => {
44 writeln!(writer, "Unexpected error from rebind: {}", e)?;
45 }
46 }
47
48 let restart_result = driver_development_proxy
49 .restart_driver_hosts(
50 cmd.url.as_str(),
51 fdd::RestartRematchFlags::REQUESTED | fdd::RestartRematchFlags::COMPOSITE_SPEC,
52 )
53 .await?;
54
55 match restart_result {
56 Ok(count) => {
57 if count > 0 {
58 writeln!(
59 writer,
60 "Successfully restarted. Rematched {} driver hosts that had the enabled driver.",
61 count
62 )?;
63 } else {
64 writeln!(writer, "{}", "Successfully restarted.")?;
65 }
66 }
67 Err(err) => {
68 return Err(format_err!(
69 "Failed to restart existing drivers: {:?}",
70 Status::from_raw(err)
71 ));
72 }
73 }
74
75 writeln!(writer, "Attempting to bind unbound nodes...")?;
76 let bind_result = driver_development_proxy.bind_all_unbound_nodes2().await?;
77 match bind_result {
78 Ok(result) => {
79 let count = result.len();
80 writeln!(writer, "Bound {count} nodes successfully.")?;
81 }
82 Err(e) => {
83 writeln!(writer, "Unexpected error from bind_all_unbound_nodes: {}", e)?;
84 }
85 }
86
87 Ok(())
88}