idlemax=900
capturetime=180
servertype='normal'
servermode='Variable Server'
IF lock('EXCLUSIVE',servermode)>0 THEN DO
SAY 'Server from location 'DIRECTORY()' already active, start aborted'
EXIT 8
END
lock('EXCLUSIVE',servermode'Start')
LIBRARY rexxgui
LIBRARY rxclip
LIBRARY rxconsole
guierr = "SYNTAX"
guiheading = 1
guicreatewindow('NORMAL')
ERROR = clipclear()
windowhandle = guiinfo("HANDLE", guiwindow)
nextwindow = clipinform(windowhandle)
again:
DO FOREVER
guigetmsg(,40000)
consay(,guiobject guisignal)
IF EXISTS('GuiObject') == 0 THEN DO
IF EXISTS('GuiSignal') THEN DO
END
END
ELSE DO
IF EXISTS('GuiSignal') == 0 THEN DROP (guiobject)
ELSE SELECT guiobject
WHEN 0 THEN NOP
OTHERWISE
END
END
CATCH NOVALUE
SAY 'Novalue Error occured'
CALL sysready
SIGNAL again
CATCH SYNTAX
SAY 'Syntax Error occured'
CALL sysready
SIGNAL again
CATCH HALT
FINALLY
guidestroywindow()
END
RETURN
wm_initdialog:
guigetctlplacement(guiwindow, , , "width", "height")
guigetctlplacement('ShutDown', "SayX", "SayY", "SayWidth", "SayHeight")
sayy = sayy+sayheight+5
height = height - sayy
concreate(, guiwindow, "CHILD", , sayy, width, height)
openfile=''
testmpin=0
mypid=GETPID()
consay(,ptime()' Variable Server Started ')
consay(,ptime()' Server PID is: 'mypid)
consay(,ptime()' Window handle: 'guiinfo("HANDLE", guiwindow))
capture=capturetime*1000
ERROR = guiaddctl("TIMER "capture)
CALL varserverini()
CALL divin()
consay(,ptime()' Variable Pool loaded')
dictin =clipnewformat('MPIN'DIRECTORY())
testmpin=1
keptdata.0=0
CALL sysini
consay(,ptime()' Server waiting for requests')
lock('RELEASE',servermode'Start')
RETURN ""
wm_drawclipboard:
DO
testmpin=testgetvar('TestMpin',0)
IF testmpin \== 0 THEN DO
IF clipavailable(dictin) THEN CALL getclip
END
testmpin=1
clipinformend(nextwindow)
END
RETURN ""
getclip:
starttime=TIME('R')
processstarttime=ptime()
savekept=0
clipget("MyVar.", dictin)
mprout=WORD(myvar.1,1)
INTERPRET myvar.2
CALL readparm()
consay(,COPIES('-',25))
consay(,ptime()' Received MPIN for 'mprout)
testmpin=0
CALL sysbusy()
IF servertype='DICTIONARY' THEN CALL ddcall()
ELSE CALL varrun()
execendtime=ptime()
CALL mprout(TIME('E'),myvar.3)
DROP option.
DROP cmd.
IF save=0 THEN consay(,ptime()' MPIN Processed, no update flag set')
ELSE consay(,ptime()' MPIN Processed, variables updated')
resettime=TIME('R')
CALL sysready()
RETURN
varrun:
SAY ptime() 'Requested call: 'myvar.3'('p.1','p.2','p.3','p.4','p.5')'
DROP mpout.
mpout.0=0
DO
CALL [myvar.3](p.1,p.2,p.3,p.4,p.5)
CATCH NOVALUE
CALL ERROR('Novalue Error occured')
CATCH SYNTAX
CALL ERROR('Syntax Error occured')
CATCH ERROR
CALL ERROR('Error condition occured')
CATCH FAILURE
CALL ERROR('Failure condition occured')
END
mpmax=mpout.0+1
mpout.mpmax=mprout
mpout.0=mpmax
save=0
DO i=1 TO dict$.variable_name.0
IF testgetvar(dict$.variable_name.i'.UPDATE',0) \= 0 THEN save=1
END
RETURN
error:
PARSE ARG errmsg
mpout.2=myvar.3'('myvar.4')'
mpout.3=' 'errmsg' in Procedure 'myvar.3
mpout.4=myvar.3' Command aborted'
mpout.0=4
consay(,ptime() errmsg 'in' myvar.3'('myvar.4')')
RETURN
wm_timer:
CALL wm_click_save
idle=stime()-idletime
IF idle>300 THEN SAY 'Server idle for 'idle' Seconds'
IF idle>idlemax THEN CALL wm_close
RETURN ''
wm_click_save:
CALL sysheart
save=0
DO i=1 TO dict$.variable_name.0
IF testgetvar(dict$.variable_name.i'.UPDATE',0) \= 0 THEN save=1
END
IF save=0 THEN RETURN
consay(,COPIES('-',25))
CALL divout()
consay(,ptime()' Variable Pool changes captured')
dive$.update=0
RETURN
wm_click_shutdown:
wm_close:
wm_click_cancel:
CALL wm_click_save
CALL sysclose
lock('RELEASE',servermode)
guidestroywindow()
RETURN
wm_extra:
p0=ARG(1)
p1=ARG(2)
event=ARG(3)
IF event=2710 THEN RETURN 2710
RETURN ""
sysini:
tcount=0
execendtime=ptime()
pid=mypid
mpin=dictin
start=ptime()
status='READY'
incommands=tcount
ideltime=stime()
sysheart:
heartbeat=stime()
RETURN
sysbusy:
tcount=tcount+1
status='BUSY'
incommands=tcount
processtime=processstarttime
lastcommand=ptime()
idletime=stime()
RETURN
sysready:
status='READY'
processend=execendtime
lastcommand=ptime()
idletime=stime()
RETURN
sysclose:
heartbeat=stime()
status='SHUT-DOWN'
testmpin=0
RETURN
readparm:
pmax=WORD(myvar.1,2)
IF pmax='' |datatype(pmax) \= 'NUM' THEN pmax=0
DROP p.
svar=''
DO i=1 TO 5
p.i=''
END
DO i=4 TO pmax
j=i-3
INTERPRET 'p.'j'=getvar(myVar.,i)'
svar=svar||p.j' '
END
svar='('STRIP(svar)')'
RETURN
mprout:
PARSE ARG elapsed,proc
mpmax=mpout.0
option.file=testgetvar('option.file')
option.fileonly=testgetvar('option.fileonly')
IF option.fileonly \='' THEN option.file=''
IF option.file \='' | option.fileonly \= '' THEN DO
mpout.mpmax=''
LOADTEXT('MPOUT.',option.file,'BS')
END
IF option.fileonly \= '' THEN DO
mpout.1='Output redirected to 'option.fileonly
mpout.0=1
END
dictout=clipnewformat(mprout)
mpmax=mpmax+1
mpout.mpmax=mprout' 'mpout.0' 'elapsed
mpout.0=mpmax
clipset('MPOUT.',dictout)
SAY ptime() mpout.0 'Lines written to MPOUT by procedure 'proc'()'
RETURN
getvar:
USE ARG testvar.,ind
IF EXISTS('testvar.'ind)=0 THEN RETURN ''
ELSE RETURN STRIP(testvar.ind)
lock: PROCEDURE
PARSE ARG mode,resource
lockfile=DIRECTORY()'\'resource'.lck'
IF ABBREV('EXCLUSIVE',mode)=1 THEN DO
IF STREAM(lockfile, "C", "OPEN WRITE REPLACE")='READY:' THEN RETURN 0
ELSE RETURN 8
END
IF ABBREV('TESTEXCLUSIVE',mode)=1 THEN DO
IF STREAM(lockfile, "C", "OPEN WRITE REPLACE")='READY:' THEN DO
STREAM(lockfile, "C", "CLOSE")
DELETEFILE(lockfile)
RETURN 0
END
ELSE RETURN 8
END
IF ABBREV('RELEASE',mode)=1 THEN DO
STREAM(lockfile, "C", "CLOSE")
DELETEFILE(lockfile)
RETURN 0
END
testgetvar:
USE ARG tvar,default
default=ARG(2)
IF EXISTS(tvar)=0 THEN DO
tvar=TRANSLATE(tvar)
IF EXISTS(tvar)=0 THEN RETURN default
END
IF STRIP(VALUE(tvar))='' THEN RETURN default
RETURN VALUE(tvar)
ptime: PROCEDURE
ptime=TIME('l')
len=LENGTH(ptime)-3
RETURN SUBSTR(ptime,1,len)
stime: PROCEDURE
PARSE ARG itime
IF itime='' THEN PARSE VALUE TIME('L') WITH hh ':' mm ':' ss '.' tt
ELSE PARSE VALUE itime WITH hh ':' mm ':' ss '.' tt
stime=hh*3600+mm*60+ss
stime=stime||'.'||tt
RETURN stime
|
|