mirror of
https://github.com/hexedtech/codemp.git
synced 2024-11-22 23:34:49 +01:00
feat: more work on java ffi glue
easy when you todo() the hard vec<string>
This commit is contained in:
parent
490670b8bc
commit
329287df53
1 changed files with 108 additions and 1 deletions
|
@ -54,7 +54,114 @@ pub extern "system" fn Java_mp_code_Workspace_create_1buffer<'local>(
|
||||||
self_ptr: jlong,
|
self_ptr: jlong,
|
||||||
input: JString<'local>
|
input: JString<'local>
|
||||||
) {
|
) {
|
||||||
let ws: Box<Workspace> = unsafe { Box::from_raw(self_ptr as *mut Workspace) };
|
let ws = unsafe { Box::leak(Box::from_raw(self_ptr as *mut Workspace)) };
|
||||||
let path = unsafe { env.get_string_unchecked(&input).expect("Couldn't get java string!") };
|
let path = unsafe { env.get_string_unchecked(&input).expect("Couldn't get java string!") };
|
||||||
RT.block_on(ws.create(path.to_str().expect("Not UTF-8"))).jexcept(&mut env);
|
RT.block_on(ws.create(path.to_str().expect("Not UTF-8"))).jexcept(&mut env);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: mp_code_Workspace
|
||||||
|
* Method: get_file_tree
|
||||||
|
* Signature: (J)V
|
||||||
|
*/
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "system" fn Java_mp_code_Workspace_get_1file_1tree<'local>(
|
||||||
|
mut env: JNIEnv,
|
||||||
|
_class: JClass<'local>,
|
||||||
|
self_ptr: jlong,
|
||||||
|
) {
|
||||||
|
let workspace = unsafe { Box::leak(Box::from_raw(self_ptr as *mut Workspace)) };
|
||||||
|
let file_tree = workspace.filetree();
|
||||||
|
todo!() // how to return Vec<String> ? []String ?
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: mp_code_Workspace
|
||||||
|
* Method: attach_to_buffer
|
||||||
|
* Signature: (J)J
|
||||||
|
*/
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "system" fn Java_mp_code_Workspace_attach_1to_1buffer<'local>(
|
||||||
|
mut env: JNIEnv,
|
||||||
|
_class: JClass<'local>,
|
||||||
|
_self_ptr: jlong,
|
||||||
|
) -> jlong {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: mp_code_Workspace
|
||||||
|
* Method: fetch_buffers
|
||||||
|
* Signature: (J)V
|
||||||
|
*/
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "system" fn Java_mp_code_Workspace_fetch_1buffers<'local>(
|
||||||
|
mut env: JNIEnv,
|
||||||
|
_class: JClass<'local>,
|
||||||
|
self_ptr: jlong,
|
||||||
|
) {
|
||||||
|
let workspace = unsafe { Box::leak(Box::from_raw(self_ptr as *mut Workspace)) };
|
||||||
|
RT.block_on(workspace.fetch_buffers()).jexcept(&mut env);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: mp_code_Workspace
|
||||||
|
* Method: fetch_users
|
||||||
|
* Signature: (J)V
|
||||||
|
*/
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "system" fn Java_mp_code_Workspace_fetch_1users<'local>(
|
||||||
|
mut env: JNIEnv,
|
||||||
|
_class: JClass<'local>,
|
||||||
|
self_ptr: jlong,
|
||||||
|
) {
|
||||||
|
let workspace = unsafe { Box::leak(Box::from_raw(self_ptr as *mut Workspace)) };
|
||||||
|
RT.block_on(workspace.fetch_users()).jexcept(&mut env);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: mp_code_Workspace
|
||||||
|
* Method: list_buffer_users
|
||||||
|
* Signature: (JLjava/lang/String;)V
|
||||||
|
*/
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "system" fn Java_mp_code_Workspace_list_1buffer_1users<'local>(
|
||||||
|
mut env: JNIEnv,
|
||||||
|
_class: JClass<'local>,
|
||||||
|
self_ptr: jlong,
|
||||||
|
input: JString<'local>,
|
||||||
|
) {
|
||||||
|
let workspace = unsafe { Box::leak(Box::from_raw(self_ptr as *mut Workspace)) };
|
||||||
|
let buffer : String = unsafe {
|
||||||
|
env.get_string_unchecked(&input)
|
||||||
|
.expect("Couldn't get java string!")
|
||||||
|
.into()
|
||||||
|
};
|
||||||
|
let users = RT.block_on(workspace.list_buffer_users(&buffer))
|
||||||
|
.jexcept(&mut env)
|
||||||
|
.into_iter()
|
||||||
|
.map(|x| x.id.to_string())
|
||||||
|
.collect::<Vec<String>>();
|
||||||
|
todo!() // how to return Vec<String>?
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: mp_code_Workspace
|
||||||
|
* Method: delete_buffer
|
||||||
|
* Signature: (JLjava/lang/String;)V
|
||||||
|
*/
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "system" fn Java_mp_code_Workspace_delete_1buffer<'local>(
|
||||||
|
mut env: JNIEnv,
|
||||||
|
_class: JClass<'local>,
|
||||||
|
self_ptr: jlong,
|
||||||
|
input: JString<'local>,
|
||||||
|
) {
|
||||||
|
let buffer : String = unsafe {
|
||||||
|
env.get_string_unchecked(&input)
|
||||||
|
.expect("Couldn't get java string!")
|
||||||
|
.into()
|
||||||
|
};
|
||||||
|
let workspace = unsafe { Box::leak(Box::from_raw(self_ptr as *mut Workspace)) };
|
||||||
|
RT.block_on(workspace.delete(&buffer)).jexcept(&mut env);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue