diff --git a/bin/darkwallet/src/main.rs b/bin/darkwallet/src/main.rs index 1e5a7a38b..5d88b9806 100644 --- a/bin/darkwallet/src/main.rs +++ b/bin/darkwallet/src/main.rs @@ -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); } diff --git a/bin/darkwallet/src/plugin.rs b/bin/darkwallet/src/plugin.rs new file mode 100644 index 000000000..be7232a7c --- /dev/null +++ b/bin/darkwallet/src/plugin.rs @@ -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, Vec)), +} + +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) -> Result<()> { + // Create /plugin/foo + // Add a method called start() + Ok(()) + } + + fn start_plugin(&mut self, plugin_name: &str) -> Result { + // 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) + } +} +