Skip to content

Commit

Permalink
src: device: manager: Fix: Remove device method
Browse files Browse the repository at this point in the history
  • Loading branch information
RaulTrombin committed Jul 29, 2024
1 parent fe8fd8f commit 86a220e
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/device/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ impl Device {
}
}

impl Drop for Device {
fn drop(&mut self) {
trace!(
"Removing Device from DeviceManager, details: {:?}",
self.info()
);
self.actor.abort();
if let Some(broadcast_handle) = &self.broadcast {
trace!("Device broadcast handle closed for: {:?}", self.info().id);
broadcast_handle.abort();
}
}
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum DeviceSelection {
Common,
Expand Down Expand Up @@ -406,8 +420,10 @@ impl DeviceManager {
pub async fn delete(&mut self, device_id: Uuid) -> Result<Answer, ManagerError> {
match self.device.remove(&device_id) {
Some(device) => {
info!("Device delete id {:?}: Success", device_id);
Ok(Answer::DeviceInfo(vec![device.info()]))
let device_info = device.info();
drop(device);
trace!("Device delete id {:?}: Success", device_id);
Ok(Answer::DeviceInfo(vec![device_info]))
}
None => {
error!("Device delete id {device_id:?} : Error, device doesn't exist");
Expand Down

0 comments on commit 86a220e

Please sign in to comment.