Fix too many ]s in try
[tcl-tlc-base.git] / scripts / domino.itcl
blob0a4cca2ff1f08aa79715d8f72361b018e076c920
1 # vim: foldmarker=<<<,>>>
3 class tlc::Domino {
4 inherit tlc::Baselog
5 # inherit tlc::Handlers
7 constructor {accessvar args} {}
8 destructor {}
10 public {
11 variable name ""
13 method tip {args}
14 method tip_now {args}
15 method attach_output {handler}
16 method detach_output {handler}
17 method attach_input {dom_obj}
18 method detach_input {dom_obj}
19 method pending {}
20 method force_if_pending {}
21 method lock {}
22 method unlock {}
25 protected {
26 method debug {level msg}
27 method tip_outputs {}
30 private {
31 variable after_id ""
32 variable outputs {}
33 variable inputs
34 variable lock 0
36 method scopevar_unset {args}
41 configbody tlc::Domino::name { #<<<1
42 set baselog_instancename $name
46 body tlc::Domino::constructor {accessvar args} { #<<<1
47 array set inputs {}
49 eval configure $args
51 if {$name == ""} {
52 set name $accessvar
55 upvar $accessvar scopevar
56 set scopevar $this
57 trace variable scopevar u [code $this scopevar_unset]
61 body tlc::Domino::destructor {} { #<<<1
62 after cancel $after_id
63 foreach dom_obj [array names inputs] {
64 detach_input $dom_obj
69 body tlc::Domino::tip {args} { #<<<1
70 if {$lock > 0} return
72 if {$after_id != ""} return
73 debug debug "tlc::Domino::tip: ($this) ($name)"
74 set after_id [after idle [code $this tip_outputs]]
78 body tlc::Domino::tip_now {args} { #<<<1
79 tip_outputs
83 body tlc::Domino::attach_output {handler} { #<<<1
84 set idx [lsearch $outputs $handler]
85 if {$idx == -1} {
86 lappend outputs $handler
87 return 1
88 } else {
89 return 0
94 body tlc::Domino::detach_output {handler} { #<<<1
95 set idx [lsearch $outputs $handler]
96 set outputs [lreplace $outputs $idx $idx]
100 body tlc::Domino::tip_outputs {} { #<<<1
101 after cancel $after_id
102 set after_id ""
103 foreach output $outputs {
104 if {[catch {
105 uplevel #0 $output
106 } errmsg]} {
107 log error "\nerror updating output ($output):\n\t$errmsg\n$::errorInfo"
113 body tlc::Domino::attach_input {dom_obj} { #<<<1
114 if {![$dom_obj isa tlc::Domino]} {
115 error "$dom_obj isn't a Domino"
118 set inputs($dom_obj) 1
120 return [$dom_obj attach_output [code $this tip]]
124 body tlc::Domino::detach_input {dom_obj} { #<<<1
125 if {![$dom_obj isa tlc::Domino]} {
126 error "$dom_obj isn't a Domino"
129 catch {unset inputs($dom_obj)}
131 return [$dom_obj detach_output [code $this tip]]
135 body tlc::Domino::debug {level msg} { #<<<1
136 # invoke_handlers debug $level $msg
140 body tlc::Domino::pending {} { #<<<1
141 return [expr {$after_id != ""}]
145 body tlc::Domino::force_if_pending {} { #<<<1
146 if {$after_id != ""} tip_now
150 body tlc::Domino::lock {} { #<<<1
151 incr lock
155 body tlc::Domino::unlock {} { #<<<1
156 incr lock -1
157 if {$lock < 0} {
158 puts stderr "$this lock went below zero!: $lock\n[tlc::stackdump]"
163 body tlc::Domino::scopevar_unset {args} { #<<<1
164 log debug
165 delete object $this