74 lines
1.8 KiB
Rust
74 lines
1.8 KiB
Rust
|
mod padfoot;
|
||
|
mod telepathy;
|
||
|
|
||
|
//use dbus::tree::{Interface, MTFn, MethodErr};
|
||
|
use dbus::{
|
||
|
blocking::{stdintf::org_freedesktop_dbus::RequestNameReply, LocalConnection},
|
||
|
tree::{Factory, Interface, MTFn, Tree},
|
||
|
};
|
||
|
|
||
|
use padfoot::{CMData, ConnectionManager};
|
||
|
|
||
|
use std::sync::Arc;
|
||
|
use std::time::Duration;
|
||
|
|
||
|
use anyhow::{anyhow, Result};
|
||
|
|
||
|
const BUS_NAME: &'static str = "org.freedesktop.Telepathy.ConnectionManager.padfoot";
|
||
|
const 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(OBJECT_PATH, cm.clone())
|
||
|
.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()?;
|
||
|
|
||
|
let result = c.request_name(BUS_NAME, false, false, true)?;
|
||
|
match result {
|
||
|
RequestNameReply::Exists => {
|
||
|
return Err(anyhow!(
|
||
|
"Another process is already registered on {}",
|
||
|
BUS_NAME
|
||
|
))
|
||
|
}
|
||
|
_ => {} // All other responses we can get are a success
|
||
|
};
|
||
|
|
||
|
println!("Bus registered: {}", BUS_NAME);
|
||
|
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);
|
||
|
}
|
||
|
}
|