2024-08-06 23:30:00 +02:00
|
|
|
package mp.code;
|
|
|
|
|
2024-09-17 17:37:22 +02:00
|
|
|
import mp.code.data.Config;
|
2024-09-15 02:00:04 +02:00
|
|
|
import mp.code.data.User;
|
2024-09-05 02:45:33 +02:00
|
|
|
import mp.code.exceptions.ConnectionException;
|
|
|
|
import mp.code.exceptions.ConnectionRemoteException;
|
2024-08-06 23:30:00 +02:00
|
|
|
|
2024-09-17 17:37:22 +02:00
|
|
|
import java.util.Objects;
|
2024-08-06 23:30:00 +02:00
|
|
|
import java.util.Optional;
|
|
|
|
|
|
|
|
public class Client {
|
|
|
|
private final long ptr;
|
|
|
|
|
2024-09-17 17:37:22 +02:00
|
|
|
public static native Client connect(Config config) throws ConnectionException;
|
2024-09-11 15:47:56 +02:00
|
|
|
|
2024-08-07 10:22:01 +02:00
|
|
|
Client(long ptr) {
|
|
|
|
this.ptr = ptr;
|
2024-08-06 23:30:00 +02:00
|
|
|
}
|
|
|
|
|
2024-09-15 02:00:04 +02:00
|
|
|
private static native User get_user(long self);
|
|
|
|
public User getUser() {
|
|
|
|
return get_user(this.ptr);
|
2024-08-06 23:30:00 +02:00
|
|
|
}
|
|
|
|
|
2024-09-05 02:45:33 +02:00
|
|
|
private static native Workspace join_workspace(long self, String id) throws ConnectionException;
|
|
|
|
public Workspace joinWorkspace(String id) throws ConnectionException {
|
2024-09-17 17:37:22 +02:00
|
|
|
return join_workspace(this.ptr, Objects.requireNonNull(id));
|
2024-08-06 23:30:00 +02:00
|
|
|
}
|
|
|
|
|
2024-09-05 02:45:33 +02:00
|
|
|
private static native void create_workspace(long self, String id) throws ConnectionRemoteException;
|
|
|
|
public void createWorkspace(String id) throws ConnectionRemoteException {
|
2024-09-17 17:37:22 +02:00
|
|
|
create_workspace(this.ptr, Objects.requireNonNull(id));
|
2024-08-27 23:04:56 +02:00
|
|
|
}
|
|
|
|
|
2024-09-05 02:45:33 +02:00
|
|
|
private static native void delete_workspace(long self, String id) throws ConnectionRemoteException;
|
|
|
|
public void deleteWorkspace(String id) throws ConnectionRemoteException {
|
2024-09-17 17:37:22 +02:00
|
|
|
delete_workspace(this.ptr, Objects.requireNonNull(id));
|
2024-08-27 23:04:56 +02:00
|
|
|
}
|
|
|
|
|
2024-09-17 17:37:22 +02:00
|
|
|
private static native void invite_to_workspace(long self, String workspaceId, String user) throws ConnectionRemoteException;
|
|
|
|
public void inviteToWorkspace(String workspaceId, String user) throws ConnectionRemoteException {
|
|
|
|
invite_to_workspace(this.ptr, Objects.requireNonNull(workspaceId), Objects.requireNonNull(user));
|
2024-08-27 23:04:56 +02:00
|
|
|
}
|
|
|
|
|
2024-09-05 02:45:33 +02:00
|
|
|
private static native String[] list_workspaces(long self, boolean owned, boolean invited) throws ConnectionRemoteException;
|
|
|
|
public String[] listWorkspaces(boolean owned, boolean invited) throws ConnectionRemoteException {
|
2024-08-27 23:04:56 +02:00
|
|
|
return list_workspaces(this.ptr, owned, invited);
|
|
|
|
}
|
|
|
|
|
2024-09-15 02:00:04 +02:00
|
|
|
private static native String[] active_workspaces(long self);
|
|
|
|
public String[] activeWorkspaces() {
|
|
|
|
return active_workspaces(this.ptr);
|
|
|
|
}
|
|
|
|
|
2024-08-08 02:45:52 +02:00
|
|
|
private static native boolean leave_workspace(long self, String id);
|
|
|
|
public boolean leaveWorkspace(String id) {
|
2024-09-17 17:37:22 +02:00
|
|
|
return leave_workspace(this.ptr, Objects.requireNonNull(id));
|
2024-08-08 02:45:52 +02:00
|
|
|
}
|
|
|
|
|
2024-09-09 16:06:05 +02:00
|
|
|
private static native Workspace get_workspace(long self, String workspace);
|
|
|
|
public Optional<Workspace> getWorkspace(String workspace) {
|
2024-09-17 17:37:22 +02:00
|
|
|
return Optional.ofNullable(get_workspace(this.ptr, Objects.requireNonNull(workspace)));
|
2024-08-06 23:30:00 +02:00
|
|
|
}
|
2024-08-27 23:04:56 +02:00
|
|
|
|
2024-09-15 02:00:04 +02:00
|
|
|
private static native void refresh(long self) throws ConnectionRemoteException;
|
2024-09-05 02:45:33 +02:00
|
|
|
public void refresh() throws ConnectionRemoteException {
|
2024-09-15 02:00:04 +02:00
|
|
|
refresh(this.ptr);
|
2024-08-27 23:04:56 +02:00
|
|
|
}
|
2024-08-06 23:30:00 +02:00
|
|
|
|
|
|
|
private static native void free(long self);
|
|
|
|
@Override
|
|
|
|
protected void finalize() {
|
|
|
|
free(this.ptr);
|
|
|
|
}
|
2024-08-07 10:22:01 +02:00
|
|
|
|
|
|
|
static {
|
2024-09-17 02:40:03 +02:00
|
|
|
Extensions.loadLibraryIfNotPresent();
|
2024-08-07 10:22:01 +02:00
|
|
|
}
|
2024-08-06 23:30:00 +02:00
|
|
|
}
|
|
|
|
|