Uniot Core
0.9.0
Loading...
Searching...
No Matches
uniot::SchedulerTask Class Reference

#include <TaskScheduler.h>

Inheritance diagram for uniot::SchedulerTask:
[legend]

Public Types

using SchedulerTaskCallback = std::function<void(SchedulerTask &, short)>
 Callback function signature for scheduled tasks.
 
using spSchedulerTaskCallback = SharedPointer<SchedulerTaskCallback>
 Shared pointer type for task callbacks.
 
- Public Types inherited from uniot::ESP8266Task
using TaskCallback = void (*)(void)
 Callback function with no arguments.
 
using TaskArgCallback = void (*)(void *)
 Callback function with void pointer argument.
 
template<typename T>
using TaskTypeCallback = void (*)(volatile T)
 Templated callback function with typed argument.
 

Public Member Functions

 SchedulerTask (IExecutor &executor)
 Constructor that wraps an IExecutor implementation.
 
 SchedulerTask (SchedulerTaskCallback callback)
 Constructor with custom callback function.
 
void attach (uint32_t ms, short times=0)
 Attach the task to run on a specified interval.
 
void once (uint32_t ms)
 Schedule the task to run once after the specified delay.
 
void trigger ()
 Run the task once on the scheduler's next pass.
 
void loop ()
 Main execution loop for the task.
 
uint64_t getTotalElapsedMs () const
 Get the total execution time of this task in milliseconds.
 
- Public Member Functions inherited from uniot::ESP8266Task
 ESP8266Task ()
 Constructor.
 
virtual ~ESP8266Task ()
 Destructor that ensures the timer is detached.
 
void attach (uint32_t ms, bool repeat, TaskCallback callback)
 Attach a simple callback to run periodically.
 
template<typename T>
void attach (uint32_t ms, bool repeat, TaskTypeCallback< volatile T > callback, volatile T arg)
 Attach a typed callback with argument to run periodically.
 
void detach ()
 Stop and detach the timer.
 
bool isAttached ()
 Check if the timer is attached.
 

Member Typedef Documentation

◆ SchedulerTaskCallback

using uniot::SchedulerTask::SchedulerTaskCallback = std::function<void(SchedulerTask &, short)>

Callback function signature for scheduled tasks.

Parameters
taskReference to the executing task
timesNumber of repetitions left (-1 for infinite)

◆ spSchedulerTaskCallback

Shared pointer type for task callbacks.

Constructor & Destructor Documentation

◆ SchedulerTask() [1/2]

uniot::SchedulerTask::SchedulerTask ( IExecutor & executor)
inline

Constructor that wraps an IExecutor implementation.

Parameters
executorThe executor to be called when the task runs

◆ SchedulerTask() [2/2]

uniot::SchedulerTask::SchedulerTask ( SchedulerTaskCallback callback)
inline

Constructor with custom callback function.

Parameters
callbackFunction to execute when the task runs

Member Function Documentation

◆ attach()

void uniot::SchedulerTask::attach ( uint32_t ms,
short times = 0 )
inline

Attach the task to run on a specified interval.

Parameters
msMillisecond interval between executions
timesNumber of times to execute (0 or negative for infinite)

◆ getTotalElapsedMs()

uint64_t uniot::SchedulerTask::getTotalElapsedMs ( ) const
inline

Get the total execution time of this task in milliseconds.

Return values
timeTotal elapsed time in milliseconds

◆ loop()

void uniot::SchedulerTask::loop ( )
inline

Main execution loop for the task.

Checks if the task is ready to execute and runs the callback if so. Tracks execution time and manages repeat counts.

◆ once()

void uniot::SchedulerTask::once ( uint32_t ms)
inline

Schedule the task to run once after the specified delay.

Parameters
msMillisecond delay before execution

◆ trigger()

void uniot::SchedulerTask::trigger ( )
inline

Run the task once on the scheduler's next pass.

Sets the same flag the task's timer sets when it fires, and nothing else, so it can be called from contexts where scheduler work is unsafe: an SDK callback running inside yield(), or another FreeRTOS task. The work itself still runs from TaskScheduler::loop(). The timer is deliberately left alone – on ESP32 attaching creates and deletes it, which two contexts arming the same task at once would race.

Triggers that arrive before the next pass run the callback once. It receives the remaining repetitions as usual: 0 for a task that was never attached, and on a task attached with a repeat count the triggered run counts as one of them. A task that is only ever triggered must be pushed under a name, since the scheduler drops unnamed tasks that are not attached.


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