Skip to main content

kernel/
signal_router.rs

1// Copyright 2026 Mark Alan Boykin
2// This Source Code Form is subject to the terms of the Mozilla Public
3// License, v. 2.0. If a copy of the MPL was not distributed with this
4// file, You can obtain one at https://mozilla.org/MPL/2.0/.
5// SPDX-License-Identifier: MPL-2.0
6
7//! Portable signal-subscription seam for frame-bound inbox consumers.
8
9use futures_util::stream::BoxStream;
10
11/// Host-provided subscription router for shell-facing runtime signals.
12pub trait SignalRouter: Send + Sync {
13    fn subscribe(&self, topic: SignalTopic) -> BoxStream<'static, SignalEnvelope>;
14}
15
16#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
17pub enum SignalTopic {
18    Lifecycle,
19    RegistryEvent,
20}
21
22#[derive(Debug, Clone, PartialEq, Eq)]
23pub enum SignalEnvelope {
24    Lifecycle(LifecycleSignal),
25    RegistryEvent(RegistrySignal),
26}
27
28impl SignalEnvelope {
29    pub fn topic(&self) -> SignalTopic {
30        match self {
31            Self::Lifecycle(..) => SignalTopic::Lifecycle,
32            Self::RegistryEvent(..) => SignalTopic::RegistryEvent,
33        }
34    }
35}
36
37#[derive(Debug, Clone, PartialEq, Eq)]
38pub enum LifecycleSignal {
39    SemanticIndexUpdated { indexed_nodes: usize },
40}
41
42#[derive(Debug, Clone, PartialEq, Eq)]
43pub enum RegistrySignal {
44    WorkbenchProjectionRefreshRequested,
45    SettingsRouteRequested { url: String },
46    ThemeChanged,
47    LensChanged,
48    PhysicsProfileChanged,
49    CanvasProfileChanged,
50    WorkbenchSurfaceChanged,
51}
52
53#[cfg(test)]
54mod tests {
55    use super::{LifecycleSignal, RegistrySignal, SignalEnvelope, SignalTopic};
56
57    #[test]
58    fn lifecycle_envelope_reports_lifecycle_topic() {
59        let envelope =
60            SignalEnvelope::Lifecycle(LifecycleSignal::SemanticIndexUpdated { indexed_nodes: 3 });
61
62        assert_eq!(envelope.topic(), SignalTopic::Lifecycle);
63    }
64
65    #[test]
66    fn registry_envelope_reports_registry_topic() {
67        let envelope =
68            SignalEnvelope::RegistryEvent(RegistrySignal::WorkbenchProjectionRefreshRequested);
69
70        assert_eq!(envelope.topic(), SignalTopic::RegistryEvent);
71    }
72}