1 # vim: ft=tcl foldmethod=marker foldmarker=<<<,>>> ts=4 shiftwidth=4
3 class tlc
::Signalsource {
8 method signal_ref
{signal
}
9 method signal_state
{signal
}
10 method waitfor
{signal
{timeout
0}}
11 method signals_available
{}
22 method signotify
{signame newstate
}
27 body tlc
::Signalsource::constructor {} { #<<<1
29 array set signotify
{}
34 body tlc
::Signalsource::destructor {} { #<<<1
36 foreach afterid
[array names afters
] {
38 array unset afters
$afterid
46 body tlc
::Signalsource::signal_ref {signal
} { #<<<1
47 if {![info exists signals
($signal)]} {
48 error "Invalid signal ($signal)"
50 return $signals($signal)
54 body tlc
::Signalsource::signal_state {signal
} { #<<<1
55 if {![info exists signals
($signal)]} {
56 error "Invalid signal ($signal)"
58 return [$signals($signal) state
]
62 body tlc
::Signalsource::waitfor {signame
{timeout
0}} { #<<<1
63 if {![info exists signals
($signame)]} {
64 error "Invalid signal: ($signame)"
66 if {![$signals($signame) state
]} {
67 $signals($signame) attach_output
[code
$this signotify
$signame]
69 set afterid
[after $timeout [list set [scope signotify
($signame)] 0]]
70 set afters
($afterid) 1
72 vwait [scope signotify
($signame)]
73 if {[info exists afterid
]} {
75 array unset afters
$afterid
78 set res
$signotify($signame)
79 array unset signotify
($signame)
81 error "Timeout waiting for signal \"$signame\"" "" \
82 [list timeout
$signame]
84 #puts stderr "${this}::waitfor got ($signame) true, proceeding"
90 body tlc
::Signalsource::signotify {signame newstate
} { #<<<1
92 set signotify
($signame) 1
97 body tlc
::Signalsource::signals_available {} { #<<<1
99 foreach signame
[lsort -dictionary [array names signals
]] {
100 lappend build
$signame $signals($signame)