00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef _TASK_DISPATCHER_H_
00027 #define _TASK_DISPATCHER_H_
00028
00029 #include <string>
00030
00031 #include "DBPlanner/task.h"
00032
00033 class SoSensor;
00034 class SoTimerSensor;
00035
00036 namespace db_planner {
00037 class DatabaseManager;
00038 class Model;
00039 class Grasp;
00040 }
00041
00042 class TaskDispatcher;
00043
00045
00073 class Task {
00074 public:
00075 enum Status{RUNNING, ERROR, DONE};
00076 protected:
00078 Status mStatus;
00080 TaskDispatcher* mDispatcher;
00082
00083 db_planner::DatabaseManager *mDBMgr;
00085 db_planner::TaskRecord mRecord;
00086
00087 public:
00088 Task(TaskDispatcher *disp, db_planner::DatabaseManager *mgr, db_planner::TaskRecord rec)
00089 : mDispatcher(disp), mDBMgr(mgr), mRecord(rec) {};
00090 virtual ~Task(){}
00091 virtual void start() = 0;
00093 Status getStatus(){return mStatus;}
00095 db_planner::TaskRecord getRecord(){return mRecord;}
00096 };
00097
00099 class TaskFactory {
00100 public:
00101 inline Task* getTask(TaskDispatcher *disp, db_planner::DatabaseManager *mgr,
00102 db_planner::TaskRecord rec);
00103 };
00104
00106
00128 class TaskDispatcher
00129 {
00130 public:
00131 enum Status {READY, NO_TASK, ERROR, RUNNING, DONE};
00132 private:
00134 TaskFactory mFactory;
00136 db_planner::DatabaseManager *mDBMgr;
00138 Task *mCurrentTask;
00139
00141 Status mStatus;
00143 int mCompletedTasks;
00145 int mMaxTasks;
00147 SoTimerSensor *mSensor;
00148 public:
00149 TaskDispatcher();
00150 ~TaskDispatcher();
00151
00153 int connect(std::string host, int port, std::string username,
00154 std::string password, std::string database);
00155
00157 void checkCurrentTask();
00159 void startNewTask();
00161 void mainLoop();
00162
00164 Status getStatus() const {return mStatus;}
00165
00167 static void sensorCB(void *data, SoSensor*);
00168 };
00169
00171
00173 class EmptyTask : public Task
00174 {
00175 private:
00176 SoTimerSensor *mSensor;
00177 void finish();
00178 public:
00179 EmptyTask(TaskDispatcher *disp, db_planner::DatabaseManager *mgr, db_planner::TaskRecord rec) :
00180 Task(disp, mgr, rec), mSensor(NULL) {}
00181 ~EmptyTask();
00182 void start();
00183 static void sensorCB(void *data, SoSensor*);
00184 };
00185
00187
00189 class EmptyOneShotTask : public Task
00190 {
00191 public:
00192 EmptyOneShotTask(TaskDispatcher *disp, db_planner::DatabaseManager *mgr, db_planner::TaskRecord rec) :
00193 Task(disp, mgr, rec) {}
00194 ~EmptyOneShotTask();
00195 void start(){mStatus = DONE;}
00196 };
00197
00198 #endif