2024-09-16 00:20:03 +02:00
|
|
|
use jni::{objects::{JClass, JString}, sys::{jboolean, jlong}, JNIEnv};
|
|
|
|
|
2024-09-17 17:37:22 +02:00
|
|
|
use super::{JExceptable, null_check};
|
2024-09-16 00:20:03 +02:00
|
|
|
|
|
|
|
/// Calculate the XXH3 hash for a given String.
|
|
|
|
#[no_mangle]
|
|
|
|
pub extern "system" fn Java_mp_code_Extensions_hash<'local>(
|
|
|
|
mut env: JNIEnv,
|
|
|
|
_class: JClass<'local>,
|
|
|
|
content: JString<'local>,
|
|
|
|
) -> jlong {
|
2024-09-17 17:37:22 +02:00
|
|
|
null_check!(env, content, 0 as jlong);
|
2024-09-16 00:20:03 +02:00
|
|
|
let content: String = env.get_string(&content)
|
|
|
|
.map(|s| s.into())
|
|
|
|
.jexcept(&mut env);
|
|
|
|
let hash = crate::ext::hash(content.as_bytes());
|
|
|
|
i64::from_ne_bytes(hash.to_ne_bytes())
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Tells the [tokio] runtime how to drive the event loop.
|
|
|
|
#[no_mangle]
|
|
|
|
pub extern "system" fn Java_mp_code_Extensions_drive(
|
|
|
|
_env: JNIEnv,
|
|
|
|
_class: JClass,
|
|
|
|
block: jboolean
|
|
|
|
) {
|
|
|
|
if block != 0 {
|
|
|
|
super::tokio().block_on(std::future::pending::<()>());
|
|
|
|
} else {
|
|
|
|
std::thread::spawn(|| {
|
|
|
|
super::tokio().block_on(std::future::pending::<()>());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-17 02:40:03 +02:00
|
|
|
/// Set up the tracing subscriber.
|
|
|
|
#[no_mangle]
|
|
|
|
#[allow(non_snake_case)]
|
|
|
|
pub extern "system" fn Java_mp_code_Extensions_setupTracing<'local>(
|
|
|
|
mut env: JNIEnv,
|
|
|
|
_class: JClass<'local>,
|
|
|
|
path: JString<'local>,
|
|
|
|
debug: jboolean
|
|
|
|
) {
|
|
|
|
super::setup_logger(
|
|
|
|
debug != 0,
|
|
|
|
Some(path)
|
|
|
|
.filter(|p| !p.is_null())
|
|
|
|
.map(|p| env.get_string(&p).map(|s| s.into())
|
|
|
|
.jexcept(&mut env))
|
|
|
|
);
|
|
|
|
}
|