mirror of
https://github.com/jkcoxson/idevice.git
synced 2026-03-02 14:36:16 +01:00
Replace manual plist creation with macro in diagnostics relay
This commit is contained in:
@@ -39,27 +39,17 @@ impl DiagnosticsRelayClient {
|
||||
/// A plist of the tree on success
|
||||
pub async fn ioregistry(
|
||||
&mut self,
|
||||
current_plane: Option<impl Into<String>>,
|
||||
entry_name: Option<impl Into<String>>,
|
||||
entry_class: Option<impl Into<String>>,
|
||||
current_plane: Option<&str>,
|
||||
entry_name: Option<&str>,
|
||||
entry_class: Option<&str>,
|
||||
) -> Result<Option<plist::Dictionary>, IdeviceError> {
|
||||
let mut req = plist::Dictionary::new();
|
||||
if let Some(plane) = current_plane {
|
||||
let plane = plane.into();
|
||||
req.insert("CurrentPlane".into(), plane.into());
|
||||
}
|
||||
if let Some(name) = entry_name {
|
||||
let name = name.into();
|
||||
req.insert("EntryName".into(), name.into());
|
||||
}
|
||||
if let Some(class) = entry_class {
|
||||
let class = class.into();
|
||||
req.insert("EntryClass".into(), class.into());
|
||||
}
|
||||
req.insert("Request".into(), "IORegistry".into());
|
||||
self.idevice
|
||||
.send_plist(plist::Value::Dictionary(req))
|
||||
.await?;
|
||||
let req = crate::plist!({
|
||||
"Request": "IORegistry",
|
||||
"CurrentPlane":? current_plane,
|
||||
"EntryName":? entry_name,
|
||||
"EntryClass":? entry_class,
|
||||
});
|
||||
self.idevice.send_plist(req).await?;
|
||||
let mut res = self.idevice.read_plist().await?;
|
||||
|
||||
match res.get("Status").and_then(|x| x.as_string()) {
|
||||
@@ -89,17 +79,11 @@ impl DiagnosticsRelayClient {
|
||||
&mut self,
|
||||
keys: Option<Vec<String>>,
|
||||
) -> Result<Option<plist::Dictionary>, IdeviceError> {
|
||||
let mut req = plist::Dictionary::new();
|
||||
req.insert("Request".into(), "MobileGestalt".into());
|
||||
|
||||
if let Some(keys) = keys {
|
||||
let keys_array: Vec<plist::Value> = keys.into_iter().map(|k| k.into()).collect();
|
||||
req.insert("MobileGestaltKeys".into(), plist::Value::Array(keys_array));
|
||||
}
|
||||
|
||||
self.idevice
|
||||
.send_plist(plist::Value::Dictionary(req))
|
||||
.await?;
|
||||
let req = crate::plist!({
|
||||
"Request": "MobileGestalt",
|
||||
"MobileGestaltKeys":? keys,
|
||||
});
|
||||
self.idevice.send_plist(req).await?;
|
||||
let mut res = self.idevice.read_plist().await?;
|
||||
|
||||
match res.get("Status").and_then(|x| x.as_string()) {
|
||||
@@ -119,12 +103,10 @@ impl DiagnosticsRelayClient {
|
||||
/// # Returns
|
||||
/// A dictionary containing gas gauge (battery) information
|
||||
pub async fn gasguage(&mut self) -> Result<Option<plist::Dictionary>, IdeviceError> {
|
||||
let mut req = plist::Dictionary::new();
|
||||
req.insert("Request".into(), "GasGauge".into());
|
||||
|
||||
self.idevice
|
||||
.send_plist(plist::Value::Dictionary(req))
|
||||
.await?;
|
||||
let req = crate::plist!({
|
||||
"Request": "GasGauge"
|
||||
});
|
||||
self.idevice.send_plist(req).await?;
|
||||
let mut res = self.idevice.read_plist().await?;
|
||||
|
||||
match res.get("Status").and_then(|x| x.as_string()) {
|
||||
@@ -144,12 +126,11 @@ impl DiagnosticsRelayClient {
|
||||
/// # Returns
|
||||
/// A dictionary containing NAND flash information
|
||||
pub async fn nand(&mut self) -> Result<Option<plist::Dictionary>, IdeviceError> {
|
||||
let mut req = plist::Dictionary::new();
|
||||
req.insert("Request".into(), "NAND".into());
|
||||
let req = crate::plist!({
|
||||
"Request": "NAND"
|
||||
});
|
||||
|
||||
self.idevice
|
||||
.send_plist(plist::Value::Dictionary(req))
|
||||
.await?;
|
||||
self.idevice.send_plist(req).await?;
|
||||
let mut res = self.idevice.read_plist().await?;
|
||||
|
||||
match res.get("Status").and_then(|x| x.as_string()) {
|
||||
@@ -169,12 +150,11 @@ impl DiagnosticsRelayClient {
|
||||
/// # Returns
|
||||
/// A dictionary containing all diagnostics information
|
||||
pub async fn all(&mut self) -> Result<Option<plist::Dictionary>, IdeviceError> {
|
||||
let mut req = plist::Dictionary::new();
|
||||
req.insert("Request".into(), "All".into());
|
||||
let req = crate::plist!({
|
||||
"Request": "All"
|
||||
});
|
||||
|
||||
self.idevice
|
||||
.send_plist(plist::Value::Dictionary(req))
|
||||
.await?;
|
||||
self.idevice.send_plist(req).await?;
|
||||
let mut res = self.idevice.read_plist().await?;
|
||||
|
||||
match res.get("Status").and_then(|x| x.as_string()) {
|
||||
@@ -194,12 +174,11 @@ impl DiagnosticsRelayClient {
|
||||
/// # Returns
|
||||
/// Result indicating success or failure
|
||||
pub async fn restart(&mut self) -> Result<(), IdeviceError> {
|
||||
let mut req = plist::Dictionary::new();
|
||||
req.insert("Request".into(), "Restart".into());
|
||||
let req = crate::plist!({
|
||||
"Request": "Restart",
|
||||
});
|
||||
|
||||
self.idevice
|
||||
.send_plist(plist::Value::Dictionary(req))
|
||||
.await?;
|
||||
self.idevice.send_plist(req).await?;
|
||||
let res = self.idevice.read_plist().await?;
|
||||
|
||||
match res.get("Status").and_then(|x| x.as_string()) {
|
||||
@@ -213,12 +192,11 @@ impl DiagnosticsRelayClient {
|
||||
/// # Returns
|
||||
/// Result indicating success or failure
|
||||
pub async fn shutdown(&mut self) -> Result<(), IdeviceError> {
|
||||
let mut req = plist::Dictionary::new();
|
||||
req.insert("Request".into(), "Shutdown".into());
|
||||
let req = crate::plist!({
|
||||
"Request": "Shutdown"
|
||||
});
|
||||
|
||||
self.idevice
|
||||
.send_plist(plist::Value::Dictionary(req))
|
||||
.await?;
|
||||
self.idevice.send_plist(req).await?;
|
||||
let res = self.idevice.read_plist().await?;
|
||||
|
||||
match res.get("Status").and_then(|x| x.as_string()) {
|
||||
@@ -232,12 +210,11 @@ impl DiagnosticsRelayClient {
|
||||
/// # Returns
|
||||
/// Result indicating success or failure
|
||||
pub async fn sleep(&mut self) -> Result<(), IdeviceError> {
|
||||
let mut req = plist::Dictionary::new();
|
||||
req.insert("Request".into(), "Sleep".into());
|
||||
let req = crate::plist!({
|
||||
"Request": "Sleep"
|
||||
});
|
||||
|
||||
self.idevice
|
||||
.send_plist(plist::Value::Dictionary(req))
|
||||
.await?;
|
||||
self.idevice.send_plist(req).await?;
|
||||
let res = self.idevice.read_plist().await?;
|
||||
|
||||
match res.get("Status").and_then(|x| x.as_string()) {
|
||||
@@ -248,12 +225,11 @@ impl DiagnosticsRelayClient {
|
||||
|
||||
/// Requests WiFi diagnostics from the device
|
||||
pub async fn wifi(&mut self) -> Result<Option<plist::Dictionary>, IdeviceError> {
|
||||
let mut req = plist::Dictionary::new();
|
||||
req.insert("Request".into(), "WiFi".into());
|
||||
let req = crate::plist!({
|
||||
"Request": "WiFi"
|
||||
});
|
||||
|
||||
self.idevice
|
||||
.send_plist(plist::Value::Dictionary(req))
|
||||
.await?;
|
||||
self.idevice.send_plist(req).await?;
|
||||
let mut res = self.idevice.read_plist().await?;
|
||||
|
||||
match res.get("Status").and_then(|x| x.as_string()) {
|
||||
@@ -270,11 +246,11 @@ impl DiagnosticsRelayClient {
|
||||
|
||||
/// Sends Goodbye request signaling end of communication
|
||||
pub async fn goodbye(&mut self) -> Result<(), IdeviceError> {
|
||||
let mut req = plist::Dictionary::new();
|
||||
req.insert("Request".into(), "Goodbye".into());
|
||||
self.idevice
|
||||
.send_plist(plist::Value::Dictionary(req))
|
||||
.await?;
|
||||
let req = crate::plist!({
|
||||
"Request": "Goodbye"
|
||||
});
|
||||
|
||||
self.idevice.send_plist(req).await?;
|
||||
let res = self.idevice.read_plist().await?;
|
||||
match res.get("Status").and_then(|x| x.as_string()) {
|
||||
Some("Success") => Ok(()),
|
||||
|
||||
Reference in New Issue
Block a user