diff --git a/idevice/src/usbmuxd/mod.rs b/idevice/src/usbmuxd/mod.rs index c27c1b4..9392369 100644 --- a/idevice/src/usbmuxd/mod.rs +++ b/idevice/src/usbmuxd/mod.rs @@ -5,7 +5,9 @@ use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4}; use log::debug; use tokio::io::{AsyncReadExt, AsyncWriteExt}; -use crate::{pairing_file::PairingFile, Idevice, IdeviceError, ReadWrite}; +use crate::{ + pairing_file::PairingFile, provider::UsbmuxdProvider, Idevice, IdeviceError, ReadWrite, +}; mod des; mod raw_packet; @@ -29,7 +31,7 @@ pub struct UsbmuxdConnection { tag: u32, } -#[derive(Debug)] +#[derive(Clone, Debug)] pub enum UsbmuxdAddr { UnixSocket(String), TcpSocket(SocketAddr), @@ -151,6 +153,14 @@ impl UsbmuxdConnection { Ok(devs) } + pub async fn get_device(&mut self, udid: &str) -> Result { + let devices = self.get_devices().await?; + match devices.into_iter().find(|x| x.udid == udid) { + Some(d) => Ok(d), + None => Err(IdeviceError::DeviceNotFound), + } + } + pub async fn get_pair_record(&mut self, udid: &str) -> Result { let mut req = plist::Dictionary::new(); req.insert("MessageType".into(), "ReadPairRecord".into()); @@ -226,3 +236,22 @@ impl UsbmuxdConnection { Ok(res) } } + +impl UsbmuxdDevice { + pub fn to_provider( + &self, + addr: UsbmuxdAddr, + tag: u32, + label: impl Into, + ) -> UsbmuxdProvider { + let label = label.into(); + + UsbmuxdProvider { + addr, + tag, + udid: self.udid.clone(), + device_id: self.device_id, + label, + } + } +}