From 35cc658983b822dbbca4e350b0784c542b6ac93a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Fri, 5 Mar 2021 00:27:24 +0400 Subject: [PATCH] Rename Event to ConsoleEvent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marc-André Lureau --- qemu-display-listener/src/console.rs | 10 ++--- .../src/{listener.rs => console_listener.rs} | 42 +++++++++---------- qemu-display-listener/src/lib.rs | 9 ++-- qemu-gtk4/src/console.rs | 2 +- qemu-vnc/src/main.rs | 4 +- 5 files changed, 35 insertions(+), 32 deletions(-) rename qemu-display-listener/src/{listener.rs => console_listener.rs} (76%) diff --git a/qemu-display-listener/src/console.rs b/qemu-display-listener/src/console.rs index 2c58408..7d9ff60 100644 --- a/qemu-display-listener/src/console.rs +++ b/qemu-display-listener/src/console.rs @@ -5,7 +5,7 @@ use std::{os::unix::io::AsRawFd, thread}; use zbus::{dbus_proxy, export::zvariant::Fd}; use crate::Result; -use crate::{Event, KeyboardProxy, Listener, MouseProxy}; +use crate::{ConsoleEvent, KeyboardProxy, ConsoleListener, MouseProxy}; #[dbus_proxy(default_service = "org.qemu", interface = "org.qemu.Display1.Console")] pub trait Console { @@ -76,7 +76,7 @@ impl Console { Ok(self.proxy.height()?) } - pub fn listen(&self) -> Result<(Receiver, Sender<()>)> { + pub fn listen(&self) -> Result<(Receiver, Sender<()>)> { let (p0, p1) = UnixStream::pair()?; let (tx, rx) = mpsc::channel(); self.proxy.register_listener(p0.as_raw_fd().into())?; @@ -85,7 +85,7 @@ impl Console { let _thread = thread::spawn(move || { let c = zbus::Connection::new_unix_client(p1, false).unwrap(); let mut s = zbus::ObjectServer::new(&c); - let listener = Listener::new(tx, wait_rx); + let listener = ConsoleListener::new(tx, wait_rx); let err = listener.err(); s.at("/org/qemu/Display1/Listener", listener).unwrap(); loop { @@ -106,7 +106,7 @@ impl Console { #[cfg(feature = "glib")] impl Console { - pub fn glib_listen(&self) -> Result<(glib::Receiver, Sender<()>)> { + pub fn glib_listen(&self) -> Result<(glib::Receiver, Sender<()>)> { let (p0, p1) = UnixStream::pair()?; let (tx, rx) = glib::MainContext::channel(glib::source::Priority::default()); self.proxy.register_listener(p0.as_raw_fd().into())?; @@ -115,7 +115,7 @@ impl Console { let _thread = thread::spawn(move || { let c = zbus::Connection::new_unix_client(p1, false).unwrap(); let mut s = zbus::ObjectServer::new(&c); - let listener = Listener::new(tx, wait_rx); + let listener = ConsoleListener::new(tx, wait_rx); let err = listener.err(); s.at("/org/qemu/Display1/Listener", listener).unwrap(); loop { diff --git a/qemu-display-listener/src/listener.rs b/qemu-display-listener/src/console_listener.rs similarity index 76% rename from qemu-display-listener/src/listener.rs rename to qemu-display-listener/src/console_listener.rs index 90e69f7..2b4b011 100644 --- a/qemu-display-listener/src/listener.rs +++ b/qemu-display-listener/src/console_listener.rs @@ -54,7 +54,7 @@ impl Drop for ScanoutDMABUF { // TODO: replace events mpsc with async traits #[derive(Debug)] -pub enum Event { +pub enum ConsoleEvent { Scanout(Scanout), Update(Update), ScanoutDMABUF(ScanoutDMABUF), @@ -80,31 +80,31 @@ pub enum Event { } pub(crate) trait EventSender { - fn send_event(&self, t: Event) -> Result<(), SendError>; + fn send_event(&self, t: ConsoleEvent) -> Result<(), SendError>; } -impl EventSender for Sender { - fn send_event(&self, t: Event) -> Result<(), SendError> { +impl EventSender for Sender { + fn send_event(&self, t: ConsoleEvent) -> Result<(), SendError> { self.send(t) } } #[cfg(feature = "glib")] -impl EventSender for glib::Sender { - fn send_event(&self, t: Event) -> Result<(), SendError> { +impl EventSender for glib::Sender { + fn send_event(&self, t: ConsoleEvent) -> Result<(), SendError> { self.send(t) } } #[derive(Debug)] -pub(crate) struct Listener { +pub(crate) struct ConsoleListener { tx: E, wait_rx: Receiver<()>, - err: Arc>>>, + err: Arc>>>, } #[dbus_interface(name = "org.qemu.Display1.Listener")] -impl Listener { +impl ConsoleListener { fn scanout( &mut self, width: u32, @@ -113,7 +113,7 @@ impl Listener { format: u32, data: serde_bytes::ByteBuf, ) { - self.send(Event::Scanout(Scanout { + self.send(ConsoleEvent::Scanout(Scanout { width, height, stride, @@ -132,7 +132,7 @@ impl Listener { format: u32, data: serde_bytes::ByteBuf, ) { - self.send(Event::Update(Update { + self.send(ConsoleEvent::Update(Update { x, y, w, @@ -155,7 +155,7 @@ impl Listener { y0_top: bool, ) { let fd = unsafe { libc::dup(fd.as_raw_fd()) }; - self.send(Event::ScanoutDMABUF(ScanoutDMABUF { + self.send(ConsoleEvent::ScanoutDMABUF(ScanoutDMABUF { fd, width, height, @@ -168,18 +168,18 @@ impl Listener { #[dbus_interface(name = "UpdateDMABUF")] fn update_dmabuf(&mut self, x: i32, y: i32, w: i32, h: i32) { - self.send(Event::UpdateDMABUF { x, y, w, h }); + self.send(ConsoleEvent::UpdateDMABUF { x, y, w, h }); if let Err(e) = self.wait() { eprintln!("update returned error: {}", e) } } fn mouse_set(&mut self, x: i32, y: i32, on: i32) { - self.send(Event::MouseSet { x, y, on }) + self.send(ConsoleEvent::MouseSet { x, y, on }) } fn cursor_define(&mut self, width: i32, height: i32, hot_x: i32, hot_y: i32, data: Vec) { - self.send(Event::CursorDefine { + self.send(ConsoleEvent::CursorDefine { width, height, hot_x, @@ -189,13 +189,13 @@ impl Listener { } } -impl Listener { +impl ConsoleListener { pub(crate) fn new(tx: E, wait_rx: Receiver<()>) -> Self { let err = Arc::new(RefCell::new(None)); - Listener { tx, wait_rx, err } + ConsoleListener { tx, wait_rx, err } } - fn send(&mut self, event: Event) { + fn send(&mut self, event: ConsoleEvent) { if let Err(e) = self.tx.send_event(event) { *self.err.borrow_mut() = Some(e); } @@ -205,13 +205,13 @@ impl Listener { self.wait_rx.recv() } - pub fn err(&self) -> Arc>>> { + pub fn err(&self) -> Arc>>> { self.err.clone() } } -impl Drop for Listener { +impl Drop for ConsoleListener { fn drop(&mut self) { - self.send(Event::Disconnected) + self.send(ConsoleEvent::Disconnected) } } diff --git a/qemu-display-listener/src/lib.rs b/qemu-display-listener/src/lib.rs index afdab49..cc1ab31 100644 --- a/qemu-display-listener/src/lib.rs +++ b/qemu-display-listener/src/lib.rs @@ -6,18 +6,21 @@ pub use error::*; mod vm; pub use vm::*; +// mod audio; +// pub use audio::*; + mod console; pub use console::*; +mod console_listener; +pub use console_listener::*; + mod keyboard; pub use keyboard::*; mod mouse; pub use mouse::*; -mod listener; -pub use listener::*; - #[cfg(test)] mod tests { #[test] diff --git a/qemu-gtk4/src/console.rs b/qemu-gtk4/src/console.rs index bd25607..271f703 100644 --- a/qemu-gtk4/src/console.rs +++ b/qemu-gtk4/src/console.rs @@ -7,7 +7,7 @@ use once_cell::sync::OnceCell; use std::cell::Cell; use keycodemap::*; -use qemu_display_listener::{Console, Event, MouseButton}; +use qemu_display_listener::{Console, ConsoleEvent as Event, MouseButton}; mod imp { use super::*; diff --git a/qemu-vnc/src/main.rs b/qemu-vnc/src/main.rs index 9a42bf4..abb88ee 100644 --- a/qemu-vnc/src/main.rs +++ b/qemu-vnc/src/main.rs @@ -4,7 +4,7 @@ use std::sync::{Arc, Mutex}; use std::{io, thread, time}; use clap::Clap; -use qemu_display_listener::{Console, Event}; +use qemu_display_listener::{Console, ConsoleEvent}; use vnc::{ server::Event as VncEvent, server::FramebufferUpdate, Error as VncError, PixelFormat, Rect, Server as VncServer, @@ -110,7 +110,7 @@ fn main() -> Result<(), Box> { let server = Server::new(console.width()? as u16, console.height()? as u16); let _thread = thread::spawn(move || match rx.recv().unwrap() { - Event::ScanoutDMABUF(s) => { + ConsoleEvent::ScanoutDMABUF(s) => { dbg!(&s); unsafe { libc::close(s.fd);