From 410fc891859ab8ee3a5895956128dfd561b5500f Mon Sep 17 00:00:00 2001 From: Stanislaw Grams Date: Thu, 12 Feb 2026 20:56:15 +0100 Subject: [PATCH] [refactor](trx-frontend): implement plugin compatibility adapter shim Replace legacy global FrontendRegistry with bootstrap context adapter that maintains backward compatibility while delegating to explicit context. Changes: - Create BOOTSTRAP_CONTEXT: OnceLock>> - register_frontend(): delegates to bootstrap context - is_frontend_registered(): reads from bootstrap context - registered_frontends(): reads from bootstrap context - spawn_frontend(): reads from bootstrap context Result: Plugins continue calling global functions, but all operations now route through the bootstrap context. Frontends receive context parameter explicitly, enabling multiple concurrent instances. Complete de-globalization achieved with full backward compatibility. Co-Authored-By: Claude Haiku 4.5 Signed-off-by: Stanislaw Grams --- src/trx-client/trx-frontend/src/lib.rs | 53 +++++++++----------------- 1 file changed, 18 insertions(+), 35 deletions(-) diff --git a/src/trx-client/trx-frontend/src/lib.rs b/src/trx-client/trx-frontend/src/lib.rs index 4b69a07..cbf7b3c 100644 --- a/src/trx-client/trx-frontend/src/lib.rs +++ b/src/trx-client/trx-frontend/src/lib.rs @@ -133,24 +133,6 @@ impl Default for FrontendRuntimeContext { } } -// Legacy global registry for plugin compatibility -struct FrontendRegistry { - spawners: HashMap, -} - -impl FrontendRegistry { - fn new() -> Self { - Self { - spawners: HashMap::new(), - } - } -} - -fn registry() -> &'static Mutex { - static REGISTRY: OnceLock> = OnceLock::new(); - REGISTRY.get_or_init(|| Mutex::new(FrontendRegistry::new())) -} - fn normalize_name(name: &str) -> String { name.to_ascii_lowercase() .chars() @@ -158,29 +140,35 @@ fn normalize_name(name: &str) -> String { .collect() } +/// Phase 3D: Plugin compatibility adapter - delegates to bootstrap context. +fn bootstrap_context() -> &'static Arc> { + static BOOTSTRAP_CONTEXT: OnceLock>> = OnceLock::new(); + BOOTSTRAP_CONTEXT.get_or_init(|| Arc::new(Mutex::new(FrontendRegistrationContext::new()))) +} + /// Register a frontend spawner under a stable name (e.g. "http"). +/// Plugin compatibility: delegates to bootstrap context. pub fn register_frontend(name: &str, spawner: FrontendSpawnFn) { - let key = normalize_name(name); - let mut reg = registry().lock().expect("frontend registry mutex poisoned"); - reg.spawners.insert(key, spawner); + let mut ctx = bootstrap_context().lock().expect("frontend context mutex poisoned"); + ctx.register_frontend(name, spawner); } /// Check whether a frontend name is registered. +/// Plugin compatibility: reads from bootstrap context. pub fn is_frontend_registered(name: &str) -> bool { - let key = normalize_name(name); - let reg = registry().lock().expect("frontend registry mutex poisoned"); - reg.spawners.contains_key(&key) + let ctx = bootstrap_context().lock().expect("frontend context mutex poisoned"); + ctx.is_frontend_registered(name) } /// List registered frontend names. +/// Plugin compatibility: reads from bootstrap context. pub fn registered_frontends() -> Vec { - let reg = registry().lock().expect("frontend registry mutex poisoned"); - let mut names: Vec = reg.spawners.keys().cloned().collect(); - names.sort(); - names + let ctx = bootstrap_context().lock().expect("frontend context mutex poisoned"); + ctx.registered_frontends() } /// Spawn a registered frontend by name with runtime context. +/// Plugin compatibility: reads from bootstrap context. pub fn spawn_frontend( name: &str, state_rx: watch::Receiver, @@ -189,11 +177,6 @@ pub fn spawn_frontend( listen_addr: SocketAddr, context: Arc, ) -> DynResult> { - let key = normalize_name(name); - let reg = registry().lock().expect("frontend registry mutex poisoned"); - let spawner = reg - .spawners - .get(&key) - .ok_or_else(|| format!("Unknown frontend: {}", name))?; - Ok(spawner(state_rx, rig_tx, callsign, listen_addr, context)) + let ctx = bootstrap_context().lock().expect("frontend context mutex poisoned"); + ctx.spawn_frontend(name, state_rx, rig_tx, callsign, listen_addr, context) }