ashpd/desktop/
realtime.rs

1//! Set threads to realtime.
2//!
3//! Wrapper of the DBus interface: [`org.freedesktop.portal.Realtime`](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.Realtime.html).
4
5use crate::{proxy::Proxy, Error, Pid};
6
7/// Interface for setting a thread to realtime from within the sandbox.
8///
9/// Wrapper of the DBus interface: [`org.freedesktop.portal.Realtime`](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.Realtime.html).
10#[derive(Debug)]
11#[doc(alias = "org.freedesktop.portal.Realtime")]
12pub struct Realtime<'a>(Proxy<'a>);
13
14impl<'a> Realtime<'a> {
15    /// Create a new instance of [`Realtime`].
16    pub async fn new() -> Result<Realtime<'a>, Error> {
17        let proxy = Proxy::new_desktop("org.freedesktop.portal.Realtime").await?;
18        Ok(Self(proxy))
19    }
20
21    #[doc(alias = "MakeThreadRealtimeWithPID")]
22    #[allow(missing_docs)]
23    pub async fn max_thread_realtime_with_pid(
24        &self,
25        process: Pid,
26        thread: u64,
27        priority: u32,
28    ) -> Result<(), Error> {
29        self.0
30            .call(
31                "MakeThreadRealtimeWithPID",
32                &(process as u64, thread, priority),
33            )
34            .await
35    }
36
37    #[doc(alias = "MakeThreadHighPriorityWithPID")]
38    #[allow(missing_docs)]
39    pub async fn max_thread_high_priority_with_pid(
40        &self,
41        process: Pid,
42        thread: u64,
43        priority: i32,
44    ) -> Result<(), Error> {
45        self.0
46            .call(
47                "MakeThreadHighPriorityWithPID",
48                &(process as u64, thread, priority),
49            )
50            .await
51    }
52
53    #[doc(alias = "MaxRealtimePriority")]
54    #[allow(missing_docs)]
55    pub async fn max_realtime_priority(&self) -> Result<i64, Error> {
56        self.0.property("MaxRealtimePriority").await
57    }
58
59    #[doc(alias = "MinNiceLevel")]
60    #[allow(missing_docs)]
61    pub async fn min_nice_level(&self) -> Result<u32, Error> {
62        self.0.property("MinNiceLevel").await
63    }
64
65    #[doc(alias = "RTTimeUSecMax")]
66    #[allow(missing_docs)]
67    pub async fn rt_time_usec_max(&self) -> Result<u32, Error> {
68        self.0.property("RTTimeUSecMax").await
69    }
70}
71
72impl<'a> std::ops::Deref for Realtime<'a> {
73    type Target = zbus::Proxy<'a>;
74
75    fn deref(&self) -> &Self::Target {
76        &self.0
77    }
78}