Extract tree building from Connection#run

This commit is contained in:
2020-05-16 19:42:41 +01:00
parent 411f34e6ce
commit 53bce50978

View File

@@ -189,50 +189,14 @@ impl Connection {
// FIXME: running several +process+ loops sure is convenient, but it also
// seems inefficient...
pub fn run(self, signal: mpsc::Sender<Option<MethodErr>>) {
let id = self.id();
let bus = self.bus();
let path = self.path();
let conns = self.conns.clone();
let state = self.state.clone();
let msgq = self.msgq.clone();
let id = self.id();
let c_rc = std::rc::Rc::new(self);
let f = dbus::tree::Factory::new_fn::<()>();
let mut tree = f.tree(());
let c_rc1 = c_rc.clone();
let conn_iface = telepathy::connection_server(&f, (), move |_| c_rc1.clone());
let c_rc2 = c_rc.clone();
let avatars_iface =
telepathy::connection_interface_avatars_server(&f, (), move |_| c_rc2.clone());
let c_rc3 = c_rc.clone();
let contacts_iface =
telepathy::connection_interface_contacts_server(&f, (), move |_| c_rc3.clone());
let c_rc4 = c_rc.clone();
let contact_list_iface =
telepathy::connection_interface_contact_list_server(&f, (), move |_| c_rc4.clone());
let c_rc5 = c_rc.clone();
let requests_iface =
telepathy::connection_interface_requests_server(&f, (), move |_| c_rc5.clone());
let simple_presence_iface =
telepathy::connection_interface_simple_presence_server(&f, (), move |_| c_rc.clone());
tree = tree.add(
f.object_path(path.clone(), ())
.introspectable()
.add(conn_iface)
.add(avatars_iface)
.add(contacts_iface)
.add(contact_list_iface)
.add(requests_iface)
.add(simple_presence_iface),
);
tree = tree.add(f.object_path("/", ()).introspectable());
let state = self.state.clone();
let tree = self.build_tree();
// Setup DBus connection
let mut c = match LocalConnection::new_session() {
@@ -301,6 +265,49 @@ impl Connection {
pub fn path(&self) -> String {
self.settings.path()
}
fn build_tree(self) -> dbus::tree::Tree<dbus::tree::MTFn, ()> {
let path = self.path();
let c_rc = std::rc::Rc::new(self);
let f = dbus::tree::Factory::new_fn::<()>();
let mut tree = f.tree(());
let c_rc1 = c_rc.clone();
let conn_iface = telepathy::connection_server(&f, (), move |_| c_rc1.clone());
let c_rc2 = c_rc.clone();
let avatars_iface =
telepathy::connection_interface_avatars_server(&f, (), move |_| c_rc2.clone());
let c_rc3 = c_rc.clone();
let contacts_iface =
telepathy::connection_interface_contacts_server(&f, (), move |_| c_rc3.clone());
let c_rc4 = c_rc.clone();
let contact_list_iface =
telepathy::connection_interface_contact_list_server(&f, (), move |_| c_rc4.clone());
let c_rc5 = c_rc.clone();
let requests_iface =
telepathy::connection_interface_requests_server(&f, (), move |_| c_rc5.clone());
let simple_presence_iface =
telepathy::connection_interface_simple_presence_server(&f, (), move |_| c_rc.clone());
tree = tree.add(
f.object_path(path, ())
.introspectable()
.add(conn_iface)
.add(avatars_iface)
.add(contacts_iface)
.add(contact_list_iface)
.add(requests_iface)
.add(simple_presence_iface),
);
tree = tree.add(f.object_path("/", ()).introspectable());
tree
}
}
fn escape_one(b: u8) -> String {