PQRST  1.2
Priority Queue for Running Simple Tasks
Public Types | Public Member Functions | List of all members
SleeperTask Class Referenceabstract

A sleeper task is one which will run only when a given condition is true. More...

#include <pqrst.h>

Inheritance diagram for SleeperTask:
Inheritance graph
[legend]
Collaboration diagram for SleeperTask:
Collaboration graph
[legend]

Public Types

enum  Awakening { KEEP_SLEEPING, WAKE, WAKE_IMMEDIATELY }
 An indication of how the task should be scheduled, when it is woken. More...
 

Public Member Functions

 SleeperTask (void)
 
virtual Awakening wake_me (void) const =0
 Indicate whether the task is ready to be woken. More...
 
- Public Member Functions inherited from Task
 Task ()
 Construct a task. More...
 
virtual ~Task ()
 
virtual void start (ms_t delay)
 Start the task. More...
 
virtual void start (void)
 Start the task immediately. More...
 
virtual void run (ms_t t)=0
 Runs one step of the task. More...
 
ms_t cancel (void)
 Cancel this task. More...
 
ms_t uncancel (void)
 Uncancel a task. More...
 
void run_at (ms_t t, Task *T=nullptr)
 Push a new task onto the queue, due at a given time. More...
 
void run_after (ms_t t, Task *T=nullptr)
 Push a new Task onto the queue, due some (non-negative) interval after the queue's current reference time. More...
 
void run_immediately (Task *T=nullptr)
 Push a task onto the queue, due immediately. More...
 
bool before (const Task *) const
 Impose an ordering on tasks. More...
 
bool set_task_slippy (bool)
 Set a task to be ‘slippy’. More...
 
bool get_task_slippy (void) const
 Determine whether a task is ‘slippy’. More...
 
bool is_enqueued_p (void) const
 Return true if the task is currently scheduled on a queue. More...
 
ms_t ready_after (void) const
 Return the interval until the Task is next ready, relative to the queue reference time. More...
 
void set_priority (unsigned char)
 Set the priority of the task. More...
 
unsigned char get_priority (void) const
 Return the priority of the task. More...
 
void set_duration (ms_t)
 Set the duration of the task. More...
 
ms_t get_duration (void) const
 Return the task's expected duration. More...
 
virtual bool user_task_p (void) const
 True if this is a ‘user task’, as opposed to a maintenance task. More...
 
void set_task_ident (const char *ident_string)
 Set the identification string for a task. More...
 
const char * get_task_ident (void) const
 Retrieve the identification string. More...
 

Additional Inherited Members

- Static Public Attributes inherited from Task
static const PROGMEM char *const pqrst_version
 Reports the PQRST version and compilation options. More...
 
- Protected Member Functions inherited from Task
virtual void signal (int signal, ms_t t)
 Receive a signal. More...
 
virtual void run_task (ms_t)
 Run this task; this is the method which is actually called when a task is due to be run. More...
 

Detailed Description

A sleeper task is one which will run only when a given condition is true.

When the condition becomes true, the task will be scheduled (but see Awakening). The condition is tested in TaskQueue::run_ready.

This functionality is available only if the code has been compiled with PQRST_WITH_SLEEPER non-zero.

See also
TaskQueue::add_sleeper
TaskQueue::clear_sleeper

Member Enumeration Documentation

◆ Awakening

An indication of how the task should be scheduled, when it is woken.

Most of the time, WAKE should be sufficient.

Enumerator
KEEP_SLEEPING 

Keep sleeping; do not awaken.

WAKE 

Wake and schedule due at the current time (like TaskQueue::push_after(0))

WAKE_IMMEDIATELY 

Wake and schedule immediately (like TaskQueue::push_immediately)

Constructor & Destructor Documentation

◆ SleeperTask()

SleeperTask::SleeperTask ( void  )
inline

Member Function Documentation

◆ wake_me()

virtual Awakening SleeperTask::wake_me ( void  ) const
pure virtual

Indicate whether the task is ready to be woken.

If a SleeperTask is registered with a queue, then this test is called very frequently, so should be both const and fast.

If this method returns something other than KEEP_SLEEPING, then the subsequent task's run method should almost certainly act so as to nullify the event that awoke it, otherwise the task will be immediately rescheduled, possibly (in the case of WAKE_IMMEDIATELY) preempting everything else on the queue.

Returns
an indication of whether and how the task is to be scheduled

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