mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-22 15:49:53 +01:00
Removed polling semaphore (not needed - Modem.dial() will return false).
This commit is contained in:
@@ -14,7 +14,6 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.Semaphore;
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
@@ -43,7 +42,6 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
|
|||||||
private final SerialPortList serialPortList;
|
private final SerialPortList serialPortList;
|
||||||
private final DuplexPluginCallback callback;
|
private final DuplexPluginCallback callback;
|
||||||
private final long pollingInterval;
|
private final long pollingInterval;
|
||||||
private final Semaphore polling;
|
|
||||||
|
|
||||||
private volatile boolean running = false;
|
private volatile boolean running = false;
|
||||||
private volatile Modem modem = null;
|
private volatile Modem modem = null;
|
||||||
@@ -56,7 +54,6 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
|
|||||||
this.serialPortList = serialPortList;
|
this.serialPortList = serialPortList;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
this.pollingInterval = pollingInterval;
|
this.pollingInterval = pollingInterval;
|
||||||
polling = new Semaphore(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TransportId getId() {
|
public TransportId getId() {
|
||||||
@@ -132,58 +129,47 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
|
|||||||
|
|
||||||
private void poll() {
|
private void poll() {
|
||||||
if(!running) return;
|
if(!running) return;
|
||||||
if(!polling.tryAcquire()) {
|
// Get the ISO 3166 code for the caller's country
|
||||||
if(LOG.isLoggable(INFO))
|
String callerIso = callback.getLocalProperties().get("iso3166");
|
||||||
LOG.info("Previous poll still in progress");
|
if(StringUtils.isNullOrEmpty(callerIso)) return;
|
||||||
return;
|
// Call contacts one at a time in a random order
|
||||||
}
|
Map<ContactId, TransportProperties> remote =
|
||||||
try {
|
callback.getRemoteProperties();
|
||||||
// Get the ISO 3166 code for the caller's country
|
List<ContactId> contacts = new ArrayList<ContactId>(remote.keySet());
|
||||||
String callerIso = callback.getLocalProperties().get("iso3166");
|
Collections.shuffle(contacts);
|
||||||
if(StringUtils.isNullOrEmpty(callerIso)) return;
|
Iterator<ContactId> it = contacts.iterator();
|
||||||
// Call contacts one at a time in a random order
|
while(it.hasNext() && running) {
|
||||||
Map<ContactId, TransportProperties> remote =
|
ContactId c = it.next();
|
||||||
callback.getRemoteProperties();
|
// Get the ISO 3166 code for the callee's country
|
||||||
List<ContactId> contacts =
|
TransportProperties properties = remote.get(c);
|
||||||
new ArrayList<ContactId>(remote.keySet());
|
if(properties == null) continue;
|
||||||
Collections.shuffle(contacts);
|
String calleeIso = properties.get("iso3166");
|
||||||
Iterator<ContactId> it = contacts.iterator();
|
if(StringUtils.isNullOrEmpty(calleeIso)) continue;
|
||||||
while(it.hasNext() && running) {
|
// Get the callee's phone number
|
||||||
ContactId c = it.next();
|
String number = properties.get("number");
|
||||||
// Get the ISO 3166 code for the callee's country
|
if(StringUtils.isNullOrEmpty(number)) continue;
|
||||||
TransportProperties properties = remote.get(c);
|
// Convert the number into direct dialling form
|
||||||
if(properties == null) continue;
|
number = CountryCodes.translate(number, callerIso, calleeIso);
|
||||||
String calleeIso = properties.get("iso3166");
|
if(number == null) continue;
|
||||||
if(StringUtils.isNullOrEmpty(calleeIso)) continue;
|
// Dial the number
|
||||||
// Get the callee's phone number
|
try {
|
||||||
String number = properties.get("number");
|
if(!modem.dial(number)) continue;
|
||||||
if(StringUtils.isNullOrEmpty(number)) continue;
|
} catch(IOException e) {
|
||||||
// Convert the number into direct dialling form
|
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||||
number = CountryCodes.translate(number, callerIso, calleeIso);
|
if(resetModem()) continue;
|
||||||
if(number == null) continue;
|
break;
|
||||||
// Dial the number
|
}
|
||||||
try {
|
if(LOG.isLoggable(INFO)) LOG.info("Outgoing call connected");
|
||||||
if(!modem.dial(number)) continue;
|
ModemTransportConnection conn = new ModemTransportConnection();
|
||||||
} catch(IOException e) {
|
callback.outgoingConnectionCreated(c, conn);
|
||||||
if(LOG.isLoggable(WARNING))
|
try {
|
||||||
LOG.log(WARNING, e.toString(), e);
|
conn.waitForDisposal();
|
||||||
if(resetModem()) continue;
|
} catch(InterruptedException e) {
|
||||||
break;
|
if(LOG.isLoggable(WARNING))
|
||||||
}
|
LOG.warning("Interrupted while polling");
|
||||||
if(LOG.isLoggable(INFO)) LOG.info("Outgoing call connected");
|
Thread.currentThread().interrupt();
|
||||||
ModemTransportConnection conn = new ModemTransportConnection();
|
break;
|
||||||
callback.outgoingConnectionCreated(c, conn);
|
|
||||||
try {
|
|
||||||
conn.waitForDisposal();
|
|
||||||
} catch(InterruptedException e) {
|
|
||||||
if(LOG.isLoggable(WARNING))
|
|
||||||
LOG.warning("Interrupted while polling");
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
polling.release();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user