1mod context;
38mod device;
39mod finger;
40mod image;
41mod print;
42
43pub use gio::Cancellable;
46pub use glib::Date as GDate;
48pub use glib::Error as GError;
50
51pub use context::FpContext;
52pub use device::{FpDevice, FpEnrollProgress, FpMatchCb};
53pub use finger::FpFinger;
54pub use image::FpImage;
55pub use print::FpPrint;
56
57#[cfg(test)]
58mod tests {
59
60 use std::io::{Read, Write};
61
62 use crate::{FpContext, FpDevice, FpPrint};
63
64 #[test]
65 fn get_names() {
66 let ctx = FpContext::new();
67 let devices = ctx.devices();
68 let dev = devices.first().unwrap();
69
70 dev.open_sync(None).unwrap();
71 let mut prints = Vec::new();
72
73 for i in 0..3 {
74 save_prints(dev, i);
75 }
76
77 for i in 0..3 {
78 let print = read_prints(i);
79 prints.push(print);
80 }
81
82 let mut new_print = FpPrint::new(dev);
83 let matched = dev
84 .identify_sync(&prints, None, Some(match_cb), None, Some(&mut new_print))
85 .unwrap();
86
87 if matched.is_some() {
88 println!("Matched");
89 } else {
90 println!("Not matched");
91 }
92 }
93 pub fn _enroll_print(dev: &FpDevice) -> FpPrint {
94 let template = FpPrint::new(dev);
95 let print = dev.enroll_sync(template, None, Some(enroll_cb), None);
96 print.unwrap()
97 }
98 pub fn save_prints(dev: &FpDevice, id: u32) {
99 let template = FpPrint::new(dev);
100 let print = dev
101 .enroll_sync(template, None, Some(enroll_cb), None)
102 .unwrap();
103 let data = print.serialize().unwrap();
104 let name = format!("prints/print{}", id);
105 let mut file = std::fs::File::create(name).unwrap();
106 file.write_all(&data).unwrap();
107 }
108 pub fn read_prints(id: u32) -> FpPrint {
109 let name = format!("prints/print{}", id);
110 let mut file = std::fs::File::open(name).unwrap();
111 let mut buf = Vec::new();
112 file.read_to_end(&mut buf).unwrap();
113
114 FpPrint::deserialize(&buf).unwrap()
115 }
116 pub fn enroll_cb(
117 _device: &FpDevice,
118 enroll_stage: i32,
119 _print: Option<FpPrint>,
120 _error: Option<glib::Error>,
121 _data: &Option<i32>,
122 ) {
123 println!("Enroll stage: {}", enroll_stage);
124 }
125 pub fn match_cb(
126 _device: &FpDevice,
127 matched_print: Option<FpPrint>,
128 _print: FpPrint,
129 _error: Option<glib::Error>,
130 _data: &Option<i32>,
131 ) {
132 if matched_print.is_some() {
133 println!("Matched");
134 } else {
135 println!("Not matched");
136 }
137 }
138}