diff options
| author | Keith Packard <keithp@keithp.com> | 2013-12-07 09:53:10 -0800 | 
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2013-12-07 09:53:10 -0800 | 
| commit | 407696f11ac1736e840c9b702592c46197d14c2c (patch) | |
| tree | 34c77c25a41e4f5097a6addccec725ce19454e45 | |
| parent | 1a47532f411488f003726aa9365ede5dc90c5b78 (diff) | |
altosui: Clean up serial close handling
Unify serial close processing in a single function (close_serial),
make everyone else call that. This avoids a couple of cases where the
device would be closed and not removed from the devices_opened list,
leading to 'device is already in use' messages.
Signed-off-by: Keith Packard <keithp@keithp.com>
| -rw-r--r-- | altosui/AltosSerial.java | 34 | 
1 files changed, 16 insertions, 18 deletions
| diff --git a/altosui/AltosSerial.java b/altosui/AltosSerial.java index 697ad539..491b6e81 100644 --- a/altosui/AltosSerial.java +++ b/altosui/AltosSerial.java @@ -57,11 +57,8 @@ public class AltosSerial extends AltosLink  {  	public void flush_output() {  		super.flush_output();  		if (altos != null) { -			if (libaltos.altos_flush(altos) != 0) { -				libaltos.altos_close(altos); -				altos = null; -				abort_reply(); -			} +			if (libaltos.altos_flush(altos) != 0) +				close_serial();  		}  	} @@ -122,6 +119,17 @@ public class AltosSerial extends AltosLink  {  		SwingUtilities.invokeLater(r);  	} +	private void close_serial() { +		synchronized (devices_opened) { +			devices_opened.remove(device.getPath()); +		} +		if (altos != null) { +			libaltos.altos_free(altos); +			altos = null; +		} +		abort_reply(); +	} +  	public void close() {  		if (remote) {  			try { @@ -132,9 +140,8 @@ public class AltosSerial extends AltosLink  {  		if (in_reply != 0)  			System.out.printf("Uh-oh. Closing active serial device\n"); -		if (altos != null) { -			libaltos.altos_close(altos); -		} +		close_serial(); +  		if (input_thread != null) {  			try {  				input_thread.interrupt(); @@ -143,13 +150,6 @@ public class AltosSerial extends AltosLink  {  			}  			input_thread = null;  		} -		if (altos != null) { -			libaltos.altos_free(altos); -			altos = null; -		} -		synchronized (devices_opened) { -			devices_opened.remove(device.getPath()); -		}  		if (debug)  			System.out.printf("Closing %s\n", device.getPath());  	} @@ -157,9 +157,7 @@ public class AltosSerial extends AltosLink  {  	private void putc(char c) {  		if (altos != null)  			if (libaltos.altos_putchar(altos, c) != 0) { -				libaltos.altos_close(altos); -				altos = null; -				abort_reply(); +				close_serial();  			}  	} | 
