ipp_printer_app/device.rs
1//! [`DeviceBackend`] trait: enumerate physical devices, resolve driver names,
2//! poll live status.
3
4use crate::flags::PrinterReason;
5use crate::printer::PrinterConfig;
6
7/// Enumerate physical printers and report their live health.
8///
9/// Implementations describe how to discover devices (e.g. via sysfs, BlueZ,
10/// USB enumeration) and how to map their identifying strings to a driver
11/// name registered with the framework.
12pub trait DeviceBackend: Send + Sync {
13 /// Call `emit(info, uri, device_id)` for each discovered device. The
14 /// closure returns `true` to continue enumeration, `false` to stop early.
15 fn list(&self, emit: &mut dyn FnMut(&str, &str, &str) -> bool);
16
17 /// Map a device's IEEE 1284 `device-id` string and URI to a driver name
18 /// that this backend recognises. Return `None` for "this isn't one of
19 /// mine, skip it".
20 fn driver_for_device(&self, device_id: &str, device_uri: &str) -> Option<String>;
21
22 /// Query live `printer-state-reasons` for a registered printer. The
23 /// background status loop calls this on each registered printer and
24 /// updates the IPP attribute when the value changes. Returning `None`
25 /// means "no update" (keep whatever the registry already holds).
26 fn poll_status(&self, _config: &PrinterConfig) -> Option<PrinterReason> {
27 None
28 }
29}