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: WakeLockNameImplementations§
§impl WakeLock
impl WakeLock
pub const DEFAULT_DEVICE: &'static str = "/proc/quec_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>
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>
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
pub const fn name(&self) -> &WakeLockName
Returns the name of the wake lock.
pub fn lock(&self) -> Result<(), Error>
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.