add: initial plugin manager
This commit is contained in:
parent
400edabf5f
commit
0c049c585e
31
src/api.rs
Normal file
31
src/api.rs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
use std::{ffi::CStr, os::raw::c_char};
|
||||||
|
|
||||||
|
use crate::plugins::PLUGIN_REGISTRAR;
|
||||||
|
|
||||||
|
pub type LoadPluginFunc = fn(*const i8) -> i32;
|
||||||
|
pub type UnloadPluginFunc = fn(*const i8) -> i32;
|
||||||
|
|
||||||
|
pub struct RustDeskApiTable {
|
||||||
|
pub register_plugin: LoadPluginFunc,
|
||||||
|
pub unload_plugin: UnloadPluginFunc,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
fn load_plugin(path: *const i8) -> i32 {
|
||||||
|
PLUGIN_REGISTRAR.load_plugin(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
fn unload_plugin(path: *const i8) -> i32 {
|
||||||
|
PLUGIN_REGISTRAR.unload_plugin(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for RustDeskApiTable {
|
||||||
|
fn default() -> Self {
|
||||||
|
let f = load_plugin;
|
||||||
|
Self {
|
||||||
|
register_plugin: load_plugin,
|
||||||
|
unload_plugin: unload_plugin,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -43,6 +43,11 @@ mod license;
|
|||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
mod port_forward;
|
mod port_forward;
|
||||||
|
|
||||||
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
|
mod plugins;
|
||||||
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
|
mod api;
|
||||||
|
|
||||||
mod tray;
|
mod tray;
|
||||||
|
|
||||||
mod ui_cm_interface;
|
mod ui_cm_interface;
|
||||||
|
57
src/plugins.rs
Normal file
57
src/plugins.rs
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
use std::{collections::HashMap, path::Path, sync::Arc, ffi::CStr};
|
||||||
|
|
||||||
|
use hbb_common::anyhow::{anyhow, Error};
|
||||||
|
use lazy_static::lazy_static;
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
pub static ref PLUGIN_REGISTRAR: Arc<PluginRegistar<PluginImpl>> =
|
||||||
|
Arc::new(PluginRegistar::<PluginImpl>::default());
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait Plugin {
|
||||||
|
// Return: the unique ID which identifies this plugin.
|
||||||
|
fn plugin_id(&self) -> String;
|
||||||
|
// Return: the name which is human-readable.
|
||||||
|
fn plugin_name(&self) -> String;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default, Clone)]
|
||||||
|
pub struct PluginImpl {
|
||||||
|
id: String,
|
||||||
|
name: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Plugin for PluginImpl {
|
||||||
|
fn plugin_id(&self) -> String {
|
||||||
|
self.id.to_owned()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn plugin_name(&self) -> String {
|
||||||
|
self.name.to_owned()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default, Clone)]
|
||||||
|
pub struct PluginRegistar<P: Plugin> {
|
||||||
|
plugins: HashMap<String, P>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<P: Plugin> PluginRegistar<P> {
|
||||||
|
pub fn load_plugin(&self, path: *const i8) -> i32 {
|
||||||
|
let p = unsafe { CStr::from_ptr(path) };
|
||||||
|
0
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn unload_plugin(&self, path: *const i8) -> i32 {
|
||||||
|
let p = unsafe { CStr::from_ptr(path) };
|
||||||
|
0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TryFrom<&Path> for PluginImpl {
|
||||||
|
type Error = Error;
|
||||||
|
|
||||||
|
fn try_from(value: &Path) -> Result<Self, Self::Error> {
|
||||||
|
Err(anyhow!("Not implemented yet."))
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user