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