From 9d76c34ea607e8801d9165967a8e6e3493505215 Mon Sep 17 00:00:00 2001 From: git-vdr Date: Tue, 4 Oct 2011 01:36:11 +0200 Subject: some new states --- .../vdrmanager/utils/svdrp/SvdrpClient.java | 79 +++++++++++++++------- 1 file changed, 55 insertions(+), 24 deletions(-) (limited to 'vdrmanager/src/de/bjusystems') diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java index ffb8b7b..374e2de 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java @@ -8,16 +8,19 @@ import java.net.Socket; import java.util.ArrayList; import java.util.List; +import android.util.Log; import de.bjusystems.vdrmanager.data.Preferences; - /** * Class for SVDRP communication + * * @author bju - * + * */ public abstract class SvdrpClient { + private final String TAG = getClass().getName(); + /** Socket for connection to SVDRP */ private Socket socket; /** Output stream for sending commands */ @@ -35,7 +38,9 @@ public abstract class SvdrpClient { /** * Parse received answer line - * @param line line + * + * @param line + * line * @return received data object or null if not completed yet */ protected abstract Result parseAnswer(String line); @@ -46,10 +51,12 @@ public abstract class SvdrpClient { /** * Constructor - * @param prefs Preferences + * + * @param prefs + * Preferences */ protected SvdrpClient() { - results.clear(); + // results.clear(); } /** @@ -61,7 +68,9 @@ public abstract class SvdrpClient { /** * Adds the listener to the list of listeners - * @param listener listener + * + * @param listener + * listener */ public void addSvdrpListener(final SvdrpListener listener) { listeners.add(listener); @@ -69,7 +78,9 @@ public abstract class SvdrpClient { /** * Removes the listener from the list of listeners - * @param listener listener + * + * @param listener + * listener */ public void removeSvdrpListener(final SvdrpListener listener) { listeners.remove(listener); @@ -84,6 +95,7 @@ public abstract class SvdrpClient { /** * Gets the list of results + * * @return results */ public List getResults() { @@ -92,10 +104,15 @@ public abstract class SvdrpClient { /** * Connect to SVDRP - * @param host host - * @param port port - * @param ssl use SSL - * @throws IOException on errors + * + * @param host + * host + * @param port + * port + * @param ssl + * use SSL + * @throws IOException + * on errors */ protected boolean connect() throws IOException { @@ -107,6 +124,7 @@ public abstract class SvdrpClient { socket = new Socket(prefs.getSvdrpHost(), prefs.getSvdrpPort()); informListener(SvdrpEvent.CONNECTED, null); } catch (final IOException e) { + Log.w(TAG, e); informListener(SvdrpEvent.CONNECT_ERROR, null); return false; } @@ -131,7 +149,9 @@ public abstract class SvdrpClient { /** * Disconnect from SVDRP if connected - * @throws IOException on errors + * + * @throws IOException + * on errors */ protected void disconnect() throws IOException { informListener(SvdrpEvent.DISCONNECTING, null); @@ -144,8 +164,11 @@ public abstract class SvdrpClient { /** * Sends one line to SVDRP - * @param line line of text - * @throws IOException on errors + * + * @param line + * line of text + * @throws IOException + * on errors */ protected void writeLine(final String line) throws IOException { @@ -157,22 +180,24 @@ public abstract class SvdrpClient { /** * Reads one line from SVDRP + * * @return line read - * @throws IOException on errors + * @throws IOException + * on errors */ protected String readLine() throws IOException { // handle not gzipped input final ByteArrayOutputStream lineBytes = new ByteArrayOutputStream(); - for(;;) { + for (;;) { // read next char final int d = inputStream.read(); if (d < 0) { break; } - final char c = (char)d; + final char c = (char) d; // skip '\r' if (c == '\r') { @@ -219,7 +244,7 @@ public abstract class SvdrpClient { } // read answer lines - for(;!abort;) { + for (; !abort;) { // get next line line = readLine(); @@ -252,10 +277,11 @@ public abstract class SvdrpClient { // disconnect disconnect(); - } catch (final IOException e) { - throw new SvdrpException(e); - } finally { - informListener(SvdrpEvent.FINISHED, null); + informListener(SvdrpEvent.FINISHED_SUCCESS, null); + + } catch (final Exception e) { + // throw new SvdrpException(e); + informListener(SvdrpEvent.FINISHED_ABNORMALY, null); } } @@ -263,8 +289,13 @@ public abstract class SvdrpClient { this.resultInfoEnabled = resultInfoEnabled; } - private void informListener(final SvdrpEvent event, final Result result) { - for(final SvdrpListener listener : listeners) { + protected void informListenerError(final SvdrpEvent event, + final Throwable result) { + + } + + protected void informListener(final SvdrpEvent event, final Result result) { + for (final SvdrpListener listener : listeners) { listener.svdrpEvent(event, result); } } -- cgit v1.2.3