From 753f4eea2ba88efb1f93445a45a98fc24b060d22 Mon Sep 17 00:00:00 2001 From: Vincenzo Palazzo Date: Wed, 14 Feb 2024 13:08:50 +0100 Subject: [PATCH] examples: kill plugins examples Signed-off-by: Vincenzo Palazzo --- plugin/examples/foo_plugin.rs | 12 ++++++------ plugin_macros/examples/macros_ex.rs | 7 +++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/plugin/examples/foo_plugin.rs b/plugin/examples/foo_plugin.rs index 536a9e4..c178fc1 100644 --- a/plugin/examples/foo_plugin.rs +++ b/plugin/examples/foo_plugin.rs @@ -27,11 +27,11 @@ impl RPCCommand for HelloRPC { } #[derive(Clone)] -struct OnChannelOpened {} +struct OnShutdown {} -impl RPCCommand for OnChannelOpened { - fn call_void<'c>(&self, _plugin: &mut Plugin, _request: &'c Value) { - _plugin.log(LogLevel::Debug, "A new channel was opened!"); +impl RPCCommand for OnShutdown { + fn call_void<'c>(&self, _: &mut Plugin, _: &'c Value) { + std::process::exit(0); } } @@ -46,11 +46,11 @@ fn main() { .add_opt( "foo", "flag", - Some("false".to_owned()), + Some("false".to_owned()) , "An example of command line option", false, ) - .register_notification("channel_opened", OnChannelOpened {}) + .register_notification("shutdown", OnShutdown {}) .on_init(|plugin: &mut Plugin<_>| -> serde_json::Value { plugin.log(LogLevel::Debug, "Custom init method called"); json!({}) diff --git a/plugin_macros/examples/macros_ex.rs b/plugin_macros/examples/macros_ex.rs index f29dcb4..0c355f7 100644 --- a/plugin_macros/examples/macros_ex.rs +++ b/plugin_macros/examples/macros_ex.rs @@ -35,12 +35,19 @@ fn on_warning(plugin: &mut Plugin, request: &Value) { plugin.log(LogLevel::Info, "received an RPC notification"); } +#[notification(on = "shutdown")] +fn on_shutdown(_: &mut Plugin, _: &Value) { + std::process::exit(0); +} + + fn main() { let plugin = plugin! { state: State::new(), dynamic: true, notification: [ on_warning, + on_shutdown, ], methods: [ foo_rpc,