ITask.cpp

00001 /***************************************************************************
00002  *                                                                         *
00003  *   (c) Art Tevs, MPI Informatik Saarbruecken                             *
00004  *       mailto: <tevs@mpi-sb.mpg.de>                                      *
00005  *                                                                         *
00006  *   This program is free software; you can redistribute it and/or modify  *
00007  *   it under the terms of the GNU General Public License as published by  *
00008  *   the Free Software Foundation; either version 2 of the License, or     *
00009  *   (at your option) any later version.                                   *
00010  *                                                                         *
00011  ***************************************************************************/
00012 
00013 
00014 //----------------------------------------------------------------------------------
00015 // Includes
00016 //----------------------------------------------------------------------------------
00017 #include "ITask.h"
00018 #include "Log.h"
00019 #include "Kernel.h"
00020 
00021 namespace nrEngine{
00022 
00023         //--------------------------------------------------------------------
00024         ITask::ITask() : IThread(){
00025                 init();
00026         }
00027 
00028         //--------------------------------------------------------------------
00029         ITask::ITask(const std::string& name) : IThread(), _taskName(name)
00030         {
00031                 init();
00032         }
00033 
00034         //--------------------------------------------------------------------
00035         void ITask::init(){
00036                 _taskCanKill = false;
00037                 _taskOrder = ORDER_NORMAL;
00038                 _taskID = 0;
00039                 _taskState = TASK_STOPPED;
00040                 _orderChanged = false;
00041                 _taskType = TASK_USER;
00042                 _taskGraphColor = 0;
00043                 _taskProperty = TASK_NONE;
00044         }
00045         
00046         //--------------------------------------------------------------------
00047         ITask::~ITask(){
00048 
00049         }
00050 
00051         //--------------------------------------------------------------------
00052         bool ITask::operator <  (const ITask &t){
00053                 return this->_taskOrder < t._taskOrder;
00054         }
00055 
00056         //--------------------------------------------------------------------
00057         bool ITask::operator == (const ITask &t){
00058                 return this->_taskOrder == t._taskOrder;
00059         }
00060 
00061         //--------------------------------------------------------------------
00062         bool ITask::operator <= (const ITask &t){
00063                 return (*this < t) || (*this == t);
00064         }
00065 
00066         //--------------------------------------------------------------------
00067         bool ITask::operator >  (const ITask &t){
00068                 return !(*this <= t) ;
00069         }
00070 
00071         //--------------------------------------------------------------------
00072         bool ITask::operator >= (const ITask &t){
00073                 return !(*this < t) || (*this == t);
00074         }
00075 
00076         //--------------------------------------------------------------------
00077         bool ITask::operator != (const ITask &t){
00078                 return !(*this == t);
00079         }
00080 
00081         //--------------------------------------------------------------------
00082         void ITask::setTaskOrder(TaskOrder order){
00083                 _taskOrder = order;
00084                 _orderChanged = true;
00085         }
00086         //--------------------------------------------------------------------
00087         void ITask::setTaskType(TaskType type){
00088                 this->_taskType = type;
00089         }
00090 
00091         //--------------------------------------------------------------------
00092         void ITask::setTaskID(TaskId id){
00093                 this->_taskID = id;
00094         }
00095 
00096         //--------------------------------------------------------------------
00097         void ITask::setTaskState(TaskState state){
00098                 this->_taskState = state;
00099         }
00100         
00101         //--------------------------------------------------------------------
00102         void ITask::setTaskProperty(TaskProperty proper){
00103                 this->_taskProperty = proper;
00104         }
00105 
00106         //--------------------------------------------------------------------
00107         void ITask::setTaskName(const std::string& name){
00108                 _taskName = name;
00109         }
00110 
00111         struct _taskSort : std::less<SharedPtr<ITask> >
00112         {
00113                 public:
00114                         bool operator () (const SharedPtr<ITask>& a, const SharedPtr<ITask>& b)
00115                         {
00116                                 return (*a) < (*b);
00117                         }
00118         };
00119 
00120         //--------------------------------------------------------------------
00121         Result ITask::addTaskDependency(SharedPtr<ITask> task)
00122         {
00123                 // add the task into the list of dependencies
00124                 _taskDependencies.push_back(task);
00125 
00126                 // sort the dependency list 
00127                 _taskDependencies.sort(_taskSort());
00128                 
00129                 // debug info
00130                 NR_Log(Log::LOG_KERNEL, Log::LL_DEBUG, "Task %s depends now on task %s", getTaskName(), task->getTaskName());
00131 
00132                 return OK;
00133         }
00134         
00135         //--------------------------------------------------------------------
00136         Result ITask::addTaskDependency(TaskId id)
00137         {
00138                 // get task from kernel based on id
00139                 SharedPtr<ITask> task = Engine::sKernel()->getTaskByID(id);
00140                 
00141                 if (task != NULL)
00142                 {
00143                         return addTaskDependency(task);
00144                 }
00145 
00146                 return KERNEL_NO_TASK_FOUND;
00147         }
00148 
00149         //--------------------------------------------------------------------
00150         Result ITask::addTaskDependency(const std::string& name)
00151         {
00152                 // get task from kernel based on id
00153                 SharedPtr<ITask> task = Engine::sKernel()->getTaskByName(name);
00154                 
00155                 if (task != NULL)
00156                 {
00157                         return addTaskDependency(task);
00158                 }
00159 
00160                 return KERNEL_NO_TASK_FOUND;
00161         }
00162         //--------------------------------------------------------------------
00163         /*Result ITask::addTaskDependency(const ITask& task)
00164         {
00165                 return addTaskDependency(task.getTaskID());
00166         }
00167 
00168         //--------------------------------------------------------------------
00169         Result ITask::addTaskDependency(const ITask* pTask)
00170         {
00171                 return addTaskDependency(pTask->getTaskID());
00172         }
00173         */
00174         
00175         //--------------------------------------------------------------------
00176         void ITask::_noticeSuspend(){
00177                 onSuspendTask();
00178         }
00179 
00180         //--------------------------------------------------------------------
00181         void ITask::_noticeResume(){
00182                 onResumeTask();
00183         }
00184 
00185         //--------------------------------------------------------------------
00186         void ITask::_noticeUpdate(){
00187                 updateTask();
00188         }
00189 
00190         //--------------------------------------------------------------------
00191         void ITask::_noticeStop(){
00192                 stopTask();
00193         }
00194 
00195 }; // end namespace
00196 

Generated on Wed Sep 12 23:19:42 2007 for nrEngine by  doxygen 1.5.1