#[cfg(unix)]
use super::screen::monitor_socket;
use crate::events::WarningCode;
use crate::formats::{SeenPort, ToolCx};
#[cfg(unix)]
use crate::port::{GuestPort, HostPort};
#[cfg(unix)]
pub(super) async fn of_qemu(cx: &ToolCx<'_>, machine: &str) -> Vec<SeenPort> {
let asked = match monitor_socket(cx, machine) {
Ok(socket) => crate::cli::qemu::host_forwards(&socket)
.await
.map_err(|e| format!("{} didn't answer: {e}", socket.display())),
Err(e) => Err(e.to_string()),
};
match asked {
Ok(forwards) => forwards
.into_iter()
.map(|f| SeenPort {
guest: GuestPort::new(f.guest),
host: HostPort::new(f.host),
protocol: Some(f.protocol),
})
.collect(),
Err(why) => {
(cx.warn)(
WarningCode::PortsUnknown,
&format!("`{machine}`'s forwarded ports are unknown: its QEMU monitor {why}"),
);
Vec::new()
}
}
}
#[cfg(not(unix))]
pub(super) fn of_qemu(cx: &ToolCx<'_>, machine: &str) -> impl Future<Output = Vec<SeenPort>> {
(cx.warn)(WarningCode::PortsUnknown, &format!("`{machine}`'s forwarded ports are unknown on this host"));
std::future::ready(Vec::new())
}