GpCoreTools/Timer.h
Go to the documentation of this file.
00001 /***************************************************************************
00002 **
00003 **  This file is part of GpCoreTools.
00004 **
00005 **  This file may be distributed and/or modified under the terms of the
00006 **  GNU General Public License version 2 or 3 as published by the Free
00007 **  Software Foundation and appearing in the file LICENSE.GPL included
00008 **  in the packaging of this file.
00009 **
00010 **  This file is distributed in the hope that it will be useful, but WITHOUT
00011 **  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 **  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
00013 **  more details.
00014 **
00015 **  You should have received a copy of the GNU General Public License
00016 **  along with this program. If not, see <http://www.gnu.org/licenses/>.
00017 **
00018 **  See http://www.geopsy.org for more information.
00019 **
00020 **  Created: 2009-08-20
00021 **  Authors:
00022 **    Marc Wathelet
00023 **    Marc Wathelet (LGIT, Grenoble, France)
00024 **
00025 ***************************************************************************/
00026 
00027 #ifndef TIMER_H
00028 #define TIMER_H
00029 
00030 #include <time.h>
00031 
00032 #include "GpCoreToolsDLLExport.h"
00033 
00034 namespace GpCoreTools {
00035 
00036 class GPCORETOOLS_EXPORT Timer
00037 {
00038 public:
00039   Timer();
00040   virtual ~Timer();
00041 
00042   void start();
00043   void stop();
00044 
00045   bool isRunning() {return _queued;}
00046 
00047   int interval() const {return _interval;}
00048   void setInterval(int i) {_interval=i;}
00049 
00050   void setTimeout();
00051   int timeout() const;
00052   bool after(Timer * o) const;
00053 
00054   void printDebug();
00055 
00056   virtual bool exec()=0;
00057 private:
00058   friend class EventLoop;
00059 
00060   int _interval;
00061   timespec _timeout;
00062 
00063   class QueueItem
00064   {
00065   public:
00066     QueueItem(Timer * t) {_timer=t;}
00067     ~QueueItem() {if(_timer) _timer->stop();}
00068 
00069     Timer * timer() {return _timer;}
00070     void detach() {_timer=0;}
00071   private:
00072     Timer * _timer;
00073   };
00074   QueueItem * _queued;
00075 };
00076 
00077 } // namespace GpCoreTools
00078 
00079 #endif // TIMER_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines