libfprint_rs/context.rs
1use glib::{translate::ToGlibPtr, wrapper};
2
3use crate::FpDevice;
4
5wrapper! {
6 /// This struct allows you to discover fingerprint scanning hardware. This is the starting point when integrating libfprint-rs into your software.
7 pub struct FpContext(Object<libfprint_sys::FpContext, libfprint_sys::FpContextClass>);
8 match fn {
9 type_ => || libfprint_sys::fp_context_get_type() as usize,
10 }
11}
12impl FpContext {
13 #[cfg(not(doctest))]
14 /// Create a new `FpContext`
15 /// # Examples:
16 /// ```rust
17 /// use libfprint_rs::FpContext;
18 ///
19 /// let context = FpContext::new();
20 /// ```
21 pub fn new() -> Self {
22 unsafe { glib::translate::from_glib_none(libfprint_sys::fp_context_new()) }
23 }
24 #[cfg(not(doctest))]
25 /// Get the list of devices connected to the system
26 /// # Examples:
27 /// ```rust
28 /// use libfprint_rs::FpContext;
29 ///
30 /// let context = FpContext::new();
31 /// let devices = context.devices();
32 /// ```
33 pub fn devices(&self) -> Vec<FpDevice> {
34 use glib::translate::FromGlibPtrContainer;
35
36 unsafe {
37 let devs = libfprint_sys::fp_context_get_devices(self.to_glib_none().0);
38
39 let devs = devs.cast::<glib::ffi::GPtrArray>();
40 FromGlibPtrContainer::from_glib_none(devs)
41 }
42 }
43
44 /// Enumerate all the devices connected to the system
45 ///
46 /// This function will enumerate all the devices connected to the system and add them to the context.
47 pub fn enumerate(&self) {
48 unsafe {
49 libfprint_sys::fp_context_enumerate(self.to_glib_none().0);
50 }
51 }
52}
53
54impl Default for FpContext {
55 fn default() -> Self {
56 Self::new()
57 }
58}