TaskDispatcher Class Reference

A high-level executive that dispatches tasks based on the contents of the database. More...

#include <taskDispatcher.h>

List of all members.

Public Types

enum  Status {
  READY, NO_TASK, ERROR, RUNNING,
  DONE
}

Public Member Functions

void checkCurrentTask ()
 Checks the status of the current task; cleans up after it if done.
int connect (std::string host, int port, std::string username, std::string password, std::string database)
 Connects to the database. Returns 0 on success.
Status getStatus () const
 Returns the status of the Dispatcher.
void mainLoop ()
 Main operation loop, called periodically.
void startNewTask ()
 Attempts to read a task from the dbase and start it.
 TaskDispatcher ()
 ~TaskDispatcher ()

Static Public Member Functions

static void sensorCB (void *data, SoSensor *)
 Static sensor callback, just calls mainLoop().

Private Attributes

int mCompletedTasks
 The number of tasks completed so far.
TaskmCurrentTask
 The task currently being executed.
db_planner::DatabaseManagermDBMgr
 The db mgr used to connect to the dbase.
TaskFactory mFactory
 A factory for instantiating the right type of task.
int mMaxTasks
 Max number of tasks to be completed. -1 means no max limit.
SoTimerSensor * mSensor
 The timer sensor used to wake up periodically.
Status mStatus
 The status of the Dispatcher.

Detailed Description

A high-level executive that dispatches tasks based on the contents of the database.

The TaskDispatcher is in charge of reading the list of tasks to be executed from the database, creating and startinng the appropriate instances of the Task class and then monitoring them.

It can run either one-shot tasks (that do something and they're done) or even-based tasks which have their own callback system. In the latter case, the Dispatcher uses a callback timer of its own to wake up periodically and check on the currently running task.

On exit, the Dispatcher will exit GraspIt's main loop, thus terminating the application. Before doing that, it will set its own status to inform the main app of the outcome of the tasks. It can exit because:

Note that if a Task itself finishes with an error, the Dispacther will mark that in the database, then proceed to the next task.

Definition at line 128 of file taskDispatcher.h.


Member Enumeration Documentation

Enumerator:
READY 
NO_TASK 
ERROR 
RUNNING 
DONE 

Definition at line 131 of file taskDispatcher.h.


Constructor & Destructor Documentation

TaskDispatcher::TaskDispatcher (  ) 

Definition at line 47 of file taskDispatcher.cpp.

TaskDispatcher::~TaskDispatcher (  ) 

Definition at line 58 of file taskDispatcher.cpp.


Member Function Documentation

void TaskDispatcher::checkCurrentTask (  ) 

Checks the status of the current task; cleans up after it if done.

Checks on the current task; if it is finished, cleans up after it and marks the result in the database.

If task is finished, sets status to READY, unless there is an error marking the finished task in the database, in which case status is set to ERROR.

Nore that even if the task finishes with an error, the dispatcher will be READY for the next task (not abort altogether). The task that had an error is marked as such in the database. However, if there is an error in communicating with the database, the dispatcher will abort altogether.

Definition at line 164 of file taskDispatcher.cpp.

int TaskDispatcher::connect ( std::string  host,
int  port,
std::string  username,
std::string  password,
std::string  database 
)

Connects to the database. Returns 0 on success.

Definition at line 69 of file taskDispatcher.cpp.

Status TaskDispatcher::getStatus (  )  const [inline]

Returns the status of the Dispatcher.

Definition at line 164 of file taskDispatcher.h.

void TaskDispatcher::mainLoop (  ) 

Main operation loop, called periodically.

Will start tasks as long as there are tasks to be run. If the tasks are of the one-shot type, it just loops in here as long as it has tasks. If the task is event-based and needs us to surrender control, it will surrender control but schedule the timer to come back here and check on the task later.

Definition at line 198 of file taskDispatcher.cpp.

void TaskDispatcher::sensorCB ( void *  data,
SoSensor *   
) [static]

Static sensor callback, just calls mainLoop().

Definition at line 229 of file taskDispatcher.cpp.

void TaskDispatcher::startNewTask (  ) 

Attempts to read a task from the dbase and start it.

Gets a new task from the database and starts it. Possible outcomes:

  • no more tasks in database; sets status to NO_TASK
  • max number of tasks exceeded; sets status to DONE
  • error in reading the task; sets status to ERROR
  • error in starting the task; sets status to READY
  • task has started and needs us to surrender control; sets status to RUNNING
  • task is finished in one shot; sets status to READY

Definition at line 103 of file taskDispatcher.cpp.


Member Data Documentation

The number of tasks completed so far.

Definition at line 143 of file taskDispatcher.h.

The task currently being executed.

Definition at line 138 of file taskDispatcher.h.

The db mgr used to connect to the dbase.

Definition at line 136 of file taskDispatcher.h.

A factory for instantiating the right type of task.

Definition at line 134 of file taskDispatcher.h.

Max number of tasks to be completed. -1 means no max limit.

Definition at line 145 of file taskDispatcher.h.

SoTimerSensor* TaskDispatcher::mSensor [private]

The timer sensor used to wake up periodically.

Definition at line 147 of file taskDispatcher.h.

The status of the Dispatcher.

Definition at line 141 of file taskDispatcher.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


graspit
Author(s):
autogenerated on Wed Jan 25 11:00:25 2012