TaskManagerIO
Loading...
Searching...
No Matches
BaseEvent Class Referenceabstract

#include <TaskTypes.h>

Inheritance diagram for BaseEvent:
Executable TmLongSchedule

Public Member Functions

 BaseEvent (TaskManager *taskMgrToUse=&taskManager)
virtual uint32_t timeOfNextCheck ()=0
void setTriggered (bool t)
bool isTriggered () const
bool isComplete () const
void setCompleted (bool complete)
void markTriggeredAndNotify ()
Public Member Functions inherited from Executable
virtual void exec ()=0
virtual ~Executable ()=default

Detailed Description

BaseEvent objects represent events that can be managed by task manager. We can create a base event as either a global variable, or as a new object that lasts at least as long as it's registered with task manager.

Events work differently to other tasks, there are two methods to implement, the first method timeOfNextCheck is for events that are polled, and you control how often it is polled by the value you return. To trigger an event you can call setTriggered(bool), and this will set a flag that task manager will look at during the next poll. If you are in the timeOfNextCheck and you set the event as triggered, it will execute immediately. If you are in an interrupt triggered by task manager, it will act on the trigger immediately. However, in other cases you can call markTriggeredAndNotify which additionally notifies task manager, making the effect immediate.

Member Function Documentation

◆ timeOfNextCheck()

virtual uint32_t BaseEvent::timeOfNextCheck ( )
pure virtual

This method must be implemented by all event handlers. It will be called when the event is first registered with task manager, then it will be called in whatever number of micros you return from the call. For polling events you'd set this to whatever frequency you needed to poll on. For interrupt / threaded situations, it may be set to a very large value, as you would not need to poll.

Returns
the number of microseconds before calling this method again.

Implemented in TmLongSchedule.

◆ setTriggered()

void BaseEvent::setTriggered ( bool t)
inline

Set the event as triggered, which means it will be executed next time around. Usually prefer to use markTriggeredAndNotify as this also notifies task manager.

◆ isTriggered()

bool BaseEvent::isTriggered ( ) const
inline
Returns
true if the event has triggered and requires execution now

◆ isComplete()

bool BaseEvent::isComplete ( ) const
inline
Returns
true if the task has completed

◆ setCompleted()

void BaseEvent::setCompleted ( bool complete)
inline

Sets the task as completed or not completed. Can be called from interrupt safely. Warning once this is called assume that task manager will remove this from the queue immediately. Further, if deleteWhenDone was true, the object would be deleted almost immediately.

◆ markTriggeredAndNotify()

ISR_ATTR void BaseEvent::markTriggeredAndNotify ( )

Set the event as triggered and then tell task manager that the event needs to be re-evaluated. It will not run immediately, rather it will do the equivalent of triggering an interrupt through taskManager. If this event already receives an interrupt through task manager, then there is no need to call notify.


The documentation for this class was generated from the following files: