2020-05-08 20:38:30 +01:00
|
|
|
mod padfoot;
|
|
|
|
mod telepathy;
|
|
|
|
|
2020-05-09 21:45:29 +01:00
|
|
|
use anyhow::{anyhow, Result};
|
2020-05-08 20:38:30 +01:00
|
|
|
use dbus::{
|
|
|
|
blocking::{stdintf::org_freedesktop_dbus::RequestNameReply, LocalConnection},
|
2020-05-09 21:45:29 +01:00
|
|
|
tree::Factory,
|
2020-05-08 20:38:30 +01:00
|
|
|
};
|
2020-05-09 21:45:29 +01:00
|
|
|
use padfoot::{ConnectionManager, Protocol};
|
2020-05-08 20:38:30 +01:00
|
|
|
use std::time::Duration;
|
|
|
|
|
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-09 21:45:29 +01:00
|
|
|
const PROTO_OBJECT_PATH: &'static str =
|
|
|
|
"/org/freedesktop/Telepathy/ConnectionManager/padfoot/delta";
|
2020-05-08 20:38:30 +01:00
|
|
|
|
2020-05-09 21:45:29 +01:00
|
|
|
fn run() -> Result<()> {
|
|
|
|
let f = Factory::new_fn::<()>();
|
2020-05-08 20:38:30 +01:00
|
|
|
let mut tree = f.tree(());
|
|
|
|
|
2020-05-09 21:45:29 +01:00
|
|
|
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);
|
2020-05-08 20:38:30 +01:00
|
|
|
|
|
|
|
tree = tree.add(
|
2020-05-09 21:45:29 +01:00
|
|
|
f.object_path(CM_OBJECT_PATH, ())
|
2020-05-08 20:38:30 +01:00
|
|
|
.introspectable()
|
2020-05-09 21:45:29 +01:00
|
|
|
.add(cm_iface),
|
|
|
|
);
|
|
|
|
tree = tree.add(
|
|
|
|
f.object_path(PROTO_OBJECT_PATH, ())
|
|
|
|
.introspectable()
|
|
|
|
.add(proto_iface),
|
2020-05-08 20:38:30 +01:00
|
|
|
);
|
|
|
|
|
2020-05-09 21:45:29 +01:00
|
|
|
tree = tree.add(f.object_path("/", ()).introspectable());
|
2020-05-08 20:38:30 +01:00
|
|
|
|
|
|
|
// Setup DBus connection
|
|
|
|
let mut c = LocalConnection::new_session()?;
|
2020-05-09 21:45:29 +01:00
|
|
|
tree.start_receive(&c);
|
2020-05-08 20:38:30 +01:00
|
|
|
|
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
|
|
|
))
|
|
|
|
}
|
2020-05-09 21:45:29 +01:00
|
|
|
_ => println!("{} listening on {}", c.unique_name(), CM_BUS_NAME), // All other responses we can get are a success
|
2020-05-08 20:38:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
loop {
|
|
|
|
c.process(Duration::from_secs(1))?;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
if let Err(e) = run() {
|
|
|
|
println!("{}", e);
|
|
|
|
std::process::exit(1);
|
|
|
|
}
|
|
|
|
}
|