Extracted the preupdate_hook to a separate cargo feature.

Moved hooks and preupdate_hook into their own modules inside hooks.rs
Also created an initial way to access the functions that are available
during the callback.
This commit is contained in:
Midas Lambrichts
2021-02-06 12:20:05 +01:00
parent d88f49f830
commit ceff6cb8b1
5 changed files with 556 additions and 447 deletions

View File

@@ -33,7 +33,7 @@ pub struct InnerConnection {
pub free_update_hook: Option<unsafe fn(*mut ::std::os::raw::c_void)>,
#[cfg(feature = "hooks")]
pub progress_handler: Option<Box<dyn FnMut() -> bool + Send>>,
#[cfg(feature = "hooks")]
#[cfg(feature = "preupdate_hook")]
pub free_preupdate_hook: Option<unsafe fn(*mut ::std::os::raw::c_void)>,
owned: bool,
}
@@ -52,9 +52,9 @@ impl InnerConnection {
#[cfg(feature = "hooks")]
free_update_hook: None,
#[cfg(feature = "hooks")]
free_preupdate_hook: None,
#[cfg(feature = "hooks")]
progress_handler: None,
#[cfg(feature = "preupdate_hook")]
free_preupdate_hook: None,
owned,
}
}
@@ -155,6 +155,7 @@ impl InnerConnection {
return Ok(());
}
self.remove_hooks();
self.remove_preupdate_hook();
let mut shared_handle = self.interrupt_lock.lock().unwrap();
assert!(
!shared_handle.is_null(),
@@ -305,6 +306,10 @@ impl InnerConnection {
#[cfg(not(feature = "hooks"))]
#[inline]
fn remove_hooks(&mut self) {}
#[cfg(not(feature = "preupdate_hook"))]
#[inline]
fn remove_preupdate_hook(&mut self) {}
}
impl Drop for InnerConnection {