pub struct RoutingEngine { /* private fields */ }Expand description
Thread-safe registry of currently-active mappings, keyed by
(device_type, device_id) for O(1) lookup per input event.
Implementations§
Source§impl RoutingEngine
impl RoutingEngine
pub fn new() -> Self
Sourcepub async fn replace_all(&self, mappings: Vec<Mapping>)
pub async fn replace_all(&self, mappings: Vec<Mapping>)
Replace all mappings with the provided set. Used on config_full push.
Sourcepub async fn upsert_mapping(&self, mapping: Mapping)
pub async fn upsert_mapping(&self, mapping: Mapping)
Insert or replace one mapping, keyed by mapping_id. Used on
config_patch upsert.
Sourcepub async fn remove_mapping(&self, id: &Uuid)
pub async fn remove_mapping(&self, id: &Uuid)
Remove any mapping with the given mapping_id. Used on
config_patch delete.
Sourcepub async fn snapshot(&self) -> Vec<Mapping>
pub async fn snapshot(&self) -> Vec<Mapping>
Snapshot every mapping currently held, grouped or not. Used to persist the local cache after an incremental patch.
Sourcepub async fn replace_cycles(&self, cycles: Vec<DeviceCycle>)
pub async fn replace_cycles(&self, cycles: Vec<DeviceCycle>)
Replace all device cycles. Used on config_full push.
Sourcepub async fn upsert_cycle(&self, cycle: DeviceCycle)
pub async fn upsert_cycle(&self, cycle: DeviceCycle)
Insert or replace a device cycle. Used on device_cycle_patch upsert.
Sourcepub async fn remove_cycle(&self, device_type: &str, device_id: &str) -> bool
pub async fn remove_cycle(&self, device_type: &str, device_id: &str) -> bool
Remove a device’s cycle. Used on device_cycle_patch delete.
Sourcepub async fn set_cycle_active(
&self,
device_type: &str,
device_id: &str,
active_mapping_id: Uuid,
) -> bool
pub async fn set_cycle_active( &self, device_type: &str, device_id: &str, active_mapping_id: Uuid, ) -> bool
Update only the active mapping ID for an existing cycle. Returns
false if no cycle exists or active_mapping_id is not in the
cycle’s mapping_ids list.
Sourcepub async fn cycles_snapshot(&self) -> Vec<DeviceCycle>
pub async fn cycles_snapshot(&self) -> Vec<DeviceCycle>
Snapshot every cycle. Used to persist the local cache.
Sourcepub async fn cycle_for(
&self,
device_type: &str,
device_id: &str,
) -> Option<DeviceCycle>
pub async fn cycle_for( &self, device_type: &str, device_id: &str, ) -> Option<DeviceCycle>
Fetch a cycle by device key, if any.
Sourcepub async fn feedback_rules_for_target(
&self,
service_type: &str,
target: &str,
) -> Vec<FeedbackRule>
pub async fn feedback_rules_for_target( &self, service_type: &str, target: &str, ) -> Vec<FeedbackRule>
Feedback rules attached to whichever mapping covers the given
(service_type, target) — either as its primary target or as a
listed candidate (including candidates that override the mapping’s
service_type). Returns an empty vec when no mapping covers the
target, letting the caller fall back to hardcoded defaults.
Feedback is stored at the mapping level (all candidates share one
rule set), so a candidate match still returns the mapping’s
feedback.
Sourcepub async fn feedback_rules_for_device_target(
&self,
device_type: &str,
device_id: &str,
service_type: &str,
target: &str,
) -> Option<Vec<FeedbackRule>>
pub async fn feedback_rules_for_device_target( &self, device_type: &str, device_id: &str, service_type: &str, target: &str, ) -> Option<Vec<FeedbackRule>>
Same as feedback_rules_for_target but scoped to one (device_type, device_id) bucket. Use this from per-device feedback pumps so a
Nuimo only reacts when the state change belongs to a mapping it
owns — otherwise a second Nuimo mapped elsewhere would flash glyphs
for unrelated service activity.
Returns None when no mapping on this device covers
(service_type, target) — the caller should skip. Returns
Some(vec) when a mapping exists; the vec may be empty, which
signals “mapping exists but user configured no rules — fall back
to hardcoded defaults” (preserves single-device behavior).
Sourcepub async fn feedback_targets_for(
&self,
service_type: &str,
target: &str,
) -> Vec<(String, String, Vec<FeedbackRule>)>
pub async fn feedback_targets_for( &self, service_type: &str, target: &str, ) -> Vec<(String, String, Vec<FeedbackRule>)>
Find every device whose mapping owns (service_type, target) and
return its (device_type, device_id, feedback_rules). Used by the
iOS feedback pump, which fans a single state update out to every
LED that should display it — typically 1 device, but two Nuimos
paired to the same iPad both deserve feedback.
Sourcepub async fn route(
&self,
device_type: &str,
device_id: &str,
input: &InputPrimitive,
) -> Vec<RoutedIntent>
pub async fn route( &self, device_type: &str, device_id: &str, input: &InputPrimitive, ) -> Vec<RoutedIntent>
Apply the given input primitive from a specific device, returning every intent it produces across all matching mappings.
When the device has a DeviceCycle, only the mapping identified
by active_mapping_id is eligible — non-active members and
non-member mappings on the same device sit dormant. Cycle-gesture
inputs are NOT short-circuited here (they would silently dispatch
nothing); use route_with_mode to surface a CycleSwitch outcome.
Sourcepub async fn route_with_mode(
&self,
device_type: &str,
device_id: &str,
input: &InputPrimitive,
) -> RouteOutcome
pub async fn route_with_mode( &self, device_type: &str, device_id: &str, input: &InputPrimitive, ) -> RouteOutcome
Same dispatch as route, but also implements:
- the device-level Cycle: cycle-gesture inputs short-circuit to a
CycleSwitchoutcome (active is advanced locally; caller relays to server). When a cycle exists, only the active mapping fires. - the legacy
target_switch_on+target_candidatesselection mode for backward compat — only consulted when no cycle exists for the device.