00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef TIMER_H
00021 #define TIMER_H
00022
00023 #include "ns3/fatal-error.h"
00024 #include "nstime.h"
00025 #include "event-id.h"
00026 #include "ns3/int-to-type.h"
00027
00028 namespace ns3 {
00029
00030 class TimerImpl;
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 class Timer
00046 {
00047 public:
00048
00049
00050
00051
00052 enum DestroyPolicy {
00053
00054
00055
00056
00057 CANCEL_ON_DESTROY = (1<<3),
00058
00059
00060
00061
00062 REMOVE_ON_DESTROY = (1<<4),
00063
00064
00065
00066
00067 CHECK_ON_DESTROY = (1<<5)
00068 };
00069 enum State {
00070 RUNNING,
00071 EXPIRED,
00072 SUSPENDED,
00073 };
00074
00075
00076
00077
00078 Timer ();
00079
00080
00081
00082 Timer (enum DestroyPolicy destroyPolicy);
00083 ~Timer ();
00084
00085
00086
00087
00088
00089
00090 template <typename FN>
00091 void SetFunction (FN fn);
00092
00093
00094
00095
00096
00097
00098
00099 template <typename MEM_PTR, typename OBJ_PTR>
00100 void SetFunction (MEM_PTR memPtr, OBJ_PTR objPtr);
00101
00102
00103
00104
00105
00106
00107
00108 template <typename T1>
00109 void SetArguments (T1 a1);
00110
00111
00112
00113
00114
00115
00116 template <typename T1, typename T2>
00117 void SetArguments (T1 a1, T2 a2);
00118
00119
00120
00121
00122
00123
00124
00125 template <typename T1, typename T2, typename T3>
00126 void SetArguments (T1 a1, T2 a2, T3 a3);
00127
00128
00129
00130
00131
00132
00133
00134
00135 template <typename T1, typename T2, typename T3, typename T4>
00136 void SetArguments (T1 a1, T2 a2, T3 a3, T4 a4);
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146 template <typename T1, typename T2, typename T3, typename T4, typename T5>
00147 void SetArguments (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
00159 void SetArguments (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6);
00160
00161
00162
00163
00164
00165
00166 void SetDelay (const Time &delay);
00167
00168
00169
00170 Time GetDelay (void) const;
00171
00172
00173
00174
00175
00176 Time GetDelayLeft (void) const;
00177
00178
00179
00180
00181 void Cancel (void);
00182
00183
00184
00185
00186 void Remove (void);
00187
00188
00189
00190 bool IsExpired (void) const;
00191
00192
00193
00194 bool IsRunning (void) const;
00195
00196
00197
00198
00199 bool IsSuspended (void) const;
00200
00201
00202
00203 enum Timer::State GetState (void) const;
00204
00205
00206
00207
00208 void Schedule (void);
00209
00210
00211
00212
00213
00214
00215 void Schedule (Time delay);
00216
00217
00218
00219
00220
00221
00222 void Suspend (void);
00223
00224
00225
00226
00227
00228 void Resume (void);
00229
00230 private:
00231
00232 enum {
00233 TIMER_SUSPENDED = (1<<7)
00234 };
00235
00236 int m_flags;
00237 Time m_delay;
00238 EventId m_event;
00239 TimerImpl *m_impl;
00240 Time m_delayLeft;
00241 };
00242
00243 }
00244
00245 #include "timer-impl.h"
00246
00247 namespace ns3 {
00248
00249
00250 template <typename FN>
00251 void
00252 Timer::SetFunction (FN fn)
00253 {
00254 delete m_impl;
00255 m_impl = MakeTimerImpl (fn);
00256 }
00257 template <typename MEM_PTR, typename OBJ_PTR>
00258 void
00259 Timer::SetFunction (MEM_PTR memPtr, OBJ_PTR objPtr)
00260 {
00261 delete m_impl;
00262 m_impl = MakeTimerImpl (memPtr, objPtr);
00263 }
00264
00265 template <typename T1>
00266 void
00267 Timer::SetArguments (T1 a1)
00268 {
00269 if (m_impl == 0)
00270 {
00271 NS_FATAL_ERROR ("You cannot set the arguments of a Timer before setting its function.");
00272 return;
00273 }
00274 m_impl->SetArgs (a1);
00275 }
00276 template <typename T1, typename T2>
00277 void
00278 Timer::SetArguments (T1 a1, T2 a2)
00279 {
00280 if (m_impl == 0)
00281 {
00282 NS_FATAL_ERROR ("You cannot set the arguments of a Timer before setting its function.");
00283 return;
00284 }
00285 m_impl->SetArgs (a1, a2);
00286 }
00287
00288 template <typename T1, typename T2, typename T3>
00289 void
00290 Timer::SetArguments (T1 a1, T2 a2, T3 a3)
00291 {
00292 if (m_impl == 0)
00293 {
00294 NS_FATAL_ERROR ("You cannot set the arguments of a Timer before setting its function.");
00295 return;
00296 }
00297 m_impl->SetArgs (a1, a2, a3);
00298 }
00299
00300 template <typename T1, typename T2, typename T3, typename T4>
00301 void
00302 Timer::SetArguments (T1 a1, T2 a2, T3 a3, T4 a4)
00303 {
00304 if (m_impl == 0)
00305 {
00306 NS_FATAL_ERROR ("You cannot set the arguments of a Timer before setting its function.");
00307 return;
00308 }
00309 m_impl->SetArgs (a1, a2, a3, a4);
00310 }
00311
00312 template <typename T1, typename T2, typename T3, typename T4, typename T5>
00313 void
00314 Timer::SetArguments (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
00315 {
00316 if (m_impl == 0)
00317 {
00318 NS_FATAL_ERROR ("You cannot set the arguments of a Timer before setting its function.");
00319 return;
00320 }
00321 m_impl->SetArgs (a1, a2, a3, a4, a5);
00322 }
00323
00324 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
00325 void
00326 Timer::SetArguments (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
00327 {
00328 if (m_impl == 0)
00329 {
00330 NS_FATAL_ERROR ("You cannot set the arguments of a Timer before setting its function.");
00331 return;
00332 }
00333 m_impl->SetArgs (a1, a2, a3, a4, a5, a6);
00334 }
00335
00336 }
00337
00338 #endif