diff --git a/src/plugin/api.rs b/src/plugin/api.rs deleted file mode 100644 index 744032e88..000000000 --- a/src/plugin/api.rs +++ /dev/null @@ -1,14 +0,0 @@ -use std::ffi::{c_char}; - -use lazy_static::lazy_static; - -use crate::{ - flutter::{FlutterHandler, SESSIONS}, - plugins::PLUGIN_REGISTRAR, - ui_session_interface::Session, -}; - -pub trait Callable { - // Call - fn onCall(method_name: String) -> bool; -} \ No newline at end of file diff --git a/src/plugin/mod.rs b/src/plugin/mod.rs index 09d0c63cb..dea7dbd2d 100644 --- a/src/plugin/mod.rs +++ b/src/plugin/mod.rs @@ -8,7 +8,8 @@ mod errno; pub mod ipc; mod plog; mod plugins; -pub mod api; +pub mod native; +mod native_handlers; pub use plugins::{ handle_client_event, handle_listen_event, handle_server_event, handle_ui_event, load_plugin, diff --git a/src/plugin/native.rs b/src/plugin/native.rs new file mode 100644 index 000000000..dad61099e --- /dev/null +++ b/src/plugin/native.rs @@ -0,0 +1,16 @@ +use std::{ffi::{c_char, c_void}, os::raw::c_uint}; + +/// The native returned value from librustdesk native. +/// +/// [Note] +/// The data is owned by librustdesk. +#[repr(C)] +pub struct NativeReturnValue{ + return_type: c_uint, + data: *const c_void +} + +pub(super) extern "C" fn cb_native_data(method: *const c_char, json: *const c_char, raw: *const c_void, raw_len: usize) -> NativeReturnValue { + // TODO: cb for native data. + return NativeReturnValue { return_type: 0, data: std::ptr::null() }; +} \ No newline at end of file diff --git a/src/plugin/native_handlers/mod.rs b/src/plugin/native_handlers/mod.rs new file mode 100644 index 000000000..9f7011cb2 --- /dev/null +++ b/src/plugin/native_handlers/mod.rs @@ -0,0 +1,24 @@ +use std::ffi::{c_void, c_ulonglong, c_ulong}; + +use serde_json::Map; + +pub mod session; + +pub type NR = super::native::NativeReturnValue; +pub type PluginNativeHandlerRegistrar = NativeHandlerRegistrar; + +pub struct NativeHandlerRegistrar{ + handlers: Vec +} + +pub(crate) trait PluginNativeHandler { + /// Try to handle the method with the given data. + /// + /// Returns: None for the message does not be handled by this handler. + fn on_message(method: &String, data: &Map) -> Option; + + /// Try to handle the method with the given data and extra void binary data. + /// + /// Returns: None for the message does not be handled by this handler. + fn on_message_raw(method: &String, data: &Map, raw: *const c_void, raw_len: usize) -> Option; +} \ No newline at end of file diff --git a/src/plugin/native_handlers/session.rs b/src/plugin/native_handlers/session.rs new file mode 100644 index 000000000..f8e8baa67 --- /dev/null +++ b/src/plugin/native_handlers/session.rs @@ -0,0 +1,28 @@ +use super::PluginNativeHandler; + + +/// Session related handler for librustdesk core. +pub struct PluginNativeSessionHandler; + + +impl PluginNativeHandler for PluginNativeSessionHandler { + fn on_message(method: &String, data: &serde_json::Map) -> Option { + None + } + + fn on_message_raw(method: &String, data: &serde_json::Map, raw: *const std::ffi::c_void, raw_len: usize) -> Option { + None + } + +} + +impl PluginNativeSessionHandler { + fn create_session() { + + } + + + fn add_session_hook() { + + } +} \ No newline at end of file diff --git a/src/plugin/plugins.rs b/src/plugin/plugins.rs index a17f24980..4441d314d 100644 --- a/src/plugin/plugins.rs +++ b/src/plugin/plugins.rs @@ -14,7 +14,7 @@ use std::{ collections::HashMap, ffi::{c_char, c_void}, path::PathBuf, - sync::{Arc, RwLock}, + sync::{Arc, RwLock}, os::raw::c_uint, }; const METHOD_HANDLE_UI: &[u8; 10] = b"handle_ui\0"; @@ -91,6 +91,14 @@ type CallbackGetId = extern "C" fn() -> *const c_char; /// level: "error", "warn", "info", "debug", "trace". /// msg: The message. type CallbackLog = extern "C" fn(level: *const c_char, msg: *const c_char); + +/// Callback to the librustdesk core. +/// +/// method: the method name of this callback. +/// json: the json data for the parameters. The argument *must* be non-null. +/// raw: the binary data for this call, nullable. +/// raw_len: the length of this binary data, only valid when we pass raw data to `raw`. +type CallbackNative = extern "C" fn(method: *const c_char, json: *const c_char, raw: *const c_void, raw_len: usize) -> super::native::NativeReturnValue; /// The main function of the plugin on the client(self) side. /// /// method: The method. "handle_ui" or "handle_peer" @@ -140,6 +148,7 @@ struct Callbacks { get_conf: CallbackGetConf, get_id: CallbackGetId, log: CallbackLog, + native: CallbackNative } /// The plugin initialize data. @@ -334,6 +343,7 @@ fn load_plugin_path(path: &str) -> ResultType<()> { get_conf: config::cb_get_conf, get_id: config::cb_get_local_peer_id, log: super::plog::plugin_log, + native: super::native::cb_native_data }, }; plugin.init(&init_data, path)?;