kordophoned: better daemon bootstrapping
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use log::info;
|
||||
use std::sync::Arc;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use crate::{daemon::Daemon, dbus::interface};
|
||||
|
||||
use dbus_crossroads::Crossroads;
|
||||
@@ -13,11 +13,11 @@ use dbus::{
|
||||
|
||||
pub struct Endpoint {
|
||||
connection: Arc<SyncConnection>,
|
||||
daemon: Arc<Daemon>,
|
||||
daemon: Arc<Mutex<Daemon>>,
|
||||
}
|
||||
|
||||
impl Endpoint {
|
||||
pub fn new(daemon: Arc<Daemon>) -> Self {
|
||||
pub fn new(daemon: Daemon) -> Self {
|
||||
let (resource, connection) = connection::new_session_sync().unwrap();
|
||||
|
||||
// The resource is a task that should be spawned onto a tokio compatible
|
||||
@@ -29,7 +29,10 @@ impl Endpoint {
|
||||
panic!("Lost connection to D-Bus: {}", err);
|
||||
});
|
||||
|
||||
Self { connection, daemon }
|
||||
Self {
|
||||
connection,
|
||||
daemon: Arc::new(Mutex::new(daemon))
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn start(&self) {
|
||||
|
||||
@@ -1,16 +1,30 @@
|
||||
use dbus::arg;
|
||||
use dbus_tree::MethodErr;
|
||||
use std::sync::Arc;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use crate::daemon::Daemon;
|
||||
use crate::dbus::interface::NetBuzzertKordophoneServer as DbusServer;
|
||||
|
||||
impl DbusServer for Arc<Daemon> {
|
||||
impl DbusServer for Arc<Mutex<Daemon>> {
|
||||
fn get_version(&mut self) -> Result<String, MethodErr> {
|
||||
Ok(self.version.clone())
|
||||
let daemon = self.lock().map_err(|_| MethodErr::failed("Failed to lock daemon"))?;
|
||||
Ok(daemon.version.clone())
|
||||
}
|
||||
|
||||
|
||||
fn get_conversations(&mut self) -> Result<Vec<arg::PropMap>, dbus::MethodErr> {
|
||||
todo!()
|
||||
// Get a repository instance and use it to fetch conversations
|
||||
let mut daemon = self.lock().map_err(|_| MethodErr::failed("Failed to lock daemon"))?;
|
||||
let conversations = daemon.get_conversations();
|
||||
|
||||
// Convert conversations to DBus property maps
|
||||
let result = conversations.into_iter().map(|conv| {
|
||||
let mut map = arg::PropMap::new();
|
||||
map.insert("guid".into(), arg::Variant(Box::new(conv.guid)));
|
||||
map.insert("display_name".into(), arg::Variant(Box::new(conv.display_name.unwrap_or_default())));
|
||||
map.insert("unread_count".into(), arg::Variant(Box::new(conv.unread_count as i32)));
|
||||
map
|
||||
}).collect();
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user