libfprint_rs/device/
mod.rs1mod callback;
2mod device_sync;
3mod enums;
4mod fp_device;
5mod user_data;
6
7pub use device_sync::{FpEnrollProgress, FpMatchCb};
8use gio::AsyncInitable;
9use glib::wrapper;
10
11wrapper! {
12#[cfg(not(doctest))]
13pub struct FpDevice(Object<libfprint_sys::FpDevice, libfprint_sys::FpDeviceClass>)
28 @implements AsyncInitable;
29
30 match fn {
31 type_ => || libfprint_sys::fp_device_get_type() as usize,
32 }
33}
34
35pub(crate) struct UserData<F, T> {
36 function: F,
37 data: Option<T>,
38}
39
40impl<F, T> Drop for UserData<F, T> {
41 fn drop(&mut self) {
42 if self.data.is_some() {
43 drop(self.data.take())
44 }
45 }
46}
47
48macro_rules! fn_pointer {
49 ($function:ident, $struct:ident) => {{
50 let ptr: *mut std::ffi::c_void = match $function {
51 Some(cb) => {
52 let data = crate::device::UserData {
53 function: cb,
54 data: $struct,
55 };
56 let boxed = std::sync::Arc::new(data);
57 std::sync::Arc::into_raw(boxed) as *mut std::ffi::c_void
58 }
59 None => std::ptr::null_mut(),
60 };
61 ptr
62 }};
63}
64
65use fn_pointer;