EMANE
1.2.1
|
The TimerServiceProvider is used by components to schedule timed events.
To schedule a timed event a component uses one of two EMANE::TimerServiceProvider methods: scheduleTimedEvent or schedule.
TimerServiceProvider::scheduleTimedEvent results in a call to TimerServiceUser::processTimedEvent. An optional opaque data pointer and reschedule interval can be specified.
The TimerServiceProvider::schedule method is used to schedule an arbirtray callable. The callable will execute on the same functor queue as all the API messages. An optional reschedule interval can be specified.
The TimerServiceProvider is accessed via the PlatformServiceProvider. All components are given a reference to the PlatformServiceProvider when they are constructed.
Timer schedule example using a lamda:
Timer schedule example using std::bind:
An attempt to schedule a timed event will always succeed. If the requested expiration time is in the past it will be scheduled to immediately fire.
When a timed event expires it is pushed onto the NEM's functor queue as a TimerServiceUser::processTimedEvent method or callable depending on the interface used to scedule the timer.
The processTimedEvent method arguments contain:
A scheduled callable contains the following arguments:
Use std::placeholders to access these parameters when using std::bind.
The three time arguments are used by the framework to track timer service performance but may be of interest to the component.
A scheduled timed event can be canceled using TimerServiceProvider::cancelTimedEvent. It is not an error to attempt to cancel a timed event that has already expired. The cancelTimedEvent method will return true if the event was canceled and false if the event has already expired prior to the cancel attempt.
It is possible that an attempt to cancel a timed event will return false indicating the event expired prior to it being executed. This can occur when the timed event message is placed on the functor queue but has not yet been serviced.