Rework to get a map of connections in ConnectionManager
This commit is contained in:
65
src/main.rs
65
src/main.rs
@@ -6,22 +6,50 @@ use dbus::{
|
||||
blocking::{stdintf::org_freedesktop_dbus::RequestNameReply, LocalConnection},
|
||||
tree::Factory,
|
||||
};
|
||||
use padfoot::{ConnectionManager, Protocol};
|
||||
use padfoot::{
|
||||
Connection, ConnectionManager, Protocol, CM_BUS_NAME, CM_CONN_BUS_NAME, CM_OBJECT_PATH,
|
||||
CONN_BUS_NAME, PROTO_BUS_NAME, PROTO_OBJECT_PATH,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
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";
|
||||
#[derive(Debug, Default)]
|
||||
struct TData {
|
||||
cm: ConnectionManager,
|
||||
p: Protocol,
|
||||
}
|
||||
|
||||
impl dbus::tree::DataType for TData {
|
||||
type Interface = Arc<TData>;
|
||||
type Tree = ();
|
||||
type Property = ();
|
||||
type ObjectPath = ();
|
||||
|
||||
type Method = ();
|
||||
type Signal = ();
|
||||
}
|
||||
|
||||
fn run() -> Result<()> {
|
||||
let f = Factory::new_fn::<()>();
|
||||
let cm = ConnectionManager::new();
|
||||
let proto = Protocol {};
|
||||
let data = Arc::new(TData { cm: cm, p: proto });
|
||||
|
||||
let f = Factory::new_fn::<TData>();
|
||||
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);
|
||||
let cm_iface = telepathy::connection_manager_server(&f, Arc::clone(&data), |m| {
|
||||
let a: &Arc<TData> = &m.iface.get_data();
|
||||
let b: &TData = &a;
|
||||
|
||||
&b.cm
|
||||
});
|
||||
|
||||
let proto_iface = telepathy::protocol_server(&f, Arc::clone(&data), |m| {
|
||||
let a: &Arc<TData> = &m.iface.get_data();
|
||||
let b: &TData = &a;
|
||||
|
||||
&b.p
|
||||
});
|
||||
|
||||
tree = tree.add(
|
||||
f.object_path(CM_OBJECT_PATH, ())
|
||||
@@ -40,16 +68,15 @@ fn run() -> Result<()> {
|
||||
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
|
||||
))
|
||||
for name in vec![CM_BUS_NAME, PROTO_BUS_NAME, CM_CONN_BUS_NAME, CONN_BUS_NAME] {
|
||||
let result = c.request_name(name, false, false, true)?;
|
||||
match result {
|
||||
RequestNameReply::Exists => {
|
||||
return Err(anyhow!("Another process is already registered on {}", name))
|
||||
}
|
||||
_ => println!("{} listening on {}", c.unique_name(), 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
|
||||
};
|
||||
}
|
||||
|
||||
loop {
|
||||
c.process(Duration::from_secs(1))?;
|
||||
|
Reference in New Issue
Block a user