mod padfoot; mod telepathy; use anyhow::{anyhow, Result}; use dbus::{ blocking::{stdintf::org_freedesktop_dbus::RequestNameReply, LocalConnection}, tree::Factory, }; use padfoot::{ConnectionManager, Protocol}; use std::time::Duration; const CM_BUS_NAME: &'static str = "org.freedesktop.Telepathy.ConnectionManager.padfoot"; const CM_OBJECT_PATH: &'static str = "/org/freedesktop/Telepathy/ConnectionManager/padfoot"; const PROTO_OBJECT_PATH: &'static str = "/org/freedesktop/Telepathy/ConnectionManager/padfoot/delta"; fn run() -> Result<()> { 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 { RequestNameReply::Exists => { return Err(anyhow!( "Another process is already registered on {}", CM_BUS_NAME )) } _ => println!("{} listening on {}", c.unique_name(), CM_BUS_NAME), // All other responses we can get are a success }; loop { c.process(Duration::from_secs(1))?; } } fn main() { if let Err(e) = run() { println!("{}", e); std::process::exit(1); } }