# TODO Maybe add ::event::onstart and ::event::onfinish commands to execute some # code when an object starts or finishes # eg # onstart hmm { do something } namespace eval event { variable sobjBusy variable END_EVENT set sobjBusy 0 array set END_EVENT {Motor MOTEND HistMem COUNTEND SingleCounter COUNTEND} namespace export waitfor } proc ::event::waitCB {args} { variable sobjBusy set sobjBusy 0 } publish ::event::waitCB user ## # @brief Wait for a sics object to finish what it's doing. # waitfor hmm {histmem start} # waitfor {samx samz} {run samx 3 samz 4} proc ::event::waitfor {sobj args} { variable END_EVENT variable sobjBusy if [ catch { set valid_sobjType [array names END_EVENT] set sobjType [SplitReply [sicslist $sobj type] ] if {[lsearch $valid_sobjType $sobjType ] == -1} { error "ERROR: You can only wait for the following types of objects $valid_sobjType" } set CBID [SplitReply [scriptcallback connect $sobj $END_EVENT($sobjType) ::event::waitCB ] ] set sobjBusy 1 set oldStatus [lindex [SplitReply [status]] 0] eval $args while {$sobjBusy == 1} { wait 1 } scriptcallback remove $sobj $CBID SetStatus $oldStatus } message ] { scriptcallback remove $sobj $CBID SetStatus $oldStatus if {$::errorCode=="NONE"} {return "Return: $message"} return -code error "Caught $message" } } namespace import ::event::waitfor publish waitfor user namespace eval ::batch::call_cleanup { } proc ::batch::cleanup {} {} ## # @brief Calls a user defined cleanup script when a batch file ends or is aborted # The cleanup script must be called ::batch::call_cleanup proc ::batch::call_cleanup {} { ::batch::cleanup proc ::batch::cleanup {} {} } publish ::batch::call_cleanup user scriptcallback connect exe BATCHEND ::batch::call_cleanup