2023-04-19 11:21:37 +08:00
|
|
|
use hbb_common::ResultType;
|
2023-04-19 17:26:36 +08:00
|
|
|
use std::ffi::{c_char, c_void, CStr};
|
2023-04-18 23:02:37 +08:00
|
|
|
|
|
|
|
mod callback_msg;
|
|
|
|
mod config;
|
|
|
|
pub mod desc;
|
2023-04-19 17:06:59 +08:00
|
|
|
mod errno;
|
2023-04-23 15:40:55 +08:00
|
|
|
pub mod ipc;
|
2023-04-19 17:26:36 +08:00
|
|
|
mod plugins;
|
2023-04-18 23:02:37 +08:00
|
|
|
|
2023-04-19 17:06:59 +08:00
|
|
|
pub use plugins::{
|
2023-04-19 17:26:36 +08:00
|
|
|
handle_client_event, handle_server_event, handle_ui_event, load_plugin, load_plugins,
|
2023-04-23 15:40:55 +08:00
|
|
|
reload_plugin, sync_ui, unload_plugin, unload_plugins,
|
2023-04-19 17:06:59 +08:00
|
|
|
};
|
2023-04-18 23:02:37 +08:00
|
|
|
|
2023-04-21 21:40:34 +08:00
|
|
|
const MSG_TO_UI_TYPE_PLUGIN_DESC: &str = "plugin_desc";
|
|
|
|
const MSG_TO_UI_TYPE_PLUGIN_EVENT: &str = "plugin_event";
|
|
|
|
const MSG_TO_UI_TYPE_PLUGIN_RELOAD: &str = "plugin_reload";
|
|
|
|
const MSG_TO_UI_TYPE_PLUGIN_OPTION: &str = "plugin_option";
|
|
|
|
|
2023-04-23 15:40:55 +08:00
|
|
|
pub use config::{ManagerConfig, PeerConfig, SharedConfig};
|
2023-04-20 20:57:47 +08:00
|
|
|
|
2023-04-18 23:02:37 +08:00
|
|
|
#[inline]
|
|
|
|
fn cstr_to_string(cstr: *const c_char) -> ResultType<String> {
|
|
|
|
Ok(String::from_utf8(unsafe {
|
|
|
|
CStr::from_ptr(cstr).to_bytes().to_vec()
|
|
|
|
})?)
|
|
|
|
}
|
2023-04-19 17:06:59 +08:00
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn get_code_msg_from_ret(ret: *const c_void) -> (i32, String) {
|
|
|
|
assert!(ret.is_null() == false);
|
|
|
|
let code_bytes = unsafe { std::slice::from_raw_parts(ret as *const u8, 4) };
|
|
|
|
let code = i32::from_le_bytes([code_bytes[0], code_bytes[1], code_bytes[2], code_bytes[3]]);
|
|
|
|
let msg = unsafe { CStr::from_ptr((ret as *const u8).add(4) as _) }
|
|
|
|
.to_str()
|
|
|
|
.unwrap_or("")
|
|
|
|
.to_string();
|
2023-04-19 17:26:36 +08:00
|
|
|
(code, msg)
|
2023-04-19 17:06:59 +08:00
|
|
|
}
|