mirror of
https://github.com/hexedtech/codemp.git
synced 2024-12-23 05:14:54 +01:00
chore: some glue code for jni
made the simple ones :p
This commit is contained in:
parent
e2ae53b35f
commit
13f862a0e8
3 changed files with 134 additions and 0 deletions
87
src/ffi/java/buffer_controller.rs
Normal file
87
src/ffi/java/buffer_controller.rs
Normal 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) };
|
||||
}
|
||||
|
44
src/ffi/java/cursor_controller.rs
Normal file
44
src/ffi/java/cursor_controller.rs
Normal 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) };
|
||||
}
|
|
@ -2,6 +2,9 @@ pub mod client;
|
|||
pub mod workspace;
|
||||
pub mod util;
|
||||
|
||||
pub mod cursor_controller;
|
||||
pub mod buffer_controller;
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
pub(crate) static ref RT: tokio::runtime::Runtime = tokio::runtime::Runtime::new().expect("could not create tokio runtime");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue