diff --git a/src/plugins.rs b/src/plugins.rs index 4e44a2643..9ca2ad8f0 100644 --- a/src/plugins.rs +++ b/src/plugins.rs @@ -4,7 +4,10 @@ use std::{ sync::{Arc, RwLock}, }; -use hbb_common::{anyhow::Error, log::debug}; +use hbb_common::{ + anyhow::Error, + log::{debug, error}, +}; use lazy_static::lazy_static; use libloading::{Library, Symbol}; @@ -82,6 +85,18 @@ impl PluginRegistar

{ match lib { Ok(lib) => match lib.try_into() { Ok(plugin) => { + let plugin: PluginImpl = plugin; + // try to initialize this plugin + if let Some(init) = plugin.plugin_vt().init { + let init_ret = init(); + if init_ret != 0 { + error!( + "Error when initializing the plugin {} with error code {}.", + plugin.name, init_ret + ); + return init_ret; + } + } PLUGIN_REGISTRAR .plugins .write() @@ -104,7 +119,12 @@ impl PluginRegistar

{ let p = unsafe { CStr::from_ptr(path) }; let lib_path = p.to_str().unwrap_or("").to_owned(); match PLUGIN_REGISTRAR.plugins.write().unwrap().remove(&lib_path) { - Some(_) => 0, + Some(plugin) => { + if let Some(dispose) = plugin.plugin_vt().dispose { + return dispose(); + } + 0 + } None => -1, } }