Make sure oneshot_state = 1 while a callback is waiting for an event.

This commit is contained in:
Ferdi Franceschini
2015-01-14 13:27:26 +11:00
parent 9d0780047c
commit f2590461b5

View File

@ -70,6 +70,7 @@ scriptcallback connect exe BATCHEND ::batch::call_cleanup
# This is meant to be called from the read command on an hdb node. It must be
# called everytime the node is polled so that the oneshot callback can be
# removed if the given event fails to occur within the allowed time.
# NOTE: set event parameter to 'fatal_error' to signal an error and remove the callback.
# @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.
@ -98,13 +99,13 @@ proc call_oneshot {hpath event args} {
hdelprop $hpath oneshot_cb
hsetprop $hpath oneshot_state -1
return -1
}
} else {
hsetprop $hpath oneshot_state 1
return 1
}
}
}
}
##
# @brief Assign a oneshot callback to which is triggered by the given event.
@ -113,13 +114,16 @@ proc call_oneshot {hpath event args} {
# @param cb_proc name of the callback procedure
# @param trigger event for callback
# @param timeout the callback is removed when the timeout expires.
# If timeout < 0 then the callback won't timeout but you can force it to be
# removed by calling set_oneshot again with timeout = 0.
# If timeout = 0 the callback will only be called if the trigger event occurs
# the first time the node is polled. If timeout < 0 then the callback will be
# called if the trigger event occurs and then it is removed.
# 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}} {
hsetprop $hpath oneshot_cb $cb_proc
hsetprop $hpath oneshot_timeout $timeout
hsetprop $hpath oneshot_start_time [hgetpropval $hpath read_time]
hsetprop $hpath oneshot_trigger $event
hsetprop $hpath oneshot_state 1
}
publish set_oneshot user