UniSet  2.6.0
LT_Object.h
1 /*
2  * Copyright (c) 2015 Pavel Vainerman.
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as
6  * published by the Free Software Foundation, version 2.1.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Lesser Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 // --------------------------------------------------------------------------
20 //---------------------------------------------------------------------------
21 #ifndef Object_LT_H_
22 #define Object_LT_H_
23 //--------------------------------------------------------------------------
24 #include <deque>
25 #include "UniSetTypes.h"
26 #include "MessageType.h"
27 #include "PassiveTimer.h"
28 #include "Exceptions.h"
29 //---------------------------------------------------------------------------
30 namespace uniset
31 {
32  class UniSetObject;
33 
34  //---------------------------------------------------------------------------
96  class LT_Object
97  {
98  public:
99  LT_Object();
100  virtual ~LT_Object();
101 
102 
110  virtual timeout_t askTimer( uniset::TimerId timerid, timeout_t timeMS, clock_t ticks = -1,
111  uniset::Message::Priority p = uniset::Message::High );
112 
113 
119  timeout_t checkTimers( UniSetObject* obj );
120 
122  //inline timeout_t getSleepTimeMS(){ return sleepTime; }
123 
124 
129  timeout_t getTimeInterval( uniset::TimerId timerid );
130 
135  timeout_t getTimeLeft( uniset::TimerId timerid );
136 
137  protected:
138 
140  virtual std::string getTimerName( int id );
141 
143  struct TimerInfo
144  {
145  TimerInfo() {};
146  TimerInfo( uniset::TimerId id, timeout_t timeMS, clock_t cnt, uniset::Message::Priority p ):
147  id(id),
148  curTimeMS(timeMS),
149  priority(p),
150  curTick(cnt - 1)
151  {
152  tmr.setTiming(timeMS);
153  };
154 
155  inline void reset()
156  {
157  curTimeMS = tmr.getInterval();
158  tmr.reset();
159  }
160 
161  uniset::TimerId id = { 0 };
162  timeout_t curTimeMS = { 0 };
163  uniset::Message::Priority priority = { uniset::Message::High };
169  clock_t curTick = { -1 };
170 
171  // таймер с меньшим временем ожидания имеет больший приоритет
172  bool operator < ( const TimerInfo& ti ) const
173  {
174  return curTimeMS > ti.curTimeMS;
175  }
176 
177  PassiveTimer tmr;
178  };
179 
180  class Timer_eq: public std::unary_function<TimerInfo, bool>
181  {
182  public:
183  Timer_eq(uniset::TimerId t): tid(t) {}
184 
185  inline bool operator()(const TimerInfo& ti) const
186  {
187  return ( ti.id == tid );
188  }
189 
190  protected:
191  uniset::TimerId tid;
192  };
193 
194  typedef std::deque<TimerInfo> TimersList;
195 
196  timeout_t sleepTime;
198  TimersList getTimersList();
199 
200  private:
201  TimersList tlst;
202 
204  uniset::uniset_rwmutex lstMutex;
205  PassiveTimer tmLast;
206  };
207  // -------------------------------------------------------------------------
208 } // end of uniset namespace
209 //--------------------------------------------------------------------------
210 #endif
Пассивный таймер
Definition: PassiveTimer.h:90
timeout_t sleepTime
Definition: LT_Object.h:196
virtual std::string getTimerName(int id)
Definition: LT_Object.cc:161
Definition: CallbackTimer.h:29
Definition: UniSetObject.h:73
Definition: LT_Object.h:180
timeout_t curTimeMS
Definition: LT_Object.h:162
virtual timeout_t setTiming(timeout_t msec) noexceptoverride
Definition: PassiveTimer.cc:59
long TimerId
Definition: UniSetTypes_i.idl:32
Definition: Mutex.h:32
virtual timeout_t askTimer(uniset::TimerId timerid, timeout_t timeMS, clock_t ticks=-1, uniset::Message::Priority p=uniset::Message::High)
Definition: LT_Object.cc:167
timeout_t getTimeInterval(uniset::TimerId timerid)
Definition: LT_Object.cc:126
timeout_t checkTimers(UniSetObject *obj)
Definition: LT_Object.cc:45
Definition: LT_Object.h:96
virtual timeout_t getInterval() const noexceptoverride
Definition: PassiveTimer.cc:84
uniset::TimerId id
Definition: LT_Object.h:161
Definition: LT_Object.h:143
uniset::Message::Priority priority
Definition: LT_Object.h:163
timeout_t getTimeLeft(uniset::TimerId timerid)
Definition: LT_Object.cc:140
virtual void reset() noexcept
Definition: PassiveTimer.cc:73
clock_t curTick
Definition: LT_Object.h:169