FileDocCategorySizeDatePackage
NamsNotifier.javaAPI DocphoneME MR2 API (J2ME)8492Wed May 02 18:00:04 BST 2007com.sun.midp.main

NamsNotifier

public class NamsNotifier extends Object implements com.sun.midp.events.EventListener
Works as a simple (display) manager to test NAMS.

Fields Summary
private Object[]
syncState
array of sync objects for midlet state change notifications - one per midlet/per state
private Object[]
syncFG
array of sync objects for display FG notifications - one per midlet
private Object
syncBG
array 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 voidinitNamsNotifier(int isolateId)
initializes native part of NamsNotifier

param
isolateId isolate where NamsNotifier is run (where to sent events)

public booleanpreprocess(com.sun.midp.events.Event event, com.sun.midp.events.Event waitingEvent)
event preprocessing event routine - empty

param
event event to check
param
waitingEvent event to compare with
return
always returns true

        return true;
    
public voidprocess(com.sun.midp.events.Event event)
main event event processing event routine

param
event event to process

        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 booleanwaitForBG(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 booleanwaitForFG(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 booleanwaitForState(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;