A Discrete-Event Network Simulator
API
watchdog.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007 INRIA
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 #ifndef WATCHDOG_H
21 #define WATCHDOG_H
22 
23 #include "nstime.h"
24 #include "event-id.h"
25 
32 namespace ns3 {
33 
34 class TimerImpl;
35 
56 class Watchdog
57 {
58 public:
60  Watchdog ();
62  ~Watchdog ();
63 
73  void Ping (Time delay);
74 
82  template <typename FN>
83  void SetFunction (FN fn);
84 
95  template <typename MEM_PTR, typename OBJ_PTR>
96  void SetFunction (MEM_PTR memPtr, OBJ_PTR objPtr);
97 
98 
107  template <typename T1>
108  void SetArguments (T1 a1);
115  template <typename T1, typename T2>
116  void SetArguments (T1 a1, T2 a2);
125  template <typename T1, typename T2, typename T3>
126  void SetArguments (T1 a1, T2 a2, T3 a3);
137  template <typename T1, typename T2, typename T3, typename T4>
138  void SetArguments (T1 a1, T2 a2, T3 a3, T4 a4);
151  template <typename T1, typename T2, typename T3, typename T4, typename T5>
152  void SetArguments (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
167  template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
168  void SetArguments (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6);
171 private:
173  void Expire (void);
183 };
184 
185 } // namespace ns3
186 
187 
188 /********************************************************************
189  * Implementation of the templates declared above.
190  ********************************************************************/
191 
192 #include "timer-impl.h"
193 
194 namespace ns3 {
195 
196 
197 template <typename FN>
198 void
200 {
201  delete m_impl;
202  m_impl = MakeTimerImpl (fn);
203 }
204 template <typename MEM_PTR, typename OBJ_PTR>
205 void
206 Watchdog::SetFunction (MEM_PTR memPtr, OBJ_PTR objPtr)
207 {
208  delete m_impl;
209  m_impl = MakeTimerImpl (memPtr, objPtr);
210 }
211 
212 template <typename T1>
213 void
215 {
216  if (m_impl == 0)
217  {
218  NS_FATAL_ERROR ("You cannot set the arguments of a Watchdog before setting its function.");
219  return;
220  }
221  m_impl->SetArgs (a1);
222 }
223 template <typename T1, typename T2>
224 void
226 {
227  if (m_impl == 0)
228  {
229  NS_FATAL_ERROR ("You cannot set the arguments of a Watchdog before setting its function.");
230  return;
231  }
232  m_impl->SetArgs (a1, a2);
233 }
234 
235 template <typename T1, typename T2, typename T3>
236 void
237 Watchdog::SetArguments (T1 a1, T2 a2, T3 a3)
238 {
239  if (m_impl == 0)
240  {
241  NS_FATAL_ERROR ("You cannot set the arguments of a Watchdog before setting its function.");
242  return;
243  }
244  m_impl->SetArgs (a1, a2, a3);
245 }
246 
247 template <typename T1, typename T2, typename T3, typename T4>
248 void
249 Watchdog::SetArguments (T1 a1, T2 a2, T3 a3, T4 a4)
250 {
251  if (m_impl == 0)
252  {
253  NS_FATAL_ERROR ("You cannot set the arguments of a Watchdog before setting its function.");
254  return;
255  }
256  m_impl->SetArgs (a1, a2, a3, a4);
257 }
258 
259 template <typename T1, typename T2, typename T3, typename T4, typename T5>
260 void
261 Watchdog::SetArguments (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
262 {
263  if (m_impl == 0)
264  {
265  NS_FATAL_ERROR ("You cannot set the arguments of a Watchdog before setting its function.");
266  return;
267  }
268  m_impl->SetArgs (a1, a2, a3, a4, a5);
269 }
270 
271 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
272 void
273 Watchdog::SetArguments (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
274 {
275  if (m_impl == 0)
276  {
277  NS_FATAL_ERROR ("You cannot set the arguments of a Watchdog before setting its function.");
278  return;
279  }
280  m_impl->SetArgs (a1, a2, a3, a4, a5, a6);
281 }
282 
283 } // namespace ns3
284 
285 
286 #endif /* WATCHDOG_H */
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Time m_end
The absolute time when the timer will expire.
Definition: watchdog.h:182
void Ping(Time delay)
Delay the timer.
Definition: watchdog.cc:49
TimerImpl * MakeTimerImpl(FN fn)
Make a TimerImpl from a function pointer taking varying numbers of arguments.
Definition: timer-impl.h:253
EventId m_event
The future event scheduled to expire the timer.
Definition: watchdog.h:180
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
void SetFunction(FN fn)
Set the function to execute when the timer expires.
Definition: watchdog.h:199
A very simple watchdog operating in virtual time.
Definition: watchdog.h:56
Watchdog()
Constructor.
Definition: watchdog.cc:34
Declaration of classes ns3::Time and ns3::TimeWithUnit, and the TimeValue implementation classes...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
~Watchdog()
Destructor.
Definition: watchdog.cc:42
The timer implementation underlying Timer and Watchdog.
Definition: timer-impl.h:42
TimerImpl * m_impl
The timer implementation, which contains the bound callback function and arguments.
Definition: watchdog.h:178
An identifier for simulation events.
Definition: event-id.h:53
void SetArguments(T1 a1)
Set the arguments to be used when invoking the expire function.
Definition: watchdog.h:214
void SetArgs(T1 a1)
Set the arguments to be used when invoking the expire function.
Definition: timer-impl.h:974
ns3::TimerImpl declaration and implementation.
ns3::EventId declarations.
void Expire(void)
Internal callback invoked when the timer expires.
Definition: watchdog.cc:62