diff --git a/src/api.rs b/src/api.rs new file mode 100644 index 000000000..d62dc4d65 --- /dev/null +++ b/src/api.rs @@ -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, + } + } +} diff --git a/src/lib.rs b/src/lib.rs index 5dcd6389c..af9f773ce 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -43,6 +43,11 @@ mod license; #[cfg(not(any(target_os = "android", target_os = "ios")))] 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 ui_cm_interface; diff --git a/src/plugins.rs b/src/plugins.rs new file mode 100644 index 000000000..bca77f8cc --- /dev/null +++ b/src/plugins.rs @@ -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> = + Arc::new(PluginRegistar::::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 { + plugins: HashMap, +} + +impl PluginRegistar

{ + 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 { + Err(anyhow!("Not implemented yet.")) + } +}