2024-08-06 23:30:00 +02:00
|
|
|
package mp.code;
|
|
|
|
|
2024-08-07 10:22:01 +02:00
|
|
|
import java.util.Optional;
|
2024-08-19 11:36:51 +02:00
|
|
|
import java.util.UUID;
|
2024-08-07 10:22:01 +02:00
|
|
|
|
2024-08-08 02:45:52 +02:00
|
|
|
import mp.code.data.DetachResult;
|
2024-08-07 02:43:25 +02:00
|
|
|
import mp.code.exceptions.CodeMPException;
|
2024-08-06 23:30:00 +02:00
|
|
|
|
|
|
|
public class Workspace {
|
|
|
|
private final long ptr;
|
|
|
|
|
|
|
|
Workspace(long ptr) {
|
|
|
|
this.ptr = ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static native String get_workspace_id(long self);
|
|
|
|
public String getWorkspaceId() {
|
|
|
|
return get_workspace_id(this.ptr);
|
|
|
|
}
|
|
|
|
|
2024-08-07 10:22:01 +02:00
|
|
|
private static native CursorController get_cursor(long self);
|
2024-08-06 23:30:00 +02:00
|
|
|
public CursorController getCursor() {
|
2024-08-07 10:22:01 +02:00
|
|
|
return get_cursor(this.ptr);
|
2024-08-06 23:30:00 +02:00
|
|
|
}
|
|
|
|
|
2024-08-07 10:22:01 +02:00
|
|
|
private static native BufferController get_buffer(long self, String path);
|
|
|
|
public Optional<BufferController> getBuffer(String path) {
|
|
|
|
return Optional.ofNullable(get_buffer(this.ptr, path));
|
2024-08-06 23:30:00 +02:00
|
|
|
}
|
|
|
|
|
2024-08-21 23:41:22 +02:00
|
|
|
private static native String[] get_file_tree(long self, String filter);
|
|
|
|
public String[] getFileTree(Optional<String> filter) {
|
|
|
|
return get_file_tree(this.ptr, filter.orElse(null));
|
2024-08-06 23:30:00 +02:00
|
|
|
}
|
|
|
|
|
2024-08-21 23:41:22 +02:00
|
|
|
private static native void create_buffer(String path) throws CodeMPException;
|
|
|
|
public void createBuffer(String path) throws CodeMPException {
|
|
|
|
create_buffer(path);
|
2024-08-06 23:30:00 +02:00
|
|
|
}
|
|
|
|
|
2024-08-07 10:22:01 +02:00
|
|
|
private static native BufferController attach_to_buffer(long self, String path) throws CodeMPException;
|
|
|
|
public BufferController attachToBuffer(String path) throws CodeMPException {
|
|
|
|
return attach_to_buffer(ptr, path);
|
2024-08-06 23:30:00 +02:00
|
|
|
}
|
|
|
|
|
2024-08-08 02:45:52 +02:00
|
|
|
private static native DetachResult detach_from_buffer(long self, String path);
|
|
|
|
public DetachResult detachFromBuffer(String path) {
|
|
|
|
return detach_from_buffer(this.ptr, path);
|
|
|
|
}
|
|
|
|
|
2024-08-07 02:43:25 +02:00
|
|
|
private static native void fetch_buffers(long self) throws CodeMPException;
|
|
|
|
public void fetchBuffers() throws CodeMPException {
|
2024-08-06 23:30:00 +02:00
|
|
|
fetch_buffers(this.ptr);
|
|
|
|
}
|
|
|
|
|
2024-08-07 02:43:25 +02:00
|
|
|
private static native void fetch_users(long self) throws CodeMPException;
|
|
|
|
public void fetchUsers() throws CodeMPException {
|
2024-08-06 23:30:00 +02:00
|
|
|
fetch_buffers(this.ptr);
|
|
|
|
}
|
|
|
|
|
2024-08-19 11:36:51 +02:00
|
|
|
private static native UUID[] list_buffer_users(long self, String path) throws CodeMPException;
|
|
|
|
public UUID[] listBufferUsers(String path) throws CodeMPException {
|
2024-08-07 02:43:25 +02:00
|
|
|
return list_buffer_users(this.ptr, path);
|
2024-08-06 23:30:00 +02:00
|
|
|
}
|
|
|
|
|
2024-08-09 14:11:13 +02:00
|
|
|
private static native void delete_buffer(long self, String path) throws CodeMPException;
|
2024-08-07 02:43:25 +02:00
|
|
|
public void deleteBuffer(String path) throws CodeMPException {
|
2024-08-06 23:30:00 +02:00
|
|
|
delete_buffer(this.ptr, path);
|
|
|
|
}
|
|
|
|
|
2024-08-09 14:11:13 +02:00
|
|
|
private static native Event event(long self) throws CodeMPException;
|
|
|
|
public Event event() throws CodeMPException {
|
|
|
|
return event(this.ptr);
|
|
|
|
}
|
|
|
|
|
2024-08-07 02:43:25 +02:00
|
|
|
private static native BufferController select_buffer(long self, long timeout) throws CodeMPException;
|
2024-08-07 10:22:01 +02:00
|
|
|
public Optional<BufferController> selectBuffer(long timeout) throws CodeMPException {
|
|
|
|
return Optional.ofNullable(select_buffer(this.ptr, timeout));
|
2024-08-07 02:43:25 +02:00
|
|
|
}
|
2024-08-06 23:30:00 +02:00
|
|
|
|
|
|
|
private static native void free(long self);
|
|
|
|
@Override
|
2024-08-07 02:43:25 +02:00
|
|
|
protected void finalize() {
|
2024-08-06 23:30:00 +02:00
|
|
|
free(this.ptr);
|
|
|
|
}
|
2024-08-09 14:11:13 +02:00
|
|
|
|
|
|
|
public static class Event {
|
|
|
|
private final Type type;
|
|
|
|
private final String argument;
|
|
|
|
|
|
|
|
Event(Type type, String argument) {
|
|
|
|
this.type = type;
|
|
|
|
this.argument = argument;
|
|
|
|
}
|
|
|
|
|
2024-08-21 23:41:22 +02:00
|
|
|
public Optional<String > getUserJoined() {
|
2024-08-09 14:11:13 +02:00
|
|
|
if(this.type == Type.USER_JOIN) {
|
|
|
|
return Optional.of(this.argument);
|
|
|
|
} else return Optional.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
public Optional<String> getUserLeft() {
|
|
|
|
if(this.type == Type.USER_LEAVE) {
|
|
|
|
return Optional.of(this.argument);
|
|
|
|
} else return Optional.empty();
|
|
|
|
}
|
|
|
|
|
2024-08-19 11:36:51 +02:00
|
|
|
public Optional<String> getTargetBuffer() {
|
|
|
|
if(this.type == Type.FILE_TREE_UPDATED) {
|
|
|
|
return Optional.of(this.argument);
|
|
|
|
} else return Optional.empty();
|
2024-08-09 14:11:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private enum Type {
|
|
|
|
USER_JOIN,
|
|
|
|
USER_LEAVE,
|
|
|
|
FILE_TREE_UPDATED
|
|
|
|
}
|
|
|
|
}
|
2024-08-06 23:30:00 +02:00
|
|
|
}
|