Fields Summary |
---|
private int | handleInteger handle that identifies notifier at native level. |
private static com.sun.midp.security.SecurityToken | internalSecurityTokenInternal security token that grants access to restricted API. |
DeviceEmul | deviceDevice this notifier works at. |
com.sun.midp.io.j2me.serversocket.Socket | serverSocketServer socet to accept connections. |
static int | nextSocketPortnext free socket port. |
private ServiceConnectionData | serviceDataKeeps options of service connection string used for this
notifier creation. |
int | portPSM or channel id. |
private ConnectionEmul | clientConnectionAn emulation of client connection. |
Acceptor | acceptorCurrent connection acceptor, null if there is no one. |
private static final byte | NOTIF_ACCEPTAccept request code. |
private static final byte | NOTIF_CLOSEClose request code. |
private static final byte | NOTIF_INITInitialize request code. |
Methods Summary |
---|
public void | close()Closes the notifier (emulation).
if (acceptor != null) {
acceptor.interrupt();
acceptor = null;
}
if (serverSocket != null) {
try {
serverSocket.close();
} catch (IOException e) {
error();
}
serverSocket = null;
}
clientConnection = null;
ConnRegistry.getInstance().unregister(handle);
if (-1 != serviceData.socketPort) {
device.unregisterService(serviceData.socketPort);
}
|
private void | error()Rgisters error occued to pass it to code above the porting layer./*need revisit*/
|
public void | initialize(ServiceConnectionData serviceData)Initializes this notifier emulation unit.
this.serviceData = serviceData;
serverSocket = new Socket();
success:
{
final int maxTrials = 32;
for (int i = 0; i < maxTrials; i++, nextSocketPort++) {
try {
serverSocket.open(nextSocketPort, internalSecurityToken);
} catch (IOException e) {
// consider port is busy and just continue trials
continue;
}
serviceData.socketPort = nextSocketPort++;
break success;
}
error();
}
|
private native void | notifyAccepted(int thisHandle, int connHandle, byte[] peerAddr, int receiveMTU, int transmitMTU)Notifies porting layer on completing acception.
|
public void | process(BytePack request)Processes request from porting layer to emulation.
switch(request.extract()) {
case NOTIF_ACCEPT:
Log.log("processing NOTIF_ACCEPT");
startAccept();
Log.log("processing NOTIF_ACCEPT done");
break;
case NOTIF_CLOSE:
Log.log("processing NOTIF_CLOSE");
close();
Log.log("processing NOTIF_CLOSE done");
break;
case NOTIF_INIT:
Log.log("processing NOTIF_INIT");
initialize(new ServiceConnectionData(
request.extractBytes(ServiceConnectionData.SERVER_DATA_SIZE),
ServiceConnectionData.SERVER_DATA));
Log.log("processing NOTIF_INIT done");
break;
default:
throw new EmulationException("Unknown Notifier request");
}
|
public void | startAccept()Starts accepting incoming connection.
IMPL_NOTE it should completely substitute accept() when moving emul
below porting layer completed
acceptor = new Acceptor();
acceptor.start();
try {
device.registerService(serviceData);
} catch (IOException e) {
error();
// IMPL_NOTE
// add e details;
}
|