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

IrNativeNotifier

public class IrNativeNotifier extends Object implements javax.microedition.io.StreamConnectionNotifier
Provides the implementation of a stream connection notifier for the IrDA protocol.

Fields Summary
private int
hints
Hint bits to be set by the server.
private String[]
ias
IAS services to be advertised by the server.
private int
peerHandle
Handle to peer connection. This handle is mainained until it is passed to IrNativeConnection to prevent resource leaks in case of VM termination. Only accessed from native code.
private int
dataHandle
Handle to native array containing connection handles, except for peer. Only accessed from native code.
private boolean
closeRq
Flag forcing acceptAndOpen() method to exit.
private final int
ACCEPT_RETRY_PERIOD
Period in milliseconds between connection attempts.
Constructors Summary
public IrNativeNotifier(int hints, String[] ias)
Class constructor.

param
hints hint bits
param
ias IAS string


       
     
	initialize();
    
	this.hints = hints;
	this.ias = ias;
    
Methods Summary
private native booleanaccept(int index)
Accepts a pending client connection.

param
index connection number starting from 0
return
true if the connection was established, false otherwise
throws
IOException if an I/O error occurs

public javax.microedition.io.StreamConnectionacceptAndOpen()
Returns a StreamConnection object that represents a server side connection.

return
a StreamConnection to communicate with a client
throws
IOException if an I/O error occurs

	try {
	    closeRq = false;
	    for (int i = 0; i < ias.length; i++) {
		listen(i, hints, ias[i]);
	    }
	    int i = 0;
	    while (!accept(i) && !closeRq) {
	        i = (i + 1) % ias.length;
	        try {
		    Thread.sleep(ACCEPT_RETRY_PERIOD);
		} catch (InterruptedException e) {
		    throw new InterruptedIOException(
		        "Operation was interrupted.");
		}
	    }
	    if (closeRq) {
		throw new IOException("Connection was closed.");
	    }
	    IrNativeConnection conn = new IrNativeConnection();
	    passPeer(conn);
	    return conn;
	} finally {
	    release();
	}
    
public voidclose()
Interrupts acceptAndOpen() operation.

throws
IOException if an I/O error occurs

	closeRq = true;
    
private native voidfinalize()
Native finalizer. Releases all native resources used by this notifier.

private static native intgetInvalidDataHandle()
Returns an invalid memory handle value to be used during initialization of instances of this class.

return
a native memory handle value considered to be invalid

private static native intgetInvalidPeerHandle()
Returns an invalid connection handle value to be used during initialization of instances of this class.

return
a native connection handle value considered to be invalid

private static native voidinitialize()
Native class initializer.

private native voidlisten(int index, int hints, java.lang.String ias)
Allocates native connection resource for listening with specified hint bits and IAS set.

param
index connection number starting from 0
param
hints hint bits to be set
param
ias IAS to be advertised
throws
IOException if an I/O error occurs

private native voidpassPeer(IrNativeConnection conn)
Passes ownership of the native peer handle to the IrNativeConnection object. peer is set to -1 after calling this method.

param
conn IrNativeConnection object to pass native peer handle to.

private native voidrelease()
Releases native resources.