Skip to content

Commit 1d679c9

Browse files
committed
Move DTX API code to external crate
1 parent 2388ffe commit 1d679c9

File tree

6 files changed

+180
-711
lines changed

6 files changed

+180
-711
lines changed

Cargo.lock

Lines changed: 140 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ anyhow = "1.0.38"
1616
clap = "2.33.3"
1717
indoc = "1.0.3"
1818
nix = "0.20.0"
19+
sdtx = { git = "https://github.com/linux-surface/libsurfacedtx", tag = "v0.1.0" }
1920
serde = "1.0.124"
2021
serde_json = "1.0.64"
21-
smallvec = "1.6.1"
2222
thiserror = "1.0.24"
2323
udev = "0.6.0"
2424

@@ -27,9 +27,9 @@ anyhow = "1.0.38"
2727
clap = "2.33.3"
2828
indoc = "1.0.3"
2929
nix = "0.20.0"
30+
sdtx = { git = "https://github.com/linux-surface/libsurfacedtx", tag = "v0.1.0" }
3031
serde = "1.0.124"
3132
serde_json = "1.0.64"
32-
smallvec = "1.6.1"
3333
thiserror = "1.0.24"
3434
udev = "0.6.0"
3535

src/cli/dtx.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl DynCommand for Command {
6868

6969
impl Command {
7070
fn lock(&self, m: &clap::ArgMatches) -> Result<()> {
71-
sys::dtx::Device::open()
71+
sdtx::Device::open()
7272
.context("Failed to open DTX device")?
7373
.latch_lock()
7474
.context("Failed to lock latch")?;
@@ -81,7 +81,7 @@ impl Command {
8181
}
8282

8383
fn unlock(&self, m: &clap::ArgMatches) -> Result<()> {
84-
sys::dtx::Device::open()
84+
sdtx::Device::open()
8585
.context("Failed to open DTX device")?
8686
.latch_unlock()
8787
.context("Failed to unlock latch")?;
@@ -94,7 +94,7 @@ impl Command {
9494
}
9595

9696
fn request(&self, m: &clap::ArgMatches) -> Result<()> {
97-
sys::dtx::Device::open()
97+
sdtx::Device::open()
9898
.context("Failed to open DTX device")?
9999
.latch_request()
100100
.context("Failed to send latch request")?;
@@ -107,7 +107,7 @@ impl Command {
107107
}
108108

109109
fn confirm(&self, m: &clap::ArgMatches) -> Result<()> {
110-
sys::dtx::Device::open()
110+
sdtx::Device::open()
111111
.context("Failed to open DTX device")?
112112
.latch_confirm()
113113
.context("Failed to send confirmation")?;
@@ -120,7 +120,7 @@ impl Command {
120120
}
121121

122122
fn heartbeat(&self, m: &clap::ArgMatches) -> Result<()> {
123-
sys::dtx::Device::open()
123+
sdtx::Device::open()
124124
.context("Failed to open DTX device")?
125125
.latch_heartbeat()
126126
.context("Failed to send heartbeat")?;
@@ -133,7 +133,7 @@ impl Command {
133133
}
134134

135135
fn cancel(&self, m: &clap::ArgMatches) -> Result<()> {
136-
sys::dtx::Device::open()
136+
sdtx::Device::open()
137137
.context("Failed to open DTX device")?
138138
.latch_cancel()
139139
.context("Failed to cancel detachment")?;
@@ -146,7 +146,7 @@ impl Command {
146146
}
147147

148148
fn get_base_info(&self, m: &clap::ArgMatches) -> Result<()> {
149-
let info = sys::dtx::Device::open()
149+
let info = sdtx::Device::open()
150150
.context("Failed to open DTX device")?
151151
.get_base_info()
152152
.context("Failed to get base info")?;
@@ -167,7 +167,7 @@ impl Command {
167167
}
168168

169169
fn get_device_mode(&self, _m: &clap::ArgMatches) -> Result<()> {
170-
let mode = sys::dtx::Device::open()
170+
let mode = sdtx::Device::open()
171171
.context("Failed to open DTX device")?
172172
.get_device_mode()
173173
.context("Failed to get device mode")?;
@@ -177,7 +177,7 @@ impl Command {
177177
}
178178

179179
fn get_latch_status(&self, _m: &clap::ArgMatches) -> Result<()> {
180-
let status = sys::dtx::Device::open()
180+
let status = sdtx::Device::open()
181181
.context("Failed to open DTX device")?
182182
.get_latch_status()
183183
.context("Failed to get latch status")?;
@@ -187,7 +187,7 @@ impl Command {
187187
}
188188

189189
fn monitor(&self, m: &clap::ArgMatches) -> Result<()> {
190-
let mut device = sys::dtx::Device::open()
190+
let mut device = sdtx::Device::open()
191191
.context("Failed to open DTX device")?;
192192

193193
let events = device.events()
@@ -216,7 +216,7 @@ impl Command {
216216
}
217217

218218

219-
struct PrettyBaseInfo(sys::dtx::BaseInfo);
219+
struct PrettyBaseInfo(sdtx::BaseInfo);
220220

221221
impl serde::Serialize for PrettyBaseInfo {
222222
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -228,15 +228,15 @@ impl serde::Serialize for PrettyBaseInfo {
228228
let mut s = serializer.serialize_struct("BaseInfo", 3)?;
229229

230230
match self.0.state {
231-
sys::dtx::BaseState::Attached => s.serialize_field("state", "attached"),
232-
sys::dtx::BaseState::Detached => s.serialize_field("state", "detached"),
233-
sys::dtx::BaseState::NotFeasible => s.serialize_field("state", "not-feasible"),
231+
sdtx::BaseState::Attached => s.serialize_field("state", "attached"),
232+
sdtx::BaseState::Detached => s.serialize_field("state", "detached"),
233+
sdtx::BaseState::NotFeasible => s.serialize_field("state", "not-feasible"),
234234
}?;
235235

236236
match self.0.device_type {
237-
sys::dtx::DeviceType::Hid => s.serialize_field("type", "hid"),
238-
sys::dtx::DeviceType::Ssh => s.serialize_field("type", "ssh"),
239-
sys::dtx::DeviceType::Unknown(x) => s.serialize_field("type", &x),
237+
sdtx::DeviceType::Hid => s.serialize_field("type", "hid"),
238+
sdtx::DeviceType::Ssh => s.serialize_field("type", "ssh"),
239+
sdtx::DeviceType::Unknown(x) => s.serialize_field("type", &x),
240240
}?;
241241

242242
s.serialize_field("id", &self.0.id)?;
@@ -245,16 +245,16 @@ impl serde::Serialize for PrettyBaseInfo {
245245
}
246246

247247

248-
struct PrettyEvent(sys::dtx::Event);
248+
struct PrettyEvent(sdtx::Event);
249249

250250
impl serde::Serialize for PrettyEvent {
251251
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
252252
where
253253
S: serde::Serializer
254254
{
255255
use serde::ser::SerializeStruct;
256-
use sys::dtx::{DeviceType, Event, HardwareError, RuntimeError, uapi};
257-
use sys::dtx::event::{BaseState, CancelReason, DeviceMode, LatchStatus};
256+
use sdtx::{DeviceType, Event, HardwareError, RuntimeError, uapi};
257+
use sdtx::event::{BaseState, CancelReason, DeviceMode, LatchStatus};
258258

259259
match &self.0 {
260260
Event::Request => {
@@ -357,8 +357,8 @@ impl serde::Serialize for PrettyEvent {
357357

358358
impl std::fmt::Display for PrettyEvent {
359359
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
360-
use sys::dtx::{DeviceType, Event};
361-
use sys::dtx::event::{BaseState, CancelReason, DeviceMode, LatchStatus};
360+
use sdtx::{DeviceType, Event};
361+
use sdtx::event::{BaseState, CancelReason, DeviceMode, LatchStatus};
362362

363363
match &self.0 {
364364
Event::Request => {

src/cli/status.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ struct DgpuStats {
4747
}
4848

4949
struct DtxStats {
50-
device_mode: Option<sys::dtx::DeviceMode>,
51-
base_state: Option<sys::dtx::BaseState>,
52-
base_type: Option<sys::dtx::DeviceType>,
50+
device_mode: Option<sdtx::DeviceMode>,
51+
base_state: Option<sdtx::BaseState>,
52+
base_type: Option<sdtx::DeviceType>,
5353
base_id: Option<u8>,
54-
latch_status: Option<sys::dtx::LatchStatus>,
54+
latch_status: Option<sdtx::LatchStatus>,
5555
}
5656

5757

@@ -106,7 +106,7 @@ impl DgpuStats {
106106

107107
impl DtxStats {
108108
fn load() -> Self {
109-
let dev = sys::dtx::Device::open().ok();
109+
let dev = sdtx::Device::open().ok();
110110

111111
let base = dev.as_ref().and_then(|d| d.get_base_info().ok());
112112
let base_state = base.map(|b| b.state);

0 commit comments

Comments
 (0)