[refactor](trx-rs): inject runtime contexts for io paths

Phase 3: replace frontend/backend hot-path globals with explicit runtime/registration context wiring while keeping plugin compatibility adapters.

Co-authored-by: Codex <codex@openai.com>,
Signed-off-by: Stanislaw Grams <stanislawgrams@gmail.com>
This commit is contained in:
2026-02-12 21:18:42 +01:00
parent 410fc89185
commit b7fb9adef7
12 changed files with 220 additions and 236 deletions
+16
View File
@@ -25,6 +25,7 @@ pub enum RigAccess {
pub type BackendFactory = fn(RigAccess) -> DynResult<Box<dyn RigCat>>;
/// Context for registering and instantiating rig backends.
#[derive(Clone)]
pub struct RegistrationContext {
factories: HashMap<String, BackendFactory>,
}
@@ -65,6 +66,13 @@ impl RegistrationContext {
.ok_or_else(|| format!("Unknown rig backend: {}", name))?;
factory(access)
}
/// Merge another registration context into this one.
pub fn extend_from(&mut self, other: &RegistrationContext) {
for (name, factory) in &other.factories {
self.factories.insert(name.clone(), *factory);
}
}
}
impl Default for RegistrationContext {
@@ -86,6 +94,14 @@ fn bootstrap_context() -> &'static Arc<Mutex<RegistrationContext>> {
BOOTSTRAP_CONTEXT.get_or_init(|| Arc::new(Mutex::new(RegistrationContext::new())))
}
/// Snapshot current plugin/bootstrap registrations into an owned context.
pub fn snapshot_bootstrap_context() -> RegistrationContext {
let ctx = bootstrap_context()
.lock()
.expect("backend context mutex poisoned");
ctx.clone()
}
/// Register a backend factory under a stable name (e.g. "ft817").
/// Plugin compatibility: delegates to bootstrap context.
pub fn register_backend(name: &str, factory: BackendFactory) {