00001 /* 00002 * This library is free software; you can redistribute it and/or 00003 * modify it under the terms of the GNU Lesser General Public 00004 * License as published by the Free Software Foundation; either 00005 * version 2.1 of the License, or (at your option) any later version. 00006 * 00007 * As a special exception, you may use this file as part of a free 00008 * software library without restriction. Specifically, if other files 00009 * instantiate templates or use macros or inline functions from this 00010 * file, or you compile this file and link it with other files to 00011 * produce an executable, this file does not by itself cause the 00012 * resulting executable to be covered by the GNU General Public 00013 * License. This exception does not however invalidate any other 00014 * reasons why the executable file might be covered by the GNU Library 00015 * General Public License. 00016 * 00017 * This library is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00020 * Lesser General Public License for more details. 00021 * 00022 * You should have received a copy of the GNU Lesser General Public 00023 * License along with this library; if not, write to the Free Software 00024 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00025 */ 00026 #ifndef Cxxtools_System_Timer_h 00027 #define Cxxtools_System_Timer_h 00028 00029 #include <cxxtools/signal.h> 00030 #include <cxxtools/timespan.h> 00031 #include <cxxtools/api.h> 00032 #include <vector> 00033 #include <cstddef> 00034 00035 namespace cxxtools { 00036 00037 class SelectorBase; 00038 00068 class CXXTOOLS_API Timer 00069 { 00070 class Sentry; 00071 00072 public: 00077 Timer(); 00078 00083 ~Timer(); 00084 00085 SelectorBase* selector() 00086 { return _selector; } 00087 00088 void setSelector(SelectorBase* s); 00089 00092 bool active() const; 00093 00098 std::size_t interval() const; 00099 00108 void start(std::size_t interval); 00109 00115 void stop(); 00116 00124 bool update(); 00125 00126 bool update(const Timespan& now); 00127 00132 Signal<> timeout; 00133 00134 const Timespan& finished() const 00135 { return _finished; } 00136 00137 private: 00138 Sentry* _sentry; 00139 SelectorBase* _selector; 00140 bool _active; 00141 std::size_t _interval; 00142 Timespan _remaining; 00143 Timespan _finished; 00144 }; 00145 00146 } 00147 00148 00149 #endif