IrOBEXControlpublic final class IrOBEXControl extends Object Performs the IrOBEX initialization, handles the device hint bits state, and
responsible for device/service discovery process. |
Constructors Summary |
---|
public IrOBEXControl()Default constructor.
|
Methods Summary |
---|
public IrOBEXConnection | createClientConnection(int hints, java.lang.String[] ias)Attempts to connect to the first device matches the criteria specified
(hint bits and IAS list). Cached devices are attempted first. If failed,
discovery process is initiated to update the cache, followed by another
connection attempt to a cached device. The procedure repeats until the
connection is established, or timout occurs.
if (ias.length == 0) {
throw new IllegalArgumentException();
}
IrNativeConnection[] connArray = new IrNativeConnection[ias.length];
for (int i = 0; i < ias.length; i++) {
connArray[i] = null;
}
int timeout = Integer.parseInt(Configuration.getProperty(
"com.sun.midp.io.j2me.irdaobex.DiscoveryTimeout"));
int interval = Integer.parseInt(Configuration.getProperty(
"com.sun.midp.io.j2me.irdaobex.DiscoveryInterval"));
long end = System.currentTimeMillis() + timeout;
while (true) {
for (int i = 0; i < ias.length; i++) {
if (System.currentTimeMillis() + interval > end) {
throw new IOException(
"Could not establish connection.");
}
IrNativeConnection conn = connArray[i];
if (conn == null) {
conn = new IrNativeConnection();
connArray[i] = conn;
}
int[] addr;
try {
addr = conn.discover(hints, ias[i]);
} catch (IOException e) {
continue;
}
for (int j = 0; j < addr.length; j++) {
try {
while (!conn.connect(addr[j], ias[i])) {
if (System.currentTimeMillis() + interval > end) {
throw new IOException(
"Could not establish connection.");
}
try {
Thread.sleep(10);
} catch (InterruptedException e) {
throw new InterruptedIOException(
"Operation was interrupted.");
}
}
return new IrOBEXConnection(conn);
} catch (InterruptedIOException ie) {
throw ie;
} catch (IOException e) {
}
}
}
}
| public IrOBEXNotifier | createServerConnection(int hints, java.lang.String[] ias)Creates the IrOBEX server notifier object by passing an underlying
connection notifier.
return new IrOBEXNotifier(new IrNativeNotifier(hints, ias));
|
|