Skip to main content

RoutingEngine

Struct RoutingEngine 

Source
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

Source

pub fn new() -> Self

Source

pub async fn replace_all(&self, mappings: Vec<Mapping>)

Replace all mappings with the provided set. Used on config_full push.

Source

pub async fn upsert_mapping(&self, mapping: Mapping)

Insert or replace one mapping, keyed by mapping_id. Used on config_patch upsert.

Source

pub async fn remove_mapping(&self, id: &Uuid)

Remove any mapping with the given mapping_id. Used on config_patch delete.

Source

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.

Source

pub async fn replace_cycles(&self, cycles: Vec<DeviceCycle>)

Replace all device cycles. Used on config_full push.

Source

pub async fn upsert_cycle(&self, cycle: DeviceCycle)

Insert or replace a device cycle. Used on device_cycle_patch upsert.

Source

pub async fn remove_cycle(&self, device_type: &str, device_id: &str) -> bool

Remove a device’s cycle. Used on device_cycle_patch delete.

Source

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.

Source

pub async fn cycles_snapshot(&self) -> Vec<DeviceCycle>

Snapshot every cycle. Used to persist the local cache.

Source

pub async fn cycle_for( &self, device_type: &str, device_id: &str, ) -> Option<DeviceCycle>

Fetch a cycle by device key, if any.

Source

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.

Source

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).

Source

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.

Source

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.

Source

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 CycleSwitch outcome (active is advanced locally; caller relays to server). When a cycle exists, only the active mapping fires.
  • the legacy target_switch_on + target_candidates selection mode for backward compat — only consulted when no cycle exists for the device.

Trait Implementations§

Source§

impl Default for RoutingEngine

Source§

fn default() -> RoutingEngine

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more