FileDocCategorySizeDatePackage
IrOBEXControl.javaAPI DocphoneME MR2 API (J2ME)4298Wed May 02 18:00:30 BST 2007com.sun.midp.io.j2me.irdaobex

IrOBEXControl

public final class IrOBEXControl extends Object
Performs the IrOBEX initialization, handles the device hint bits state, and responsible for device/service discovery process.

Fields Summary
Constructors Summary
public IrOBEXControl()
Default constructor.

    
Methods Summary
public IrOBEXConnectioncreateClientConnection(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.

param
hints hint bits required to be set on the device
param
ias services required to be provided by the device
return
IrOBEXConnection object
exception
IOException if something goes wrong

	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 IrOBEXNotifiercreateServerConnection(int hints, java.lang.String[] ias)
Creates the IrOBEX server notifier object by passing an underlying connection notifier.

param
hints hint bits
param
ias service class names separated by comma
return
IrOBEXNotifier object
exception
IOException if something goes wrong

	return new IrOBEXNotifier(new IrNativeNotifier(hints, ias));