ni_syscfg/
hardware_filter.rs

1//! Functions to support the hardware filters when searching for hardware resources.
2//!
3use crate::error::{api_status, Result};
4use crate::handles::close_handle;
5use crate::Session;
6use ni_syscfg_sys::*;
7use std::ptr::null_mut;
8
9/// Used with [Session::find_hardware](crate::Session::find_hardware) to specify which pieces of hardware are of interest.
10pub struct HardwareFilter {
11    handle: NISysCfgFilterHandle,
12    mode: FilterMode,
13}
14
15impl HardwareFilter {
16    pub fn new(session: &Session) -> Result<Self> {
17        let mut handle = null_mut();
18        unsafe {
19            api_status(NISysCfgCreateFilter(*session.handle(), &mut handle))?;
20        }
21        Ok(Self {
22            handle,
23            mode: FilterMode::MatchValuesAll,
24        })
25    }
26
27    /// Set the mode for the filter, determining how the filter match is applied.
28    pub fn set_mode(&mut self, mode: FilterMode) -> &mut Self {
29        self.mode = mode;
30        self
31    }
32
33    pub fn mode(&self) -> FilterMode {
34        self.mode
35    }
36
37    pub(crate) fn handle(&self) -> NISysCfgFilterHandle {
38        self.handle
39    }
40}
41
42impl Drop for HardwareFilter {
43    fn drop(&mut self) {
44        let _ = close_handle(self.handle);
45        println!("Drop Filter");
46    }
47}
48
49#[repr(i32)]
50#[derive(Clone, Copy, Debug, PartialEq, Eq)]
51/// Give the way that the filter properties are used to match against items.
52pub enum FilterMode {
53    /// Includes all of the properties specified in the input filter.
54    MatchValuesAll = NISysCfgFilterMode_NISysCfgFilterModeMatchValuesAll,
55    /// Includes any of the properties specified in the input filter.
56    MatchValuesAny = NISysCfgFilterMode_NISysCfgFilterModeMatchValuesAny,
57    /// Includes none of the properties in the input filter.
58    MatchValuesNone = NISysCfgFilterMode_NISysCfgFilterModeMatchValuesNone,
59    /// Includes all of the properties specified in the input filter, regardless of the values.
60    AllPropertiesExist = NISysCfgFilterMode_NISysCfgFilterModeAllPropertiesExist,
61}