2024-08-06 23:30:00 +02:00
|
|
|
package mp.code;
|
|
|
|
|
2024-09-15 02:00:04 +02:00
|
|
|
import mp.code.data.Callback;
|
2024-08-06 23:30:00 +02:00
|
|
|
import mp.code.data.Cursor;
|
2024-09-05 02:45:33 +02:00
|
|
|
import mp.code.exceptions.ControllerException;
|
2024-08-06 23:30:00 +02:00
|
|
|
|
2024-08-07 10:22:01 +02:00
|
|
|
import java.util.Optional;
|
|
|
|
|
2024-08-06 23:30:00 +02:00
|
|
|
public class CursorController {
|
|
|
|
private final long ptr;
|
|
|
|
|
|
|
|
CursorController(long ptr) {
|
|
|
|
this.ptr = ptr;
|
|
|
|
}
|
|
|
|
|
2024-09-05 02:45:33 +02:00
|
|
|
private static native Cursor try_recv(long self) throws ControllerException;
|
|
|
|
public Optional<Cursor> tryRecv() throws ControllerException {
|
2024-08-07 10:22:01 +02:00
|
|
|
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 {
|
2024-08-07 10:22:01 +02:00
|
|
|
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, Cursor cursor) throws ControllerException;
|
|
|
|
public void send(Cursor cursor) throws ControllerException {
|
2024-08-06 23:30:00 +02:00
|
|
|
send(this.ptr, cursor);
|
|
|
|
}
|
|
|
|
|
2024-09-15 02:00:04 +02:00
|
|
|
private static native void callback(long self, Callback<CursorController> cb);
|
|
|
|
public void callback(Callback<CursorController> cb) {
|
|
|
|
callback(this.ptr, cb);
|
|
|
|
}
|
|
|
|
|
2024-09-17 02:40:03 +02:00
|
|
|
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
|
2024-08-07 02:43:25 +02:00
|
|
|
protected void finalize() {
|
2024-08-06 23:30:00 +02:00
|
|
|
free(this.ptr);
|
|
|
|
}
|
2024-09-17 02:40:03 +02:00
|
|
|
|
|
|
|
static {
|
|
|
|
Extensions.loadLibraryIfNotPresent();
|
|
|
|
}
|
2024-08-06 23:30:00 +02:00
|
|
|
}
|