registry: add backend/frontend registries and plugin loader
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
# SPDX-FileCopyrightText: 2025 Stanislaw Grams <stanislawgrams@gmail.com>
|
||||
#
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
|
||||
[package]
|
||||
name = "trx-plugin-example"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
trx-backend = { path = "../../src/trx-backend" }
|
||||
trx-core = { path = "../../src/trx-core" }
|
||||
trx-frontend = { path = "../../src/trx-frontend" }
|
||||
tokio = { workspace = true, features = ["full"] }
|
||||
tracing = { workspace = true }
|
||||
@@ -0,0 +1,19 @@
|
||||
# trx-plugin-example
|
||||
|
||||
This is a minimal shared-library plugin that registers a backend and frontend.
|
||||
The backend is a stub that returns an error; the frontend is a no-op spawner.
|
||||
|
||||
Build:
|
||||
|
||||
```bash
|
||||
cargo build -p trx-plugin-example --release
|
||||
```
|
||||
|
||||
Install (example):
|
||||
|
||||
```bash
|
||||
mkdir -p plugins
|
||||
cp target/release/libtrx_plugin_example.* plugins/
|
||||
```
|
||||
|
||||
Run `trx-bin` with `TRX_PLUGIN_DIRS=./plugins` to discover the plugin.
|
||||
@@ -0,0 +1,42 @@
|
||||
// SPDX-FileCopyrightText: 2025 Stanislaw Grams <stanislawgrams@gmail.com>
|
||||
//
|
||||
// SPDX-License-Identifier: BSD-2-Clause
|
||||
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use tokio::sync::{mpsc, watch};
|
||||
use tokio::task::JoinHandle;
|
||||
use tracing::info;
|
||||
|
||||
use trx_backend::{register_backend, RigAccess};
|
||||
use trx_core::{DynResult, RigRequest, RigState};
|
||||
use trx_frontend::{register_frontend, FrontendSpawner};
|
||||
|
||||
const BACKEND_NAME: &str = "example";
|
||||
const FRONTEND_NAME: &str = "example-frontend";
|
||||
|
||||
/// Entry point called by trx-bin when the plugin is loaded.
|
||||
#[no_mangle]
|
||||
pub extern "C" fn trx_register() {
|
||||
register_backend(BACKEND_NAME, example_backend_factory);
|
||||
register_frontend(FRONTEND_NAME, ExampleFrontend::spawn_frontend);
|
||||
}
|
||||
|
||||
fn example_backend_factory(_access: RigAccess) -> DynResult<Box<dyn trx_core::rig::RigCat>> {
|
||||
Err("example plugin backend not implemented".into())
|
||||
}
|
||||
|
||||
struct ExampleFrontend;
|
||||
|
||||
impl FrontendSpawner for ExampleFrontend {
|
||||
fn spawn_frontend(
|
||||
_state_rx: watch::Receiver<RigState>,
|
||||
_rig_tx: mpsc::Sender<RigRequest>,
|
||||
_callsign: Option<String>,
|
||||
listen_addr: SocketAddr,
|
||||
) -> JoinHandle<()> {
|
||||
tokio::spawn(async move {
|
||||
info!("example frontend loaded at {} (no-op)", listen_addr);
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user