forked from arcnmx/qapi-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qmp_query.rs
39 lines (30 loc) · 1 KB
/
qmp_query.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#[cfg(feature = "qmp")]
mod main {
use std::thread::sleep;
use std::time::Duration;
use std::env::args;
use std::os::unix::net::UnixStream;
use qapi::{qmp, Qmp};
pub fn main() {
::env_logger::init();
let socket_addr = args().nth(1).expect("argument: QMP socket path");
let stream = UnixStream::connect(socket_addr).expect("failed to connect to socket");
let mut qmp = Qmp::from_stream(&stream);
let info = qmp.handshake().expect("handshake failed");
println!("QMP info: {:#?}", info);
let status = qmp.execute(&qmp::query_status { }).unwrap().unwrap();
println!("VCPU status: {:#?}", status);
loop {
qmp.nop().unwrap();
for event in qmp.events() {
println!("Got event: {:#?}", event);
}
sleep(Duration::from_secs(1));
}
}
}
#[cfg(not(feature = "qmp"))]
mod main {
pub fn main() { panic!("requires feature qmp") }
}
fn main() { main::main() }