use of com.biglybt.pifimpl.remote.torrent.RPTorrent in project BiglyBT by BiglySoftware.
the class RPTracker method _process.
@Override
public RPReply _process(RPRequest request) {
String method = request.getMethod();
Object[] params = request.getParams();
if (method.equals("host[Torrent,boolean]")) {
try {
Torrent torrent = params[0] == null ? null : (Torrent) ((RPTorrent) params[0])._setLocal();
if (torrent == null) {
throw (new RPException("Invalid torrent"));
}
TrackerTorrent tt = delegate.host(torrent, ((Boolean) params[1]).booleanValue());
RPTrackerTorrent res = RPTrackerTorrent.create(tt);
return (new RPReply(res));
} catch (TrackerException e) {
return (new RPReply(e));
}
} else if (method.equals("getTorrents")) {
TrackerTorrent[] torrents = delegate.getTorrents();
RPTrackerTorrent[] res = new RPTrackerTorrent[torrents.length];
for (int i = 0; i < res.length; i++) {
res[i] = RPTrackerTorrent.create(torrents[i]);
}
return (new RPReply(res));
}
throw (new RPException("Unknown method: " + method));
}
use of com.biglybt.pifimpl.remote.torrent.RPTorrent in project BiglyBT by BiglySoftware.
the class RPDownloadManager method _process.
@Override
public RPReply _process(RPRequest request) {
String method = request.getMethod();
Object[] params = request.getParams();
if (method.equals("getDownloads")) {
Download[] downloads = delegate.getDownloads();
// unfortunately downloads with broken torrents can exist and have no associated
// Torrent. Easiest fix here is to filter them out.
RPDownload[] res = new RPDownload[downloads.length];
for (int i = 0; i < res.length; i++) {
res[i] = RPDownload.create(downloads[i]);
}
return (new RPReply(res));
} else if (method.equals("getDownloads[boolean]")) {
Download[] downloads = delegate.getDownloads(((Boolean) request.getParams()[0]).booleanValue());
RPDownload[] res = new RPDownload[downloads.length];
for (int i = 0; i < res.length; i++) {
res[i] = RPDownload.create(downloads[i]);
}
return (new RPReply(res));
} else if (method.equals("addDownload[Torrent]")) {
try {
RPTorrent torrent = (RPTorrent) request.getParams()[0];
Download res = delegate.addDownload((Torrent) torrent._setLocal());
return (new RPReply(RPDownload.create(res)));
} catch (DownloadException e) {
throw (new RPException("DownloadManager::addDownload failed", e));
}
} else if (method.equals("addDownload[Torrent,String,String]")) {
try {
RPTorrent torrent = (RPTorrent) request.getParams()[0];
File f1 = params[1] == null ? null : new File((String) params[1]);
File f2 = params[2] == null ? null : new File((String) params[2]);
Download res = delegate.addDownload((Torrent) torrent._setLocal(), f1, f2);
return (new RPReply(RPDownload.create(res)));
} catch (DownloadException e) {
throw (new RPException("DownloadManager::addDownload failed", e));
}
} else if (method.equals("addDownload[URL]")) {
try {
delegate.addDownload((URL) request.getParams()[0]);
} catch (DownloadException e) {
throw (new RPException("DownloadManager::addDownload failed", e));
}
return (new RPReply(null));
} else if (method.equals("pauseDownloads")) {
delegate.pauseDownloads();
return (null);
} else if (method.equals("resumeDownloads")) {
delegate.resumeDownloads();
return (null);
} else if (method.equals("stopAllDownloads")) {
delegate.stopAllDownloads();
return (null);
} else if (method.equals("startAllDownloads")) {
delegate.startAllDownloads();
return (null);
}
throw (new RPException("Unknown method: " + method));
}
Aggregations