Initial protocol implementation
Empathy needs this patch before it will display the settings: https://gitlab.gnome.org/GNOME/telepathy-account-widgets/-/merge_requests/1
This commit is contained in:
63
src/main.rs
63
src/main.rs
@@ -1,49 +1,44 @@
|
||||
mod padfoot;
|
||||
mod telepathy;
|
||||
|
||||
//use dbus::tree::{Interface, MTFn, MethodErr};
|
||||
use anyhow::{anyhow, Result};
|
||||
use dbus::{
|
||||
blocking::{stdintf::org_freedesktop_dbus::RequestNameReply, LocalConnection},
|
||||
tree::{Factory, MTFn, Tree},
|
||||
tree::Factory,
|
||||
};
|
||||
|
||||
use padfoot::{CMData, ConnectionManager};
|
||||
|
||||
use std::sync::Arc;
|
||||
use padfoot::{ConnectionManager, Protocol};
|
||||
use std::time::Duration;
|
||||
|
||||
use anyhow::{anyhow, Result};
|
||||
|
||||
const CM_BUS_NAME: &'static str = "org.freedesktop.Telepathy.ConnectionManager.padfoot";
|
||||
const CM_OBJECT_PATH: &'static str = "/org/freedesktop/Telepathy/ConnectionManager/padfoot";
|
||||
|
||||
fn create_tree(cm: &Arc<ConnectionManager>) -> Tree<MTFn<CMData>, CMData> {
|
||||
let f = Factory::new_fn();
|
||||
let mut tree = f.tree(());
|
||||
|
||||
let iface = telepathy::connection_manager_server(&f, (), |m| {
|
||||
let a: &Arc<ConnectionManager> = m.path.get_data();
|
||||
let b: &ConnectionManager = &a;
|
||||
|
||||
b
|
||||
});
|
||||
|
||||
tree = tree.add(
|
||||
f.object_path(CM_OBJECT_PATH, cm.clone())
|
||||
.introspectable()
|
||||
.add(iface),
|
||||
);
|
||||
tree = tree.add(f.object_path("/", cm.clone()).introspectable());
|
||||
|
||||
tree
|
||||
}
|
||||
const PROTO_OBJECT_PATH: &'static str =
|
||||
"/org/freedesktop/Telepathy/ConnectionManager/padfoot/delta";
|
||||
|
||||
fn run() -> Result<()> {
|
||||
let cm: ConnectionManager = ConnectionManager {};
|
||||
let tree = create_tree(&Arc::new(cm));
|
||||
let f = Factory::new_fn::<()>();
|
||||
let mut tree = f.tree(());
|
||||
|
||||
let proto: &'static Protocol = &Protocol {};
|
||||
let cm: &'static ConnectionManager = &ConnectionManager {};
|
||||
let cm_iface = telepathy::connection_manager_server(&f, (), move |_m| cm);
|
||||
let proto_iface = telepathy::protocol_server(&f, (), move |_m| proto);
|
||||
|
||||
tree = tree.add(
|
||||
f.object_path(CM_OBJECT_PATH, ())
|
||||
.introspectable()
|
||||
.add(cm_iface),
|
||||
);
|
||||
tree = tree.add(
|
||||
f.object_path(PROTO_OBJECT_PATH, ())
|
||||
.introspectable()
|
||||
.add(proto_iface),
|
||||
);
|
||||
|
||||
tree = tree.add(f.object_path("/", ()).introspectable());
|
||||
|
||||
// Setup DBus connection
|
||||
let mut c = LocalConnection::new_session()?;
|
||||
tree.start_receive(&c);
|
||||
|
||||
let result = c.request_name(CM_BUS_NAME, false, false, true)?;
|
||||
match result {
|
||||
@@ -53,15 +48,11 @@ fn run() -> Result<()> {
|
||||
CM_BUS_NAME
|
||||
))
|
||||
}
|
||||
_ => {} // All other responses we can get are a success
|
||||
_ => println!("{} listening on {}", c.unique_name(), CM_BUS_NAME), // All other responses we can get are a success
|
||||
};
|
||||
|
||||
println!("Bus registered: {}", CM_BUS_NAME);
|
||||
tree.start_receive(&c);
|
||||
|
||||
loop {
|
||||
c.process(Duration::from_secs(1))?;
|
||||
println!("Tick");
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user