All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Radiant::SingleShotTask Class Reference

Same as FunctionTask, but executes the function only once. More...

#include <Radiant/Task.hpp>

Inheritance diagram for Radiant::SingleShotTask:
Radiant::Task Patterns::NotCopyable

Public Member Functions

virtual void doTask ()
 The actual work the task does should be implemented in here. More...
 
 SingleShotTask (std::function< void()> func)
 Construct a new FunctionTask. More...
 
- Public Member Functions inherited from Radiant::Task
bool isCanceled () const
 Returns whether a task has been canceled. More...
 
Priority priority () const
 Get the current priority of the task. More...
 
void runNow (bool finish)
 If the task isn't already finished, runs the task immediately in the calling thread. More...
 
void schedule (Radiant::TimeStamp ts)
 Schedule the next execution time for this task. More...
 
Radiant::TimeStamp scheduled () const
 Return a timestamp for the next execution of the task. More...
 
void scheduleFromNow (Radiant::TimeStamp wait)
 Schedule the next execution time for this task. More...
 
void scheduleFromNowSecs (double seconds)
 Schedule the next execution time for this task. More...
 
void setCanceled ()
 Marks the task as canceled, so it will be removed.
 
void setFinished ()
 Marks the task as finished, so it will be removed.
 
void setPriority (Priority priority)
 Sets priority for task. More...
 
State state () const
 Get the current state of the task. More...
 
 Task (Priority p=PRIORITY_NORMAL)
 Constructs a task with the given priority. More...
 
virtual ~Task ()
 Destructor.
 

Static Public Member Functions

static void run (std::function< void()> func)
 Executes the given function exactly once in BGThread.
 
static void run (double delayS, std::function< void()> func)
 Executes the given function exactly once in BGThread after given delay. More...
 

Additional Inherited Members

- Public Types inherited from Radiant::Task
enum  { PRIORITY_LOW = 1, PRIORITY_NORMAL = 500, PRIORITY_HIGH = 1000, PRIORITY_URGENT = 1500 }
 Standard priorities for tasks. More...
 
enum  State { WAITING, RUNNING, DONE }
 State of the task. More...
 
- Protected Member Functions inherited from Radiant::Task
virtual void canceled ()
 Cancel the task. More...
 
virtual void finished ()
 Finished the task. More...
 
virtual void initialize ()
 Initialize the task. Called by BGThread before the task is processed.
 
void setState (State s)
 Sets the task state. More...
 

Detailed Description

Same as FunctionTask, but executes the function only once.

Constructor & Destructor Documentation

Radiant::SingleShotTask::SingleShotTask ( std::function< void()>  func)

Construct a new FunctionTask.

Parameters
funcfunction to execute

Member Function Documentation

virtual void Radiant::SingleShotTask::doTask ( )
virtual

The actual work the task does should be implemented in here.

Override in the derived class. When the task is finished it is important to set the State of the task to State::DONE (f.ex. calling setFinished) so that BGThread can properly release the task. If the state of the task is not set to State::DONE after call to this function this task is scheduled to be executed later.

Implements Radiant::Task.

static void Radiant::SingleShotTask::run ( double  delayS,
std::function< void()>  func 
)
static

Executes the given function exactly once in BGThread after given delay.

Parameters
delaySdelay in seconds