altos: AltosSerial.flush_input shouldn't discard Interrupted exceptions
authorKeith Packard <keithp@keithp.com>
Sun, 14 Aug 2011 04:10:15 +0000 (21:10 -0700)
committerKeith Packard <keithp@keithp.com>
Sun, 14 Aug 2011 04:10:15 +0000 (21:10 -0700)
The eeprom download code wants to interrupt serial communication so
that it can stop downloading stuff in the middle of a run. Make
flush_input pass the exception along instead of discarding it.

Signed-off-by: Keith Packard <keithp@keithp.com>
altosui/AltosDebug.java
altosui/AltosEepromDelete.java
altosui/AltosEepromDownload.java
altosui/AltosEepromManage.java
altosui/AltosSerial.java

index 8d435b667d5ecb584b118bed27a5d9945b4abb92..d18de80d09d36e0fe9d84f0652f79bbdbd533d5a 100644 (file)
@@ -62,7 +62,10 @@ public class AltosDebug extends AltosSerial {
        void ensure_debug_mode() {
                if (!debug_mode) {
                        printf("D\n");
-                       flush_input();
+                       try {
+                               flush_input();
+                       } catch (InterruptedException ie) {
+                       }
                        debug_mode = true;
                }
        }
index cd9abfabc02fcf3b00e25f8324cb9f35ca6bd67c..a9d77788d06f84be4800ae0d8d4fb4255bb6ff99 100644 (file)
@@ -104,10 +104,14 @@ public class AltosEepromDelete implements Runnable {
                                                  serial_line.device.toShortString()),
                                    "Connection Failed");
                } finally {
-                       if (remote)
-                               serial_line.stop_remote();
-                       serial_line.flush_output();
-                       serial_line.close();
+                       try {
+                               if (remote)
+                                       serial_line.stop_remote();
+                       } catch (InterruptedException ie) {
+                       } finally {
+                               serial_line.flush_output();
+                               serial_line.close();
+                       }
                }
                if (listener != null) {
                        Runnable r = new Runnable() {
index b44a1451b241db864a3790df8ff00389e95678a3..358ad337900e204435726f005cd529a299fc20ab 100644 (file)
@@ -373,8 +373,12 @@ public class AltosEepromDownload implements Runnable {
                                     "Connection Failed",
                                     JOptionPane.ERROR_MESSAGE);
                } finally {
-                       if (remote)
-                               serial_line.stop_remote();
+                       if (remote) {
+                               try {
+                                       serial_line.stop_remote();
+                               } catch (InterruptedException ie) {
+                               }
+                       }
                        serial_line.flush_output();
                }
                monitor.done();
index 0652ca0498c06a401a589dbc838ff35a2648399a..2e5206280b1e308e5aef46d5358faefc4b769835 100644 (file)
@@ -44,7 +44,10 @@ public class AltosEepromManage implements ActionListener {
 
        public void finish() {
                if (serial_line != null) {
-                       serial_line.flush_input();
+                       try {
+                               serial_line.flush_input();
+                       } catch (InterruptedException ie) {
+                       }
                        serial_line.close();
                        serial_line = null;
                }
index b089c9c40c580beb7764135fb0c3ead7be9a374a..f0e25fa56dd110e697e34db7566e0816862ad55a 100644 (file)
@@ -187,7 +187,7 @@ public class AltosSerial implements Runnable {
                return abort;
        }
 
-       public void flush_input() {
+       public void flush_input() throws InterruptedException {
                flush_output();
                boolean got_some;
 
@@ -195,10 +195,7 @@ public class AltosSerial implements Runnable {
                if (remote)
                        timeout = 500;
                do {
-                       try {
-                               Thread.sleep(timeout);
-                       } catch (InterruptedException ie) {
-                       }
+                       Thread.sleep(timeout);
                        got_some = !reply_queue.isEmpty();
                        synchronized(this) {
                                if (!"VERSION".startsWith(line) &&
@@ -271,8 +268,12 @@ public class AltosSerial implements Runnable {
        }
 
        public void close() {
-               if (remote)
-                       stop_remote();
+               if (remote) {
+                       try {
+                               stop_remote();
+                       } catch (InterruptedException ie) {
+                       }
+               }
                if (in_reply != 0)
                        System.out.printf("Uh-oh. Closing active serial device\n");
 
@@ -422,7 +423,7 @@ public class AltosSerial implements Runnable {
                remote = true;
        }
 
-       public void stop_remote() {
+       public void stop_remote() throws InterruptedException {
                if (debug)
                        System.out.printf("stop remote\n");
                try {