!------------------------------------------------------------------------------!
! Test to show List2 flash issues.
!
!   Author : J. Helton
!   Version: $Id: test_list2_refresh.mm,v 1.1 2008/05/05 18:26:53 jsr Exp $
!------------------------------------------------------------------------------!
startmacro/msgid=main/quiet/ntimers=1

  env get pid mpid
  env get user muser
! env get home mhome

  fname statfile HOME statmon_^{muser}_^{mpid} tmp AUX

  set s:name "xxx"
  timex now d:dtim
  set d:arch 1.0
  set i:ffts 1k
  set d:favg 2
  set i:sel 1
  set i:sel2 1
  set i:stat 100k

  switch INTERACTIVE interAct   GET DEF=TRUE

  if interAct then
    set instructions "List2 refresh test. Refreshes the listing every two seconds. Known DR."

    file open/d/n ctag ^statfile{sr=(name/2a,dtim/sd,arch/sd,ffts/si,favg/si,sel/si,sel2/si,stat/si)}  
    file close ctag

    call initStatFile

    pipe init
      panel/setup/controls=gc

      gcontrol label  macro   "MACRO"
      gcontrol menu MAIN "Exit with Status = " "PASS,FAIL" /tleft
      set gc.MAIN.itemColors {PASS=GREEN,FAIL=RED}

      gcontrol text   idtext    "Instructions" "^{instructions}" 24 14 /title

      list2/msgid=MAIN/id=listid/poll=2/base=0/nice/legacy ^statfile AUTOSELECT=FALSE

      invoke ,, this.setTimers(1)
      set this.timer(0,1.0)

    pipe run
    pipe wait

    pipe off
  endif
endmacro

!------------------------------------------------------------------------------!
procedure processMessage m:msg
!
! Procedure for handling all messages
!
  if msg.name EQS "MAIN" then
    if msg.data EQS "EXIT" then
      erase statfile
      pipe stop
    else
      assert/text="LIST2 Refresh tests" "PASS" SUBS msg.data
      erase statfile
      pipe stop
    endif
  elseif msg.name EQS "TIMER" then
    if ^msg.info eq 0 then
      call updateStatus
    endif
  else
    say "Unhandled messagename: ^msg.name from fid: ^msg.fid data: ^msg.data"
  endif

return

!------------------------------------------------------------------------------!
procedure updateStatus

!  say "****** Update Status *******"
  file open/d/w cttag ^statfile

  calc/quiet d:ffts ^ffts 1k +
  calc/quiet i:favg ^favg 1 +
  calc/quiet i:sel ^sel 1 +

  if name eqs "xxx" then
    set s:name "yyy"
  else
    set s:name "xxx"
  endif

  if ffts gt 100k then
    res d:ffts 1k
  endif

  if favg gt 200 then
    res i:favg 2
  endif

  if sel gt 100 then
    res i:sel 1
    res i:sel2 1
  endif

  do count 0 11 1
    timex now d:dtim
    table updatetab create {name="^name",dtim=^dtim,ffts=^ffts,favg=^favg,sel=^sel,sel2=^sel2,stat=^stat}
!    res updatetab
    invoke ,, cttag.setData(^count,^updatetab)
  enddo
  file close cttag
return

!------------------------------------------------------------------------------!
procedure initStatFile

  file open/d/w cttag ^statfile

  do count 0 11 1
    timex now d:timeNow
    table inittab create {NAME="INIT",DTIM=^timeNow,ARCH="-1.0",FFTS="16384",FAVG="10",SEL="0",SEL2="0",STAT="100k"}
    invoke ,, cttag.setData(^count,^{inittab})
  enddo

 file close cttag

return
