pub use atri_ffi::plugin::PluginInstance;
use atri_ffi::plugin::PluginVTable;
use atri_ffi::RustStr;
pub trait Plugin
where
Self: Sized,
{
fn new() -> Self;
fn enable(&mut self);
fn disable(&mut self) {
}
fn should_drop() -> bool {
true
}
}
#[doc(hidden)]
pub fn __get_instance<P: Plugin>(name: &str) -> PluginInstance {
extern "C" fn _new<P: Plugin>() -> *mut () {
let b = Box::new(P::new());
Box::into_raw(b) as *mut ()
}
extern "C" fn _enable<P: Plugin>(ptr: *mut ()) {
let p = unsafe { &mut *(ptr as *mut P) };
p.enable();
}
extern "C" fn _disable<P: Plugin>(ptr: *mut ()) {
let p = unsafe { &mut *(ptr as *mut P) };
p.disable();
}
extern "C" fn _drop<T>(ptr: *mut ()) {
drop(unsafe { Box::from_raw(ptr.cast::<T>()) })
}
let should_drop = P::should_drop();
let vtb = PluginVTable {
new: _new::<P>,
enable: _enable::<P>,
disable: _disable::<P>,
drop: _drop::<P>,
};
PluginInstance {
should_drop,
vtb,
abi_ver: atri_ffi::plugin::abi_version(),
name: RustStr::from(name),
}
}