调整jni模块、优化cmd模块展示

This commit is contained in:
lubeilin
2023-07-17 01:31:05 +08:00
parent 24140c2145
commit c2b7b02f3f
39 changed files with 1184 additions and 390 deletions
+28 -3
View File
@@ -2,7 +2,7 @@ use std::ptr;
use jni::errors::Error;
use jni::JNIEnv;
use jni::objects::{JClass, JObject, JValue};
use jni::sys::{jbyte, jint, jlong, jobject, jobjectArray, jsize};
use jni::sys::{jboolean, jbyte, jint, jlong, jobject, jobjectArray, jsize};
use switch::channel::Route;
use switch::core::sync::SwitchSync;
use switch::handle::PeerDeviceInfo;
@@ -27,6 +27,31 @@ pub unsafe extern "C" fn Java_top_wherewego_switchjni_Switch_waitStop0(
let _ = (&mut *switch).wait_stop();
}
#[no_mangle]
pub unsafe extern "C" fn Java_top_wherewego_switchjni_Switch_waitStopMs0(
_env: JNIEnv,
_class: JClass,
raw_switch: jlong,
ms: jlong,
) -> jboolean {
let switch = raw_switch as *mut SwitchSync;
if (&mut *switch).wait_stop_ms(ms as _) {
jni::sys::JNI_TRUE
} else {
jni::sys::JNI_FALSE
}
}
#[no_mangle]
pub unsafe extern "C" fn Java_top_wherewego_switchjni_Switch_drop0(
_env: JNIEnv,
_class: JClass,
raw_switch: jlong,
) {
let switch = raw_switch as *mut SwitchSync;
let _ = Box::from_raw(switch).stop();
}
#[no_mangle]
pub unsafe extern "C" fn Java_top_wherewego_switchjni_Switch_list0(
mut env: JNIEnv,
@@ -69,14 +94,14 @@ pub unsafe extern "C" fn Java_top_wherewego_switchjni_Switch_list0(
Err(e) => {
env.throw_new("java/lang/RuntimeException", format!("error:{:?}", e))
.expect("throw");
return ptr::null_mut()
return ptr::null_mut();
}
}
}
Err(e) => {
env.throw_new("java/lang/RuntimeException", format!("error:{:?}", e))
.expect("throw");
return ptr::null_mut()
return ptr::null_mut();
}
}
}
+5 -4
View File
@@ -53,9 +53,10 @@ fn new_sync(env: &mut JNIEnv, config: JObject) -> Result<SwitchUtilSync, Error>
let token = to_string_not_null(env, &config, "token")?;
let name = to_string_not_null(env, &config, "name")?;
let device_id = to_string_not_null(env, &config, "deviceId")?;
let server = to_string_not_null(env, &config, "server")?;
let password = to_string(env, &config, "password")?;
let server_address_str = to_string_not_null(env, &config, "server")?;
let nat_test_server = to_string_not_null(env, &config, "natTestServer")?;
let server_address = match server.to_socket_addrs() {
let server_address = match server_address_str.to_socket_addrs() {
Ok(mut rs) => {
if let Some(addr) = rs.next() {
addr
@@ -75,9 +76,9 @@ fn new_sync(env: &mut JNIEnv, config: JObject) -> Result<SwitchUtilSync, Error>
.collect::<Vec<_>>();
let config = Config::new(false,
token, device_id, name,
server_address,
server_address, server_address_str,
nat_test_server, vec![],
vec![], None, false, );
vec![], password, false, None);
match SwitchUtilSync::new(config) {
Ok(switch_util) => {
Ok(switch_util)