fix build
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
f7e2938e6b
commit
5c42b4a1e8
@ -1398,7 +1398,7 @@ pub fn send_url_scheme(_url: String) {
|
|||||||
pub fn plugin_event(id: String, event: Vec<u8>) {
|
pub fn plugin_event(id: String, event: Vec<u8>) {
|
||||||
#[cfg(feature = "plugin_framework")]
|
#[cfg(feature = "plugin_framework")]
|
||||||
{
|
{
|
||||||
crate::plugin::handle_ui_event(&id, &event);
|
allow_err!(crate::plugin::handle_ui_event(&id, &event));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,11 @@ use super::cstr_to_string;
|
|||||||
use crate::flutter::{self, APP_TYPE_CM, APP_TYPE_MAIN, SESSIONS};
|
use crate::flutter::{self, APP_TYPE_CM, APP_TYPE_MAIN, SESSIONS};
|
||||||
use hbb_common::{lazy_static, log, message_proto::PluginRequest};
|
use hbb_common::{lazy_static, log, message_proto::PluginRequest};
|
||||||
use serde_json;
|
use serde_json;
|
||||||
use std::{collections::HashMap, ffi::c_char, sync::Arc};
|
use std::{
|
||||||
|
collections::HashMap,
|
||||||
|
ffi::{c_char, c_void},
|
||||||
|
sync::Arc,
|
||||||
|
};
|
||||||
|
|
||||||
const MSG_TO_PEER_TARGET: &str = "peer";
|
const MSG_TO_PEER_TARGET: &str = "peer";
|
||||||
const MSG_TO_UI_TARGET: &str = "ui";
|
const MSG_TO_UI_TARGET: &str = "ui";
|
||||||
@ -42,7 +46,7 @@ pub fn callback_msg(
|
|||||||
peer: *const c_char,
|
peer: *const c_char,
|
||||||
target: *const c_char,
|
target: *const c_char,
|
||||||
id: *const c_char,
|
id: *const c_char,
|
||||||
content: *const c_char,
|
content: *const c_void,
|
||||||
len: usize,
|
len: usize,
|
||||||
) {
|
) {
|
||||||
macro_rules! callback_msg_field {
|
macro_rules! callback_msg_field {
|
||||||
@ -66,12 +70,12 @@ pub fn callback_msg(
|
|||||||
let content_slice =
|
let content_slice =
|
||||||
unsafe { std::slice::from_raw_parts(content as *const u8, len) };
|
unsafe { std::slice::from_raw_parts(content as *const u8, len) };
|
||||||
let content_vec = Vec::from(content_slice);
|
let content_vec = Vec::from(content_slice);
|
||||||
let plugin = PluginRequest {
|
let request = PluginRequest {
|
||||||
id,
|
id,
|
||||||
content: bytes::Bytes::from(content_vec),
|
content: bytes::Bytes::from(content_vec),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
session.send_plugin(plugin);
|
session.send_plugin_request(request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MSG_TO_UI_TARGET => {
|
MSG_TO_UI_TARGET => {
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
pub const ERR_SUCCESS: i32 = 0;
|
pub const ERR_SUCCESS: i32 = 0;
|
||||||
|
|
||||||
// ======================================================
|
// ======================================================
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
use hbb_common::ResultType;
|
use hbb_common::ResultType;
|
||||||
use std::ffi::{c_char, CStr};
|
use std::ffi::{c_char, c_void, CStr};
|
||||||
|
|
||||||
mod callback_msg;
|
mod callback_msg;
|
||||||
mod config;
|
mod config;
|
||||||
pub mod desc;
|
pub mod desc;
|
||||||
mod plugins;
|
|
||||||
mod errno;
|
mod errno;
|
||||||
|
mod plugins;
|
||||||
|
|
||||||
pub use plugins::{
|
pub use plugins::{
|
||||||
handle_client_event, handle_ui_event, load_plugin, load_plugins, reload_plugin, unload_plugin,
|
handle_client_event, handle_server_event, handle_ui_event, load_plugin, load_plugins,
|
||||||
|
reload_plugin, unload_plugin,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -27,5 +28,5 @@ fn get_code_msg_from_ret(ret: *const c_void) -> (i32, String) {
|
|||||||
.to_str()
|
.to_str()
|
||||||
.unwrap_or("")
|
.unwrap_or("")
|
||||||
.to_string();
|
.to_string();
|
||||||
Ok((code, msg))
|
(code, msg)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
ffi::c_char,
|
ffi::{c_char, c_void},
|
||||||
path::Path,
|
path::Path,
|
||||||
sync::{Arc, RwLock},
|
sync::{Arc, RwLock},
|
||||||
};
|
};
|
||||||
@ -176,13 +176,13 @@ pub fn load_plugin(path: &str) -> ResultType<()> {
|
|||||||
fn handle_event(method: &[u8], id: &str, event: &[u8]) -> ResultType<()> {
|
fn handle_event(method: &[u8], id: &str, event: &[u8]) -> ResultType<()> {
|
||||||
match PLUGINS.read().unwrap().get(id) {
|
match PLUGINS.read().unwrap().get(id) {
|
||||||
Some(plugin) => {
|
Some(plugin) => {
|
||||||
let ret = (plugin.fn_call)(method.as_ptr() as _, event.as_ptr(), event.len());
|
let ret = (plugin.fn_call)(method.as_ptr() as _, event.as_ptr() as _, event.len());
|
||||||
if ret.is_null() {
|
if ret.is_null() {
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
let (code, msg) = get_code_msg_from_ret(ret);
|
let (code, msg) = get_code_msg_from_ret(ret);
|
||||||
unsafe {
|
unsafe {
|
||||||
libc::free(ret);
|
libc::free(ret as _);
|
||||||
}
|
}
|
||||||
bail!(
|
bail!(
|
||||||
"Failed to handle plugin event, id: {}, method: {}, code: {}, msg: {}",
|
"Failed to handle plugin event, id: {}, method: {}, code: {}, msg: {}",
|
||||||
@ -213,7 +213,7 @@ pub fn handle_client_event(id: &str, event: &[u8]) -> Option<Message> {
|
|||||||
Some(plugin) => {
|
Some(plugin) => {
|
||||||
let ret = (plugin.fn_call)(
|
let ret = (plugin.fn_call)(
|
||||||
METHOD_HANDLE_PEER.as_ptr() as _,
|
METHOD_HANDLE_PEER.as_ptr() as _,
|
||||||
event.as_ptr(),
|
event.as_ptr() as _,
|
||||||
event.len(),
|
event.len(),
|
||||||
);
|
);
|
||||||
if ret.is_null() {
|
if ret.is_null() {
|
||||||
@ -221,13 +221,10 @@ pub fn handle_client_event(id: &str, event: &[u8]) -> Option<Message> {
|
|||||||
} else {
|
} else {
|
||||||
let (code, msg) = get_code_msg_from_ret(ret);
|
let (code, msg) = get_code_msg_from_ret(ret);
|
||||||
unsafe {
|
unsafe {
|
||||||
libc::free(ret);
|
libc::free(ret as _);
|
||||||
}
|
}
|
||||||
if code > ERR_RUSTDESK_HANDLE_BASE && code < ERR_PLUGIN_HANDLE_BASE {
|
if code > ERR_RUSTDESK_HANDLE_BASE && code < ERR_PLUGIN_HANDLE_BASE {
|
||||||
let name = match PLUGINS.read().unwrap().get(id) {
|
let name = plugin.desc.as_ref().unwrap().name();
|
||||||
Some(plugin) => plugin.desc.as_ref().unwrap().name(),
|
|
||||||
None => "",
|
|
||||||
};
|
|
||||||
match code {
|
match code {
|
||||||
ERR_CALL_NOT_SUPPORTED_METHOD => Some(make_plugin_response(
|
ERR_CALL_NOT_SUPPORTED_METHOD => Some(make_plugin_response(
|
||||||
id,
|
id,
|
||||||
|
@ -1813,7 +1813,7 @@ impl Connection {
|
|||||||
#[cfg(all(feature = "flutter", feature = "plugin_framework"))]
|
#[cfg(all(feature = "flutter", feature = "plugin_framework"))]
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
Some(misc::Union::PluginRequest(p)) => {
|
Some(misc::Union::PluginRequest(p)) => {
|
||||||
if let Some(msg) = create::plugin::handle_client_event(&p.id, &p.content) {
|
if let Some(msg) = crate::plugin::handle_client_event(&p.id, &p.content) {
|
||||||
self.send(msg).await;
|
self.send(msg).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -246,9 +246,9 @@ impl<T: InvokeUiSession> Session<T> {
|
|||||||
|
|
||||||
#[cfg(all(feature = "flutter", feature = "plugin_framework"))]
|
#[cfg(all(feature = "flutter", feature = "plugin_framework"))]
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
pub fn send_plugin(&self, plugin: Plugin) {
|
pub fn send_plugin_request(&self, request: PluginRequest) {
|
||||||
let mut misc = Misc::new();
|
let mut misc = Misc::new();
|
||||||
misc.set_plugin(plugin);
|
misc.set_plugin_request(request);
|
||||||
let mut msg_out = Message::new();
|
let mut msg_out = Message::new();
|
||||||
msg_out.set_misc(misc);
|
msg_out.set_misc(misc);
|
||||||
self.send(Data::Message(msg_out));
|
self.send(Data::Message(msg_out));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user