mirror of
https://github.com/rzuasti/oott.git
synced 2026-07-08 19:21:54 +02:00
Separate events and notifications into focused modules
The events.rs file mixed three domains: device-event recording, change detection, and the entire notification pipeline (rendering + delivery + sending). This made it long, gave functions side effects beyond their stated goal (classify_* silently recorded events), and intertwined the events and notifications logic. Split along domain boundaries: - model::device_events now owns DeviceChange, the shared contract. - events records device events only (record_new_device/record_known_device); events/detection.rs holds pure change detection. - new notifications module owns rendering, delivery, and sending (notifications.rs + delivery.rs + render.rs); pushover/error moved here. Data now flows one way: events produces DeviceChange, notifications consumes it, both depend only on model. Scanners/pipeline/main orchestrate. classify_* renamed to record_* so the write is the stated goal; send and send_notification collapsed into persist_and_deliver. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
9efe84c099
commit
09e7915547
@@ -1,14 +1,16 @@
|
||||
use log::{debug, error};
|
||||
|
||||
use crate::db;
|
||||
use crate::events::{self, DeviceChange};
|
||||
use crate::model::device_events::DeviceEventScanner;
|
||||
use crate::events;
|
||||
use crate::model::device_events::{DeviceChange, DeviceEventScanner};
|
||||
use crate::model::devices::Device;
|
||||
use crate::notifications;
|
||||
|
||||
/// Persist a device sighting and record its device event, then return any notification-worthy
|
||||
/// changes it produced (without sending). This feeds every scanner (ARP, mDNS, SSDP, DHCP, SNMP)
|
||||
/// through one code path. Active scanners accumulate the changes across a whole scan and pass them
|
||||
/// to `events::notify` once, consolidating per type; passive listeners use `record_and_notify`.
|
||||
/// to `notifications::notify` once, consolidating per type; passive listeners use
|
||||
/// `record_and_notify`.
|
||||
///
|
||||
/// When the device is already known, the sighting is reconciled with the stored record:
|
||||
/// - a previously stored hostname is kept rather than overwritten by this sighting's name;
|
||||
@@ -37,7 +39,7 @@ pub fn record_sighting(mut device: Device, scanner: DeviceEventScanner) -> Vec<D
|
||||
error!("Failed to update device {}: {err}", device.mac_address);
|
||||
return Vec::new();
|
||||
}
|
||||
events::classify_existing_device(recorded, device, scanner)
|
||||
events::record_known_device(recorded, device, scanner)
|
||||
}
|
||||
None => {
|
||||
debug!("New device {} discovered; inserting", device.mac_address);
|
||||
@@ -45,7 +47,7 @@ pub fn record_sighting(mut device: Device, scanner: DeviceEventScanner) -> Vec<D
|
||||
error!("Failed to insert device {}: {err}", device.mac_address);
|
||||
return Vec::new();
|
||||
}
|
||||
events::classify_new_device(device, scanner)
|
||||
events::record_new_device(device, scanner)
|
||||
.into_iter()
|
||||
.collect()
|
||||
}
|
||||
@@ -56,7 +58,7 @@ pub fn record_sighting(mut device: Device, scanner: DeviceEventScanner) -> Vec<D
|
||||
/// listeners (mDNS, SSDP, DHCP), which process one device per event and so have nothing to
|
||||
/// consolidate across a scan.
|
||||
pub fn record_and_notify(device: Device, scanner: DeviceEventScanner) {
|
||||
events::notify(record_sighting(device, scanner));
|
||||
notifications::notify(record_sighting(device, scanner));
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user