chore: some glue code for jni

made the simple ones :p
This commit is contained in:
əlemi 2024-08-06 23:55:57 +02:00
parent e2ae53b35f
commit 13f862a0e8
Signed by: alemi
GPG key ID: A4895B84D311642C
3 changed files with 134 additions and 0 deletions

View file

@ -0,0 +1,87 @@
use jni::{objects::{JClass, JObject}, sys::{jlong, jobject, jstring}, JNIEnv};
use crate::{api::Controller, buffer::Controller};
use super::util::JExceptable;
/*
* Class: mp_code_BufferController
* Method: get_name
* Signature: (J)Ljava/lang/String;
*/
#[no_mangle]
pub extern "system" fn Java_mp_code_BufferController_get_1name<'local>(
env: JNIEnv,
_class: JClass<'local>,
self_ptr: jlong,
) -> jstring {
let controller = unsafe { Box::leak(Box::from_raw(self_ptr as *mut crate::buffer::Controller)) };
let content = controller.name();
env.new_string(content)
.expect("could not create jstring")
.as_raw()
}
/*
* Class: mp_code_BufferController
* Method: get_content
* Signature: (J)Ljava/lang/String;
*/
#[no_mangle]
pub extern "system" fn Java_mp_code_BufferController_get_1content<'local>(
env: JNIEnv,
_class: JClass<'local>,
self_ptr: jlong,
) -> jstring {
let controller = unsafe { Box::leak(Box::from_raw(self_ptr as *mut crate::buffer::Controller)) };
let content = controller.content();
env.new_string(content)
.expect("could not create jstring")
.as_raw()
}
/*
* Class: mp_code_BufferController
* Method: try_recv
* Signature: (J)Lmp/code/data/TextChange;
*/
#[no_mangle]
pub extern "system" fn Java_mp_code_BufferController_try_1recv<'local>(
mut env: JNIEnv,
_class: JClass<'local>,
self_ptr: jlong,
) -> jobject {
let controller = unsafe { Box::leak(Box::from_raw(self_ptr as *mut crate::buffer::Controller)) };
let change = controller.try_recv().jexcept(&mut env);
todo!()
}
/*
* Class: mp_code_BufferController
* Method: send
* Signature: (JLmp/code/data/TextChange;)V
*/
#[no_mangle]
pub extern "system" fn Java_mp_code_BufferController_send<'local>(
mut env: JNIEnv,
_class: JClass<'local>,
self_ptr: jlong,
input: JObject<'local>
) {
todo!()
}
/*
* Class: mp_code_BufferController
* Method: free
* Signature: (J)V
*/
#[no_mangle]
pub extern "system" fn Java_mp_code_BufferController_free<'local>(
_env: JNIEnv,
_class: JClass<'local>,
self_ptr: jlong,
) {
unsafe { Box::from_raw(self_ptr as *mut crate::cursor::Controller) };
}

View file

@ -0,0 +1,44 @@
use jni::{objects::{JClass, JObject}, sys::{jlong, jobject}, JNIEnv};
/*
* Class: mp_code_CursorController
* Method: recv
* Signature: (J)Lmp/code/data/Cursor;
*/
#[no_mangle]
pub extern "system" fn Java_mp_code_CursorController_recv<'local>(
mut env: JNIEnv,
_class: JClass<'local>,
self_ptr: jlong,
) -> jobject {
todo!()
}
/*
* Class: mp_code_CursorController
* Method: send
* Signature: (JLmp/code/data/Cursor;)V
*/
#[no_mangle]
pub extern "system" fn Java_mp_code_CursorController_send<'local>(
mut env: JNIEnv,
_class: JClass<'local>,
self_ptr: jlong,
input: JObject<'local>,
) {
}
/*
* Class: mp_code_CursorController
* Method: free
* Signature: (J)V
*/
#[no_mangle]
pub extern "system" fn Java_mp_code_CursorController_free<'local>(
_env: JNIEnv,
_class: JClass<'local>,
self_ptr: jlong,
) {
unsafe { Box::from_raw(self_ptr as *mut crate::cursor::Controller) };
}

View file

@ -2,6 +2,9 @@ pub mod client;
pub mod workspace; pub mod workspace;
pub mod util; pub mod util;
pub mod cursor_controller;
pub mod buffer_controller;
lazy_static::lazy_static! { lazy_static::lazy_static! {
pub(crate) static ref RT: tokio::runtime::Runtime = tokio::runtime::Runtime::new().expect("could not create tokio runtime"); pub(crate) static ref RT: tokio::runtime::Runtime = tokio::runtime::Runtime::new().expect("could not create tokio runtime");
} }