Private
Public Access
1
0

kordophoned: reorg: server impl in separate file, skeleton for conversations

This commit is contained in:
2025-02-12 00:26:32 -08:00
parent 6a7d376aa9
commit 68ff158d6c
5 changed files with 45 additions and 32 deletions

View File

@@ -4,5 +4,16 @@
<method name="GetVersion">
<arg type="s" name="version" direction="out" />
</method>
<method name="GetConversations">
<arg type="aa{sv}" direction="out" name="conversations">
<annotation name="org.freedesktop.DBus.DocString"
value="Array of dictionaries. Each dictionary has keys:
'id' (string): Unique identifier
'title' (string): Display name
'last_message' (string): Preview text
'is_unread' (boolean): Unread status"/>
</arg>
</method>
</interface>
</node>

View File

@@ -1,5 +1,3 @@
use std::sync::Arc;
pub struct Daemon {
pub version: String,
}

View File

@@ -1,26 +1,16 @@
use crate::{dbus::interface::OBJECT_PATH, daemon::Daemon};
use log::info;
use std::sync::Arc;
use crate::{daemon::Daemon, dbus::interface};
use crossroads::Crossroads;
use dbus_crossroads::Crossroads;
use dbus_tokio::connection;
use dbus::{
channel::{MatchingReceiver, Sender},
message::MatchRule,
nonblock::SyncConnection,
channel::{Sender, MatchingReceiver},
Path,
};
use dbus_crossroads as crossroads;
use dbus_tokio::connection;
use dbus_tree::{DataType, MethodErr};
use log::info;
use std::{future::Future, sync::Arc, thread};
mod dbus_interface {
#![allow(unused)]
include!(concat!(env!("OUT_DIR"), "/kordophone-server.rs"));
}
use dbus_interface::NetBuzzertKordophoneServer;
pub struct Endpoint {
connection: Arc<SyncConnection>,
daemon: Arc<Daemon>,
@@ -62,8 +52,8 @@ impl Endpoint {
)));
// Register the daemon as a D-Bus object.
let token = dbus_interface::register_net_buzzert_kordophone_server(&mut cr);
cr.insert(OBJECT_PATH, &[token], self.daemon.clone());
let token = interface::register_net_buzzert_kordophone_server(&mut cr);
cr.insert(interface::OBJECT_PATH, &[token], self.daemon.clone());
// Start receiving messages.
self.connection.start_receive(
@@ -80,14 +70,7 @@ impl Endpoint {
where
S: dbus::message::SignalArgs + dbus::arg::AppendAll,
{
let message = signal.to_emit_message(&Path::new(OBJECT_PATH).unwrap());
let message = signal.to_emit_message(&Path::new(interface::OBJECT_PATH).unwrap());
self.connection.send(message)
}
}
impl NetBuzzertKordophoneServer for Arc<Daemon> {
fn get_version(&mut self) -> Result<String, MethodErr> {
Ok(self.version.clone())
}
}

View File

@@ -1,6 +1,11 @@
pub mod endpoint;
mod server_impl;
pub mod interface {
pub static NAME: &str = "net.buzzert.kordophonecd";
pub static OBJECT_PATH: &str = "/net/buzzert/kordophone/Server";
mod interface {
#![allow(unused)]
pub const NAME: &str = "net.buzzert.kordophonecd";
pub const OBJECT_PATH: &str = "/net/buzzert/kordophonecd";
include!(concat!(env!("OUT_DIR"), "/kordophone-server.rs"));
}

View File

@@ -0,0 +1,16 @@
use dbus::arg;
use dbus_tree::MethodErr;
use std::sync::Arc;
use crate::daemon::Daemon;
use crate::dbus::interface::NetBuzzertKordophoneServer as DbusServer;
impl DbusServer for Arc<Daemon> {
fn get_version(&mut self) -> Result<String, MethodErr> {
Ok(self.version.clone())
}
fn get_conversations(&mut self) -> Result<Vec<arg::PropMap>, dbus::MethodErr> {
todo!()
}
}