codemp/dist/java/src/mp/code/BufferController.java

73 lines
1.8 KiB
Java
Raw Normal View History

2024-08-06 23:30:00 +02:00
package mp.code;
import mp.code.data.Callback;
import mp.code.data.Cursor;
2024-08-06 23:30:00 +02:00
import mp.code.data.TextChange;
2024-09-05 02:45:33 +02:00
import mp.code.exceptions.ControllerException;
2024-08-06 23:30:00 +02:00
import java.util.Objects;
import java.util.Optional;
2024-08-06 23:30:00 +02:00
public class BufferController {
private final long ptr;
BufferController(long ptr) {
this.ptr = ptr;
}
2024-08-14 19:09:48 +02:00
private static native String get_name(long self);
2024-08-06 23:30:00 +02:00
public String getName() {
return get_name(this.ptr);
}
2024-09-05 02:45:33 +02:00
private static native String get_content(long self) throws ControllerException;
public String getContent() throws ControllerException {
2024-08-06 23:30:00 +02:00
return get_content(this.ptr);
}
2024-09-05 02:45:33 +02:00
private static native TextChange try_recv(long self) throws ControllerException;
public Optional<TextChange> tryRecv() throws ControllerException {
return Optional.ofNullable(try_recv(this.ptr));
}
2024-09-05 02:45:33 +02:00
private static native Cursor recv(long self) throws ControllerException;
public Cursor recv() throws ControllerException {
return recv(this.ptr);
2024-08-06 23:30:00 +02:00
}
2024-09-05 02:45:33 +02:00
private static native void send(long self, TextChange change) throws ControllerException;
public void send(TextChange change) throws ControllerException {
send(this.ptr, Objects.requireNonNull(change));
2024-08-06 23:30:00 +02:00
}
private static native void callback(long self, Callback<BufferController> cb);
public void callback(Callback<BufferController> cb) {
callback(this.ptr, Objects.requireNonNull(cb));
}
private static native void clear_callback(long self);
public void clearCallback() {
clear_callback(this.ptr);
}
private static native void poll(long self);
public void poll() {
poll(this.ptr);
}
private static native boolean stop(long self);
public boolean stop() {
return stop(this.ptr);
}
2024-08-06 23:30:00 +02:00
private static native void free(long self);
@Override
protected void finalize() {
2024-08-06 23:30:00 +02:00
free(this.ptr);
}
static {
Extensions.loadLibraryIfNotPresent();
}
2024-08-06 23:30:00 +02:00
}