1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
pub mod context;
pub mod device;
pub mod error;
pub mod finger;
pub mod image;
pub mod print;
pub(crate) mod utils;

#[cfg(test)]
mod tests {

    use crate::{context::FpContext, device::FpDevice, error::GError, print::FpPrint};
    struct UserData {
        _count: u32,
        _name: String,
    }
    fn generate_print<'a>(dev: &'a FpDevice) -> FpPrint<'a> {
        let mut user_data = UserData {
            _count: 304,
            _name: "Donda".into(),
        };

        let template = FpPrint::new(&dev);
        let print1 = dev
            .enroll(template, Some(callback_fn), Some(&mut user_data))
            .unwrap();
        let print2 = print1.clone();
        drop(print2);
        return print1;
    }

    fn callback_fn(
        device: &FpDevice,
        completed_stages: i32,
        _print: FpPrint,
        _error: Option<GError>,
        _user_data: &mut Option<&mut UserData>,
    ) {
        println!(
            "Enrolling: {} of {}",
            completed_stages,
            device.get_nr_enroll_stages()
        );
    }

    fn callback_function(
        _device: &FpDevice,             // The fingerprint scanner device
        matched_print: Option<FpPrint>, // The matched print, if any.
        _new_print: FpPrint,            // New print scanned.
        _error: Option<GError>,         // Optinal error in case of an error.
        _match_data: &Option<()>,       // User data can be any data type.
    ) {
        if matched_print.is_some() {
            println!("Found matched print!");
        }
    }
    fn ident_test() {
        let ctx = FpContext::new();
        let dev = match ctx.get_devices().iter().next() {
            Some(dev) => dev,
            None => {
                return;
            }
        }; // Throws errors if no device is connected
        let f = dev.get_features();
        println!("{:?}", f);

        dev.open().unwrap(); // Open the device

        let prints = vec![generate_print(&dev), generate_print(&dev)];

        let mut matched_print = FpPrint::new(&dev);
        matched_print.set_username("Some username should be here");
        let mut new_print = FpPrint::new(&dev);

        dev.identify(
            prints,
            Some(callback_function),
            None,
            Some(&mut matched_print),
            Some(&mut new_print),
        )
        .unwrap();
    }
}