/usr/share/tcltk/tcllib1.18/tool/event.tcl is in tcllib 1.18-dfsg-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | ###
# This file implements the Tool event manager
###
::namespace eval ::tool {}
::namespace eval ::tool::event {}
###
# topic: f2853d380a732845610e40375bcdbe0f
# description: Cancel a scheduled event
###
proc ::tool::event::cancel {self {task *}} {
variable timer_event
foreach {id event} [array get timer_event $self:$task] {
::after cancel $event
set timer_event($id) {}
}
}
###
# topic: 8ec32f6b6ba78eaf980524f8dec55b49
# description:
# Generate an event
# Adds a subscription mechanism for objects
# to see who has recieved this event and prevent
# spamming or infinite recursion
###
proc ::tool::event::generate {self event args} {
set wholist [Notification_list $self $event]
if {$wholist eq {}} return
set dictargs [::oo::meta::args_to_options {*}$args]
set info $dictargs
set strict 0
set debug 0
set sender $self
dict with dictargs {}
dict set info id [::tool::event::nextid]
dict set info origin $self
dict set info sender $sender
dict set info rcpt {}
foreach who $wholist {
catch {::tool::event::notify $who $self $event $info}
}
}
###
# topic: 891289a24b8cc52b6c228f6edb169959
# title: Return a unique event handle
###
proc ::tool::event::nextid {} {
return "event#[format %0.8x [incr ::tool::event_count]]"
}
###
# topic: 1e53e8405b4631aec17f98b3e8a5d6a4
# description:
# Called recursively to produce a list of
# who recieves notifications
###
proc ::tool::event::Notification_list {self event {stackvar {}}} {
set notify_list {}
foreach {obj patternlist} [array get ::tool::object_subscribe] {
if {$obj eq $self} continue
foreach pattern $patternlist {
lassign $pattern objpat eventpat
if {![string match $objpat $self]} continue
if {![string match $eventpat $event]} continue
lappend notify_list $obj
break
}
}
return $notify_list
}
###
# topic: b4b12f6aed69f74529be10966afd81da
###
proc ::tool::event::notify {rcpt sender event eventinfo} {
if {[info commands $rcpt] eq {}} return
if {$::tool::trace} {
puts [list event notify rcpt $rcpt sender $sender event $event info $eventinfo]
}
$rcpt notify $event $sender $eventinfo
}
###
# topic: 829c89bda736aed1c16bb0c570037088
###
proc ::tool::event::process {self handle script} {
variable timer_event
array unset timer_event $self:$handle
set err [catch {uplevel #0 $script} result]
if $err {
puts "BGError: $self $handle $script
ERR: $result"
}
}
###
# topic: eba686cffe18cd141ac9b4accfc634bb
# description: Schedule an event to occur later
###
proc ::tool::event::schedule {self handle interval script} {
variable timer_event
if {$::tool::trace} {
puts [list $self schedule $handle $interval]
}
if {[info exists timer_event($self:$handle)]} {
::after cancel $timer_event($self:$handle)
}
set timer_event($self:$handle) [::after $interval [list ::tool::event::process $self $handle $script]]
}
###
# topic: e64cff024027ee93403edddd5dd9fdde
###
proc ::tool::event::subscribe {self who event} {
lappend ::tool::object_subscribe($self) [list $who $event]
}
###
# topic: 5f74cfd01735fb1a90705a5f74f6cd8f
###
proc ::tool::event::unsubscribe {self args} {
if {![info exists ::tool::object_subscribe($self)]} continue
switch {[llength $args]} {
0 {
set ::tool::object_subscribe($self) {}
}
1 {
set event [lindex $args 0]
set oldlist $::tool::object_subscribe($self)
set newlist {}
foreach pattern $oldlist {
lassign $pattern objpat eventpat
if {[string match $eventpat $event]} continue
lappend newlist $pattern
}
set ::tool::object_subscribe($self) $newlist
}
}
}
::tool::define ::tool::object {
###
# topic: 20b4a97617b2b969b96997e7b241a98a
###
method event {submethod args} {
::tool::event::$submethod [self] {*}$args
}
}
###
# topic: 37e7bd0be3ca7297996da2abdf5a85c7
# description: The event manager for Tool
###
namespace eval ::tool::event {
variable nextevent {}
variable nexteventtime 0
}
|