use wdk_sys::{
NTSTATUS,
WDF_OBJECT_ATTRIBUTES,
WDF_TIMER_CONFIG,
WDFTIMER,
call_unsafe_wdf_function_binding,
};
use crate::nt_success;
pub struct Timer {
wdf_timer: WDFTIMER,
}
impl Timer {
pub fn try_new(
timer_config: &mut WDF_TIMER_CONFIG,
attributes: &mut WDF_OBJECT_ATTRIBUTES,
) -> Result<Self, NTSTATUS> {
let mut timer = Self {
wdf_timer: core::ptr::null_mut(),
};
let nt_status;
unsafe {
nt_status = call_unsafe_wdf_function_binding!(
WdfTimerCreate,
timer_config,
attributes,
&mut timer.wdf_timer as *mut WDFTIMER,
);
}
nt_success(nt_status).then_some(timer).ok_or(nt_status)
}
pub fn create(
timer_config: &mut WDF_TIMER_CONFIG,
attributes: &mut WDF_OBJECT_ATTRIBUTES,
) -> Result<Self, NTSTATUS> {
Self::try_new(timer_config, attributes)
}
#[must_use]
pub fn start(&self, due_time: i64) -> bool {
let result;
unsafe {
result = call_unsafe_wdf_function_binding!(WdfTimerStart, self.wdf_timer, due_time);
}
result != 0
}
#[must_use]
pub fn stop(&self, wait: bool) -> bool {
let result;
unsafe {
result =
call_unsafe_wdf_function_binding!(WdfTimerStop, self.wdf_timer, u8::from(wait));
}
result != 0
}
}