diff --git a/src/main.rs b/src/main.rs index 9c7187f..0d08379 100644 --- a/src/main.rs +++ b/src/main.rs @@ -43,8 +43,8 @@ fn run() -> Result<()> { let mut c = LocalConnection::new_session()?; tree.start_receive(&c); - 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)?; + for name in &[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)) diff --git a/src/padfoot/connection.rs b/src/padfoot/connection.rs index a0837c0..321acee 100644 --- a/src/padfoot/connection.rs +++ b/src/padfoot/connection.rs @@ -1,6 +1,7 @@ mod avatars; pub use self::avatars::*; +#[allow(clippy::module_inception)] mod connection; pub use self::connection::*; @@ -69,7 +70,7 @@ impl Connection { }; let mut dbfile = directories::ProjectDirs::from("gs", "ur", "telepathy-padfoot") - .ok_or(MethodErr::no_arg()) + .ok_or_else(MethodErr::no_arg) .and_then(|p| Ok(p.data_local_dir().to_path_buf()))?; dbfile.push(&id); @@ -137,9 +138,9 @@ impl Connection { Ok(Connection { id, + msgq, ctx: Arc::new(RwLock::new(ctx)), state: Arc::new(RwLock::new(ConnState::Initial)), - msgq: msgq.clone(), }) } @@ -177,12 +178,11 @@ impl Connection { let requests_iface = telepathy::connection_interface_requests_server(&f, (), move |_| c_rc5.clone()); - let c_rc6 = c_rc.clone(); let simple_presence_iface = - telepathy::connection_interface_simple_presence_server(&f, (), move |_| c_rc6.clone()); + telepathy::connection_interface_simple_presence_server(&f, (), move |_| c_rc.clone()); tree = tree.add( - f.object_path(path.clone(), ()) + f.object_path(path, ()) .introspectable() .add(conn_iface) .add(avatars_iface) @@ -223,18 +223,14 @@ impl Connection { println!("Error processing: {}", e); return; - } + }; // Spend a bit of time sending any outgoing messages - signals, mostly - loop { - let msg = match msgq.lock().unwrap().pop_front() { - Some(msg) => msg, - None => break, - }; - + while let Some(msg) = msgq.lock().unwrap().pop_front() { print!("Connection<{}>: Sending message...", id); + match c.send(msg) { - Err(e) => println!("error! {:?}", e), + Err(e) => println!("error! {:?}", e), // FIXME: handle error better? _ => println!("OK!"), } } diff --git a/src/padfoot/connection/avatars.rs b/src/padfoot/connection/avatars.rs index 6b2fadc..98a16e8 100644 --- a/src/padfoot/connection/avatars.rs +++ b/src/padfoot/connection/avatars.rs @@ -11,9 +11,11 @@ impl AsRef for std::rc::Rc< } } +type AvatarRequirementSpec = (Vec, u16, u16, u16, u16, u32); + // TODO: come back and do this properly, I'm just putting it in for consistency impl telepathy::ConnectionInterfaceAvatars for Connection { - fn get_avatar_requirements(&self) -> Result<(Vec, u16, u16, u16, u16, u32), MethodErr> { + fn get_avatar_requirements(&self) -> Result { println!("Connection<{}>::get_avatar_requirements()", self.id); Ok((vec![], 0, 0, 0, 0, 0)) } diff --git a/src/padfoot/connection/requests.rs b/src/padfoot/connection/requests.rs index b7298db..4e77d65 100644 --- a/src/padfoot/connection/requests.rs +++ b/src/padfoot/connection/requests.rs @@ -15,6 +15,10 @@ impl AsRef for std::rc::Rc } } +type ChannelSpec = (dbus::Path<'static>, HashMap); + +type RequestableChannelSpec = (HashMap, Vec); + impl telepathy::ConnectionInterfaceRequests for Connection { fn create_channel( &self, @@ -33,14 +37,12 @@ impl telepathy::ConnectionInterfaceRequests for Connection { Err(MethodErr::no_arg()) // FIXME: should be NotImplemented? } - fn channels(&self) -> Result, HashMap)>, MethodErr> { + fn channels(&self) -> Result, MethodErr> { println!("Connection<{}>::channels()", self.id); Ok(vec![]) } - fn requestable_channel_classes( - &self, - ) -> Result, Vec)>, MethodErr> { + fn requestable_channel_classes(&self) -> Result, MethodErr> { println!("Connection<{}>::requestable_channel_classes()", self.id); Ok(crate::padfoot::requestables()) }