|
Open Model Railroad Network (OpenMRN)
|
This timer takes care of limiting the number of speed updates we send out in a second. More...
#include <LimitTimer.hxx>
Public Member Functions | |
| LimitTimer (ExecutorBase *ex, uint16_t update_delay_msec, uint8_t max_tokens, std::function< void()> callback) | |
| Constructor. | |
| ~LimitTimer () | |
| Destructor. | |
| bool | try_take () |
| Attempts to take a token out of the bucket. | |
| void | take_no_callback () |
| Takes one entry from the bucket, and does not give a callback if there is no entry left. | |
Public Member Functions inherited from Timer | |
| Timer (ActiveTimers *timers) | |
| Constructor. | |
| ~Timer () | |
| Destructor. | |
| void | run () override |
| Callback from the executor when this timer is scheduled. | |
| long long | schedule_time () |
| void | start (long long period=-1) |
| Starts a timer. | |
| void | start_absolute (long long expiry_time_nsec) |
| Starts the timer with an absolute deadline. | |
| void | restart () |
| Restart a timer with the existing period but from the current time. | |
| void | trigger () |
| This will wakeup the timer prematurely, immediately. | |
| void | ensure_triggered () |
| Triggers the timer if it is not expired yet. | |
| void | cancel () |
| Dangerous, do not call. | |
| bool | is_triggered () |
| void | set_triggered () |
| Sets the timer as if it was woken up by a trigger(), even if it was never started. | |
Public Member Functions inherited from Executable | |
| void | test_deletion () |
| void | notify () override |
| Crashes the program – everyone who is expecting notify calls must override this function. | |
| virtual void | alloc_result (QMember *item) |
| Return the result of an alloc_async() from a memory Pool. | |
Public Member Functions inherited from QMember | |
| void | init () |
| Initiailize a QMember, in place of a public placement construction. | |
Private Member Functions | |
| long long | timeout () override |
| Callback from the timer infrastructure. Called periodically. | |
Private Attributes | |
| uint16_t | updateDelayMsec_ |
| cooldown delay in msec | |
| uint8_t | bucket_ |
| number of available tokens | |
| uint8_t | bucketMax_: 7 |
| maximum number of tokens in the bucket | |
| uint8_t | needUpdate_: 1 |
| if non-zero, wake up parent when token is available. | |
| std::function< void()> | callback_ |
| callback after cooldown period. | |
Additional Inherited Members | |
Public Types inherited from Timer | |
| enum | { NONE = 0 , RESTART = 1 , DELETE = -1 } |
| Special return values from the timeout function. More... | |
Protected Member Functions inherited from Timer | |
| void | update_period (long long period) |
| Updates the period, to be used after the next expiration of the timer in order to restart it. | |
Protected Member Functions inherited from QMember | |
| QMember () | |
| Constructor. | |
| ~QMember () | |
| Destructor. | |
Protected Attributes inherited from QMember | |
| QMember * | next |
| pointer to the next member in the queue | |
This timer takes care of limiting the number of speed updates we send out in a second.
It is a token bucket filter.
Definition at line 45 of file LimitTimer.hxx.
|
inline |
Constructor.
| ex | executor to run on |
| update_delay_msec | cooldown time delay in milliseconds |
| max_tokens | number of available tokens, <= 127 max |
| callback | callback called once after cooldown time delay |
Definition at line 53 of file LimitTimer.hxx.
|
inline |
Destructor.
Definition at line 66 of file LimitTimer.hxx.
|
inline |
Takes one entry from the bucket, and does not give a callback if there is no entry left.
Must be called from the same executor that was passed in the object construction.
Definition at line 97 of file LimitTimer.hxx.
|
inlineoverrideprivatevirtual |
Callback from the timer infrastructure. Called periodically.
Implements Timer.
Definition at line 107 of file LimitTimer.hxx.
|
inline |
Attempts to take a token out of the bucket.
Must be called from the same executor that was passed in the object construction.
Definition at line 76 of file LimitTimer.hxx.
|
private |
number of available tokens
Definition at line 129 of file LimitTimer.hxx.
|
private |
maximum number of tokens in the bucket
Definition at line 132 of file LimitTimer.hxx.
|
private |
callback after cooldown period.
Definition at line 138 of file LimitTimer.hxx.
|
private |
if non-zero, wake up parent when token is available.
Definition at line 135 of file LimitTimer.hxx.
|
private |
cooldown delay in msec
Definition at line 126 of file LimitTimer.hxx.