Skip to content

Commit

Permalink
(fixes #161) Deprecate EventId::IsRunning() and replace it with Event…
Browse files Browse the repository at this point in the history
…Id::IsPending()
  • Loading branch information
Gabrielcarvfer committed May 14, 2024
1 parent 21f3c98 commit 01138ef
Show file tree
Hide file tree
Showing 58 changed files with 180 additions and 164 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ application model is added.
Applications have a new Attribute to set the IPv4 ToS field.
* (core) Deprecated enum `TestDuration` in `TestCase` class. It has been replaced by enum class `Duration`.
* (core) In `TestSuite` class, deprecated `ALL`, `UNIT`, `SYSTEM`, `EXAMPLE` and `PERFORMANCE`. They have been replaced by `Type::ALL`, `Type::UNIT`, `Type::SYSTEM`, `Type::EXAMPLE` and `Type::PERFORMANCE`, respectively.
* (core) Deprecated `EventId::IsRunning()`. It has been replaced with `EventId::IsPending()`.
* (wifi) Deprecated `WIFI_TID_TO_LINK_MAPPING_{NOT_SUPPORTED,SAME_LINK_SET,ANY_LINK_SET}`. They have been replaced by `WifiTidToLinkMappingNegSupport::{NOT_SUPPORTED,SAME_LINK_SET,ANY_LINK_SET}`, respectively.
* (wifi) Deprecated `{IDLE, CCA_BUSY, TX, RX, SWITCHING, SLEEP, OFF}`. They have been replaced by `WifiPhyState::{IDLE, CCA_BUSY, TX, RX, SWITCHING, SLEEP, OFF}`, respectively.
* (lr-wpan) `MacPibAttributeIdentifier` attribute ids are now standard compliant.
Expand Down
4 changes: 2 additions & 2 deletions doc/tutorial/source/tracing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1763,7 +1763,7 @@ creating simulation events.
{
m_running = false;

if (m_sendEvent.IsRunning())
if (m_sendEvent.IsPending())
{
Simulator::Cancel(m_sendEvent);
}
Expand All @@ -1776,7 +1776,7 @@ creating simulation events.

Every time a simulation event is scheduled, an ``Event`` is created.
If the ``Event`` is pending execution or executing, its method
``IsRunning`` will return ``true``. In this code, if ``IsRunning()``
``IsPending`` will return ``true``. In this code, if ``IsPending()``
returns true, we ``Cancel`` the event which removes it from the
simulator event queue. By doing this, we break the chain of events
that the ``Application`` is using to keep sending its ``Packets`` and
Expand Down
2 changes: 1 addition & 1 deletion examples/tutorial/tutorial-app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ TutorialApp::StopApplication()
{
m_running = false;

if (m_sendEvent.IsRunning())
if (m_sendEvent.IsPending())
{
Simulator::Cancel(m_sendEvent);
}
Expand Down
2 changes: 1 addition & 1 deletion src/applications/model/onoff-application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ OnOffApplication::CancelEvents()
{
NS_LOG_FUNCTION(this);

if (m_sendEvent.IsRunning() && m_cbrRateFailSafe == m_cbrRate)
if (m_sendEvent.IsPending() && m_cbrRateFailSafe == m_cbrRate)
{ // Cancel the pending send packet event
// Calculate residual bits since last packet sent
Time delta(Simulator::Now() - m_lastStartTime);
Expand Down
8 changes: 7 additions & 1 deletion src/core/model/event-id.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,18 @@ EventId::IsExpired() const
}

bool
EventId::IsRunning() const
EventId::IsPending() const
{
NS_LOG_FUNCTION(this);
return !IsExpired();
}

bool
EventId::IsRunning() const
{
return IsPending();
}

EventImpl*
EventId::PeekEventImpl() const
{
Expand Down
11 changes: 10 additions & 1 deletion src/core/model/event-id.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#ifndef EVENT_ID_H
#define EVENT_ID_H

#include "deprecated.h"
#include "event-impl.h"
#include "ptr.h"

Expand Down Expand Up @@ -47,7 +48,7 @@ class EventImpl;
* The important thing to remember about this class is that
* every variable of this type is _always_ in a valid state,
* even when it has not been assigned an EventId coming from a
* Simulator::Schedule() method: calling Simulator::Cancel(), IsRunning(),
* Simulator::Schedule() method: calling Simulator::Cancel(), IsPending(),
* IsExpired() or passing around instances of this object
* will not result in crashes or memory leaks.
*/
Expand Down Expand Up @@ -101,6 +102,14 @@ class EventId
*
* \returns \c true if the event has not expired, \c false otherwise.
*/
bool IsPending() const;

/**
* This method is syntactic sugar for !IsExpired().
*
* \returns \c true if the event has not expired, \c false otherwise.
*/
NS_DEPRECATED_3_42("Use IsPending instead")
bool IsRunning() const;

public:
Expand Down
2 changes: 1 addition & 1 deletion src/core/model/simulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ class Simulator
* Note that it is not possible to test for the expiration of
* events which were scheduled for the "destroy" time. Doing so
* will result in a program error (crash).
* An event is said to "expire" when it starts being scheduled
* An event is said to "expire" when it starts being executed,
* which means that if the code executed by the event calls
* this function, it will get true.
*
Expand Down
6 changes: 3 additions & 3 deletions src/core/model/timer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Timer::~Timer()
NS_LOG_FUNCTION(this);
if (m_flags & CHECK_ON_DESTROY)
{
if (m_event.IsRunning())
if (m_event.IsPending())
{
NS_FATAL_ERROR("Event is still running while destroying.");
}
Expand Down Expand Up @@ -129,7 +129,7 @@ bool
Timer::IsRunning() const
{
NS_LOG_FUNCTION(this);
return !IsSuspended() && m_event.IsRunning();
return !IsSuspended() && m_event.IsPending();
}

bool
Expand Down Expand Up @@ -170,7 +170,7 @@ Timer::Schedule(Time delay)
{
NS_LOG_FUNCTION(this << delay);
NS_ASSERT(m_impl != nullptr);
if (m_event.IsRunning())
if (m_event.IsPending())
{
NS_FATAL_ERROR("Event is still running while re-scheduling.");
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/model/trickle-timer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ TrickleTimer::GetDelayLeft() const
{
NS_LOG_FUNCTION(this);

if (m_timerExpiration.IsRunning())
if (m_timerExpiration.IsPending())
{
return Simulator::GetDelayLeft(m_timerExpiration);
}
Expand All @@ -145,7 +145,7 @@ TrickleTimer::GetIntervalLeft() const
{
NS_LOG_FUNCTION(this);

if (m_intervalExpiration.IsRunning())
if (m_intervalExpiration.IsPending())
{
return Simulator::GetDelayLeft(m_intervalExpiration);
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/model/unix-fd-reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ FdReader::Start(int fd, Callback<void, uint8_t*, ssize_t> readCallback)
// scheduling a "destroy time" method to make sure the thread exits before
// proceeding.
//
if (!m_destroyEvent.IsRunning())
if (!m_destroyEvent.IsPending())
{
// hold a reference to ensure that this object is not
// deallocated before the destroy-time event fires
Expand Down
2 changes: 1 addition & 1 deletion src/core/model/watchdog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Watchdog::Ping(Time delay)
NS_LOG_FUNCTION(this << delay);
Time end = Simulator::Now() + delay;
m_end = std::max(m_end, end);
if (m_event.IsRunning())
if (m_event.IsPending())
{
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/model/win32-fd-reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ FdReader::Start(int fd, Callback<void, uint8_t*, ssize_t> readCallback)
// scheduling a "destroy time" method to make sure the thread exits before
// proceeding.
//
if (!m_destroyEvent.IsRunning())
if (!m_destroyEvent.IsPending())
{
// hold a reference to ensure that this object is not
// deallocated before the destroy-time event fires
Expand Down
4 changes: 2 additions & 2 deletions src/dsdv/model/dsdv-rtable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ RoutingTable::AnyRunningEvent(Ipv4Address address)
return false;
}
event = i->second;
return event.IsRunning();
return event.IsPending();
}

bool
Expand Down Expand Up @@ -340,7 +340,7 @@ RoutingTable::DeleteIpv4Event(Ipv4Address address)
return false;
}
event = i->second;
if (event.IsRunning())
if (event.IsPending())
{
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/internet-apps/model/ping.cc
Original file line number Diff line number Diff line change
Expand Up @@ -626,11 +626,11 @@ void
Ping::StopApplication()
{
NS_LOG_FUNCTION(this);
if (m_stopEvent.IsRunning())
if (m_stopEvent.IsPending())
{
m_stopEvent.Cancel();
}
if (m_next.IsRunning())
if (m_next.IsPending())
{
m_next.Cancel();
}
Expand Down
2 changes: 1 addition & 1 deletion src/internet-apps/model/radvd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ Radvd::HandleRead(Ptr<Socket> socket)
if (m_solicitedEventIds.find((*it)->GetInterface()) !=
m_solicitedEventIds.end())
{
if (m_solicitedEventIds[(*it)->GetInterface()].IsRunning())
if (m_solicitedEventIds[(*it)->GetInterface()].IsPending())
{
scheduleSingle = false;
}
Expand Down
8 changes: 4 additions & 4 deletions src/internet-apps/model/v4traceroute.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,12 @@ V4TraceRoute::StopApplication()
{
NS_LOG_FUNCTION(this);

if (m_next.IsRunning())
if (m_next.IsPending())
{
m_next.Cancel();
}

if (m_waitIcmpReplyTimer.IsRunning())
if (m_waitIcmpReplyTimer.IsPending())
{
m_waitIcmpReplyTimer.Cancel();
}
Expand All @@ -193,7 +193,7 @@ V4TraceRoute::DoDispose()
{
NS_LOG_FUNCTION(this);

if (m_next.IsRunning() || m_waitIcmpReplyTimer.IsRunning())
if (m_next.IsPending() || m_waitIcmpReplyTimer.IsPending())
{
StopApplication();
}
Expand Down Expand Up @@ -422,7 +422,7 @@ void
V4TraceRoute::StartWaitReplyTimer()
{
NS_LOG_FUNCTION(this);
if (!m_waitIcmpReplyTimer.IsRunning())
if (!m_waitIcmpReplyTimer.IsPending())
{
NS_LOG_LOGIC("Starting WaitIcmpReplyTimer at " << Simulator::Now() << " for "
<< m_waitIcmpReplyTimeout);
Expand Down
2 changes: 1 addition & 1 deletion src/internet/doc/tcp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1986,7 +1986,7 @@ processing of the SYN-ACK:
if (h.GetFlags() & TcpHeader::SYN)
{
EventId persistentEvent = GetPersistentEvent(SENDER);
NS_TEST_ASSERT_MSG_EQ(persistentEvent.IsRunning(), true,
NS_TEST_ASSERT_MSG_EQ(persistentEvent.IsPending(), true,
"Persistent event not started");
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/internet/model/arp-cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ ArpCache::DoDispose()
Flush();
m_device = nullptr;
m_interface = nullptr;
if (!m_waitReplyTimer.IsRunning())
if (!m_waitReplyTimer.IsPending())
{
m_waitReplyTimer.Cancel();
}
Expand Down Expand Up @@ -184,7 +184,7 @@ void
ArpCache::StartWaitReplyTimer()
{
NS_LOG_FUNCTION(this);
if (!m_waitReplyTimer.IsRunning())
if (!m_waitReplyTimer.IsPending())
{
NS_LOG_LOGIC("Starting WaitReplyTimer at " << Simulator::Now() << " for "
<< m_waitReplyTimeout);
Expand Down Expand Up @@ -250,7 +250,7 @@ ArpCache::Flush()
delete (*i).second;
}
m_arpCache.erase(m_arpCache.begin(), m_arpCache.end());
if (m_waitReplyTimer.IsRunning())
if (m_waitReplyTimer.IsPending())
{
NS_LOG_LOGIC("Stopping WaitReplyTimer at " << Simulator::Now().GetSeconds()
<< " due to ArpCache flush");
Expand Down
2 changes: 1 addition & 1 deletion src/internet/model/icmpv6-l4-protocol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ Icmpv6L4Protocol::HandleRA(Ptr<Packet> packet,
{
NS_LOG_FUNCTION(this << packet << src << dst << interface);

if (m_handleRsTimeoutEvent.IsRunning())
if (m_handleRsTimeoutEvent.IsPending())
{
m_handleRsTimeoutEvent.Cancel();
// We need to update this in case we need to restart RS retransmissions.
Expand Down
6 changes: 3 additions & 3 deletions src/internet/model/ipv4-l3-protocol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,12 @@ Ipv4L3Protocol::DoDispose()

m_fragments.clear();
m_timeoutEventList.clear();
if (m_timeoutEvent.IsRunning())
if (m_timeoutEvent.IsPending())
{
m_timeoutEvent.Cancel();
}

if (m_cleanDpd.IsRunning())
if (m_cleanDpd.IsPending())
{
m_cleanDpd.Cancel();
}
Expand Down Expand Up @@ -1800,7 +1800,7 @@ Ipv4L3Protocol::UpdateDuplicate(Ptr<const Packet> p, const Ipv4Header& header)
}

// set cleanup job for new duplicate entries
if (!m_cleanDpd.IsRunning() && m_purge.IsStrictlyPositive())
if (!m_cleanDpd.IsPending() && m_purge.IsStrictlyPositive())
{
m_cleanDpd = Simulator::Schedule(m_expire, &Ipv4L3Protocol::RemoveDuplicates, this);
}
Expand Down
2 changes: 1 addition & 1 deletion src/internet/model/ipv6-extension.cc
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ Ipv6ExtensionFragment::DoDispose()

m_fragments.clear();
m_timeoutEventList.clear();
if (m_timeoutEvent.IsRunning())
if (m_timeoutEvent.IsPending())
{
m_timeoutEvent.Cancel();
}
Expand Down
6 changes: 3 additions & 3 deletions src/internet/model/rip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ Rip::InvalidateRoute(RipRoutingTableEntry* route)
route->SetRouteStatus(RipRoutingTableEntry::RIP_INVALID);
route->SetRouteMetric(m_linkDown);
route->SetRouteChanged(true);
if (it->second.IsRunning())
if (it->second.IsPending())
{
it->second.Cancel();
}
Expand Down Expand Up @@ -1275,7 +1275,7 @@ Rip::SendTriggeredRouteUpdate()
{
NS_LOG_FUNCTION(this);

if (m_nextTriggeredUpdate.IsRunning())
if (m_nextTriggeredUpdate.IsPending())
{
NS_LOG_LOGIC("Skipping Triggered Update due to cooldown");
return;
Expand Down Expand Up @@ -1307,7 +1307,7 @@ Rip::SendUnsolicitedRouteUpdate()
{
NS_LOG_FUNCTION(this);

if (m_nextTriggeredUpdate.IsRunning())
if (m_nextTriggeredUpdate.IsPending())
{
m_nextTriggeredUpdate.Cancel();
}
Expand Down
6 changes: 3 additions & 3 deletions src/internet/model/ripng.cc
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ RipNg::InvalidateRoute(RipNgRoutingTableEntry* route)
route->SetRouteStatus(RipNgRoutingTableEntry::RIPNG_INVALID);
route->SetRouteMetric(m_linkDown);
route->SetRouteChanged(true);
if (it->second.IsRunning())
if (it->second.IsPending())
{
it->second.Cancel();
}
Expand Down Expand Up @@ -1276,7 +1276,7 @@ RipNg::SendTriggeredRouteUpdate()
{
NS_LOG_FUNCTION(this);

if (m_nextTriggeredUpdate.IsRunning())
if (m_nextTriggeredUpdate.IsPending())
{
NS_LOG_LOGIC("Skipping Triggered Update due to cooldown");
return;
Expand Down Expand Up @@ -1308,7 +1308,7 @@ RipNg::SendUnsolicitedRouteUpdate()
{
NS_LOG_FUNCTION(this);

if (m_nextTriggeredUpdate.IsRunning())
if (m_nextTriggeredUpdate.IsPending())
{
m_nextTriggeredUpdate.Cancel();
}
Expand Down
Loading

0 comments on commit 01138ef

Please sign in to comment.