wallet: add stubs for plugin subsystem

This commit is contained in:
rsx
2024-05-18 10:30:19 +02:00
parent 1369300ba2
commit 28aaec3bba
2 changed files with 106 additions and 0 deletions

View File

@@ -18,6 +18,8 @@ use net::ZeroMQAdapter;
mod scene;
use scene::{SceneGraph, SceneGraphPtr};
mod plugin;
mod prop;
mod shader;
@@ -35,9 +37,19 @@ fn start_zmq(scene_graph: SceneGraphPtr) {
});
}
fn start_sentinel(scene_graph: SceneGraphPtr) {
// detach thread
// Sentinel should cleanly close when sent a stop signal.
let _ = thread::spawn(move || {
let mut sentinel = plugin::Sentinel::new(scene_graph);
sentinel.run();
});
}
fn main() {
let scene_graph = Arc::new(Mutex::new(SceneGraph::new()));
start_zmq(scene_graph.clone());
start_sentinel(scene_graph.clone());
run_gui(scene_graph);
}

View File

@@ -0,0 +1,94 @@
use crate::{
error::{Error, Result},
scene::{SceneGraph, SceneGraphPtr}
};
enum Category {
Null,
}
enum SubCategory {
Null,
}
struct SemVer {
pub major: u64,
pub minor: u64,
pub patch: u64,
pub pre: String,
pub build: String,
}
struct PluginMetadata {
pub name: String,
pub title: String,
pub desc: String,
pub author: String,
pub version: SemVer,
pub cat: Category,
pub subcat: SubCategory,
// icon
// Permissions
// whitelisted nodes + props/methods (use * for all)
// /window/input/*
}
enum PluginEvent {
// (signal_data, user_data)
RecvSignal((Vec<u8>, Vec<u8>)),
}
trait Plugin {
fn metadata(&self) -> PluginMetadata;
fn init(&mut self) -> Result<()>;
fn update(&mut self, event: PluginEvent) -> Result<()>;
}
type InstanceId = u32;
pub struct Sentinel {
scene_graph: SceneGraphPtr
}
impl Sentinel {
pub fn new(scene_graph: SceneGraphPtr) -> Self {
// Create /plugin in scene graph
//
// Methods provided in SceneGraph under /plugin:
//
// * import_plugin(pycode)
Self {
scene_graph
}
}
pub fn run(&mut self) {
// loop {
// Monitor all running plugins
// Check last update times
// Kill any slowpokes
// Check any SceneGraph method requests
// }
}
fn import_plugin(&mut self, plugin: Box<dyn Plugin>) -> Result<()> {
// Create /plugin/foo
// Add a method called start()
Ok(())
}
fn start_plugin(&mut self, plugin_name: &str) -> Result<InstanceId> {
// Lookup plugin by name
// Call init()
// Spawn a new thread, allocate it an ID
// Thread waits for events from the scene_graph and calls update() when they occur.
// See src/net.rs:81 for an example
Ok(0)
}
}