mirror of
https://gitlab.com/marcandre.lureau/qemu-display.git
synced 2025-02-26 03:52:17 +00:00
Add chardev proxy
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
parent
4c29af1595
commit
3b614f2e66
44
qemu-display-listener/src/chardev.rs
Normal file
44
qemu-display-listener/src/chardev.rs
Normal file
@ -0,0 +1,44 @@
|
||||
use std::convert::TryFrom;
|
||||
use zbus::dbus_proxy;
|
||||
use zbus::export::zvariant::{Fd, ObjectPath};
|
||||
|
||||
use crate::Result;
|
||||
|
||||
#[dbus_proxy(default_service = "org.qemu", interface = "org.qemu.Display1.Chardev")]
|
||||
pub trait Chardev {
|
||||
/// Register method
|
||||
fn register(&self, stream: Fd) -> zbus::Result<()>;
|
||||
|
||||
/// SendBreak method
|
||||
fn send_break(&self) -> zbus::Result<()>;
|
||||
|
||||
/// Echo property
|
||||
#[dbus_proxy(property)]
|
||||
fn echo(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// FEOpened property
|
||||
#[dbus_proxy(property, name = "FEOpened")]
|
||||
fn fe_opened(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// Name property
|
||||
#[dbus_proxy(property)]
|
||||
fn name(&self) -> zbus::Result<String>;
|
||||
}
|
||||
|
||||
#[derive(derivative::Derivative)]
|
||||
#[derivative(Debug)]
|
||||
pub struct Chardev {
|
||||
#[derivative(Debug = "ignore")]
|
||||
pub proxy: AsyncChardevProxy<'static>,
|
||||
}
|
||||
|
||||
impl Chardev {
|
||||
pub async fn new(conn: &zbus::azync::Connection, id: &str) -> Result<Self> {
|
||||
let obj_path = ObjectPath::try_from(format!("/org/qemu/Display1/Chardev_{}", id))?;
|
||||
let proxy = AsyncChardevProxy::builder(conn)
|
||||
.path(&obj_path)?
|
||||
.build_async()
|
||||
.await?;
|
||||
Ok(Self { proxy })
|
||||
}
|
||||
}
|
@ -12,6 +12,9 @@ pub use vm::*;
|
||||
mod audio;
|
||||
pub use audio::*;
|
||||
|
||||
mod chardev;
|
||||
pub use chardev::*;
|
||||
|
||||
mod clipboard;
|
||||
pub use clipboard::*;
|
||||
|
||||
|
@ -2,7 +2,9 @@ use gio::ApplicationFlags;
|
||||
use glib::{clone, MainContext};
|
||||
use gtk::{gio, glib, prelude::*};
|
||||
use once_cell::sync::OnceCell;
|
||||
use qemu_display_listener::Console;
|
||||
use qemu_display_listener::{Chardev, Console};
|
||||
use std::os::unix::io::AsRawFd;
|
||||
use std::os::unix::net::UnixStream;
|
||||
use zbus::Connection;
|
||||
|
||||
mod audio;
|
||||
@ -45,6 +47,22 @@ fn main() {
|
||||
Err(e) => log::warn!("Failed to setup clipboard: {}", e),
|
||||
}
|
||||
|
||||
if let Ok(c) = Chardev::new(&conn, "qmp").await {
|
||||
use std::io::BufReader;
|
||||
use std::io::prelude::*;
|
||||
|
||||
let (p0, p1) = UnixStream::pair().unwrap();
|
||||
if c.proxy.register(p1.as_raw_fd().into()).await.is_ok() {
|
||||
let mut reader = BufReader::new(p0.try_clone().unwrap());
|
||||
let mut line = String::new();
|
||||
std::thread::spawn(move || loop {
|
||||
if reader.read_line(&mut line).unwrap() > 0 {
|
||||
println!("{}", &line);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
window.show();
|
||||
}));
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user