feat: add native session handlers

This commit is contained in:
Kingtous
2023-04-27 23:37:13 +08:00
parent 4acc3052cc
commit 3774f8308f
6 changed files with 81 additions and 16 deletions

View File

@@ -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)?;