daemon: scaffolding for settings / sync
This commit is contained in:
@@ -1,19 +1,36 @@
|
||||
use dbus::arg;
|
||||
use dbus_tree::MethodErr;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::sync::{Arc, Mutex, MutexGuard};
|
||||
use log::info;
|
||||
|
||||
use crate::daemon::Daemon;
|
||||
use crate::dbus::interface::NetBuzzertKordophoneServer as DbusServer;
|
||||
use crate::dbus::interface::NetBuzzertKordophoneRepository as DbusRepository;
|
||||
use crate::dbus::interface::NetBuzzertKordophoneSettings as DbusSettings;
|
||||
|
||||
impl DbusServer for Arc<Mutex<Daemon>> {
|
||||
#[derive(Clone)]
|
||||
pub struct ServerImpl {
|
||||
daemon: Arc<Mutex<Daemon>>,
|
||||
}
|
||||
|
||||
impl ServerImpl {
|
||||
pub fn new(daemon: Arc<Mutex<Daemon>>) -> Self {
|
||||
Self { daemon }
|
||||
}
|
||||
|
||||
pub fn get_daemon(&self) -> Result<MutexGuard<'_, Daemon>, MethodErr> {
|
||||
self.daemon.lock().map_err(|_| MethodErr::failed("Failed to lock daemon"))
|
||||
}
|
||||
}
|
||||
|
||||
impl DbusRepository for ServerImpl {
|
||||
fn get_version(&mut self) -> Result<String, MethodErr> {
|
||||
let daemon = self.lock().map_err(|_| MethodErr::failed("Failed to lock daemon"))?;
|
||||
let daemon = self.get_daemon()?;
|
||||
Ok(daemon.version.clone())
|
||||
}
|
||||
|
||||
fn get_conversations(&mut self) -> Result<Vec<arg::PropMap>, dbus::MethodErr> {
|
||||
// Get a repository instance and use it to fetch conversations
|
||||
let mut daemon = self.lock().map_err(|_| MethodErr::failed("Failed to lock daemon"))?;
|
||||
let mut daemon = self.get_daemon()?;
|
||||
let conversations = daemon.get_conversations();
|
||||
|
||||
// Convert conversations to DBus property maps
|
||||
@@ -27,4 +44,49 @@ impl DbusServer for Arc<Mutex<Daemon>> {
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
}
|
||||
|
||||
fn sync_all_conversations(&mut self) -> Result<bool, dbus::MethodErr> {
|
||||
let mut daemon = self.get_daemon()?;
|
||||
daemon.sync_all_conversations().map_err(|e| {
|
||||
log::error!("Failed to sync conversations: {}", e);
|
||||
MethodErr::failed(&format!("Failed to sync conversations: {}", e))
|
||||
})?;
|
||||
|
||||
Ok(true)
|
||||
}
|
||||
}
|
||||
|
||||
impl DbusSettings for ServerImpl {
|
||||
fn set_server(&mut self, url: String, user: String) -> Result<(), dbus::MethodErr> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn set_credential_item_(&mut self, item_path: dbus::Path<'static>) -> Result<(), dbus::MethodErr> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn server_url(&self) -> Result<String, dbus::MethodErr> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn set_server_url(&self, value: String) -> Result<(), dbus::MethodErr> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn username(&self) -> Result<String, dbus::MethodErr> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn set_username(&self, value: String) -> Result<(), dbus::MethodErr> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn credential_item(&self) -> Result<dbus::Path<'static>, dbus::MethodErr> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn set_credential_item(&self, value: dbus::Path<'static>) -> Result<(), dbus::MethodErr> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user