00001 /* 00002 Copyright 2007, 2008, 2009, 2010, 2011 Instituto de Sistemas e Robotica, Instituto Superior Tecnico 00003 00004 This file is part of MeRMaID. 00005 00006 MeRMaID is free software: you can redistribute it and/or modify 00007 it under the terms of the GNU Lesser General Public License as published by 00008 the Free Software Foundation, either version 3 of the License, or 00009 (at your option) any later version. 00010 00011 MeRMaID is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU Lesser General Public License for more details. 00015 00016 You should have received a copy of the GNU Lesser General Public License 00017 along with MeRMaID. If not, see <http://www.gnu.org/licenses/>. 00018 */ 00019 00020 00021 00022 /** 00023 * @Filename Task.hpp 00024 * @Description Task declaration 00025 * @Status Work in Progress 00026 * @Version $Id: Task.hpp 1 2011-03-04 18:13:18Z jreis $ 00027 * @Maintainer nmsra (nmsra@mega.ist.utl.pt) 00028 */ 00029 00030 #ifndef __ACTIVEOBJECT_TASK_H 00031 #define __ACTIVEOBJECT_TASK_H 00032 00033 #include <boost/shared_ptr.hpp> 00034 00035 #include <Time.hpp> 00036 00037 namespace mermaid 00038 { 00039 namespace support 00040 { 00041 namespace activeobject 00042 { 00043 using boost::shared_ptr; 00044 using mermaid::support::system::Time; 00045 00046 /** 00047 * @Class Task Task.hpp "Task.hpp" 00048 * @Description Task base class. 00049 * @Author Marco Barbosa + Nelson Ramos 00050 */ 00051 class Task 00052 { 00053 public: 00054 /** 00055 * @Description Task constructor. 00056 * @Param scheduledTime Time at which Task should be executed 00057 * @Param repeatScheduling If true, the Task will be rescheduled after it has completed its execution. 00058 * @Param repeatFrequency Defines the frequency at which the Task should execute 00059 * @Author Marco Barbosa + Nelson Ramos 00060 */ 00061 Task (Time scheduledTime = Time::getCurrentTime(), bool repeatScheduling = false, float repeatFrequency = 0.0); 00062 virtual ~Task(); 00063 00064 /** 00065 * @Description Method to run the Task. 00066 * @Author Marco Barbosa + Nelson Ramos 00067 * @TODO Make this a pure virtual method 00068 */ 00069 virtual void run(); 00070 00071 /** 00072 * @Description Scheduled time getter. 00073 * @Returns Time that Task is scheduled to run 00074 * @Author Marco Barbosa + Nelson Ramos 00075 */ 00076 Time getScheduledTime(); 00077 00078 bool hasRepeatScheduling(); 00079 00080 void incrementScheduledTimeForRepeat(); 00081 00082 void cancelRepeat(); 00083 00084 bool isOkToRun(); 00085 00086 private: 00087 bool okToRun_; 00088 bool repeatScheduling_; 00089 float repeatFrequency_; 00090 00091 Time scheduledTime_; 00092 }; // Task 00093 } // namespace activeobject 00094 } // namespace support 00095 } // namespace mermaid 00096 00097 #endif // __ACTIVEOBJECT_TASK_H