/// An enumeration context. /// /// An Enumerator scans `/sys` for devices matching its filters. Filters are added to an Enumerator /// by calling its `match_*` and `nomatch_*` methods. After the filters are setup, the /// `scan_devices()` method finds devices in `/sys` that match the filters. pubstruct Enumerator<'a> {
context: &'a Context,
enumerator: *mut ::ffi::udev_enumerate
}
impl<'a> Drop for Enumerator<'a> { fn drop(&mutself) { unsafe { ::ffi::udev_enumerate_unref(self.enumerator) };
}
}
impl<'a> Enumerator<'a> { /// Creates a new Enumerator. pubfn new(context: &'a Context) -> ::Result<Self> { let ptr = try_alloc!(unsafe { ::ffi::udev_enumerate_new(context.as_ptr()) });
/// Adds a filter that matches only initialized devices. pubfn match_is_initialized(&mutself) -> ::Result<()> {
::util::errno_to_result(unsafe {
::ffi::udev_enumerate_add_match_is_initialized(self.enumerator)
})
}
/// Adds a filter that matches only devices that belong to the given kernel subsystem. pubfn match_subsystem<T: AsRef<OsStr>>(&mutself, subsystem: T) -> ::Result<()> { let subsystem = try!(::util::os_str_to_cstring(subsystem));
/// Adds a filter that matches only devices with the given attribute value. pubfn match_attribute<T: AsRef<OsStr>, U: AsRef<OsStr>>(&mutself, attribute: T, value: U) -> ::Result<()> { let attribute = try!(::util::os_str_to_cstring(attribute)); let value = try!(::util::os_str_to_cstring(value));
/// Adds a filter that matches only devices with the given kernel device name. pubfn match_sysname<T: AsRef<OsStr>>(&mutself, sysname: T) -> ::Result<()> { let sysname = try!(::util::os_str_to_cstring(sysname));
/// Adds a filter that matches only devices with the given property value. pubfn match_property<T: AsRef<OsStr>, U: AsRef<OsStr>>(&mutself, property: T, value: U) -> ::Result<()> { let property = try!(::util::os_str_to_cstring(property)); let value = try!(::util::os_str_to_cstring(value));
/// Adds a filter that matches only devices with the given tag. pubfn match_tag<T: AsRef<OsStr>>(&mutself, tag: T) -> ::Result<()> { let tag = try!(::util::os_str_to_cstring(tag));
/// Includes the parent device and all devices in the subtree of the parent device. pubfn match_parent(&mutself, parent: &Device) -> ::Result<()> {
::util::errno_to_result(unsafe {
::ffi::udev_enumerate_add_match_parent(self.enumerator, parent.as_ptr())
})
}
/// Adds a filter that matches only devices that don't belong to the given kernel subsystem. pubfn nomatch_subsystem<T: AsRef<OsStr>>(&mutself, subsystem: T) -> ::Result<()> { let subsystem = try!(::util::os_str_to_cstring(subsystem));
/// Adds a filter that matches only devices that don't have the the given attribute value. pubfn nomatch_attribute<T: AsRef<OsStr>, U: AsRef<OsStr>>(&mutself, attribute: T, value: U) -> ::Result<()> { let attribute = try!(::util::os_str_to_cstring(attribute)); let value = try!(::util::os_str_to_cstring(value));
/// Includes the device with the given syspath. pubfn add_syspath(&mutself, syspath: &Path) -> ::Result<()> { let syspath = try!(::util::os_str_to_cstring(syspath));
/// Scans `/sys` for devices matching the attached filters. /// /// The devices will be sorted in dependency order. pubfn scan_devices(&mutself) -> ::Result<Devices> { try!(::util::errno_to_result(unsafe {
::ffi::udev_enumerate_scan_devices(self.enumerator)
}));
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.