api: cffi: add dc_accounts_background_fetch_with_timeout

This commit is contained in:
Simon Laux
2023-12-12 01:26:36 +01:00
committed by bjoern
parent d2c61dc90e
commit f7903df805
2 changed files with 42 additions and 0 deletions

View File

@@ -4898,6 +4898,34 @@ pub unsafe extern "C" fn dc_accounts_maybe_network_lost(accounts: *mut dc_accoun
block_on(async move { accounts.write().await.maybe_network_lost().await });
}
#[no_mangle]
pub unsafe extern "C" fn dc_accounts_background_fetch_with_timeout(
accounts: *mut dc_accounts_t,
timeout_in_seconds: u64,
) -> libc::c_int {
if accounts.is_null() || timeout_in_seconds <= 2 {
eprintln!("ignoring careless call to dc_accounts_background_fetch_with_timeout()");
return 0;
}
let accounts = &*accounts;
block_on(async move {
let accounts = accounts.write().await;
match accounts
.background_fetch_with_timeout(Duration::from_secs(timeout_in_seconds))
.await
{
Ok(()) => 1,
Err(err) => {
accounts.emit_event(EventType::Error(format!(
"Failed to do background fetch: {err:#}"
)));
0
}
}
})
}
#[no_mangle]
pub unsafe extern "C" fn dc_accounts_get_event_emitter(
accounts: *mut dc_accounts_t,