| 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 |
|
| 5 |
use crate::{Error, Pid, proxy::Proxy}; |
| 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")] |
| 12 |
pub struct Realtime(Proxy<'static>); |
| 13 |
|
| 14 |
impl Realtime { |
| 15 |
/// Create a new instance of [`Realtime`]. |
| 16 |
pub async fn new() -> Result<Self, Error> { |
| 17 |
let proxy = Proxy::new_desktop("org.freedesktop.portal.Realtime").await?; |
| 18 |
Ok(Self(proxy)) |
| 19 |
} |
| 20 |
|
| 21 |
/// Create a new instance of [`Realtime`]. |
| 22 |
pub async fn with_connection(connection: zbus::Connection) -> Result<Self, Error> { |
| 23 |
let proxy = |
| 24 |
Proxy::new_desktop_with_connection(connection, "org.freedesktop.portal.Realtime") |
| 25 |
.await?; |
| 26 |
Ok(Self(proxy)) |
| 27 |
} |
| 28 |
|
| 29 |
/// Returns the version of the portal interface. |
| 30 |
pub fn version(&self) -> u32 { |
| 31 |
self.0.version() |
| 32 |
} |
| 33 |
|
| 34 |
#[doc(alias = "MakeThreadRealtimeWithPID")] |
| 35 |
#[allow(missing_docs)] |
| 36 |
pub async fn max_thread_realtime_with_pid( |
| 37 |
&self, |
| 38 |
process: Pid, |
| 39 |
thread: u64, |
| 40 |
priority: u32, |
| 41 |
) -> Result<(), Error> { |
| 42 |
self.0 |
| 43 |
.call( |
| 44 |
"MakeThreadRealtimeWithPID", |
| 45 |
&(process as u64, thread, priority), |
| 46 |
) |
| 47 |
.await |
| 48 |
} |
| 49 |
|
| 50 |
#[doc(alias = "MakeThreadHighPriorityWithPID")] |
| 51 |
#[allow(missing_docs)] |
| 52 |
pub async fn max_thread_high_priority_with_pid( |
| 53 |
&self, |
| 54 |
process: Pid, |
| 55 |
thread: u64, |
| 56 |
priority: i32, |
| 57 |
) -> Result<(), Error> { |
| 58 |
self.0 |
| 59 |
.call( |
| 60 |
"MakeThreadHighPriorityWithPID", |
| 61 |
&(process as u64, thread, priority), |
| 62 |
) |
| 63 |
.await |
| 64 |
} |
| 65 |
|
| 66 |
#[doc(alias = "MaxRealtimePriority")] |
| 67 |
#[allow(missing_docs)] |
| 68 |
pub async fn max_realtime_priority(&self) -> Result<i64, Error> { |
| 69 |
self.0.property("MaxRealtimePriority").await |
| 70 |
} |
| 71 |
|
| 72 |
#[doc(alias = "MinNiceLevel")] |
| 73 |
#[allow(missing_docs)] |
| 74 |
pub async fn min_nice_level(&self) -> Result<u32, Error> { |
| 75 |
self.0.property("MinNiceLevel").await |
| 76 |
} |
| 77 |
|
| 78 |
#[doc(alias = "RTTimeUSecMax")] |
| 79 |
#[allow(missing_docs)] |
| 80 |
pub async fn rt_time_usec_max(&self) -> Result<u32, Error> { |
| 81 |
self.0.property("RTTimeUSecMax").await |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
impl std::ops::Deref for Realtime { |
| 86 |
type Target = zbus::Proxy<'static>; |
| 87 |
|
| 88 |
fn deref(&self) -> &Self::Target { |
| 89 |
&self.0 |
| 90 |
} |
| 91 |
} |