Skip to content

Commit c852b72

Browse files
doprzkavishdevar
authored andcommitted
fix(linux-rust): format and fix syntax error
1 parent 902b12a commit c852b72

File tree

19 files changed

+2030
-1374
lines changed

19 files changed

+2030
-1374
lines changed

linux-rust/src/bluetooth/aacp.rs

Lines changed: 244 additions & 117 deletions
Large diffs are not rendered by default.

linux-rust/src/bluetooth/att.rs

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use bluer::l2cap::{SocketAddr, Socket, SeqPacket};
2-
use bluer::{Address, AddressType, Result, Error};
3-
use log::{info, error, debug};
1+
use bluer::l2cap::{SeqPacket, Socket, SocketAddr};
2+
use bluer::{Address, AddressType, Error, Result};
3+
use hex;
4+
use log::{debug, error, info};
5+
use std::collections::HashMap;
46
use std::sync::Arc;
57
use tokio::sync::{Mutex, mpsc};
68
use tokio::task::JoinSet;
7-
use tokio::time::{sleep, Duration, Instant};
8-
use std::collections::HashMap;
9-
use hex;
9+
use tokio::time::{Duration, Instant, sleep};
1010

1111
const PSM_ATT: u16 = 0x001F;
1212
const CONNECT_TIMEOUT: Duration = Duration::from_secs(10);
@@ -25,7 +25,7 @@ pub enum ATTHandles {
2525
AirPodsLoudSoundReduction = 0x1B,
2626
AirPodsHearingAid = 0x2A,
2727
NothingEverything = 0x8002,
28-
NothingEverythingRead = 0x8005 // for some reason, and not the same as the write handle
28+
NothingEverythingRead = 0x8005, // for some reason, and not the same as the write handle
2929
}
3030

3131
#[repr(u16)]
@@ -43,7 +43,7 @@ impl From<ATTHandles> for ATTCCCDHandles {
4343
ATTHandles::AirPodsLoudSoundReduction => ATTCCCDHandles::LoudSoundReduction,
4444
ATTHandles::AirPodsHearingAid => ATTCCCDHandles::HearingAid,
4545
ATTHandles::NothingEverything => panic!("No CCCD for NothingEverything handle"), // we don't request it
46-
ATTHandles::NothingEverythingRead => panic!("No CCD for NothingEverythingRead handle") // it sends notifications without CCCD
46+
ATTHandles::NothingEverythingRead => panic!("No CCD for NothingEverythingRead handle"), // it sends notifications without CCCD
4747
}
4848
}
4949
}
@@ -57,7 +57,7 @@ impl ATTManagerState {
5757
fn new() -> Self {
5858
ATTManagerState {
5959
sender: None,
60-
listeners: HashMap::new()
60+
listeners: HashMap::new(),
6161
}
6262
}
6363
}
@@ -82,11 +82,15 @@ impl ATTManager {
8282
}
8383

