Skip to content

Commit

Permalink
Prepare tests and examples for ios devices run
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Dec 5, 2024
1 parent 3b7744d commit 406f677
Show file tree
Hide file tree
Showing 14 changed files with 737 additions and 639 deletions.
38 changes: 25 additions & 13 deletions cidre/examples/am-device-list/main.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
use cidre::am;
fn main() {
let devices = am::Device::list().unwrap();
#[cfg(target_os = "macos")]
mod macos {
use cidre::am;

pub fn main() {
let devices = am::Device::list().unwrap();

for d in devices.iter() {
let f = d.connected().expect("Failed to connect to device");
println!(
"uuid: {:?}, if: {:?} {:?}",
f.id().to_string(),
f.iface_type(),
f.name().to_string()
);
for d in devices.iter() {
let f = d.connected().expect("Failed to connect to device");
println!(
"uuid: {:?}, if: {:?} {:?}",
f.id().to_string(),
f.iface_type(),
f.name().to_string()
);

let s = f.start_session().expect("started session");
s.show();
let s = f.start_session().expect("started session");
s.show();
}
}
}

#[cfg(target_os = "macos")]
pub use macos::main;

#[cfg(not(target_os = "macos"))]
fn main() {
todo!()
}
193 changes: 102 additions & 91 deletions cidre/examples/am-device-mount-dev-image/main.rs
Original file line number Diff line number Diff line change
@@ -1,102 +1,113 @@
use std::ffi::c_void;

use cidre::{
am::{self, device::discovery::NotificationInfo},
cf,
};

const DEVICE_ID: &str = "00008120-000168A20210C01E";

pub extern "C" fn callback(info: &NotificationInfo, _context: *mut c_void) {
match info.safe() {
am::device::discovery::SafeInfo::Attached(device) => {
let id = device.id().to_string();
if id.eq(DEVICE_ID) {
println!("identifier {:?}", id);
device.show();
let connected = device.connected().expect("connected");
println!("Device: {}", connected.name().to_string());

let session = connected.start_session().expect("started session");
println!(
"batery level {:?}",
session.battery_level().unwrap().to_i64()
);
// println!("batery level {}", session.battery_level().expect("level").to_string());
session.mount_developer_image().expect("mounted");
session.start_debug_server().expect("debug");
println!("disk mounted");
#[cfg(target_os = "macos")]
mod macos {
use std::ffi::c_void;

use cidre::{
am::{self, device::discovery::NotificationInfo},
cf,
};

const DEVICE_ID: &str = "00008120-000168A20210C01E";

extern "C" fn callback(info: &NotificationInfo, _context: *mut c_void) {
match info.safe() {
am::device::discovery::SafeInfo::Attached(device) => {
let id = device.id().to_string();
if id.eq(DEVICE_ID) {
println!("identifier {:?}", id);
device.show();
let connected = device.connected().expect("connected");
println!("Device: {}", connected.name().to_string());

let session = connected.start_session().expect("started session");
println!(
"batery level {:?}",
session.battery_level().unwrap().to_i64()
);
// println!("batery level {}", session.battery_level().expect("level").to_string());
session.mount_developer_image().expect("mounted");
session.start_debug_server().expect("debug");
println!("disk mounted");
}
}
am::device::discovery::SafeInfo::Detached(_) => {}
am::device::discovery::SafeInfo::NotificationStopped => {}
am::device::discovery::SafeInfo::Paired(_) => {}
}
am::device::discovery::SafeInfo::Detached(_) => {}
am::device::discovery::SafeInfo::NotificationStopped => {}
am::device::discovery::SafeInfo::Paired(_) => {}
}
}

#[tokio::main]
async fn main() {
let devices = am::device::QueryBuilder::new_match_all()
.udids(&[DEVICE_ID])
// .udids(&["00008120-000168A20210C01E"])
.matching_list(None)
.unwrap();

if devices.is_empty() {
println!("device not found");
return;
}
#[tokio::main]
pub async fn main() {
let devices = am::device::QueryBuilder::new_match_all()
.udids(&[DEVICE_ID])
// .udids(&["00008120-000168A20210C01E"])
.matching_list(None)
.unwrap();

let ipad = &devices[0].retained();
let connected = ipad.connected().expect("connected");
println!("Device: {}", connected.name().to_string());

let session = connected.start_session().expect("started session");
session.mount_developer_image().expect("mounted");
println!("disk mounted");
let connection = session.start_debug_server().expect("debug");

unsafe {
extern "C" fn cb(
_s: &cf::Socket,
_cb_type: cf::SocketCbType,
_address: &cf::Data,
_data: *const u8,
_info: *mut c_void,
) {
println!("??????????")
if devices.is_empty() {
println!("device not found");
return;
}
let sock = cf::Socket::create_with_native(
connection.socket().unwrap(),
cf::SocketCbType::READ,
cb,
None,
)
.unwrap();
let source = sock.create_runloop_source(0).unwrap();
cf::RunLoop::main().add_source(&source, cf::RunLoopMode::common());
// source.invalidate();

let n = connection.send(&[1]).unwrap();
println!("sent {}", n);
}

// println!("pre send");
// let n = connection.send(&[0,0,0,0]).unwrap();
// println!("post send {}", n);
// connection.http_proxy().await.unwrap();
// let fd = service.socket().expect("valid socket");
// println!("FD {:?}", fd);
let ipad = &devices[0].retained();
let connected = ipad.connected().expect("connected");
println!("Device: {}", connected.name().to_string());

// device::start_lldb_proxy(fd).await.unwrap();
let session = connected.start_session().expect("started session");
session.mount_developer_image().expect("mounted");
println!("disk mounted");
let connection = session.start_debug_server().expect("debug");

unsafe {
extern "C" fn cb(
_s: &cf::Socket,
_cb_type: cf::SocketCbType,
_address: &cf::Data,
_data: *const u8,
_info: *mut c_void,
) {
println!("??????????")
}
let sock = cf::Socket::create_with_native(
connection.socket().unwrap(),
cf::SocketCbType::READ,
cb,
None,
)
.unwrap();
let source = sock.create_runloop_source(0).unwrap();
cf::RunLoop::main().add_source(&source, cf::RunLoopMode::common());
// source.invalidate();

let n = connection.send(&[1]).unwrap();
println!("sent {}", n);
}

// println!("pre send");
// let n = connection.send(&[0,0,0,0]).unwrap();
// println!("post send {}", n);
// connection.http_proxy().await.unwrap();
// let fd = service.socket().expect("valid socket");
// println!("FD {:?}", fd);

// device::start_lldb_proxy(fd).await.unwrap();

// let note = am::device::Notification::with(
// callback,
// DeviceSpeed::ANY,
// DeviceInterfaceConnectionType::Any,
// std::ptr::null_mut(),
// )
// .unwrap();

cf::RunLoop::run();
}
}

// let note = am::device::Notification::with(
// callback,
// DeviceSpeed::ANY,
// DeviceInterfaceConnectionType::Any,
// std::ptr::null_mut(),
// )
// .unwrap();
#[cfg(target_os = "macos")]
pub use macos::main;

cf::RunLoop::run();
#[cfg(not(target_os = "macos"))]
fn main() {
todo!()
}
Loading

0 comments on commit 406f677

Please sign in to comment.