|
UniSet
2.2.1
|
00001 /* This file is part of the UniSet project 00002 * Copyright (c) 2002 Free Software Foundation, Inc. 00003 * Copyright (c) 2002 Pavel Vainerman 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 */ 00019 // -------------------------------------------------------------------------- 00023 //--------------------------------------------------------------------------- 00024 #ifndef Object_LT_H_ 00025 #define Object_LT_H_ 00026 //-------------------------------------------------------------------------- 00027 #include <deque> 00028 #include "UniSetTypes.h" 00029 #include "MessageType.h" 00030 #include "PassiveTimer.h" 00031 #include "Exceptions.h" 00032 00033 //--------------------------------------------------------------------------- 00034 class UniSetObject; 00035 //--------------------------------------------------------------------------- 00097 class LT_Object 00098 { 00099 public: 00100 LT_Object(); 00101 virtual ~LT_Object(); 00102 00103 00111 virtual timeout_t askTimer( UniSetTypes::TimerId timerid, timeout_t timeMS, clock_t ticks = -1, 00112 UniSetTypes::Message::Priority p = UniSetTypes::Message::High ); 00113 00114 00120 timeout_t checkTimers( UniSetObject* obj ); 00121 00123 //inline timeout_t getSleepTimeMS(){ return sleepTime; } 00124 00125 00130 timeout_t getTimeInterval( UniSetTypes::TimerId timerid ); 00131 00136 timeout_t getTimeLeft( UniSetTypes::TimerId timerid ); 00137 00138 protected: 00139 00141 struct TimerInfo 00142 { 00143 TimerInfo(): id(0), curTimeMS(0), priority(UniSetTypes::Message::High) {}; 00144 TimerInfo(UniSetTypes::TimerId id, timeout_t timeMS, short cnt, UniSetTypes::Message::Priority p): 00145 id(id), 00146 curTimeMS(timeMS), 00147 priority(p), 00148 curTick(cnt - 1) 00149 { 00150 tmr.setTiming(timeMS); 00151 }; 00152 00153 inline void reset() 00154 { 00155 curTimeMS = tmr.getInterval(); 00156 tmr.reset(); 00157 } 00158 00159 UniSetTypes::TimerId id; 00160 timeout_t curTimeMS; 00161 UniSetTypes::Message::Priority priority; 00167 clock_t curTick; 00168 00169 // таймер с меньшим временем ожидания имеет больший приоритет 00170 bool operator < ( const TimerInfo& ti ) const 00171 { 00172 return curTimeMS > ti.curTimeMS; 00173 } 00174 00175 PassiveTimer tmr; 00176 }; 00177 00178 class Timer_eq: public std::unary_function<TimerInfo, bool> 00179 { 00180 public: 00181 Timer_eq(UniSetTypes::TimerId t): tid(t) {} 00182 00183 inline bool operator()(const TimerInfo& ti) const 00184 { 00185 return ( ti.id == tid ); 00186 } 00187 00188 protected: 00189 UniSetTypes::TimerId tid; 00190 }; 00191 00192 typedef std::deque<TimerInfo> TimersList; 00193 00194 timeout_t sleepTime; 00196 TimersList getTimersList(); 00197 00199 virtual std::string getTimerName( int id ){ return ""; } 00200 00201 private: 00202 TimersList tlst; 00204 UniSetTypes::uniset_rwmutex lstMutex; 00205 PassiveTimer tmLast; 00206 }; 00207 //-------------------------------------------------------------------------- 00208 #endif
1.7.6.1