UniSet  2.0.0
LT_Object.h
См. документацию.
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 //---------------------------------------------------------------------------
00095 class LT_Object
00096 {
00097     public:
00098         LT_Object();
00099         virtual ~LT_Object();
00100 
00101 
00110         timeout_t askTimer( UniSetTypes::TimerId timerid, timeout_t timeMS, clock_t ticks=-1,
00111                         UniSetTypes::Message::Priority p=UniSetTypes::Message::High );
00112 
00113 
00120         timeout_t checkTimers( UniSetObject* obj );
00121 
00123         //inline timeout_t getSleepTimeMS(){ return sleepTime; }
00124 
00125     protected:
00126 
00128         struct TimerInfo
00129         {
00130             TimerInfo():id(0), curTimeMS(0), priority(UniSetTypes::Message::High){};
00131             TimerInfo(UniSetTypes::TimerId id, timeout_t timeMS, short cnt, UniSetTypes::Message::Priority p):
00132                 id(id),
00133                 curTimeMS(timeMS),
00134                 priority(p),
00135                 curTick(cnt-1)
00136             {
00137                 tmr.setTiming(timeMS);
00138             };
00139 
00140             inline void reset()
00141             {
00142                 curTimeMS = tmr.getInterval();
00143                 tmr.reset();
00144             }
00145 
00146             UniSetTypes::TimerId id;    
00147             timeout_t curTimeMS;                
00148             UniSetTypes::Message::Priority priority; 
00154             clock_t curTick;
00155 
00156             // таймер с меньшим временем ожидания имеет больший приоритет
00157             bool operator < ( const TimerInfo& ti ) const
00158             {
00159                 return curTimeMS > ti.curTimeMS;
00160             }
00161 
00162             PassiveTimer tmr;
00163         };
00164 
00165         class Timer_eq: public std::unary_function<TimerInfo, bool>
00166         {
00167             public:
00168                 Timer_eq(UniSetTypes::TimerId t):tid(t){}
00169 
00170             inline bool operator()(const TimerInfo& ti) const
00171             {
00172                 return ( ti.id == tid );
00173             }
00174 
00175             protected:
00176                 UniSetTypes::TimerId tid;
00177         };
00178 
00179         typedef std::deque<TimerInfo> TimersList;
00180 
00181     private:
00182         TimersList tlst;
00184         UniSetTypes::uniset_rwmutex lstMutex;
00185         timeout_t sleepTime; 
00186         PassiveTimer tmLast;
00187 };
00188 //--------------------------------------------------------------------------
00189 #endif