- All crates: rust-version = 1.70, license = MIT - Root + example-plugin: publish = false (not intended for crates.io) - plugin-sdk: proper description for potential future publication
ShowenV2 Plugin SDK
插件开发者使用此 SDK 编写动态插件(.so 文件),运行时由主程序动态加载。
核心接口
ShowenPlugintrait: 插件作者实现的高级接口(init / start / handle_message / stop)MessageSender: 封装 FFI SendCallback,插件通过它向主程序发送消息export_plugin!宏: 自动生成extern "C"胶水代码,导出PluginVTable
类型
SDK 独立定义了与主程序 JSON 兼容的消息类型:
PluginInfo,Envelope,Destination,Message
用法
use showen_plugin_sdk::{export_plugin, ShowenPlugin, MessageSender, PluginInfo, Message};
struct MyPlugin { sender: Option<MessageSender> }
impl ShowenPlugin for MyPlugin {
fn info(&self) -> PluginInfo { /* ... */ }
fn init(&mut self, config_json: &str, sender: MessageSender) -> Result<(), String> { Ok(()) }
fn start(&mut self) -> Result<(), String> { Ok(()) }
fn handle_message(&mut self, msg_json: &str) -> Result<(), String> { Ok(()) }
fn stop(&mut self) -> Result<(), String> { Ok(()) }
}
export_plugin!(MyPlugin, MyPlugin::new);
编译
cd plugin-sdk
cargo build
插件项目在 Cargo.toml 中依赖此 SDK:
[dependencies]
showen-plugin-sdk = { path = "../plugin-sdk" }