Skip to content

Commit

Permalink
backend: Pass handle token to close
Browse files Browse the repository at this point in the history
This lets the implementer to know on which `Request` `close` was called.
  • Loading branch information
arun-mani-j committed Dec 19, 2024
1 parent 220b8d9 commit 6d6fdd4
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions backend-demo/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ pub struct Account;

#[async_trait]
impl RequestImpl for Account {
async fn close(&self) {
tracing::debug!("IN Close()");
async fn close(&self, token: HandleToken) {
tracing::debug!("IN Close(): {token}");
}
}

Expand Down
4 changes: 2 additions & 2 deletions backend-demo/src/screenshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ pub struct Screenshot;

#[async_trait]
impl RequestImpl for Screenshot {
async fn close(&self) {
tracing::debug!("IN Close()");
async fn close(&self, token: HandleToken) {
tracing::debug!("IN Close(): {token}");
}
}

Expand Down
4 changes: 2 additions & 2 deletions backend-demo/src/secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ pub struct Secret;

#[async_trait]
impl RequestImpl for Secret {
async fn close(&self) {
tracing::debug!("IN Close()");
async fn close(&self, token: HandleToken) {
tracing::debug!("IN Close(): {token}");
}
}

Expand Down
6 changes: 3 additions & 3 deletions backend-demo/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use ashpd::{
request::RequestImpl,
settings::{SettingsImpl, SettingsSignalEmitter},
},
desktop::settings::{ColorScheme, Namespace, APPEARANCE_NAMESPACE, COLOR_SCHEME_KEY},
desktop::{settings::{ColorScheme, Namespace, APPEARANCE_NAMESPACE, COLOR_SCHEME_KEY}, HandleToken},
zbus::zvariant::OwnedValue,
PortalError,
};
Expand All @@ -20,8 +20,8 @@ pub struct Settings {

#[async_trait]
impl RequestImpl for Settings {
async fn close(&self) {
tracing::debug!("IN Close()");
async fn close(&self, token: HandleToken) {
tracing::debug!("IN Close(): {token}");
}
}

Expand Down
4 changes: 2 additions & 2 deletions backend-demo/src/wallpaper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ pub struct Wallpaper;

#[async_trait]
impl RequestImpl for Wallpaper {
async fn close(&self) {
tracing::debug!("IN Close()");
async fn close(&self, token: HandleToken) {
tracing::debug!("IN Close(): {token}");
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/backend/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use futures_util::future::{abortable, AbortHandle};
use tokio::sync::Mutex;
use zbus::zvariant::{ObjectPath, OwnedObjectPath};

use crate::desktop::Response;
use crate::desktop::{HandleToken, Response};

#[async_trait]
pub trait RequestImpl: Send + Sync {
async fn close(&self);
async fn close(&self, token: HandleToken);
}

pub struct Request {
Expand Down Expand Up @@ -39,9 +39,10 @@ impl Request {
#[cfg(feature = "tracing")]
tracing::debug!("{_method}");
let (fut, abort_handle) = abortable(callback);
let token = HandleToken::try_from(&path).unwrap();
let close_cb = || {
tokio::spawn(async move {
RequestImpl::close(&*imp).await;
RequestImpl::close(&*imp, token).await;
});
};
let request = Request::new(close_cb, path.clone(), abort_handle, cnx.clone());
Expand Down

0 comments on commit 6d6fdd4

Please sign in to comment.