UniSet 2.32.1
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//---------------------------------------------------------------------------
31namespace uniset
32{
33 class UniSetObject;
34
35 //---------------------------------------------------------------------------
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
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 curTimeMS = timeMS;
151 };
152
153 inline void reset()
154 {
155 curTimeMS = tmr.getInterval();
156 tmr.reset();
157 }
158
159 uniset::TimerId id = { 0 };
160 timeout_t curTimeMS = { 0 };
161 uniset::Message::Priority priority = { uniset::Message::High };
167 clock_t curTick = { -1 };
168
169 // таймер с меньшим временем ожидания имеет больший приоритет
170 bool operator < ( const TimerInfo& ti ) const
171 {
172 return curTimeMS > ti.curTimeMS;
173 }
174
175 PassiveTimer tmr;
176 };
177
179#if __cplusplus < 201103L
180 : public std::unary_function<TimerInfo, bool>
181#endif
182 {
183 public:
184 Timer_eq(uniset::TimerId t): tid(t) {}
185
186 inline bool operator()(const TimerInfo& ti) const
187 {
188 return ( ti.id == tid );
189 }
190
191 protected:
192 uniset::TimerId tid;
193 };
194
195 typedef std::deque<TimerInfo> TimersList;
196
197 timeout_t sleepTime;
199 TimersList getTimersList() const;
200
201 private:
202 TimersList tlst;
203
205 mutable uniset::uniset_rwmutex lstMutex;
206 PassiveTimer tmLast;
207
208 Debug::type loglevel = { Debug::LEVEL3 };
209 };
210 // -------------------------------------------------------------------------
211} // end of uniset namespace
212//--------------------------------------------------------------------------
213#endif
Definition LT_Object.h:182
Definition LT_Object.h:98
timeout_t sleepTime
Definition LT_Object.h:197
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 Calibration.h:27
long TimerId
Definition UniSetTypes_i.idl:32
Definition LT_Object.h:141
uniset::TimerId id
Definition LT_Object.h:159
timeout_t curTimeMS
Definition LT_Object.h:160
uniset::Message::Priority priority
Definition LT_Object.h:161
clock_t curTick
Definition LT_Object.h:167