Read-only archive of the All About Symbian forum (2001–2013) · About this archive

Asynchronous Event Handling - bugs in OPL for v6/S80

0 replies · 2,496 views · Started 02 October 2003

The following is an application template which works both for v5/Eikon (in which we have used this structure in several applications) and v6/S80 (in which we have used it for one application). It has been tested on:

- Psion netBook (v5/Eikon)
- WINS for v5/Eikon
- WINS for v6/S80
- Nokia 9210 (v6/S80)

When running in v5/Eikon, it works as expected and no stray signals are ever generated.

When running in v6/S80, lots of stray signals are generated. Furthermore, if not two IOSIGNAL are added to the stray signal handling, the application will hang after a while. Therefore, we had to add a KAddSomeExtraIoSignalB% which should be set to KFalse% in v5/Eikon and to KTrue% in v6/S80.

We have not tried this in v6.1/S60 yet.

We think that asynchronous event handling is a very important part of OPL. It has been indicated before that v6/S80 is quite flaky in this area but we hope to be able to identify where the problems are in order to make it better going forward.

cheers
Martin

(sorry, all the indentations were removed after posting, don't know how to get them back. An indented version is available as dpNote0028 at www.dp.com.my)

REM // Asynchronous Event Handling
REM // Getevent loop with non-activity timer
REM // - can be used for 'screensavers' etc
REM // 19/6/2003 Digital Progress Pte Ltd
REM // www.dp.com.my

INCLUDE "Const.oph"
INCLUDE "System.oxh"

REM // select platform before compilation
rem CONST KSymbianOsVersion$="v5/Eikon"
CONST KSymbianOsVersion$="v6/S80"
rem CONST KSymbianOsVersion$="v6/S60"
rem CONST KSymbianOsVersion$="v7/UIQ"
rem CONST KSymbianOsVersion$="v7/S60"

CONST KTimeOut%=5 REM // seconds
CONST KTimerStart&=0 REM // reset timer

REM // needs to be set KTrue% for v6/S80
REM // otherwise application will hang
REM // but should not be needed were OPL for v6/S80 bugfree
CONST KAddSomeExtraIoSignalB%=KTrue%

PROC Main:
LOCAL t$(KMaxStringLen%),a$(KMaxStringLen%),b$(KMaxStringLen%)
t$="Eventloop with non-activity timer"
a$="This is a template for application"+NewLine$:+"development"
b$=NewLine$:+"This machine is: "+GetMachineName$:
InfoDialogue😞t$,a$,b$)
EventLoopA:
ENDP

