diff --git a/src/trx-server/src/main.rs b/src/trx-server/src/main.rs index 8ece3e7..2dc579a 100644 --- a/src/trx-server/src/main.rs +++ b/src/trx-server/src/main.rs @@ -24,7 +24,10 @@ use tracing::{error, info}; use trx_core::audio::AudioStreamInfo; use trx_app::normalize_name; -use trx_backend::{is_backend_registered, register_builtin_backends, registered_backends, RigAccess}; +use trx_backend::{ + is_backend_registered, register_builtin_backends, register_builtin_backends_on, + registered_backends, RegistrationContext, RigAccess, +}; use trx_core::rig::controller::{AdaptivePolling, ExponentialBackoff}; use trx_core::rig::request::RigRequest; use trx_core::rig::state::RigState; @@ -209,6 +212,14 @@ fn build_rig_task_config( async fn main() -> DynResult<()> { tracing_subscriber::fmt().with_target(false).init(); + // Phase 3B: Create bootstrap context for explicit initialization. + // This replaces reliance on global mutable state, though currently + // built-in backends still register on globals for plugin compatibility. + // Full de-globalization would require threading context through rig_task and listener. + let mut bootstrap_ctx = RegistrationContext::new(); + register_builtin_backends_on(&mut bootstrap_ctx); + info!("Bootstrap context initialized with {} backends", bootstrap_ctx.registered_backends().len()); + register_builtin_backends(); let _plugin_libs = plugins::load_plugins(); diff --git a/src/trx-server/trx-backend/src/lib.rs b/src/trx-server/trx-backend/src/lib.rs index 5cb52a7..90508ce 100644 --- a/src/trx-server/trx-backend/src/lib.rs +++ b/src/trx-server/trx-backend/src/lib.rs @@ -105,7 +105,16 @@ pub fn register_backend(name: &str, factory: BackendFactory) { reg.factories.insert(key, factory); } -/// Register all built-in backends enabled by features. +/// Register all built-in backends enabled by features on a context. +pub fn register_builtin_backends_on(context: &mut RegistrationContext) { + context.register_backend("dummy", dummy_factory); + #[cfg(feature = "ft817")] + context.register_backend("ft817", ft817_factory); + #[cfg(feature = "ft450d")] + context.register_backend("ft450d", ft450d_factory); +} + +/// Register all built-in backends enabled by features (global, for plugin compatibility). pub fn register_builtin_backends() { register_backend("dummy", dummy_factory); #[cfg(feature = "ft817")]