codemp/src/ffi/java/workspace.rs

87 lines
3 KiB
Rust
Raw Normal View History

2024-09-22 02:22:51 +02:00
use jni_toolbox::jni;
use crate::{errors::{ConnectionError, ControllerError, RemoteError}, Workspace};
2024-08-06 23:30:00 +02:00
2024-09-05 02:45:33 +02:00
/// Get the workspace id.
2024-09-23 18:12:13 +02:00
#[jni(package = "mp.code", class = "Workspace")]
fn get_workspace_id(workspace: Workspace) -> String {
workspace.id()
}
2024-09-05 02:45:33 +02:00
/// Get a cursor controller by name and returns a pointer to it.
2024-09-23 18:12:13 +02:00
#[jni(package = "mp.code", class = "Workspace")]
fn get_cursor(workspace: Workspace) -> crate::cursor::Controller {
workspace.cursor()
}
2024-09-05 02:45:33 +02:00
/// Get a buffer controller by name and returns a pointer to it.
2024-09-23 18:12:13 +02:00
#[jni(package = "mp.code", class = "Workspace")]
fn get_buffer(workspace: Workspace, path: String) -> Option<crate::buffer::Controller> {
workspace.buffer_by_name(&path)
2024-08-06 23:30:00 +02:00
}
2024-09-05 02:45:33 +02:00
/// Get the filetree.
2024-09-23 18:12:13 +02:00
#[jni(package = "mp.code", class = "Workspace")]
fn get_file_tree(workspace: Workspace, filter: Option<String>, strict: bool) -> Vec<String> {
workspace.filetree(filter.as_deref(), strict)
}
/// Gets a list of the active buffers.
2024-09-23 18:12:13 +02:00
#[jni(package = "mp.code", class = "Workspace")]
fn active_buffers(workspace: Workspace) -> Vec<String> {
workspace.buffer_list()
}
/// Create a new buffer.
#[jni(package = "mp.code", class = "Workspace")]
2024-09-23 18:12:13 +02:00
fn create_buffer(workspace: Workspace, path: String) -> Result<(), RemoteError> {
super::tokio().block_on(workspace.create(&path))
}
2024-09-05 02:45:33 +02:00
/// Attach to a buffer and return a pointer to its [crate::buffer::Controller].
2024-09-23 18:12:13 +02:00
#[jni(package = "mp.code", class = "Workspace")]
fn attach_to_buffer(workspace: Workspace, path: String) -> Result<crate::buffer::Controller, ConnectionError> {
super::tokio().block_on(workspace.attach(&path))
}
2024-09-05 02:45:33 +02:00
/// Detach from a buffer.
2024-09-23 18:12:13 +02:00
#[jni(package = "mp.code", class = "Workspace")]
fn detach_from_buffer(workspace: Workspace, path: String) -> crate::workspace::DetachResult {
workspace.detach(&path)
}
2024-09-05 02:45:33 +02:00
/// Update the local buffer list.
#[jni(package = "mp.code", class = "Workspace")]
2024-09-23 18:12:13 +02:00
fn fetch_buffers(workspace: Workspace) -> Result<(), RemoteError> {
super::tokio().block_on(workspace.fetch_buffers())
}
2024-09-05 02:45:33 +02:00
/// Update the local user list.
#[jni(package = "mp.code", class = "Workspace")]
2024-09-23 18:12:13 +02:00
fn fetch_users(workspace: Workspace) -> Result<(), RemoteError> {
super::tokio().block_on(workspace.fetch_users())
}
2024-09-05 02:45:33 +02:00
/// List users attached to a buffer.
2024-09-23 18:12:13 +02:00
#[jni(package = "mp.code", class = "Workspace")]
fn list_buffer_users(workspace: Workspace, path: String) -> Result<Vec<crate::api::User>, RemoteError> {
super::tokio().block_on(workspace.list_buffer_users(&path))
}
2024-09-05 02:45:33 +02:00
/// Delete a buffer.
#[jni(package = "mp.code", class = "Workspace")]
2024-09-23 18:12:13 +02:00
fn delete_buffer(workspace: Workspace, path: String) -> Result<(), RemoteError> {
super::tokio().block_on(workspace.delete(&path))
}
2024-09-05 02:45:33 +02:00
/// Receive a workspace event if present.
2024-09-23 18:12:13 +02:00
#[jni(package = "mp.code", class = "Workspace")]
fn event(workspace: Workspace) -> Result<crate::api::Event, ControllerError> {
super::tokio().block_on(workspace.event())
2024-08-09 14:11:13 +02:00
}
2024-08-08 00:29:54 +02:00
/// Called by the Java GC to drop a [Workspace].
#[jni(package = "mp.code", class = "Workspace")]
fn free(input: jni::sys::jlong) {
let _ = unsafe { Box::from_raw(input as *mut crate::Workspace) };
2024-08-08 00:29:54 +02:00
}