#!/bin/sh  
# \
exec oagwish "$0" "$@"


set auto_path [linsert $auto_path 0  /usr/local/oag/apps/lib/$env(HOST_ARCH)]
set auto_path [linsert $auto_path 0 /usr/local/oag/lib_patch/$env(HOST_ARCH)]
APSDebugPath

set CVSRevisionAuthor "\$Revision: 1.1 $ \$Author: borland $"


APSApplication . -name clockCheck -version $CVSRevisionAuthor -overview \
        "Provides a way to check the clocks on all the MCR workstations."


set status Ready.
APSScrolledStatus .status -parent .userFrame -textVariable status -width 60

APSButton .run -parent .userFrame -text Run -command StartClocks
APSButton .stop -parent .userFrame -text Stop -command StopClocks
set hostList [lsort {charis echo herema talos phoenix \
                       iris demeter ariel chaos artemus cadmus cyclops}]

APSCheckButtonFrame .hosts -parent .userFrame -label "Host choices" \
  -variableList $hostList -buttonList $hostList -orientation vertical \
  -allNone 1 -contextHelp "Choose which hosts (i.e., workstations) you want to scan."

foreach elem $hostList {
    set $elem 1
}

proc StartClocks {} {
    global hostList env apsScriptHost
    set display $apsScriptHost$env(DISPLAY)
    set index 0
    foreach workstation $hostList {
        global $workstation fid$workstation
        set fid$workstation ""
        if ![subst \$$workstation] continue
        set xpos [expr int($index/8)*400+100]
        set ypos [expr ($index%8)*100+10]
        incr index
        set fid$workstation [open "|rlogin $workstation" r+]
        puts [subst \$fid$workstation] "wishClock -display $display -geometry +$xpos+$ypos &"
        flush [subst \$fid$workstation]
        global status
        set status "Launched clock for $workstation"
        update
    }
}

proc StopClocks {} {
    global hostList
    foreach workstation $hostList {
        global $workstation fid$workstation
        if [string length [subst \$fid$workstation]] {
            puts [subst \$fid$workstation] "kill %1"
            flush [subst \$fid$workstation]
            global status
            set status "Killed clock for $workstation"
            update
            catch {close [subst \$fid$workstation]}
            set fid$workstation ""
        }
    }
}


