feat: add native session handlers
This commit is contained in:
parent
4acc3052cc
commit
3774f8308f
@ -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;
|
|
||||||
}
|
|
@ -8,7 +8,8 @@ mod errno;
|
|||||||
pub mod ipc;
|
pub mod ipc;
|
||||||
mod plog;
|
mod plog;
|
||||||
mod plugins;
|
mod plugins;
|
||||||
pub mod api;
|
pub mod native;
|
||||||
|
mod native_handlers;
|
||||||
|
|
||||||
pub use plugins::{
|
pub use plugins::{
|
||||||
handle_client_event, handle_listen_event, handle_server_event, handle_ui_event, load_plugin,
|
handle_client_event, handle_listen_event, handle_server_event, handle_ui_event, load_plugin,
|
||||||
|
16
src/plugin/native.rs
Normal file
16
src/plugin/native.rs
Normal file
@ -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() };
|
||||||
|
}
|
24
src/plugin/native_handlers/mod.rs
Normal file
24
src/plugin/native_handlers/mod.rs
Normal file
@ -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<dyn PluginNativeHandler>;
|
||||||
|
|
||||||
|
pub struct NativeHandlerRegistrar<H>{
|
||||||
|
handlers: Vec<H>
|
||||||
|
}
|
||||||
|
|
||||||
|
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<String, serde_json::Value>) -> Option<NR>;
|
||||||
|
|
||||||
|
/// 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<String, serde_json::Value>, raw: *const c_void, raw_len: usize) -> Option<NR>;
|
||||||
|
}
|
28
src/plugin/native_handlers/session.rs
Normal file
28
src/plugin/native_handlers/session.rs
Normal file
@ -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<String, serde_json::Value>) -> Option<super::NR> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
fn on_message_raw(method: &String, data: &serde_json::Map<String, serde_json::Value>, raw: *const std::ffi::c_void, raw_len: usize) -> Option<super::NR> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PluginNativeSessionHandler {
|
||||||
|
fn create_session() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn add_session_hook() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -14,7 +14,7 @@ use std::{
|
|||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
ffi::{c_char, c_void},
|
ffi::{c_char, c_void},
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
sync::{Arc, RwLock},
|
sync::{Arc, RwLock}, os::raw::c_uint,
|
||||||
};
|
};
|
||||||
|
|
||||||
const METHOD_HANDLE_UI: &[u8; 10] = b"handle_ui\0";
|
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".
|
/// level: "error", "warn", "info", "debug", "trace".
|
||||||
/// msg: The message.
|
/// msg: The message.
|
||||||
type CallbackLog = extern "C" fn(level: *const c_char, msg: *const c_char);
|
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.
|
/// The main function of the plugin on the client(self) side.
|
||||||
///
|
///
|
||||||
/// method: The method. "handle_ui" or "handle_peer"
|
/// method: The method. "handle_ui" or "handle_peer"
|
||||||
@ -140,6 +148,7 @@ struct Callbacks {
|
|||||||
get_conf: CallbackGetConf,
|
get_conf: CallbackGetConf,
|
||||||
get_id: CallbackGetId,
|
get_id: CallbackGetId,
|
||||||
log: CallbackLog,
|
log: CallbackLog,
|
||||||
|
native: CallbackNative
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The plugin initialize data.
|
/// The plugin initialize data.
|
||||||
@ -334,6 +343,7 @@ fn load_plugin_path(path: &str) -> ResultType<()> {
|
|||||||
get_conf: config::cb_get_conf,
|
get_conf: config::cb_get_conf,
|
||||||
get_id: config::cb_get_local_peer_id,
|
get_id: config::cb_get_local_peer_id,
|
||||||
log: super::plog::plugin_log,
|
log: super::plog::plugin_log,
|
||||||
|
native: super::native::cb_native_data
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
plugin.init(&init_data, path)?;
|
plugin.init(&init_data, path)?;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user