scheduler::Scheduler Class Reference

A task scheduler. More...

#include <scheduler.h>

List of all members.

Public Types

typedef
list_type::size_type 
size_type
 Size type.
typedef
list_type::const_iterator 
iterator
 Task list iterator.
typedef
list_type::const_iterator 
const_iterator
 Task list constant iterator.
typedef
list_type::const_reverse_iterator 
reverse_iterator
 Task list reverse iterator.
typedef
list_type::const_reverse_iterator 
const_reverse_iterator
 Task list constant reverse iterator.

Public Member Functions

 Scheduler ()
 Default constructor.
 Scheduler (Scheduler const &s)
 Copy constructor.
Scheduleroperator= (Scheduler const &right)
 Assignment operator.
bool add (Task &task)
 Adds a task.
void remove (Task &task)
 Removes a task.
size_type remove_bymodule (modules::Module const *module, bool free=false)
 Removes all tasks belonging to a given module.
size_type remove_byname (modules::Module const *module, std::string const &name, bool free=false)
 Removes all tasks with a name belonging to a module.
bool run ()
 Runs tasks.
size_type run_bymodule (modules::Module const *module)
 Runs tasks belonging to a module.
size_type run_byname (modules::Module const *module, std::string const &name)
 Runs tasks with a given name belonging to a module.
Task const * current_task () const
 Returns the current task being run by the scheduler (0 if none).
iterator begin ()
 Returns the first iterator of the tasks list.
const_iterator begin () const
 Same, const version.
iterator end ()
 Returns the last iterator of the tasks list.
const_iterator end () const
 Same, const version.
reverse_iterator rbegin ()
 Returns the first reverse iterator of the tasks list.
const_reverse_iterator rbegin () const
 Same, const version.
reverse_iterator rend ()
 Returns the last reverse iterator of the tasks list.
const_reverse_iterator rend () const
 Same, const version.
bool empty () const
 Returns whether there are tasks in the scheduler.
list_type::size_type size () const
 Returns the number of tasks in the scheduler.


Detailed Description

The Scheduler class manages a list of Task objects and runs them at times determined by the task itself.

Member Function Documentation

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

Adds a task to the list of scheduled tasks. When the module the task belongs to is unloaded, the task is automatically removed from the scheduler, though it is still the module responsibility to dispose of it.

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

void 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.

size_type scheduler::Scheduler::remove_bymodule ( modules::Module const *  module,
bool  free = false 
)

Removes all tasks belonging to a given module from the list of scheduled tasks.

The core module calls removeby_module(module, false) when a module is being unloaded.

Parameters:
[in] module The module whose tasks must be removed.
[in] free Whether operator delete must be called on tasks before removing them.
Returns:
The number of tasks that have been removed.

size_type scheduler::Scheduler::remove_byname ( modules::Module const *  module,
std::string const &  name,
bool  free = false 
)

Removes all tasks with the given name belonging to the given module from the list of scheduled tasks.

Parameters:
[in] module The module whose tasks must be removed.
[in] name The name of the tasks to be removed.
[in] free Whether operator delete must be called on tasks before removing them.
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).

size_type scheduler::Scheduler::run_bymodule ( modules::Module const *  module  ) 

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

Parameters:
[in] module The module whose tasks must be run.
Returns:
The number of tasks that have been run.

size_type scheduler::Scheduler::run_byname ( modules::Module const *  module,
std::string const &  name 
)

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

Parameters:
[in] module The module whose tasks must 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 Fri Apr 18 22:03:29 2008 for Epona API by  doxygen 1.5.3