diff --git a/briar-core/libs/jssc-0.9-briar.jar b/briar-core/libs/jssc-0.9-briar.jar index e977fe43f8f79abde82413a41ea140a5b6c2cdbf..3c4ae47c7c60ac49e6d25798daecba9eabc0cd83 100644 Binary files a/briar-core/libs/jssc-0.9-briar.jar and b/briar-core/libs/jssc-0.9-briar.jar differ diff --git a/briar-core/src/net/sf/briar/plugins/modem/Modem.java b/briar-core/src/net/sf/briar/plugins/modem/Modem.java index 87ac4532c0fc6348c0f953494a56a607b2383ebe..ffb372f9831c1a4c9b7e6d912a921ff757d6735a 100644 --- a/briar-core/src/net/sf/briar/plugins/modem/Modem.java +++ b/briar-core/src/net/sf/briar/plugins/modem/Modem.java @@ -13,7 +13,13 @@ interface Modem { /** * Call this method after creating the modem and before making any calls. */ - void init() throws IOException; + void start() throws IOException; + + /** + * Call this method when the modem is no longer needed. If a call is in + * progress it will be terminated. + */ + void stop() throws IOException; /** * Initiates an outgoing call and returns true if the call connects. If the diff --git a/briar-core/src/net/sf/briar/plugins/modem/ModemImpl.java b/briar-core/src/net/sf/briar/plugins/modem/ModemImpl.java index 2576d7dacdbccb23211ae734b3cab7d0e2e4a92e..633ac118121e021859692ab38f07bc02a4c48119 100644 --- a/briar-core/src/net/sf/briar/plugins/modem/ModemImpl.java +++ b/briar-core/src/net/sf/briar/plugins/modem/ModemImpl.java @@ -51,7 +51,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener { reliabilityLayer = new ReliabilityLayer(this); } - public void init() throws IOException { + public void start() throws IOException { if(LOG.isLoggable(INFO)) LOG.info("Initialising"); try { if(!port.openPort()) @@ -90,6 +90,14 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener { throw new IOException("Modem did not respond"); } + public void stop() throws IOException { + try { + port.closePort(); + } catch(SerialPortException e) { + throw new IOException(e.toString()); + } + } + public boolean dial(String number) throws IOException { if(!offHook.tryAcquire()) { if(LOG.isLoggable(INFO)) @@ -178,9 +186,8 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener { if(LOG.isLoggable(INFO)) LOG.info("Modem status: " + s); if(s.startsWith("CONNECT")) { synchronized(connected) { - if(connected.getAndSet(true)) - throw new IOException("Connected twice"); - connected.notifyAll(); + if(!connected.getAndSet(true)) + connected.notifyAll(); } // There might be data in the buffer as well as text int off = i + 1; @@ -190,6 +197,10 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener { reliabilityLayer.handleRead(data); } return; + } else if(s.equals("BUSY") || s.equals("NO DIALTONE")) { + synchronized(connected) { + connected.notifyAll(); + } } else if(s.equals("OK")) { synchronized(initialised) { if(!initialised.getAndSet(true)) diff --git a/briar-core/src/net/sf/briar/plugins/modem/ModemPlugin.java b/briar-core/src/net/sf/briar/plugins/modem/ModemPlugin.java index 1b65b619edea878aea13e5a3c2806e4fd4510099..eaa8536bddfa7bf01106436b7cb919a5d31ac9ba 100644 --- a/briar-core/src/net/sf/briar/plugins/modem/ModemPlugin.java +++ b/briar-core/src/net/sf/briar/plugins/modem/ModemPlugin.java @@ -72,7 +72,7 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback { LOG.info("Trying to initialise modem on " + portName); modem = modemFactory.createModem(this, portName); try { - modem.init(); + modem.start(); if(LOG.isLoggable(INFO)) LOG.info("Initialised modem on " + portName); running = true; @@ -86,6 +86,13 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback { public void stop() { running = false; + if(modem != null) { + try { + modem.stop(); + } catch(IOException e) { + if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e); + } + } } private boolean resetModem() { @@ -93,7 +100,7 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback { for(String portName : SerialPortList.getPortNames()) { modem = modemFactory.createModem(this, portName); try { - modem.init(); + modem.start(); if(LOG.isLoggable(INFO)) LOG.info("Initialised modem on " + portName); return true;