87 template<
typename CLOCK_,
typename EVENT_>
140 explicit JobCaller(
const CLOCK& clock) : clock_{clock} {}
141 bool operator()(Job& job);
204 Job(
const Job&) =
default;
205 Job& operator=(
const Job&) =
default;
230 template<
typename CLOCK,
typename T>
friend class Scheduler;
234 template<
typename CLOCK,
typename T>
bool Scheduler<CLOCK, T>::JobCaller::operator()(Job& job)
236 uint32_t now = clock_.millis();
237 if (job.next_time() <= now)
239 job.on_schedule(now);
240 if (!job.is_periodic())
return true;
241 job.reschedule(now + job.period());
A wrapper for items stored in a LinkedList.
Linked list of type T_ items.
void traverse(F func)
Traverse all items of this list and execute f functor.
void insert(T &item) INLINE
Insert item at the beginning of this list.
bool remove(T &item) INLINE
Remove item from this list.
Abstract event handler, used by Dispatcher to get called back when an event of the expected type is d...
uint8_t type() const INLINE
The type of event that this handler accepts and can act upon.
virtual void on_event(const EVENT_ &event)=0
This pure virtual method is called by Dispatcher::dispatch() when event.type() matches the type suppo...
Abstract class holding some action to be executed at given periods of time.
virtual void on_schedule(uint32_t millis)=0
This method is called by Scheduler whenever current clock time is greater or equal to next_time().
Job(uint32_t next=0, uint32_t period=0) INLINE
Construct a new Job.
uint32_t period() const INLINE
Return the period of this job, or 0 if this is a one-shot job.
bool is_periodic() const INLINE
Tell if this job is periodic or not.
void reschedule(uint32_t when) INLINE
Reschedule this job for a later time (in ms).
uint32_t next_time() const INLINE
Tell next time (in ms) when this job shall be executed.
Schedule jobs at predefined periods of time.
Scheduler(const CLOCK &clock, uint8_t type) INLINE
Create a new Scheduler based on the given clock.
void unschedule(Job &job) INLINE
Remove job from this scheduler.
void schedule(Job &job) INLINE
Add job to this scheduler.
EVENT_ EVENT
The events::Event<T> dispatched by the system and expected by this Scheduler.
CLOCK_ CLOCK
The type of clock source used by this Scheduler.
#define INLINE
Specific GCC attribute to force the compiler to always inline code of a given function.
#define UNUSED
Specific GCC attribute to declare an argument or variable unused, so that the compiler does not emit ...
Support for events management.
Utility API to handle linked list containers.
Defines all API to handle events within FastArduino programs.