Skip to main content

WakeLock

Struct WakeLock 

pub struct WakeLock {
    fd: OwnedFd,
    device: PathBuf,
    name: WakeLockName,
}
Expand description

A kernel wake lock that keeps the system awake while locked.

A new wake lock is unlocked. Locking twice or unlocking a lock that isn’t held is not an error. Locks aren’t counted, so one unlock releases the wake lock however often it was locked.

Dropping the wake lock closes its file descriptor. After the last close, the kernel releases and deletes the lock and also turns autosleep off. See the crate documentation.

Any user can create wake locks. The device has mode 0444 and the driver doesn’t check permissions on its ioctls, so a read-only descriptor is enough.

The kernel has no timeout for these wake locks.

Fields§

§fd: OwnedFd§device: PathBuf§name: WakeLockName

Implementations§

§

impl WakeLock

pub const DEFAULT_DEVICE: &'static str = "/proc/quec_wakelock"

Default path of the wake lock device.

pub fn new(name: WakeLockName) -> Result<Self, Error>

Creates a wake lock using Self::DEFAULT_DEVICE.

§Errors

Returns an error if the device can’t be opened or the kernel rejects the wake lock.

pub fn with_device<P: Into<PathBuf>>( device: P, name: WakeLockName, ) -> Result<Self, Error>

Creates a wake lock using a custom device path.

device must be a quec_wakelock device.

§Errors

Returns an error if the device can’t be opened or the kernel rejects the wake lock.

pub const fn name(&self) -> &WakeLockName

Returns the name of the wake lock.

pub fn lock(&self) -> Result<(), Error>

Locks the wake lock, which keeps the system from suspending until it is unlocked.

§Errors

Returns an error if the ioctl fails.

pub fn unlock(&self) -> Result<(), Error>

Unlocks the wake lock.

§Errors

Returns an error if the ioctl fails.

fn set_locked(&self, locked: bool) -> Result<(), Error>

Trait Implementations§

§

impl Debug for WakeLock

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.