2024-08-06 23:30:00 +02:00
|
|
|
package mp.code;
|
|
|
|
|
2024-08-07 02:43:25 +02:00
|
|
|
import mp.code.exceptions.CodeMPException;
|
2024-08-06 23:30:00 +02:00
|
|
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
|
|
|
public class Client {
|
|
|
|
private final long ptr;
|
|
|
|
private final String url;
|
|
|
|
|
2024-08-07 02:43:25 +02:00
|
|
|
public static native long setup_tracing(String path);
|
2024-08-06 23:30:00 +02:00
|
|
|
|
2024-08-07 02:43:25 +02:00
|
|
|
private static native long connect(String url) throws CodeMPException;
|
|
|
|
public Client(String url) throws CodeMPException {
|
2024-08-06 23:30:00 +02:00
|
|
|
this.ptr = connect(url);
|
|
|
|
this.url = url;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getUrl() {
|
|
|
|
return this.url;
|
|
|
|
}
|
|
|
|
|
2024-08-07 02:43:25 +02:00
|
|
|
private static native void login(long self, String username, String password, String workspace) throws CodeMPException;
|
|
|
|
public void login(String username, String password, String workspace) throws CodeMPException {
|
2024-08-06 23:30:00 +02:00
|
|
|
login(this.ptr, username, password, workspace);
|
|
|
|
}
|
|
|
|
|
2024-08-07 02:43:25 +02:00
|
|
|
private static native long join_workspace(long self, String id) throws CodeMPException;
|
|
|
|
public Workspace joinWorkspace(String id) throws CodeMPException {
|
2024-08-06 23:30:00 +02:00
|
|
|
return new Workspace(join_workspace(this.ptr, id));
|
|
|
|
}
|
|
|
|
|
|
|
|
private static native long get_workspace(long self);
|
|
|
|
public Optional<Workspace> getWorkspace() {
|
|
|
|
long ptr = get_workspace(this.ptr);
|
|
|
|
if(ptr == 0) { // TODO it would be better to init in rust directly
|
|
|
|
return Optional.empty();
|
|
|
|
} else {
|
|
|
|
return Optional.of(new Workspace(ptr));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static native void free(long self);
|
|
|
|
@Override
|
|
|
|
@SuppressWarnings("removal") // muh java 8
|
|
|
|
protected void finalize() {
|
|
|
|
free(this.ptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|