2024-05-10 07:07:44 -04:00
|
|
|
//use cvm12_rs::qmp;
|
|
|
|
//use tokio::net::UnixStream;
|
|
|
|
//use std::time::Duration;
|
2024-05-09 04:25:09 -04:00
|
|
|
|
2024-05-08 21:33:09 -04:00
|
|
|
#[tokio::main]
|
|
|
|
async fn main() {
|
2024-05-09 04:25:09 -04:00
|
|
|
let subscriber = tracing_subscriber::FmtSubscriber::builder()
|
|
|
|
.with_max_level(tracing::Level::TRACE)
|
|
|
|
.finish();
|
2024-05-08 21:33:09 -04:00
|
|
|
|
2024-05-09 04:25:09 -04:00
|
|
|
tracing::subscriber::set_global_default(subscriber).expect("You Banned");
|
2024-05-08 21:33:09 -04:00
|
|
|
|
2024-05-10 07:07:44 -04:00
|
|
|
/*
|
2024-05-09 04:25:09 -04:00
|
|
|
// Create a stream to connect
|
2024-05-08 21:33:09 -04:00
|
|
|
let stream = UnixStream::connect("/home/lily/vms/xpiss/qmp.sock")
|
|
|
|
.await
|
|
|
|
.expect("Could not connect");
|
|
|
|
|
2024-05-10 07:07:44 -04:00
|
|
|
let client = qmp::Client::new(stream);
|
2024-05-08 21:33:09 -04:00
|
|
|
|
2024-05-09 04:25:09 -04:00
|
|
|
// Handshake QMP
|
|
|
|
client.handshake().await.expect("Could not handshake QMP");
|
2024-05-08 21:33:09 -04:00
|
|
|
|
2024-05-09 04:25:09 -04:00
|
|
|
println!("Connected to QMP server");
|
2024-05-08 21:33:09 -04:00
|
|
|
|
2024-05-09 04:25:09 -04:00
|
|
|
// Create a copy of the client handle so we can issue a command in this other task.
|
2024-05-10 07:07:44 -04:00
|
|
|
// This other task waits 120 seconds and closes the client, which causes the actor to stop.
|
2024-05-09 04:25:09 -04:00
|
|
|
let copy = client.clone();
|
2024-05-08 21:33:09 -04:00
|
|
|
|
2024-05-09 04:25:09 -04:00
|
|
|
tokio::spawn(async move {
|
2024-05-10 07:07:44 -04:00
|
|
|
tokio::time::sleep(Duration::from_secs(120)).await;
|
|
|
|
println!("Closing client after 120 seconds");
|
2024-05-09 04:25:09 -04:00
|
|
|
copy.close().await.expect("Closing shouldn't fail");
|
|
|
|
});
|
2024-05-09 03:36:09 -04:00
|
|
|
|
2024-05-09 04:25:09 -04:00
|
|
|
println!(
|
2024-05-10 07:07:44 -04:00
|
|
|
"info block command: {}",
|
2024-05-09 04:25:09 -04:00
|
|
|
client
|
|
|
|
.execute_hmp("info block".into())
|
|
|
|
.await
|
|
|
|
.expect("this shouldn't fail")
|
|
|
|
);
|
2024-05-09 03:36:09 -04:00
|
|
|
|
2024-05-09 04:25:09 -04:00
|
|
|
// let's try to get all STOP events from QMP now.
|
|
|
|
let mut rx = client.subscribe_to_event("STOP".into()).await.unwrap();
|
2024-05-08 21:33:09 -04:00
|
|
|
|
2024-05-09 04:25:09 -04:00
|
|
|
// If this worked, then now we can recieve all the events.
|
|
|
|
// This code here allows running a VM with the -no-shutdown option,
|
|
|
|
// automatially resetting it on shutdown.
|
|
|
|
while let Some(message) = rx.recv().await {
|
|
|
|
println!("Got stop event! {:?}", message);
|
2024-05-09 00:48:42 -04:00
|
|
|
|
2024-05-09 04:25:09 -04:00
|
|
|
let res1 = client
|
|
|
|
.execute("system_reset".into(), None)
|
|
|
|
.await
|
|
|
|
.expect("FUCK");
|
|
|
|
let res2 = client.execute("cont".into(), None).await.expect("FUCK");
|
2024-05-09 00:48:42 -04:00
|
|
|
|
2024-05-09 04:25:09 -04:00
|
|
|
println!("Result of running: {:?}, {:?}", res1, res2);
|
|
|
|
}
|
2024-05-10 07:07:44 -04:00
|
|
|
*/
|
2024-03-28 11:02:14 -04:00
|
|
|
}
|