scheduler::Scheduler Class Reference

A task scheduler. More...

#include <scheduler.h>

List of all members.

Public Types

typedef std::list< Task * > list_type
 Type of the list of tasks.

Public Member Functions

 Scheduler ()
 Default constructor.
 Scheduler (Scheduler const &s)
 Copy constructor.
Scheduleroperator= (Scheduler const &right)
 Assignment operator.
int register_type ()
 Registers a task type.
bool add (Task &task)
 Adds a task.
bool remove (Task &task)
 Removes a task.
list_type::size_type remove_bytype (int type)
 Removes all tasks of a given type.
list_type::size_type remove_byname (int type, std::string const &name)
 Removes all tasks with the given name and type.
bool run ()
 Runs tasks.
list_type::size_type run_bytype (int type)
 Runs tasks of the given type.
list_type::size_type run_byname (int type, std::string const &name)
 Runs tasks with the given name and type.
list_type const & tasks () const
 Returns the list of tasks.
Task const * current_task () const
 Returns the current task being run by the scheduler (0 if none).


Detailed Description

The Scheduler class manages a list of Task objects and runs them when they need.


Member Function Documentation

int scheduler::Scheduler::register_type (  )  [inline]

Registers a task type.

Returns:
A new task type ID.
See also:
Task

bool scheduler::Scheduler::add ( Task task  ) 

Adds a task to the list of scheduled tasks.

Parameters:
[in] task The task to be added.
Returns:
true if successful, false otherwise.

bool scheduler::Scheduler::remove ( Task task  ) 

Removes a task from the list of scheduled tasks.

Parameters:
[in] task The task to be removed. The function doesn't free the memory pointed by task; it is the caller's responsibility.
Returns:
true if successful, false otherwise.

list_type::size_type scheduler::Scheduler::remove_bytype ( int  type  ) 

Removes all tasks of a given type from the list of scheduled tasks. operator delete is called for each removed task.

Parameters:
[in] type The type of the tasks to be removed.
Returns:
The number of tasks that have been removed.

list_type::size_type scheduler::Scheduler::remove_byname ( int  type,
std::string const &  name 
)

Removes all tasks with the given name and type from the list of scheduled tasks. operator delete is called for each removed task.

Parameters:
[in] type The type of the tasks to be removed.
[in] name The name of the tasks to be removed.
Returns:
The number of tasks that have been removed.

bool scheduler::Scheduler::run (  ) 

Iterates once in the list of tasks, calling Task::poll() on each task. For tasks that need to be run, Task::run() is called, and the task is either removed or left alone depending on the return value.

Returns:
true if the main loop must sleep, false if one of the tasks already slept (and there is therefore no second sleep needed).

list_type::size_type scheduler::Scheduler::run_bytype ( int  type  ) 

Iterates once in the list of tasks, calling Task::run() on each task of the given type. The task is either removed or left alone depending on the return value. Task::poll() is NOT called to determine whether the task should be run or not.

Parameters:
[in] type The type of the tasks to be run.
Returns:
The number of tasks that have been run.

list_type::size_type scheduler::Scheduler::run_byname ( int  type,
std::string const &  name 
)

Iterates once in the list of tasks, calling Task::run() on each task with the given name and type. The task is either removed or left alone depending on the return value. Task::poll() is NOT called to determine whether the task should be run or not.

Parameters:
[in] type The type of the tasks to be run.
[in] name The name of the tasks to be run.
Returns:
The number of tasks that have been run.


The documentation for this class was generated from the following file:
Generated on Wed Aug 15 00:37:23 2007 for Epona API by  doxygen 1.5.2