Added PluginContext
This commit is contained in:
42
src/plugman/plugin/loader.rs
Normal file
42
src/plugman/plugin/loader.rs
Normal file
@@ -0,0 +1,42 @@
|
||||
use std::ffi::c_char;
|
||||
|
||||
use dlopen::raw::Library;
|
||||
|
||||
use super::{context::PluginContext, Plugin, PluginInfo};
|
||||
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct PluginSyms {
|
||||
pub(super) init: unsafe extern "C" fn(ctx: *const PluginContext),
|
||||
pub(super) pre_reload: unsafe extern "C" fn() -> *const (),
|
||||
pub(super) post_reload: unsafe extern "C" fn(state: *const ()),
|
||||
pub(super) poll: unsafe extern "C" fn(buf: *mut c_char, len: usize),
|
||||
pub(super) free: unsafe extern "C" fn(),
|
||||
pub(super) get_info: unsafe extern "C" fn() -> *const PluginInfo,
|
||||
}
|
||||
|
||||
impl Plugin {
|
||||
pub fn reload_symbols(&mut self) -> Result<(), dlopen::Error> {
|
||||
log::debug!("Loading {:?}", self.path);
|
||||
let lib = Library::open(&self.path)?;
|
||||
let symbols = PluginSyms {
|
||||
init: unsafe { lib.symbol("plug_init")? },
|
||||
pre_reload: unsafe { lib.symbol("plug_pre_reload")? },
|
||||
post_reload: unsafe { lib.symbol("plug_post_reload")? },
|
||||
poll: unsafe { lib.symbol("plug_poll")? },
|
||||
free: unsafe { lib.symbol("plug_free")? },
|
||||
|
||||
get_info: unsafe { lib.symbol("plug_get_info")? },
|
||||
};
|
||||
unsafe {
|
||||
if (symbols.get_info)().is_null() {
|
||||
log::error!("Info fields for plugin {:?} are null", self.path);
|
||||
self.disable();
|
||||
}
|
||||
}
|
||||
|
||||
self.syms = Some(symbols);
|
||||
self.lib = Some(lib);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user