From 6bcf6edd8ec3c65a1409201bbff6c7016a618a3c Mon Sep 17 00:00:00 2001 From: lado Date: Wed, 2 Nov 2011 21:57:10 +0100 Subject: let user also cancel the client even if connect() blockin. After it gets connected abort will be found to be true and it breaks --- .../vdrmanager/gui/SvdrpProgressDialog.java | 7 +- .../vdrmanager/utils/svdrp/SvdrpClient.java | 100 ++++++++------------- 2 files changed, 39 insertions(+), 68 deletions(-) (limited to 'vdrmanager/src') diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/SvdrpProgressDialog.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/SvdrpProgressDialog.java index 4e34590..304e922 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/SvdrpProgressDialog.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/SvdrpProgressDialog.java @@ -22,7 +22,6 @@ public class SvdrpProgressDialog extends ProgressDialog implements this.client = client; progress = new ProgressDialog(activity); progress.setOnCancelListener(this); - progress.setCancelable(false); } public void svdrpEvent(final SvdrpEvent event) { @@ -74,10 +73,8 @@ public class SvdrpProgressDialog extends ProgressDialog implements } private void abort() { - if (client.isConnected()) { - client.abort(); - dismiss(); - } + client.abort(); + dismiss(); } public void dismiss() { diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java index 46c8e9d..9553fd5 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java @@ -36,20 +36,20 @@ public abstract class SvdrpClient { /** listener */ private final List> listeners = new ArrayList>(); /** list of results */ - //private final List results = new ArrayList(); + // private final List results = new ArrayList(); /** should the listener be informed about each received result */ - //private boolean resultInfoEnabled = false; + // private boolean resultInfoEnabled = false; /** * @return true if the client has result */ -// public boolean hasResults(){ -// return results.isEmpty() == false; -// } + // public boolean hasResults(){ + // return results.isEmpty() == false; + // } private Timer watchDog = new Timer(); - - public boolean isConnected(){ - if(socket == null){ + + public boolean isConnected() { + if (socket == null) { return false; } return socket.isConnected(); @@ -111,17 +111,10 @@ public abstract class SvdrpClient { public void abort() { abort = true; try { - if (socket != null) { - if (socket.isConnected()) { - socket.shutdownInput(); - socket.shutdownOutput(); - socket.close(); - } else { - if(st != null){ - st.interrupt(); - } - socket.close(); - } + if (isConnected()) { + socket.shutdownInput(); + socket.shutdownOutput(); + socket.close(); } } catch (Exception ex) { Log.w(TAG, ex); @@ -129,17 +122,15 @@ public abstract class SvdrpClient { } -// /** -// * Gets the list of results -// * -// * @return results -// */ -// public List getResults() { -// return results; -// } - - private Thread st; - + // /** + // * Gets the list of results + // * + // * @return results + // */ + // public List getResults() { + // return results; + // } + /** * Connect to SVDRP * @@ -159,31 +150,14 @@ public abstract class SvdrpClient { // connect informListener(SvdrpEvent.CONNECTING, null); socket = new Socket(); - //st = new Thread(){ -// @Override -// public void run() { -// try{ - socket.connect( - new InetSocketAddress(prefs.getSvdrpHost(), prefs - .getSvdrpPort()), - prefs.getConnectionTimeout() * 1000);// 8 secs for connect -// }catch(IOException iox){ -// throw new RuntimeException(); -// } -// } -// -// }; - -// st.start(); -// -// try { -// st.join(); -// } catch (InterruptedException e) { -// Thread.currentThread().interrupt(); -// // TODO Auto-generated catch block -// e.printStackTrace(); -// } -// + socket.connect( + new InetSocketAddress(prefs.getSvdrpHost(), prefs + .getSvdrpPort()), + prefs.getConnectionTimeout() * 1000);// 8 secs for connect + if(abort){ + informListener(SvdrpEvent.ABORTED, null); + } + // socket.setSoTimeout(prefs.getReadTimeout() * 1000);// 15 sec for // each read final long delay = C.ONE_MINUTE_IN_MILLIS * prefs.getTimeout() * 60; // in @@ -301,7 +275,7 @@ public abstract class SvdrpClient { abort = false; // clear results - //results.clear(); + // results.clear(); // connect final boolean connected = connect(); @@ -355,10 +329,10 @@ public abstract class SvdrpClient { break; } if (result != null) { - //results.add(result); - //if (resultInfoEnabled) { - informListener(SvdrpEvent.RESULT_RECEIVED, result); - //} + // results.add(result); + // if (resultInfoEnabled) { + informListener(SvdrpEvent.RESULT_RECEIVED, result); + // } } } @@ -379,9 +353,9 @@ public abstract class SvdrpClient { } } -// public void setResultInfoEnabled(final boolean resultInfoEnabled) { -// this.resultInfoEnabled = resultInfoEnabled; -// } + // public void setResultInfoEnabled(final boolean resultInfoEnabled) { + // this.resultInfoEnabled = resultInfoEnabled; + // } protected void informListenerError(final SvdrpEvent event, final Throwable result) { -- cgit v1.2.3