SICS-841: You can now use set_oneshot to remove a callback.
This commit is contained in:
@ -74,7 +74,8 @@ scriptcallback connect exe BATCHEND ::batch::call_cleanup
|
||||
# @param hpath hdb path to a node which regularly calls this procedure.
|
||||
# @param event an event which may trigger a callback.
|
||||
# @param args is a list of arguments which will be passed to the callback.
|
||||
# @return state: -2 = fatal error, -1 = timer expired, 0 = callback triggered, 1 = waiting for event
|
||||
# @return state: -3 = callback cleared/removed by user, -2 = fatal error,
|
||||
# -1 = timer expired, 0 = callback triggered, 1 = waiting for event
|
||||
# remaining before expiry.
|
||||
proc call_oneshot {hpath event args} {
|
||||
if [hpropexists $hpath oneshot_cb] {
|
||||
@ -119,11 +120,23 @@ proc call_oneshot {hpath event args} {
|
||||
# If timeout = 0 the callback will only be called if the trigger event occurs
|
||||
# the first time the node is polled. If there is no trigger event then the
|
||||
# callback is simply removed.
|
||||
proc set_oneshot {hpath cb_proc event {timeout 60}} {
|
||||
# TODO Maybe. Allow registering a callback for each event on hpath.
|
||||
proc set_oneshot {hpath cb_proc event {cb_timeout 60}} {
|
||||
set catch_status [ catch {
|
||||
if {$cb_timeout == "clear"} {
|
||||
hdelprop $hpath oneshot_cb
|
||||
hsetprop $hpath oneshot_state -3
|
||||
return
|
||||
}
|
||||
if {![string is integer $cb_timeout]} {
|
||||
error "Valid values for the timeout are 'clear' or an integer"
|
||||
}
|
||||
hsetprop $hpath oneshot_cb $cb_proc
|
||||
hsetprop $hpath oneshot_timeout $timeout
|
||||
hsetprop $hpath oneshot_timeout $cb_timeout
|
||||
hsetprop $hpath oneshot_start_time [hgetpropval $hpath read_time]
|
||||
hsetprop $hpath oneshot_trigger $event
|
||||
hsetprop $hpath oneshot_state 1
|
||||
} catch_message ]
|
||||
handle_exception ${catch_status} ${catch_message}
|
||||
}
|
||||
publish set_oneshot user
|
||||
|
Reference in New Issue
Block a user