[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>,
|
||||
callsign: Option<String>,
|
||||
listen_addr: SocketAddr,
|
||||
context: Arc<FrontendRuntimeContext>,
|
||||
) -> JoinHandle<()>;
|
||||
}
|
||||
|
||||
@@ -30,6 +31,7 @@ pub type FrontendSpawnFn = fn(
|
||||
mpsc::Sender<RigRequest>,
|
||||
Option<String>,
|
||||
SocketAddr,
|
||||
Arc<FrontendRuntimeContext>,
|
||||
) -> JoinHandle<()>;
|
||||
|
||||
/// Context for registering and spawning frontends.
|
||||
@@ -64,7 +66,7 @@ impl FrontendRegistrationContext {
|
||||
names
|
||||
}
|
||||
|
||||
/// Spawn a registered frontend by name.
|
||||
/// Spawn a registered frontend by name with runtime context.
|
||||
pub fn spawn_frontend(
|
||||
&self,
|
||||
name: &str,
|
||||
@@ -72,13 +74,14 @@ impl FrontendRegistrationContext {
|
||||
rig_tx: mpsc::Sender<RigRequest>,
|
||||
callsign: Option<String>,
|
||||
listen_addr: SocketAddr,
|
||||
context: Arc<FrontendRuntimeContext>,
|
||||
) -> DynResult<JoinHandle<()>> {
|
||||
let key = normalize_name(name);
|
||||
let spawner = self
|
||||
.spawners
|
||||
.get(&key)
|
||||
.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
|
||||
}
|
||||
|
||||
/// Spawn a registered frontend by name.
|
||||
/// Spawn a registered frontend by name with runtime context.
|
||||
pub fn spawn_frontend(
|
||||
name: &str,
|
||||
state_rx: watch::Receiver<RigState>,
|
||||
rig_tx: mpsc::Sender<RigRequest>,
|
||||
callsign: Option<String>,
|
||||
listen_addr: SocketAddr,
|
||||
context: Arc<FrontendRuntimeContext>,
|
||||
) -> DynResult<JoinHandle<()>> {
|
||||
let key = normalize_name(name);
|
||||
let reg = registry().lock().expect("frontend registry mutex poisoned");
|
||||
@@ -191,5 +195,5 @@ pub fn spawn_frontend(
|
||||
.spawners
|
||||
.get(&key)
|
||||
.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