use std::{os::raw::c_int, os::raw::c_void, sync::Arc};
use glib::translate::{FromGlibPtrBorrow, FromGlibPtrNone};
use crate::print::FpPrint;
use super::{FpDevice, UserData};
pub(crate) extern "C" fn fp_enroll_progress<F, T>(
device: *mut libfprint_sys::FpDevice,
completed_stages: c_int,
print: *mut libfprint_sys::FpPrint, user_data: *mut c_void,
error: *mut libfprint_sys::GError,
) where
F: Fn(&FpDevice, i32, Option<FpPrint>, Option<glib::Error>, &Option<T>),
{
if !user_data.is_null() {
let callback_data: Arc<UserData<F, T>> = unsafe { Arc::from_raw(user_data.cast()) };
let device = unsafe { FpDevice::from_glib_borrow(device) };
let print = match print.is_null() {
true => None,
false => Some(unsafe { FpPrint::from_glib_none(print) }),
};
let error = match error.is_null() {
true => None,
false => Some(unsafe { glib::Error::from_glib_none(error.cast()) }),
};
callback_data.callback_enroll(&device, completed_stages, print, error);
std::mem::forget(callback_data);
}
}
pub(crate) extern "C" fn fp_match_cb<F, T>(
device: *mut libfprint_sys::FpDevice,
match_print: *mut libfprint_sys::FpPrint,
print: *mut libfprint_sys::FpPrint,
user_data: *mut c_void,
error: *mut libfprint_sys::GError,
) where
F: Fn(&FpDevice, Option<FpPrint>, FpPrint, Option<glib::Error>, &Option<T>),
{
if !user_data.is_null() {
let callback_data: Arc<UserData<F, T>> = unsafe { Arc::from_raw(user_data.cast()) };
let device = unsafe { FpDevice::from_glib_none(device) };
let match_print = match match_print.is_null() {
true => None,
false => Some(unsafe { FpPrint::from_glib_none(match_print) }),
};
let print = unsafe { FpPrint::from_glib_none(print) };
let error = match error.is_null() {
true => None,
false => Some(unsafe { glib::Error::from_glib_none(error.cast()) }),
};
callback_data.callback_match(&device, match_print, print, error);
}
}