Mbed OS Reference
Loading...
Searching...
No Matches
Task< R(A0, A1)> Class Template Reference

Task. More...

#include <Task.h>

Inheritance diagram for Task< R(A0, A1)>:
TaskBase LinkEntry

Public Member Functions

 Task (TaskQueue *q=NULL, mbed::Callback< R(A0, A1)> cb=mbed::Callback< R(A0, A1)>())
 Construct a new task. More...
 
Taskoperator= (mbed::Callback< R(A0, A1)> cb)
 Set the callback of this task. More...
 
void call (A0 a0, A1 a1)
 Post this task for execution. More...
 
void set (TaskQueue *q)
 Set the queue of this task. More...
 
void cancel ()
 Cancel the execution of this task. More...
 
bool ready ()
 Return true if this task is ready to be posted. More...
 
void wait ()
 Wait for this task to finish execution. More...
 
bool finished ()
 Check if the callback has run to completion or been fully canceled. More...
 

Protected Member Functions

virtual uint32_t size ()
 Size of buffer required for TaskBase::start. More...
 
virtual run_callback_t start (void *data, uint32_t max_size)
 Copy any callback data and return a callback to run. More...
 
virtual void finish ()
 Inform this task that execution has finished. More...
 
void post ()
 Post this task to the set TaskQueue for execution. More...
 

Detailed Description

template<typename R, typename A0, typename A1>
class events::Task< R(A0, A1)>

Task.

Representation of a postable task

Definition at line 590 of file Task.h.

Constructor & Destructor Documentation

◆ Task()

Task ( TaskQueue q = NULL,
mbed::Callback< R(A0, A1)>  cb = mbed::Callback<R(A0, A1)>() 
)

Construct a new task.

Parameters
qTaskQueue to post to
cbCallback to run

Definition at line 599 of file Task.h.

Member Function Documentation

◆ operator=()

Task & operator= ( mbed::Callback< R(A0, A1)>  cb)

Set the callback of this task.

Parameters
cbCallback to run

Definition at line 609 of file Task.h.

◆ call()

void call ( A0  a0,
A1  a1 
)

Post this task for execution.

The number of arguments to call should match the type of the callback. For example Task<void(int, int)> expects two integers as arguments to call, while Task<void()> expects no arguments.

Parameters
a0First callback parameter
a1Second callback parameter

Definition at line 626 of file Task.h.

◆ size()

virtual uint32_t size ( )
protectedvirtual

Size of buffer required for TaskBase::start.

Returns
requested buffer size

Implements TaskBase.

Definition at line 635 of file Task.h.

◆ start()

virtual run_callback_t start ( void *  data,
uint32_t  size 
)
protectedvirtual

Copy any callback data and return a callback to run.

Parameters
dataBuffer to copy data to. Do not copy more than TaskBase::size() data.
sizeMaximum size to copy

Implements TaskBase.

Definition at line 640 of file Task.h.

◆ set()

void set ( TaskQueue q)
inherited

Set the queue of this task.

Parameters
qTaskQueue to post to

◆ cancel()

void cancel ( )
inherited

Cancel the execution of this task.

Once cancelled the task can be posted again. Previous calls to post may still run. If you need to ensure the callback has finished the function wait() can be used.

Note
This function is interrupt safe

◆ ready()

bool ready ( )
inherited

Return true if this task is ready to be posted.

Check if this task is on a queue waiting to be run.

Returns
true if it is safe to call post

◆ wait()

void wait ( )
inherited

Wait for this task to finish execution.

When this function returns then this task is in the finished state.

◆ finished()

bool finished ( )
inherited

Check if the callback has run to completion or been fully canceled.

When an task is finished the queue is completely done with it and the callback is either fully complete or has been canceled and will not run.

Returns
true if this task has been flushed from the queue, false otherwise

◆ finish()

virtual void finish ( )
protectedvirtualinherited

Inform this task that execution has finished.

◆ post()

void post ( )
protectedinherited

Post this task to the set TaskQueue for execution.