NamsNotifierpublic class NamsNotifier extends Object implements com.sun.midp.events.EventListenerWorks as a simple (display) manager to test NAMS. |
Fields Summary |
---|
private Object[] | syncStatearray of sync objects for midlet state change notifications -
one per midlet/per state | private Object[] | syncFGarray of sync objects for display FG notifications -
one per midlet | private Object | syncBGarray of sync objects for display BG notifications -
one for all midlets |
Constructors Summary |
---|
public NamsNotifier()public constructor.
registers itself as an event listener for TEST_EVENT
int i, j;
EventQueue eventQueue;
// appId = 0 is reserved for NamsManager itself
initNamsNotifier(MIDletSuiteUtils.getIsolateId());
// register self as the listener for
eventQueue = EventQueue.getEventQueue();
// if (eventQueue == null)
// Logging.report(Logging.ERROR, LogChannels.LC_CORE,
// "DEBUG: Notifier: constructor - event queue is null !!!");
eventQueue.registerEventListener(EventTypes.TEST_EVENT, this);
syncState = new Object[NamsStorage.NAMS_STORAGE_SIZE][6];
syncFG = new Object[NamsStorage.NAMS_STORAGE_SIZE];
syncBG = new Object();
for (i = 0; i < NamsStorage.NAMS_STORAGE_SIZE; ++i) {
for (j = 0; j < 6; ++j) {
syncState[i][j] = new Object();
}
syncFG[i] = new Object();
}
|
Methods Summary |
---|
private native void | initNamsNotifier(int isolateId)initializes native part of NamsNotifier
| public boolean | preprocess(com.sun.midp.events.Event event, com.sun.midp.events.Event waitingEvent)event preprocessing event routine - empty
return true;
| public void | process(com.sun.midp.events.Event event)main event event processing event routine
NativeEvent e = (NativeEvent)event;
int appId = e.intParam1;
int callbackId = e.intParam2;
int state = e.intParam3;
int reason = e.intParam4;
switch (callbackId) {
case 0:
/* BG callback - no parameters */
/*
Logging.report(Logging.WARNING, LogChannels.LC_CORE,
"DEBUG: Got Notification: {" +
"appId=-1, " +
"BG=" + callbackId + ", " +
"x, " +
"reason=" + reason + "}");
*/
synchronized (syncBG) {
syncBG.notifyAll();
}
break;
case 1:
/* FG callback */
if (appId < 0 || appId > NamsStorage.NAMS_STORAGE_SIZE) {
/*
Logging.report(Logging.WARNING, LogChannels.LC_CORE,
"DEBUG: Notifier: FG callback - " +
"index out of bounds ..." +
" " + appId);
*/
} else {
/*
Logging.report(Logging.WARNING, LogChannels.LC_CORE,
"DEBUG: Got Notification: {" +
" appId=" + appId + ", " +
"FG=" + callbackId + ", " +
"x, " +
"reason=" + reason + "}");
*/
synchronized (syncFG[appId]) {
syncFG[appId].notifyAll();
}
}
break;
case 2:
/* State callback */
if (appId < 0 || appId >= NamsStorage.NAMS_STORAGE_SIZE ||
state < 1 || state > 5) {
/*
Logging.report(Logging.WARNING, LogChannels.LC_CORE,
"DEBUG: Notifier: State callback - " +
"index out of bounds ..." +
" " + appId +
" " + state);
*/
} else {
/*
Logging.report(Logging.WARNING, LogChannels.LC_CORE,
"DEBUG: Got Notification: {" +
" appId=" + appId + ", " +
"STATE=" + callbackId + ", " +
"state=" + state + ", " +
"reason=" + reason + "}");
*/
synchronized (syncState[appId][state]) {
syncState[appId][state].notifyAll();
}
}
break;
}
| public boolean | waitForBG(long timeout)
boolean value = true;
synchronized (syncBG) {
try {
/*
Logging.report(Logging.ERROR, LogChannels.LC_CORE,
"DEBUG: Enter Waiting for BG");
*/
syncBG.wait(timeout);
} catch (InterruptedException ie) {
value = false;
} catch (IllegalMonitorStateException ime) {
Logging.report(Logging.ERROR, LogChannels.LC_CORE,
"Unexpected monitor exception");
}
}
return value;
| public boolean | waitForFG(int appId, long timeout)
boolean value = true;
synchronized (syncFG[appId]) {
try {
/*
Logging.report(Logging.ERROR, LogChannels.LC_CORE,
"DEBUG: Enter Waiting for appId=" + appId + "FG");
*/
syncFG[appId].wait(timeout);
} catch (InterruptedException ie) {
value = false;
} catch (IllegalMonitorStateException ime) {
Logging.report(Logging.ERROR, LogChannels.LC_CORE,
"Unexpected monitor exception");
}
}
return value;
| public boolean | waitForState(int appId, int state, long timeout)
boolean value = true;
synchronized (syncState[appId][state]) {
try {
/*
Logging.report(Logging.ERROR, LogChannels.LC_CORE,
"DEBUG: Enter Waiting for appId=" + appId +
" state=" + state);
*/
syncState[appId][state].wait(timeout);
} catch (InterruptedException ie) {
value = false;
} catch (IllegalMonitorStateException ime) {
Logging.report(Logging.ERROR, LogChannels.LC_CORE,
"Unexpected monitor exception");
}
}
return value;
|
|