From 34f6d135a8479f5a7674a66e9bd4a49d00866881 Mon Sep 17 00:00:00 2001 From: William Edwards Date: Thu, 2 May 2024 13:02:04 -0700 Subject: [PATCH] feat(CompositeDevice): add stop method to dbus interface --- src/input/composite_device/mod.rs | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/input/composite_device/mod.rs b/src/input/composite_device/mod.rs index 1bcc3315..57d9f54e 100644 --- a/src/input/composite_device/mod.rs +++ b/src/input/composite_device/mod.rs @@ -119,6 +119,14 @@ impl DBusInterface { Ok(profile_name) } + /// Stop the composite device and all target devices + async fn stop(&self) -> fdo::Result<()> { + self.tx + .send(Command::Stop) + .map_err(|e| fdo::Error::Failed(e.to_string()))?; + Ok(()) + } + /// Load the device profile from the given path async fn load_profile_path(&self, path: String) -> fdo::Result<()> { let (sender, mut receiver) = mpsc::channel::>(1); @@ -746,13 +754,15 @@ impl CompositeDevice { // Stop all target devices log::debug!("Stopping target devices"); - #[allow(clippy::for_kv_map)] - for (_, target) in &self.target_devices { - target.send(TargetCommand::Stop).await?; + for (path, target) in &self.target_devices { + if let Err(e) = target.send(TargetCommand::Stop).await { + log::error!("Failed to stop target device {path}: {e:?}"); + } } - #[allow(clippy::for_kv_map)] - for (_, target) in &self.target_dbus_devices { - target.send(TargetCommand::Stop).await?; + for (path, target) in &self.target_dbus_devices { + if let Err(e) = target.send(TargetCommand::Stop).await { + log::error!("Failed to stop dbus device {path}: {e:?}"); + } } // Unhide all source devices @@ -767,6 +777,13 @@ impl CompositeDevice { } } + // Send stop command to all source devices + for (path, source) in &self.source_devices { + if let Err(e) = source.send(SourceCommand::Stop).await { + log::debug!("Failed to stop source device {path}: {e:?}"); + } + } + // Wait on all tasks log::debug!("Waiting for source device tasks to finish"); while let Some(res) = self.source_device_tasks.join_next().await {