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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#[cfg(not(target_os = "fuchsia"))]
#[macro_use]
extern crate lazy_static;
pub mod args;
mod common;
mod subcommands;
use {
anyhow::{Context, Result},
args::{DriverCommand, DriverSubCommand},
driver_connector::DriverConnector,
std::io,
};
#[cfg(not(target_os = "fuchsia"))]
use {futures::lock::Mutex, std::sync::Arc};
pub async fn driver(
cmd: DriverCommand,
driver_connector: impl DriverConnector,
writer: &mut dyn io::Write,
) -> Result<()> {
match cmd.subcommand {
#[cfg(not(target_os = "fuchsia"))]
DriverSubCommand::Conformance(_subcmd) => {
conformance_lib::conformance(_subcmd, &driver_connector)
.await
.context("Conformance subcommand failed")?;
}
DriverSubCommand::DebugBind(subcmd) => {
let driver_development_proxy = driver_connector
.get_driver_development_proxy(subcmd.select)
.await
.context("Failed to get driver development proxy")?;
subcommands::debug_bind::debug_bind(subcmd, writer, driver_development_proxy)
.await
.context("Debug-bind subcommand failed")?;
}
DriverSubCommand::Device(subcmd) => {
let dev = driver_connector
.get_dev_proxy(subcmd.select)
.await
.context("Failed to get dev proxy")?;
subcommands::device::device(subcmd, dev).await.context("Device subcommand failed")?;
}
DriverSubCommand::Dump(subcmd) => {
let driver_development_proxy = driver_connector
.get_driver_development_proxy(subcmd.select)
.await
.context("Failed to get driver development proxy")?;
subcommands::dump::dump(subcmd, writer, driver_development_proxy)
.await
.context("Dump subcommand failed")?;
}
#[cfg(not(target_os = "fuchsia"))]
DriverSubCommand::I2c(ref subcmd) => {
let dev =
driver_connector.get_dev_proxy(false).await.context("Failed to get dev proxy")?;
subcommands::i2c::i2c(subcmd, writer, &dev).await.context("I2C subcommand failed")?;
}
DriverSubCommand::List(subcmd) => {
let driver_development_proxy = driver_connector
.get_driver_development_proxy(subcmd.select)
.await
.context("Failed to get driver development proxy")?;
subcommands::list::list(subcmd, writer, driver_development_proxy)
.await
.context("List subcommand failed")?;
}
DriverSubCommand::ListComposites(subcmd) => {
let driver_development_proxy = driver_connector
.get_driver_development_proxy(subcmd.select)
.await
.context("Failed to get driver development proxy")?;
subcommands::list_composites::list_composites(subcmd, writer, driver_development_proxy)
.await
.context("List composites subcommand failed")?;
}
DriverSubCommand::ListDevices(subcmd) => {
let driver_development_proxy = driver_connector
.get_driver_development_proxy(subcmd.select)
.await
.context("Failed to get driver development proxy")?;
subcommands::list_devices::list_devices(subcmd, driver_development_proxy)
.await
.context("List-devices subcommand failed")?;
}
DriverSubCommand::ListHosts(subcmd) => {
let driver_development_proxy = driver_connector
.get_driver_development_proxy(subcmd.select)
.await
.context("Failed to get driver development proxy")?;
subcommands::list_hosts::list_hosts(subcmd, driver_development_proxy)
.await
.context("List-hosts subcommand failed")?;
}
DriverSubCommand::ListCompositeNodeSpecs(subcmd) => {
let driver_development_proxy = driver_connector
.get_driver_development_proxy(subcmd.select)
.await
.context("Failed to get driver development proxy")?;
subcommands::list_composite_node_specs::list_composite_node_specs(
subcmd,
writer,
driver_development_proxy,
)
.await
.context("list-composite-node-specs subcommand failed")?;
}
#[cfg(not(target_os = "fuchsia"))]
DriverSubCommand::Lsblk(subcmd) => {
let dev = driver_connector
.get_dev_proxy(subcmd.select)
.await
.context("Failed to get dev proxy")?;
subcommands::lsblk::lsblk(subcmd, dev).await.context("Lsblk subcommand failed")?;
}
#[cfg(not(target_os = "fuchsia"))]
DriverSubCommand::Lspci(subcmd) => {
let dev = driver_connector
.get_dev_proxy(subcmd.select)
.await
.context("Failed to get dev proxy")?;
subcommands::lspci::lspci(subcmd, dev).await.context("Lspci subcommand failed")?;
}
#[cfg(not(target_os = "fuchsia"))]
DriverSubCommand::Lsusb(subcmd) => {
let device_watcher_proxy = driver_connector
.get_device_watcher_proxy()
.await
.context("Failed to get device watcher proxy")?;
subcommands::lsusb::lsusb(subcmd, device_watcher_proxy)
.await
.context("Lsusb subcommand failed")?;
}
#[cfg(not(target_os = "fuchsia"))]
DriverSubCommand::PrintInputReport(ref subcmd) => {
let writer = Arc::new(Mutex::new(io::stdout()));
let dev =
driver_connector.get_dev_proxy(false).await.context("Failed to get dev proxy")?;
subcommands::print_input_report::print_input_report(subcmd, writer, dev)
.await
.context("Print-input-report subcommand failed")?;
}
DriverSubCommand::Register(subcmd) => {
let driver_registrar_proxy = driver_connector
.get_driver_registrar_proxy(subcmd.select)
.await
.context("Failed to get driver registrar proxy")?;
let driver_development_proxy = driver_connector
.get_driver_development_proxy(subcmd.select)
.await
.context("Failed to get driver development proxy")?;
subcommands::register::register(
subcmd,
writer,
driver_registrar_proxy,
driver_development_proxy,
)
.await
.context("Register subcommand failed")?;
}
DriverSubCommand::Restart(subcmd) => {
let driver_development_proxy = driver_connector
.get_driver_development_proxy(subcmd.select)
.await
.context("Failed to get driver development proxy")?;
subcommands::restart::restart(subcmd, writer, driver_development_proxy)
.await
.context("Restart subcommand failed")?;
}
#[cfg(not(target_os = "fuchsia"))]
DriverSubCommand::RunTool(subcmd) => {
let tool_runner_proxy = driver_connector
.get_tool_runner_proxy(false)
.await
.context("Failed to get tool runner proxy")?;
subcommands::runtool::run_tool(subcmd, writer, tool_runner_proxy)
.await
.context("RunTool subcommand failed")?;
}
#[cfg(not(target_os = "fuchsia"))]
DriverSubCommand::StaticChecks(subcmd) => {
static_checks_lib::static_checks(subcmd, writer)
.await
.context("StaticChecks subcommand failed")?;
}
DriverSubCommand::TestNode(subcmd) => {
let driver_development_proxy = driver_connector
.get_driver_development_proxy(subcmd.select)
.await
.context("Failed to get driver development proxy")?;
subcommands::test_node::test_node(&subcmd, driver_development_proxy)
.await
.context("AddTestNode subcommand failed")?;
}
};
Ok(())
}