mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: dbus: broadcast event_monitor events over the DBus API
This commit builds on top of the `Monitor::subscribe` function and makes it possible to broadcast events published from `event-monitor` over D-Bus. The broadcasting functionality is enabled if the D-Bus API is enabled and users who wish to also enable the file based `event-monitor` can do so with the CLI arg `--event-monitor`. Signed-off-by: Omer Faruk Bayram <omer.faruk@sartura.hr>
This commit is contained in:
committed by
Bo Chen
parent
e02efe9ba0
commit
2ed96cd3ed
@@ -24,12 +24,12 @@ struct Event<'a> {
|
||||
|
||||
pub struct Monitor {
|
||||
pub rx: flume::Receiver<String>,
|
||||
pub file: File,
|
||||
pub file: Option<File>,
|
||||
pub broadcast: Vec<flume::Sender<Arc<String>>>,
|
||||
}
|
||||
|
||||
impl Monitor {
|
||||
pub fn new(rx: flume::Receiver<String>, file: File) -> Self {
|
||||
pub fn new(rx: flume::Receiver<String>, file: Option<File>) -> Self {
|
||||
Self {
|
||||
rx,
|
||||
file,
|
||||
@@ -68,11 +68,14 @@ fn set_file_nonblocking(file: &File) -> io::Result<()> {
|
||||
|
||||
/// This function must only be called once from the main thread before any threads
|
||||
/// are created to avoid race conditions.
|
||||
pub fn set_monitor(file: File) -> io::Result<Monitor> {
|
||||
pub fn set_monitor(file: Option<File>) -> io::Result<Monitor> {
|
||||
// SAFETY: there is only one caller of this function, so MONITOR is written to only once
|
||||
assert!(unsafe { MONITOR.is_none() });
|
||||
|
||||
set_file_nonblocking(&file)?;
|
||||
if let Some(ref file) = file {
|
||||
set_file_nonblocking(file)?;
|
||||
}
|
||||
|
||||
let (tx, rx) = flume::unbounded();
|
||||
let monitor = Monitor::new(rx, file);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user