1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-23 20:42:06 +01:00

Start implementing cancel abilities

This commit is contained in:
vanitasvitae 2017-07-11 13:30:17 +02:00
parent f9086439a8
commit ad529be705
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
3 changed files with 29 additions and 5 deletions

View file

@ -17,6 +17,7 @@
package org.jivesoftware.smackx.jingle_filetransfer;
import java.io.File;
import java.util.concurrent.Future;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -50,8 +51,15 @@ public class IncomingJingleFileOffer extends JingleFileTransferSession implement
@Override
public void cancel() {
//TODO: Actually cancel
notifyEndedListeners(JingleReason.Reason.cancel);
if (state == State.active) {
Future<?> task = queued.get(0);
if (task != null) {
task.cancel(true);
queued.remove(task);
}
notifyEndedListeners(JingleReason.Reason.cancel);
}
}
public enum State {

View file

@ -17,6 +17,7 @@
package org.jivesoftware.smackx.jingle_filetransfer;
import java.io.File;
import java.util.concurrent.Future;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -47,8 +48,21 @@ public class OutgoingJingleFileOffer extends JingleFileTransferSession {
private static final Logger LOGGER = Logger.getLogger(OutgoingJingleFileOffer.class.getName());
@Override
public void cancel() {
//TODO: Actually cancel
public void cancel() throws InterruptedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException {
switch (state) {
case terminated:
return;
case active:
Future<?> task = queued.get(0);
if (task != null) {
task.cancel(true);
queued.remove(task);
}
default:
jutil.sendSessionTerminateCancel(getRemote(), getSessionId());
}
notifyEndedListeners(JingleReason.Reason.cancel);
}

View file

@ -16,6 +16,8 @@
*/
package org.jivesoftware.smackx.jingle_filetransfer.handler;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.jingle.element.JingleReason;
/**
@ -26,7 +28,7 @@ public interface FileTransferHandler {
/**
* Cancels the current file transfer.
*/
void cancel();
void cancel() throws InterruptedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException;
/**
* Returns true, if the file transfer is ended.