PROC EventLoopA:
LOCAL ev&(16),EventStatus%
LOCAL TimeOut&,hTimer%,TimerStatus%,TimerReturn%
LOCAL StraySignalCount%
LOCAL ForeGroundB%
REM // program starts in foreground
ForeGroundB%=KTrue%
REM // reset stray signal counter
StraySignalCount%=0
REM // create a timer
IOOPEN(hTimer%,KIOTimer$,KIOModeDeviceOnly%)
REM // ensure at least one loop
ev&(1)=0
WHILE ev&(1)<>KKeyEsc%
REM // set async
GETEVENTA32 EventStatus%,ev&()
REM // set timer only if in foreground
IF ForeGroundB%
TimeOut&=KTimeOut%*10
TimerReturn%=IOC(hTimer%,1,TimerStatus%,TimeOut&,#KTimerStart&😉
ENDIF
REM // wait for something to happen
IOWAIT
IF EventStatus%<>KStatusPending% REM // event
REM // cancel timer only if in foreground, i.e. if it has been
REM // initialised earlier
IF ForeGroundB%
IOCANCEL(hTimer%)
IOWAITSTAT hTimer%
ENDIF
REM // handle input events
IF ev&(KEvType%)=KEvFocusLost& REM // program moved to background
Message😞"Disappearing..."😉
rem HotKeyHandler:
ForeGroundB%=KFalse%
ELSEIF ev&(KEvType%)=KEvFocusGained& REM // program moved to foreground
Message😞"Reappearing..."😉
ForeGroundB%=KTrue%
ELSEIF ev&(KEvType%)=KEvDateChanged&
Message😞"Tempus fugit..."😉
ELSE REM // data input event
IF (ev&(KEvType%)<>KEvKeyDown& AND ev&(KEvType%)<>KEvKeyUp&😉
IF (ev&(KEvType%)<>KEvPtr&😉 AND (ev&(KEvType%)<>KEvPtrEnter&😉 AND (ev&(KEvType%)<>KEvPtrExit&😉
REM // replaces (ev&(KEvType%) AND KEvNotKeyMask&😉=0
EventKeyProcess😞ev&(KEvType%),ev&(KEvMod%),ev&(KEvScan%))
ELSE
EventPenProcess😞ev&(KEvWinID%),ev&(KEvPtrType%),ev&(KEvPtrX%),ev&(KEvPtrY%))
ENDIF
ENDIF
ENDIF
ELSEIF TimerStatus%<>KStatusPending% REM // time out
GETEVENTC(EventStatus%)
TimeOutProcess:
ELSE REM // stray signal
MessageLeft😞"Stray signal count = "+GEN$(StraySignalCount%,5))
StraySignalCount%=StraySignalCount%+1
GETEVENTC(EventStatus%)
IF ForeGroundB%
IOCANCEL(hTimer%)
IOWAITSTAT hTimer%
ENDIF
IF KAddSomeExtraIoSignalB%
IOSIGNAL :IOSIGNAL
ENDIF
ENDIF REM // end of async status checks
ENDWH
REM // put stray signals back again
WHILE StraySignalCount%>0
IOSIGNAL
StraySignalCount%=StraySignalCount%-1
ENDWH
Info😞"Finished"😉
ENDP

PROC EventKeyProcess😞aKeyType&,aKeyMod&,aKeyScan&😉
Message😞"Key "+HEX$(aKeyType&😉+" "+HEX$(aKeyMod&😉)
ENDP

PROC EventPenProcess😞aPtrWID&,aPtrType&,aPtrX&,aPtrY&😉
Message😞"Pen "+GEN$(aPtrWID&,2)+" "+GEN$(aPtrX&,3)+" "+GEN$(aPtrY&,3))
ENDP

PROC TimeOutProcess:
Message😞"Time out!"😉
ENDP

PROC ___standard_stuff: :ENDP

PROC Message😞aMsg$)
gIPRINT aMsg$,KBusyTopRight%
ENDP

PROC MessageLeft😞aMsg$)
gIPRINT aMsg$,KBusyTopLeft%
ENDP

PROC Info😞aText$)
InfoDialogue😞aText$,"",""😉
ENDP

PROC InfoDialogue😞aTitle$,aLine1$,aLine2$)
LOCAL Title$(KMaxStringLen%),Text$(KMaxStringLen%)
LOCAL choice%
IF aTitle$="Error"
dINIT "Error"
dTEXT "",ERRX$,KdTextCentre%
dTEXT "",ERR$(ERR),KdTextCentre%
GOTO Lbl_Dialog::
ELSEIF aTitle$=""
Title$="Note"
ELSE
Title$=aTitle$
ENDIF
Text$=aLine1$
IF aLine2$<>""
Text$=Text$+NewLine$:+aLine2$
ENDIF
dINIT Title$
IF Text$<>""
dTEXT "",Text$
ENDIF
Lbl_Dialog::
dBUTTONS "Close",KKeyEnter%
LOCK ON :choice%=DIALOG :LOCK OFF
ENDP

PROC NewLine$:
RETURN CHR$(10) REM CHR$(KLineFeed&😉
ENDP

PROC GetMachineType&:
LOCAL value&,return&
value&=0
return&=SyGetHAL&😞KSyMachineUID&,value&😉
RETURN value&
ENDP

PROC GetMachineName$:
LOCAL value&
IF KSymbianOsVersion$="v5/Eikon"
RETURN MachineName$:
ENDIF
value&=GetMachineType&:
IF value&=&10005f62 REM // KSyMachineUid_Win32Emulator&
RETURN "Win32 ER6 Emulator"
ELSEIF value&=&10005e33 REM // KSyMachineUid_Linda&
RETURN "Nokia 9200 Series"
ELSEIF value&=&1000118a REM // KSyMachineUid_Series5mx&
RETURN "Psion Series 5mx"
ELSE
RETURN "unknown"
ENDIF
ENDP