A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
watchdog.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007 INRIA
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 */
8#include "watchdog.h"
9
10#include "log.h"
11
12/**
13 * \file
14 * \ingroup timer
15 * ns3::Watchdog timer class implementation.
16 */
17
18namespace ns3
19{
20
21NS_LOG_COMPONENT_DEFINE("Watchdog");
22
24 : m_impl(nullptr),
25 m_event(),
26 m_end(MicroSeconds(0))
27{
29}
30
32{
33 NS_LOG_FUNCTION(this);
35 delete m_impl;
36}
37
38void
40{
41 NS_LOG_FUNCTION(this << delay);
42 Time end = Simulator::Now() + delay;
43 m_end = std::max(m_end, end);
44 if (m_event.IsPending())
45 {
46 return;
47 }
49}
50
51void
53{
54 NS_LOG_FUNCTION(this);
55 if (m_end == Simulator::Now())
56 {
57 m_impl->Invoke();
58 }
59 else
60 {
62 }
63}
64
65} // namespace ns3
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition event-id.cc:44
bool IsPending() const
This method is syntactic sugar for !IsExpired().
Definition event-id.cc:65
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
internal::TimerImpl * m_impl
The timer implementation, which contains the bound callback function and arguments.
Definition watchdog.h:112
void Expire()
Internal callback invoked when the timer expires.
Definition watchdog.cc:52
EventId m_event
The future event scheduled to expire the timer.
Definition watchdog.h:114
~Watchdog()
Destructor.
Definition watchdog.cc:31
Watchdog()
Constructor.
Definition watchdog.cc:23
void Ping(Time delay)
Delay the timer.
Definition watchdog.cc:39
Time m_end
The absolute time when the timer will expire.
Definition watchdog.h:116
virtual void Invoke()=0
Invoke the expire function.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition simulator.cc:294
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1332
Debug message logging.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Watchdog timer class declaration.