summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2011-01-16 14:30:38 -0800
committerKeith Packard <keithp@keithp.com>2011-01-16 14:30:38 -0800
commit1bfdce6fc3367fdf03e0dc7ddd94da18723b8ba3 (patch)
treec8a7289ef21f43bc1ef2581eaf6e9be9be652c7c
parent987039b8f0b1d889aca9109d4c6a83f034ff64a7 (diff)
altosui: Ensure serial device is closed after eeprom download finishes
As this code is all event-driven, track which events will trigger further work and block closing the device in those specific cases, ensuring that all other code paths end up closing the device. Signed-off-by: Keith Packard <keithp@keithp.com>
-rw-r--r--altosui/AltosEepromManage.java31
1 files changed, 17 insertions, 14 deletions
diff --git a/altosui/AltosEepromManage.java b/altosui/AltosEepromManage.java
index c7efe478..d10f7954 100644
--- a/altosui/AltosEepromManage.java
+++ b/altosui/AltosEepromManage.java
@@ -44,7 +44,7 @@ public class AltosEepromManage implements ActionListener {
public void finish() {
if (serial_line != null) {
- serial_line.flush_output();
+ serial_line.flush_input();
serial_line.close();
serial_line = null;
}
@@ -67,14 +67,15 @@ public class AltosEepromManage implements ActionListener {
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
boolean success = e.getID() != 0;
+ boolean running = false;
System.out.printf("Eeprom manager action %s %d\n", cmd, e.getID());
if (cmd.equals("download")) {
if (success) {
- if (any_delete)
+ if (any_delete) {
delete.start();
- else
- finish();
+ running = true;
+ }
}
} else if (cmd.equals("delete")) {
if (success) {
@@ -84,12 +85,15 @@ public class AltosEepromManage implements ActionListener {
serial_line.device.toShortString(),
JOptionPane.INFORMATION_MESSAGE);
}
- finish();
}
+ if (!running)
+ finish();
}
public AltosEepromManage(JFrame given_frame) {
+ boolean running = false;
+
frame = given_frame;
device = AltosDeviceDialog.show(frame, AltosDevice.product_any);
@@ -139,15 +143,15 @@ public class AltosEepromManage implements ActionListener {
* Start flight log download
*/
- if (any_download)
+ if (any_download) {
download.start();
- else if (any_delete)
+ running = true;
+ }
+ else if (any_delete) {
delete.start();
- else
- finish();
+ running = true;
+ }
}
- } else {
- finish();
}
} catch (FileNotFoundException ee) {
JOptionPane.showMessageDialog(frame,
@@ -166,17 +170,16 @@ public class AltosEepromManage implements ActionListener {
device.toShortString(),
ee.getLocalizedMessage(),
JOptionPane.ERROR_MESSAGE);
- finish();
} catch (TimeoutException te) {
JOptionPane.showMessageDialog(frame,
String.format("Communications failed with \"%s\"",
device.toShortString()),
"Cannot open target device",
JOptionPane.ERROR_MESSAGE);
- finish();
} catch (InterruptedException ie) {
- finish();
}
+ if (!running)
+ finish();
}
}
}