Removed a redundant variable.

The offHook flag was equivalent to reliabilityLayer != null.
This commit is contained in:
akwizgran
2012-12-14 19:42:55 +00:00
parent 0bfa4f15a1
commit 6e567e1e55

View File

@@ -36,9 +36,8 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
private int lineLen = 0; private int lineLen = 0;
// All of the following are locking: this private ReliabilityLayer reliabilityLayer = null; // Locking: this
private ReliabilityLayer reliabilityLayer = null; private boolean initialised = false, connected = false; // Locking: this
private boolean initialised = false, offHook = false, connected = false;
ModemImpl(Executor executor, Callback callback, String portName) { ModemImpl(Executor executor, Callback callback, String portName) {
this.executor = executor; this.executor = executor;
@@ -145,18 +144,17 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
private void hangUpInner() throws IOException { private void hangUpInner() throws IOException {
ReliabilityLayer reliabilityLayer; ReliabilityLayer reliabilityLayer;
synchronized(this) { synchronized(this) {
if(!offHook) { if(this.reliabilityLayer == null) {
if(LOG.isLoggable(INFO)) if(LOG.isLoggable(INFO))
LOG.info("Not hanging up - already on the hook"); LOG.info("Not hanging up - already on the hook");
return; return;
} }
if(LOG.isLoggable(INFO)) LOG.info("Hanging up");
reliabilityLayer = this.reliabilityLayer; reliabilityLayer = this.reliabilityLayer;
this.reliabilityLayer = null; this.reliabilityLayer = null;
offHook = false;
connected = false; connected = false;
} }
reliabilityLayer.stop(); reliabilityLayer.stop();
if(LOG.isLoggable(INFO)) LOG.info("Hanging up");
try { try {
port.setDTR(false); port.setDTR(false);
} catch(SerialPortException e) { } catch(SerialPortException e) {
@@ -179,13 +177,12 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
LOG.info("Not dialling - modem not initialised"); LOG.info("Not dialling - modem not initialised");
return false; return false;
} }
if(offHook) { if(this.reliabilityLayer != null) {
if(LOG.isLoggable(INFO)) if(LOG.isLoggable(INFO))
LOG.info("Not dialling - call in progress"); LOG.info("Not dialling - call in progress");
return false; return false;
} }
this.reliabilityLayer = reliabilityLayer; this.reliabilityLayer = reliabilityLayer;
offHook = true;
} }
reliabilityLayer.start(); reliabilityLayer.start();
if(LOG.isLoggable(INFO)) LOG.info("Dialling"); if(LOG.isLoggable(INFO)) LOG.info("Dialling");
@@ -358,13 +355,12 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
LOG.info("Not answering - modem not initialised"); LOG.info("Not answering - modem not initialised");
return; return;
} }
if(offHook) { if(this.reliabilityLayer != null) {
if(LOG.isLoggable(INFO)) if(LOG.isLoggable(INFO))
LOG.info("Not answering - call in progress"); LOG.info("Not answering - call in progress");
return; return;
} }
this.reliabilityLayer = reliabilityLayer; this.reliabilityLayer = reliabilityLayer;
offHook = true;
} }
reliabilityLayer.start(); reliabilityLayer.start();
if(LOG.isLoggable(INFO)) LOG.info("Answering"); if(LOG.isLoggable(INFO)) LOG.info("Answering");