TTimer.h Source File

Simu5G: TTimer.h Source File
Simu5G
TTimer.h
1//
2// Simu5G
3//
4// Copyright (C) 2012-2021 Giovanni Nardini, Giovanni Stea, Antonio Virdis et al. (University of Pisa)
5// Copyright (C) 2022-2026 Giovanni Nardini, Giovanni Stea et al. (University of Pisa)
6//
7// This file is part of a software released under the license included in file
8// "license.pdf". Please read LICENSE and README files before using it.
9// The above files and the present reference are part of the software itself,
10// and cannot be removed from it.
11//
12
13#ifndef _LTE_TTIMER_H_
14#define _LTE_TTIMER_H_
15
16#include "simu5g/common/LteCommon.h"
17#include "simu5g/common/timer/TTimerMsg_m.h"
18#include "simu5g/common/timer/TMultiTimerMsg_m.h"
19
20namespace simu5g {
21
22//using namespace omnetpp;
23
25class TTimer : public cObject
26{
27 public:
33 explicit TTimer(cSimpleModule *module) : module_(module), start_(0), expire_(0)
34 {
35 }
36
42 void start(simtime_t t);
43
47 void stop();
48
52 void handle();
53
58 unsigned int getTimerId() const
59 {
60 return timerId_;
61 }
62
68 void setTimerId(unsigned int timerId_)
69 {
70 this->timerId_ = timerId_;
71 }
72
77 bool busy()
78 {
79 return busy_;
80 }
81
86 bool idle()
87 {
88 return !busy_;
89 }
90
95 simtime_t elapsed()
96 {
97 return NOW - start_;
98 }
99
104 simtime_t remaining()
105 {
106 return expire_ - NOW;
107 }
108
109 protected:
111 unsigned int timerId_ = 0;
112
114 opp_component_ptr<cSimpleModule> module_;
115
117 TTimerMsg *intr_ = nullptr;
118
120 bool busy_ = false;
121
123 simtime_t start_;
124
126 simtime_t expire_;
127};
128
137class TMultiTimer : public cObject
138{
139 public:
141 TMultiTimer(cSimpleModule *module) : module_(module)
142 {
143 }
144
150 virtual void add(simtime_t t, unsigned int event);
151
156 unsigned int getTimerId() const
157 {
158 return timerId_;
159 }
160
166 void setTimerId(unsigned int timerId_)
167 {
168 this->timerId_ = timerId_;
169 }
170
175 virtual void remove(const unsigned int event);
176
181 void handle(unsigned int event);
182
187 virtual bool busy() const
188 {
189 return busy_;
190 }
191
197 virtual bool busy(const unsigned int event) const;
198
203 virtual bool idle() const
204 {
205 return !busy_;
206 }
207
208 protected:
210 unsigned int timerId_ = 0;
211
213 opp_component_ptr<cSimpleModule> module_;
214
216 TMultiTimerMsg *intr_ = nullptr;
217
219 bool busy_ = false;
220
222
224 std::multimap<const simtime_t, const unsigned int> directList_;
225
227 typedef std::multimap<const simtime_t, const unsigned int>::iterator Event_it;
228
230 std::map<const unsigned int, const Event_it> reverseList_;
231};
232
233} //namespace
234
235#endif
236
bool busy_
True if there is at least one scheduled event.
Definition TTimer.h:219
virtual bool busy() const
Definition TTimer.h:187
unsigned int getTimerId() const
Definition TTimer.h:156
void setTimerId(unsigned int timerId_)
Definition TTimer.h:166
std::multimap< constsimtime_t, constunsignedint >::iterator Event_it
Event iterator.
Definition TTimer.h:227
void handle(unsigned int event)
virtual void add(simtime_t t, unsigned int event)
std::multimap< const simtime_t, const unsigned int > directList_
The event list.
Definition TTimer.h:224
TMultiTimer(cSimpleModule *module)
Build an idle multi-timer.
Definition TTimer.h:141
TMultiTimerMsg * intr_
Used for scheduling an event into the Omnet++ event scheduler.
Definition TTimer.h:216
std::map< const unsigned int, const Event_it > reverseList_
The removable list. Each event id matches with an iterator.
Definition TTimer.h:230
virtual void remove(const unsigned int event)
virtual bool busy(const unsigned int event) const
unsigned int timerId_
Timer identifier - will be inserted in each timer-generated message.
Definition TTimer.h:210
virtual bool idle() const
Definition TTimer.h:203
opp_component_ptr< cSimpleModule > module_
Object for handling the event.
Definition TTimer.h:213
bool busy_
True if the timer has already been started.
Definition TTimer.h:120
unsigned int getTimerId() const
Definition TTimer.h:58
simtime_t expire_
Expire time.
Definition TTimer.h:126
void setTimerId(unsigned int timerId_)
Definition TTimer.h:68
TTimerMsg * intr_
Used for scheduling an event into the Omnet++ event scheduler.
Definition TTimer.h:117
simtime_t remaining()
Definition TTimer.h:104
simtime_t start_
Last time the timer was started.
Definition TTimer.h:123
bool idle()
Definition TTimer.h:86
TTimer(cSimpleModule *module)
Definition TTimer.h:33
void start(simtime_t t)
unsigned int timerId_
Timer identifier - will be inserted in each timer-generated message.
Definition TTimer.h:111
bool busy()
Definition TTimer.h:77
opp_component_ptr< cSimpleModule > module_
Object for handling the event.
Definition TTimer.h:114
simtime_t elapsed()
Definition TTimer.h:95
Definition AlertReceiver.h:24