8484
pub async fn connect(&mut self, addr: Address) -> Result<()> {
85-
info!("ATTManager connecting to {} on PSM {:#06X}...", addr, PSM_ATT);
85+
info!(
86+
"ATTManager connecting to {} on PSM {:#06X}...",
87+
addr, PSM_ATT
88+
);
8689
let target_sa = SocketAddr::new(addr, AddressType::BrEdr, PSM_ATT);
8790

8891
let socket = Socket::new_seq_packet()?;
89-
let seq_packet_result = tokio::time::timeout(CONNECT_TIMEOUT, socket.connect(target_sa)).await;
92+
let seq_packet_result =
93+
tokio::time::timeout(CONNECT_TIMEOUT, socket.connect(target_sa)).await;
9094
let seq_packet = match seq_packet_result {
9195
Ok(Ok(s)) => Arc::new(s),
9296
Ok(Err(e)) => {
@@ -95,7 +99,10 @@ impl ATTManager {
9599
}
96100
Err(_) => {
97101
error!("L2CAP connect timed out");
98-
return Err(Error::from(std::io::Error::new(std::io::ErrorKind::TimedOut, "Connection timeout")));
102+
return Err(Error::from(std::io::Error::new(
103+
std::io::ErrorKind::TimedOut,
104+
"Connection timeout",
105+
)));
99106
}
100107
};
101108

@@ -106,7 +113,8 @@ impl ATTManager {
106113
Ok(peer) if peer.cid != 0 => break,
107114
Ok(_) => {}
108115
Err(e) => {
109-
if e.raw_os_error() == Some(107) { // ENOTCONN
116+
if e.raw_os_error() == Some(107) {
117+
// ENOTCONN
110118
error!("Peer has disconnected during connection setup.");
111119
return Err(e.into());
112120
}
@@ -115,7 +123,10 @@ impl ATTManager {
115123
}
116124
if start.elapsed() >= CONNECT_TIMEOUT {
117125
error!("Timed out waiting for L2CAP connection to be fully established.");
118-
return Err(Error::from(std::io::Error::new(std::io::ErrorKind::TimedOut, "Connection timeout")));
126+
return Err(Error::from(std::io::Error::new(
127+
std::io::ErrorKind::TimedOut,
128+
"Connection timeout",
129+
)));
119130
}
120131
sleep(POLL_INTERVAL).await;
121132
}
@@ -180,11 +191,17 @@ impl ATTManager {
180191
if let Some(sender) = &state.sender {
181192
sender.send(data.to_vec()).await.map_err(|e| {
182193
error!("Failed to send packet to channel: {}", e);
183-
Error::from(std::io::Error::new(std::io::ErrorKind::NotConnected, "L2CAP send channel closed"))
194+
Error::from(std::io::Error::new(
195+
std::io::ErrorKind::NotConnected,
196+
"L2CAP send channel closed",
197+
))
184198
})
185199
} else {
186200
error!("Cannot send packet, sender is not available.");
187-
Err(Error::from(std::io::Error::new(std::io::ErrorKind::NotConnected, "L2CAP stream not connected")))
201+
Err(Error::from(std::io::Error::new(
202+
std::io::ErrorKind::NotConnected,
203+
"L2CAP stream not connected",
204+
)))
188205
}
189206
}
190207

@@ -195,11 +212,11 @@ impl ATTManager {
195212
Ok(Some(resp)) => Ok(resp),
196213
Ok(None) => Err(Error::from(std::io::Error::new(
197214
std::io::ErrorKind::UnexpectedEof,
198-
"Response channel closed"
215+
"Response channel closed",
199216
))),
200217
Err(_) => Err(Error::from(std::io::Error::new(
201218
std::io::ErrorKind::TimedOut,
202-
"Response timeout"
219+
"Response timeout",
203220
))),
204221
}
205222
}

linux-rust/src/bluetooth/discovery.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use std::io::Error;
21
use bluer::Adapter;
32
use log::debug;
3+
use std::io::Error;
44

55
pub(crate) async fn find_connected_airpods(adapter: &Adapter) -> bluer::Result<bluer::Device> {
66
let target_uuid = uuid::Uuid::parse_str("74ec2172-0bad-4d01-8f77-997b2be0722a").unwrap();
@@ -10,15 +10,22 @@ pub(crate) async fn find_connected_airpods(adapter: &Adapter) -> bluer::Result<b
1010
let device = adapter.device(addr)?;
1111
if device.is_connected().await.unwrap_or(false)
1212
&& let Ok(uuids) = device.uuids().await
13-
&& let Some(uuids) = uuids
14-
&& uuids.iter().any(|u| *u == target_uuid) {
15-
return Ok(device);
16-
}
13+
&& let Some(uuids) = uuids
14+
&& uuids.iter().any(|u| *u == target_uuid)
15+
{
16+
return Ok(device);
17+
}
1718
}
18-
Err(bluer::Error::from(Error::new(std::io::ErrorKind::NotFound, "No connected AirPods found")))
19+
Err(bluer::Error::from(Error::new(
20+
std::io::ErrorKind::NotFound,
21+
"No connected AirPods found",
22+
)))
1923
}
2024

21-
pub async fn find_other_managed_devices(adapter: &Adapter, managed_macs: Vec<String>) -> bluer::Result<Vec<bluer::Device>> {
25+
pub async fn find_other_managed_devices(
26+
adapter: &Adapter,
27+
managed_macs: Vec<String>,
28+
) -> bluer::Result<Vec<bluer::Device>> {
2229
let addrs = adapter.device_addresses().await?;
2330
let mut devices = Vec::new();
2431
for addr in addrs {
@@ -35,5 +42,8 @@ pub async fn find_other_managed_devices(adapter: &Adapter, managed_macs: Vec<Str
3542
return Ok(devices);
3643
}
3744
debug!("No other managed devices found");
38-
Err(bluer::Error::from(Error::new(std::io::ErrorKind::NotFound, "No other managed devices found")))
39-
}
45+
Err(bluer::Error::from(Error::new(
46+
std::io::ErrorKind::NotFound,
47+
"No other managed devices found",
48+
)))
49+
}

0 commit comments

Comments
 (0)