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
32namespace ns3 {
33
34class TimerImpl;
35
57{
58public:
60 Watchdog ();
62 ~Watchdog ();
63
73 void Ping (Time delay);
74
83 template <typename FN>
84 void SetFunction (FN fn);
85
96 template <typename MEM_PTR, typename OBJ_PTR>
97 void SetFunction (MEM_PTR memPtr, OBJ_PTR objPtr);
98
99
108 template <typename... Ts>
109 void SetArguments (Ts&&... args);
112private:
114 void Expire (void);
124};
125
126} // namespace ns3
127
128
129/********************************************************************
130 * Implementation of the templates declared above.
131 ********************************************************************/
132
133#include "timer-impl.h"
134
135namespace ns3 {
136
137
138template <typename FN>
139void
141{
142 delete m_impl;
143 m_impl = MakeTimerImpl (fn);
144}
145template <typename MEM_PTR, typename OBJ_PTR>
146void
147Watchdog::SetFunction (MEM_PTR memPtr, OBJ_PTR objPtr)
148{
149 delete m_impl;
150 m_impl = MakeTimerImpl (memPtr, objPtr);
151}
152
153template <typename... Ts>
154void
156{
157 if (m_impl == 0)
158 {
159 NS_FATAL_ERROR ("You cannot set the arguments of a Watchdog before setting its function.");
160 return;
161 }
162 m_impl->SetArgs (std::forward<Ts>(args)...);
163}
164
165} // namespace ns3
166
167
168#endif /* WATCHDOG_H */
An identifier for simulation events.
Definition: event-id.h:54
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
The timer implementation underlying Timer and Watchdog.
Definition: timer-impl.h:43
void SetArgs(T1 a1)
Set the arguments to be used when invoking the expire function.
Definition: timer-impl.h:959
A very simple watchdog operating in virtual time.
Definition: watchdog.h:57
void Expire(void)
Internal callback invoked when the timer expires.
Definition: watchdog.cc:63
void SetArguments(Ts &&... args)
Set the arguments to be used when invoking the expire function.
Definition: watchdog.h:155
EventId m_event
The future event scheduled to expire the timer.
Definition: watchdog.h:121
~Watchdog()
Destructor.
Definition: watchdog.cc:42
Watchdog()
Constructor.
Definition: watchdog.cc:34
void Ping(Time delay)
Delay the timer.
Definition: watchdog.cc:50
void SetFunction(FN fn)
Set the function to execute when the timer expires.
Definition: watchdog.h:140
TimerImpl * m_impl
The timer implementation, which contains the bound callback function and arguments.
Definition: watchdog.h:119
Time m_end
The absolute time when the timer will expire.
Definition: watchdog.h:123
ns3::EventId declarations.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
TimerImpl * MakeTimerImpl(FN fn)
Make a TimerImpl from a function pointer taking varying numbers of arguments.
Definition: timer-impl.h:252
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Declaration of classes ns3::Time and ns3::TimeWithUnit, and the TimeValue implementation classes.
ns3::TimerImpl declaration and implementation.