2020-05-08 20:38:30 +01:00
|
|
|
mod padfoot;
|
|
|
|
mod telepathy;
|
|
|
|
|
|
|
|
//use dbus::tree::{Interface, MTFn, MethodErr};
|
|
|
|
use dbus::{
|
|
|
|
blocking::{stdintf::org_freedesktop_dbus::RequestNameReply, LocalConnection},
|
2020-05-09 11:19:40 +01:00
|
|
|
tree::{Factory, MTFn, Tree},
|
2020-05-08 20:38:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
use padfoot::{CMData, ConnectionManager};
|
|
|
|
|
|
|
|
use std::sync::Arc;
|
|
|
|
use std::time::Duration;
|
|
|
|
|
|
|
|
use anyhow::{anyhow, Result};
|
|
|
|
|
2020-05-09 11:19:40 +01:00
|
|
|
const CM_BUS_NAME: &'static str = "org.freedesktop.Telepathy.ConnectionManager.padfoot";
|
|
|
|
const CM_OBJECT_PATH: &'static str = "/org/freedesktop/Telepathy/ConnectionManager/padfoot";
|
2020-05-08 20:38:30 +01:00
|
|
|
|
|
|
|
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(
|
2020-05-09 11:19:40 +01:00
|
|
|
f.object_path(CM_OBJECT_PATH, cm.clone())
|
2020-05-08 20:38:30 +01:00
|
|
|
.introspectable()
|
|
|
|
.add(iface),
|
|
|
|
);
|
|
|
|
tree = tree.add(f.object_path("/", cm.clone()).introspectable());
|
|
|
|
|
|
|
|
tree
|
|
|
|
}
|
|
|
|
|
|
|
|
fn run() -> Result<()> {
|
|
|
|
let cm: ConnectionManager = ConnectionManager {};
|
|
|
|
let tree = create_tree(&Arc::new(cm));
|
|
|
|
|
|
|
|
// Setup DBus connection
|
|
|
|
let mut c = LocalConnection::new_session()?;
|
|
|
|
|
2020-05-09 11:19:40 +01:00
|
|
|
let result = c.request_name(CM_BUS_NAME, false, false, true)?;
|
2020-05-08 20:38:30 +01:00
|
|
|
match result {
|
|
|
|
RequestNameReply::Exists => {
|
|
|
|
return Err(anyhow!(
|
|
|
|
"Another process is already registered on {}",
|
2020-05-09 11:19:40 +01:00
|
|
|
CM_BUS_NAME
|
2020-05-08 20:38:30 +01:00
|
|
|
))
|
|
|
|
}
|
|
|
|
_ => {} // All other responses we can get are a success
|
|
|
|
};
|
|
|
|
|
2020-05-09 11:19:40 +01:00
|
|
|
println!("Bus registered: {}", CM_BUS_NAME);
|
2020-05-08 20:38:30 +01:00
|
|
|
tree.start_receive(&c);
|
|
|
|
|
|
|
|
loop {
|
|
|
|
c.process(Duration::from_secs(1))?;
|
|
|
|
println!("Tick");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
if let Err(e) = run() {
|
|
|
|
println!("{}", e);
|
|
|
|
std::process::exit(1);
|
|
|
|
}
|
|
|
|
}
|