Private
Public Access
1
0

daemon: start working on events. notes:

Probably need to make the locking mechanism more granular. Only lock the
database during db writes, see if we can do multiple readers and a
single writer. Otherwise, the daemon will not be able to service
requests while an event is being handled, which is not good.
This commit is contained in:
2025-04-25 21:42:29 -07:00
parent 82192ffbe5
commit ef74df9f28
7 changed files with 90 additions and 46 deletions

View File

@@ -2,9 +2,12 @@ mod dbus;
mod daemon;
use std::future;
use std::sync::{Arc, Mutex};
use std::sync::mpsc;
use log::LevelFilter;
use std::sync::Arc;
use tokio::sync::Mutex;
use daemon::Daemon;
use dbus::endpoint::Endpoint as DbusEndpoint;
use dbus::interface;
@@ -21,6 +24,8 @@ fn initialize_logging() {
async fn main() {
initialize_logging();
let (sender, receiver) = mpsc::channel::<daemon::Event>();
// Create the daemon
let daemon = Arc::new(
Mutex::new(
@@ -34,7 +39,7 @@ async fn main() {
);
// Create the server implementation
let server = ServerImpl::new(daemon);
let server = ServerImpl::new(daemon.clone(), sender);
// Register DBus interfaces with endpoint
let endpoint = DbusEndpoint::new(server.clone());
@@ -49,6 +54,13 @@ async fn main() {
}
).await;
tokio::spawn(async move {
for event in receiver {
// Important! Only lock the daemon when handling events.
daemon.lock().await.handle_event(event).await;
}
});
future::pending::<()>().await;
unreachable!()
}