Use AsRefClosure when generating the bindings

This simplifies things significantly \o/
This commit is contained in:
2020-05-11 00:48:18 +01:00
parent ad0d95ab40
commit 9151f64a6d
126 changed files with 1633 additions and 1054 deletions

View File

@@ -7,7 +7,7 @@ use std::time::Duration;
pub const CONN_BUS_NAME: &'static str = "org.freedesktop.Telepathy.Connection.padfoot.delta";
pub const CONN_OBJECT_PATH: &'static str = "/org/freedesktop/Telepathy/Connection/padfoot/delta";
#[derive(Debug, Default)]
#[derive(Debug)]
pub struct Connection {
id: String,
account: String,
@@ -67,19 +67,6 @@ mod tests {
}
}
#[derive(Debug, Default)]
struct CData;
impl dbus::tree::DataType for CData {
type Interface = Connection;
type Tree = ();
type Property = ();
type ObjectPath = ();
type Method = ();
type Signal = ();
}
impl Connection {
// This is run inside its own thread
//
@@ -88,8 +75,10 @@ impl Connection {
pub fn run(self) {
let bus = self.bus();
let path = self.path();
let f = tree::Factory::new_fn::<CData>();
let iface = telepathy::connection_server(&f, self, |m| m.iface.get_data());
let c_rc = std::rc::Rc::new(self);
let f = tree::Factory::new_fn::<()>();
let iface = telepathy::connection_server(&f, (), move |_| c_rc.clone());
let mut tree = f.tree(());
tree = tree.add(f.object_path(path, ()).introspectable().add(iface));
@@ -169,6 +158,10 @@ impl Connection {
}
}
impl AsRef<dyn telepathy::Connection + 'static> for std::rc::Rc<Connection> {
fn as_ref(&self) -> &(dyn telepathy::Connection + 'static) { &**self }
}
impl telepathy::Connection for Connection {
fn connect(&self) -> Result<(), tree::MethodErr> {
Err(tree::MethodErr::no_arg()) // FIXME: should be NotImplemented?