A high-level executive that dispatches tasks based on the contents of the database. More...
#include <dbTaskDispatcher.h>
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. | |
DBTask * | mCurrentTask |
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. |
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.
Definition at line 87 of file dbTaskDispatcher.h.
Definition at line 49 of file dbTaskDispatcher.cpp.
Definition at line 56 of file dbTaskDispatcher.cpp.
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.
Status graspit_dbase_tasks::DBTaskDispatcher::getStatus | ( | ) | const [inline] |
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:
Definition at line 101 of file dbTaskDispatcher.cpp.
std::vector<std::string> graspit_dbase_tasks::DBTaskDispatcher::mAcceptedTaskTypes [private] |
A list of accepted task types. Empty if all task types are accepted.
Definition at line 108 of file dbTaskDispatcher.h.
int graspit_dbase_tasks::DBTaskDispatcher::mCompletedTasks [private] |
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.
int graspit_dbase_tasks::DBTaskDispatcher::mMaxTasks [private] |
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.
std::map<std::string,DBTaskCreator*> graspit_dbase_tasks::DBTaskDispatcher::mTaskCreators [private] |
Map from task name in database to task creators.
Definition at line 90 of file dbTaskDispatcher.h.