Skip to content

Commit

Permalink
examples: kill plugins examples
Browse files Browse the repository at this point in the history
Signed-off-by: Vincenzo Palazzo <[email protected]>
  • Loading branch information
vincenzopalazzo committed Feb 14, 2024
1 parent 0e8f3d9 commit 753f4ee
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
12 changes: 6 additions & 6 deletions plugin/examples/foo_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ impl RPCCommand<PluginState> for HelloRPC {
}

#[derive(Clone)]
struct OnChannelOpened {}
struct OnShutdown {}

impl RPCCommand<PluginState> for OnChannelOpened {
fn call_void<'c>(&self, _plugin: &mut Plugin<PluginState>, _request: &'c Value) {
_plugin.log(LogLevel::Debug, "A new channel was opened!");
impl RPCCommand<PluginState> for OnShutdown {
fn call_void<'c>(&self, _: &mut Plugin<PluginState>, _: &'c Value) {
std::process::exit(0);
}
}

Expand All @@ -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!({})
Expand Down
7 changes: 7 additions & 0 deletions plugin_macros/examples/macros_ex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,19 @@ fn on_warning(plugin: &mut Plugin<State>, request: &Value) {
plugin.log(LogLevel::Info, "received an RPC notification");
}

#[notification(on = "shutdown")]
fn on_shutdown(_: &mut Plugin<State>, _: &Value) {
std::process::exit(0);
}


fn main() {
let plugin = plugin! {
state: State::new(),
dynamic: true,
notification: [
on_warning,
on_shutdown,
],
methods: [
foo_rpc,
Expand Down

0 comments on commit 753f4ee

Please sign in to comment.