[feat](trx-frontend): update FrontendSpawner trait to accept context
Update FrontendSpawner trait and related functions to accept and pass Arc<FrontendRuntimeContext> parameter instead of relying on global accessors for audio channels, decode channels, and auth tokens. Changes: - FrontendSpawner::spawn_frontend now accepts context parameter - FrontendSpawnFn type signature includes context parameter - FrontendRegistrationContext::spawn_frontend passes context to spawner - Global spawn_frontend function accepts and passes context This enables frontends to receive runtime data explicitly without accessing globals, improving testability and supporting multiple concurrent frontends with different contexts. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com> Signed-off-by: Stanislaw Grams <stanislawgrams@gmail.com>
This commit is contained in:
@@ -22,6 +22,7 @@ pub trait FrontendSpawner {
|
|||||||
rig_tx: mpsc::Sender<RigRequest>,
|
rig_tx: mpsc::Sender<RigRequest>,
|
||||||
callsign: Option<String>,
|
callsign: Option<String>,
|
||||||
listen_addr: SocketAddr,
|
listen_addr: SocketAddr,
|
||||||
|
context: Arc<FrontendRuntimeContext>,
|
||||||
) -> JoinHandle<()>;
|
) -> JoinHandle<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,6 +31,7 @@ pub type FrontendSpawnFn = fn(
|
|||||||
mpsc::Sender<RigRequest>,
|
mpsc::Sender<RigRequest>,
|
||||||
Option<String>,
|
Option<String>,
|
||||||
SocketAddr,
|
SocketAddr,
|
||||||
|
Arc<FrontendRuntimeContext>,
|
||||||
) -> JoinHandle<()>;
|
) -> JoinHandle<()>;
|
||||||
|
|
||||||
/// Context for registering and spawning frontends.
|
/// Context for registering and spawning frontends.
|
||||||
@@ -64,7 +66,7 @@ impl FrontendRegistrationContext {
|
|||||||
names
|
names
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Spawn a registered frontend by name.
|
/// Spawn a registered frontend by name with runtime context.
|
||||||
pub fn spawn_frontend(
|
pub fn spawn_frontend(
|
||||||
&self,
|
&self,
|
||||||
name: &str,
|
name: &str,
|
||||||
@@ -72,13 +74,14 @@ impl FrontendRegistrationContext {
|
|||||||
rig_tx: mpsc::Sender<RigRequest>,
|
rig_tx: mpsc::Sender<RigRequest>,
|
||||||
callsign: Option<String>,
|
callsign: Option<String>,
|
||||||
listen_addr: SocketAddr,
|
listen_addr: SocketAddr,
|
||||||
|
context: Arc<FrontendRuntimeContext>,
|
||||||
) -> DynResult<JoinHandle<()>> {
|
) -> DynResult<JoinHandle<()>> {
|
||||||
let key = normalize_name(name);
|
let key = normalize_name(name);
|
||||||
let spawner = self
|
let spawner = self
|
||||||
.spawners
|
.spawners
|
||||||
.get(&key)
|
.get(&key)
|
||||||
.ok_or_else(|| format!("Unknown frontend: {}", name))?;
|
.ok_or_else(|| format!("Unknown frontend: {}", name))?;
|
||||||
Ok(spawner(state_rx, rig_tx, callsign, listen_addr))
|
Ok(spawner(state_rx, rig_tx, callsign, listen_addr, context))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,13 +180,14 @@ pub fn registered_frontends() -> Vec<String> {
|
|||||||
names
|
names
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Spawn a registered frontend by name.
|
/// Spawn a registered frontend by name with runtime context.
|
||||||
pub fn spawn_frontend(
|
pub fn spawn_frontend(
|
||||||
name: &str,
|
name: &str,
|
||||||
state_rx: watch::Receiver<RigState>,
|
state_rx: watch::Receiver<RigState>,
|
||||||
rig_tx: mpsc::Sender<RigRequest>,
|
rig_tx: mpsc::Sender<RigRequest>,
|
||||||
callsign: Option<String>,
|
callsign: Option<String>,
|
||||||
listen_addr: SocketAddr,
|
listen_addr: SocketAddr,
|
||||||
|
context: Arc<FrontendRuntimeContext>,
|
||||||
) -> DynResult<JoinHandle<()>> {
|
) -> DynResult<JoinHandle<()>> {
|
||||||
let key = normalize_name(name);
|
let key = normalize_name(name);
|
||||||
let reg = registry().lock().expect("frontend registry mutex poisoned");
|
let reg = registry().lock().expect("frontend registry mutex poisoned");
|
||||||
@@ -191,5 +195,5 @@ pub fn spawn_frontend(
|
|||||||
.spawners
|
.spawners
|
||||||
.get(&key)
|
.get(&key)
|
||||||
.ok_or_else(|| format!("Unknown frontend: {}", name))?;
|
.ok_or_else(|| format!("Unknown frontend: {}", name))?;
|
||||||
Ok(spawner(state_rx, rig_tx, callsign, listen_addr))
|
Ok(spawner(state_rx, rig_tx, callsign, listen_addr, context))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user