Public Types | Public Member Functions | Private Member Functions | Private Attributes
graspit_dbase_tasks::DBTaskDispatcher Class Reference

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

#include <dbTaskDispatcher.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.
 DBTaskDispatcher ()
Status getStatus () const
 Returns the status of the Dispatcher.
int init (int argc, char **argv)
 Calls the database connection function.
int mainLoop ()
 Main operation loop, called periodically.
void registerTaskCreator (std::string task_name, DBTaskCreator *creator)
 Register a new task creator for a task with the given name.
void startNewTask ()
 Attempts to read a task from the dbase and start it.
 ~DBTaskDispatcher ()

Private Member Functions

int connect (std::string host, int port, std::string username, std::string password, std::string database)
 Connects to the database. Returns 0 on success.

Private Attributes

std::vector< std::string > mAcceptedTaskTypes
 A list of accepted task types. Empty if all task types are accepted.
int mCompletedTasks
 The number of tasks completed so far.
DBTaskmCurrentTask
 The task currently being executed.
db_planner::DatabaseManager * mDBMgr
 The db mgr used to connect to the dbase.
int mMaxTasks
 Max number of tasks to be completed. -1 means no max limit.
Status mStatus
 The status of the Dispatcher.
std::map< std::string,
DBTaskCreator * > 
mTaskCreators
 Map from task name in database to task creators.

Detailed Description

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

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

It can run either one-shot tasks (that do something and they're done) or event-based tasks which have their own callback system.

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 DBTask itself finishes with an error, the Dispatcher will mark that in the database, then proceed to the next task.

The DBTaskDispatcher is a GraspIt! Plugin.

Definition at line 84 of file dbTaskDispatcher.h.


Member Enumeration Documentation

Enumerator:
READY 
NO_TASK 
ERROR 
RUNNING 
DONE 

Definition at line 87 of file dbTaskDispatcher.h.


Constructor & Destructor Documentation

Definition at line 49 of file dbTaskDispatcher.cpp.

Definition at line 56 of file dbTaskDispatcher.cpp.


Member Function Documentation

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 151 of file dbTaskDispatcher.cpp.

int graspit_dbase_tasks::DBTaskDispatcher::connect ( std::string  host,
int  port,
std::string  username,
std::string  password,
std::string  database 
) [private]

Connects to the database. Returns 0 on success.

Definition at line 66 of file dbTaskDispatcher.cpp.

Returns the status of the Dispatcher.

Definition at line 138 of file dbTaskDispatcher.h.

int graspit_dbase_tasks::DBTaskDispatcher::init ( int  argc,
char **  argv 
)

Calls the database connection function.

Definition at line 87 of file dbTaskDispatcher.cpp.

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 190 of file dbTaskDispatcher.cpp.

void graspit_dbase_tasks::DBTaskDispatcher::registerTaskCreator ( std::string  task_name,
DBTaskCreator creator 
) [inline]

Register a new task creator for a task with the given name.

Definition at line 128 of file dbTaskDispatcher.h.

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 101 of file dbTaskDispatcher.cpp.


Member Data Documentation

A list of accepted task types. Empty if all task types are accepted.

Definition at line 108 of file dbTaskDispatcher.h.

The number of tasks completed so far.

Definition at line 102 of file dbTaskDispatcher.h.

The task currently being executed.

Definition at line 96 of file dbTaskDispatcher.h.

db_planner::DatabaseManager* graspit_dbase_tasks::DBTaskDispatcher::mDBMgr [private]

The db mgr used to connect to the dbase.

Definition at line 93 of file dbTaskDispatcher.h.

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

Definition at line 105 of file dbTaskDispatcher.h.

The status of the Dispatcher.

Definition at line 99 of file dbTaskDispatcher.h.

Map from task name in database to task creators.

Definition at line 90 of file dbTaskDispatcher.h.


The documentation for this class was generated from the following files:


graspit_dbase_tasks
Author(s): Matei Ciocarlie
autogenerated on Mon Jan 6 2014 11:20:09