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
pub mod linux;

use crate::{
    launcher,
    qmp::{Client, UnixSocket},
    storage::{DirectoryStorageHandler, StorageHandler},
};
use anyhow::Result;
use std::os::unix::net::UnixStream;

pub struct EmulatorController {
    dsh: DirectoryStorageHandler,
}

impl EmulatorController {
    pub fn new(dsh: DirectoryStorageHandler) -> Self {
        Self { dsh }
    }
}

impl launcher::EmulatorController for EmulatorController {
    fn shutdown(&self, name: &str) -> Result<()> {
        let stream = UnixStream::connect(self.dsh.monitor_path(name)?)?;
        let mut us = UnixSocket::new(stream)?;
        us.handshake()?;
        us.send_command("qmp_capabilities", None)?;
        us.send_command("system_powerdown", None)?;
        Ok(())
    }
}