kordophoned: reorg: server impl in separate file, skeleton for conversations
This commit is contained in:
@@ -4,5 +4,16 @@
|
|||||||
<method name="GetVersion">
|
<method name="GetVersion">
|
||||||
<arg type="s" name="version" direction="out" />
|
<arg type="s" name="version" direction="out" />
|
||||||
</method>
|
</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>
|
</interface>
|
||||||
</node>
|
</node>
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
pub struct Daemon {
|
pub struct Daemon {
|
||||||
pub version: String,
|
pub version: String,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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::{
|
use dbus::{
|
||||||
channel::{MatchingReceiver, Sender},
|
|
||||||
message::MatchRule,
|
message::MatchRule,
|
||||||
nonblock::SyncConnection,
|
nonblock::SyncConnection,
|
||||||
|
channel::{Sender, MatchingReceiver},
|
||||||
Path,
|
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 {
|
pub struct Endpoint {
|
||||||
connection: Arc<SyncConnection>,
|
connection: Arc<SyncConnection>,
|
||||||
daemon: Arc<Daemon>,
|
daemon: Arc<Daemon>,
|
||||||
@@ -62,8 +52,8 @@ impl Endpoint {
|
|||||||
)));
|
)));
|
||||||
|
|
||||||
// Register the daemon as a D-Bus object.
|
// Register the daemon as a D-Bus object.
|
||||||
let token = dbus_interface::register_net_buzzert_kordophone_server(&mut cr);
|
let token = interface::register_net_buzzert_kordophone_server(&mut cr);
|
||||||
cr.insert(OBJECT_PATH, &[token], self.daemon.clone());
|
cr.insert(interface::OBJECT_PATH, &[token], self.daemon.clone());
|
||||||
|
|
||||||
// Start receiving messages.
|
// Start receiving messages.
|
||||||
self.connection.start_receive(
|
self.connection.start_receive(
|
||||||
@@ -80,14 +70,7 @@ impl Endpoint {
|
|||||||
where
|
where
|
||||||
S: dbus::message::SignalArgs + dbus::arg::AppendAll,
|
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)
|
self.connection.send(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
impl NetBuzzertKordophoneServer for Arc<Daemon> {
|
|
||||||
fn get_version(&mut self) -> Result<String, MethodErr> {
|
|
||||||
Ok(self.version.clone())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
pub mod endpoint;
|
pub mod endpoint;
|
||||||
|
mod server_impl;
|
||||||
|
|
||||||
pub mod interface {
|
mod interface {
|
||||||
pub static NAME: &str = "net.buzzert.kordophonecd";
|
#![allow(unused)]
|
||||||
pub static OBJECT_PATH: &str = "/net/buzzert/kordophone/Server";
|
|
||||||
|
pub const NAME: &str = "net.buzzert.kordophonecd";
|
||||||
|
pub const OBJECT_PATH: &str = "/net/buzzert/kordophonecd";
|
||||||
|
|
||||||
|
include!(concat!(env!("OUT_DIR"), "/kordophone-server.rs"));
|
||||||
}
|
}
|
||||||
16
kordophoned/src/dbus/server_impl.rs
Normal file
16
kordophoned/src/dbus/server_impl.rs
Normal 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!()
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user