UniSet  2.24.2
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 "Debug.h"
26 #include "UniSetTypes.h"
27 #include "MessageType.h"
28 #include "PassiveTimer.h"
29 #include "Exceptions.h"
30 //---------------------------------------------------------------------------
31 namespace uniset
32 {
33  class UniSetObject;
34 
35  //---------------------------------------------------------------------------
97  class LT_Object
98  {
99  public:
100  LT_Object();
101  virtual ~LT_Object();
102 
103 
111  virtual timeout_t askTimer( uniset::TimerId timerid, timeout_t timeMS, clock_t ticks = -1,
112  uniset::Message::Priority p = uniset::Message::High );
113 
114 
120  timeout_t checkTimers( UniSetObject* obj );
121 
126  timeout_t getTimeInterval( uniset::TimerId timerid ) const;
127 
132  timeout_t getTimeLeft( uniset::TimerId timerid ) const;
133 
134  protected:
135 
137  virtual std::string getTimerName( int id ) const;
138 
140  struct TimerInfo
141  {
142  TimerInfo() {};
143  TimerInfo( uniset::TimerId id, timeout_t timeMS, clock_t cnt, uniset::Message::Priority p ):
144  id(id),
145  curTimeMS(timeMS),
146  priority(p),
147  curTick(cnt - 1)
148  {
149  tmr.setTiming(timeMS);
150  };
151 
152  inline void reset()
153  {
154  curTimeMS = tmr.getInterval();
155  tmr.reset();
156  }
157 
158  uniset::TimerId id = { 0 };
159  timeout_t curTimeMS = { 0 };
160  uniset::Message::Priority priority = { uniset::Message::High };
166  clock_t curTick = { -1 };
167 
168  // таймер с меньшим временем ожидания имеет больший приоритет
169  bool operator < ( const TimerInfo& ti ) const
170  {
171  return curTimeMS > ti.curTimeMS;
172  }
173 
174  PassiveTimer tmr;
175  };
176 
177  class Timer_eq: public std::unary_function<TimerInfo, bool>
178  {
179  public:
180  Timer_eq(uniset::TimerId t): tid(t) {}
181 
182  inline bool operator()(const TimerInfo& ti) const
183  {
184  return ( ti.id == tid );
185  }
186 
187  protected:
188  uniset::TimerId tid;
189  };
190 
191  typedef std::deque<TimerInfo> TimersList;
192 
193  timeout_t sleepTime;
195  TimersList getTimersList() const;
196 
197  private:
198  TimersList tlst;
199 
201  mutable uniset::uniset_rwmutex lstMutex;
202  PassiveTimer tmLast;
203 
204  Debug::type loglevel = { Debug::LEVEL3 };
205  };
206  // -------------------------------------------------------------------------
207 } // end of uniset namespace
208 //--------------------------------------------------------------------------
209 #endif
Definition: LT_Object.h:178
Definition: LT_Object.h:98
timeout_t sleepTime
Definition: LT_Object.h:193
timeout_t getTimeInterval(uniset::TimerId timerid) const
Definition: LT_Object.cc:126
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 checkTimers(UniSetObject *obj)
Definition: LT_Object.cc:45
timeout_t getTimeLeft(uniset::TimerId timerid) const
Definition: LT_Object.cc:140
virtual std::string getTimerName(int id) const
Definition: LT_Object.cc:161
Пассивный таймер
Definition: PassiveTimer.h:94
virtual timeout_t setTiming(timeout_t msec) noexcept override
Definition: PassiveTimer.cc:59
virtual timeout_t getInterval() const noexcept override
Definition: PassiveTimer.cc:84
virtual void reset() noexcept override
Definition: PassiveTimer.cc:73
Definition: UniSetObject.h:80
Definition: Mutex.h:32
Definition: CommonEventLoop.h:15
long TimerId
Definition: UniSetTypes_i.idl:32
Definition: LT_Object.h:141
uniset::TimerId id
Definition: LT_Object.h:158
timeout_t curTimeMS
Definition: LT_Object.h:159
uniset::Message::Priority priority
Definition: LT_Object.h:160
clock_t curTick
Definition: LT_Object.h:166