Skip to content

Commit

Permalink
feat(CompositeDevice): add stop method to dbus interface
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadowApex committed May 2, 2024
1 parent 0323dc1 commit 34f6d13
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/input/composite_device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Result<(), String>>(1);
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 34f6d13

Please sign in to comment.