use crate::errors;
use crate::statecallback::StateCallback;
use crate::transport::platformmonitor::Monitor;
use runloop::RunLoop;
use std::ffi::OsString;
pub struct Transaction {
thread: Option<RunLoop>,
}
impl Transaction {
pub fn new<F, T>(
timeout: u64,
callback: StateCallback<crate::Result<T>>,
new_device_cb: F,
) -> crate::Result<Self>
where
F: Fn(OsString, &dyn Fn() -> bool) + Sync + Send + 'static,
T: 'static,
{
let thread = RunLoop::new_with_timeout(
move |alive| {
let mut monitor = Monitor::new(new_device_cb);
try_or!(monitor.run(alive), |_| callback
.call(Err(errors::AuthenticatorError::Platform)));
callback.call(Err(errors::AuthenticatorError::U2FToken(
errors::U2FTokenError::NotAllowed,
)));
},
timeout,
)
.map_err(|_| errors::AuthenticatorError::Platform)?;
Ok(Self {
thread: Some(thread),
})
}
pub fn cancel(&mut self) {
self.thread.take().unwrap().cancel();
}
}