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>
public void finish() {
if (serial_line != null) {
public void finish() {
if (serial_line != null) {
- serial_line.flush_output();
+ serial_line.flush_input();
serial_line.close();
serial_line = null;
}
serial_line.close();
serial_line = null;
}
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
boolean success = e.getID() != 0;
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) {
System.out.printf("Eeprom manager action %s %d\n", cmd, e.getID());
if (cmd.equals("download")) {
if (success) {
}
} else if (cmd.equals("delete")) {
if (success) {
}
} else if (cmd.equals("delete")) {
if (success) {
serial_line.device.toShortString(),
JOptionPane.INFORMATION_MESSAGE);
}
serial_line.device.toShortString(),
JOptionPane.INFORMATION_MESSAGE);
}
+ if (!running)
+ finish();
}
public AltosEepromManage(JFrame given_frame) {
}
public AltosEepromManage(JFrame given_frame) {
+ boolean running = false;
+
frame = given_frame;
device = AltosDeviceDialog.show(frame, AltosDevice.product_any);
frame = given_frame;
device = AltosDeviceDialog.show(frame, AltosDevice.product_any);
* Start flight log download
*/
* Start flight log download
*/
+ running = true;
+ }
+ else if (any_delete) {
}
} catch (FileNotFoundException ee) {
JOptionPane.showMessageDialog(frame,
}
} catch (FileNotFoundException ee) {
JOptionPane.showMessageDialog(frame,
device.toShortString(),
ee.getLocalizedMessage(),
JOptionPane.ERROR_MESSAGE);
device.toShortString(),
ee.getLocalizedMessage(),
JOptionPane.ERROR_MESSAGE);
} catch (TimeoutException te) {
JOptionPane.showMessageDialog(frame,
String.format("Communications failed with \"%s\"",
device.toShortString()),
"Cannot open target device",
JOptionPane.ERROR_MESSAGE);
} catch (TimeoutException te) {
JOptionPane.showMessageDialog(frame,
String.format("Communications failed with \"%s\"",
device.toShortString()),
"Cannot open target device",
JOptionPane.ERROR_MESSAGE);
} catch (InterruptedException ie) {
} catch (InterruptedException ie) {
+ if (!running)
+ finish();