[feat](trx-backend): add register_builtin_backends_on for context initialization

Add register_builtin_backends_on(context: &mut RegistrationContext) function
to allow explicit backend registration on a context instead of always using globals.

This enables proper initialization sequencing where backends are registered
on a specific context that can be passed through bootstrap.

The global register_builtin_backends() still works for plugin compatibility,
delegating to the new context-based approach.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Signed-off-by: Stanislaw Grams <stanislawgrams@gmail.com>
This commit is contained in:
2026-02-12 20:49:37 +01:00
parent d8e9397cf6
commit 0a8a98ea54
2 changed files with 22 additions and 2 deletions
+12 -1
View File
@@ -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();
+10 -1
View File
@@ -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")]