add Simulator::GetDelayLeft

This commit is contained in:
Mathieu Lacage
2007-10-03 13:01:12 +02:00
parent e216675ca1
commit 1440302ab3
2 changed files with 28 additions and 3 deletions

View File

@@ -67,9 +67,10 @@ public:
EventId ScheduleDestroy (const Ptr<EventImpl> &event);
void Remove (const EventId &ev);
void Cancel (const EventId &ev);
bool IsExpired (const EventId &ev);
bool IsExpired (const EventId &ev) const;
void Run (void);
Time Now (void) const;
Time GetDelayLeft (const EventId &id) const;
private:
void ProcessOneEvent (void);
@@ -251,6 +252,18 @@ SimulatorPrivate::Now (void) const
{
return TimeStep (m_currentTs);
}
Time
SimulatorPrivate::GetDelayLeft (const EventId &id) const
{
if (IsExpired (id))
{
return TimeStep (0);
}
else
{
return TimeStep (id.GetTs () - m_currentTs);
}
}
void
SimulatorPrivate::Remove (const EventId &ev)
@@ -293,12 +306,12 @@ SimulatorPrivate::Cancel (const EventId &id)
}
bool
SimulatorPrivate::IsExpired (const EventId &ev)
SimulatorPrivate::IsExpired (const EventId &ev) const
{
if (ev.GetUid () == 2)
{
// destroy events.
for (DestroyEvents::iterator i = m_destroyEvents.begin (); i != m_destroyEvents.end (); i++)
for (DestroyEvents::const_iterator i = m_destroyEvents.begin (); i != m_destroyEvents.end (); i++)
{
if (*i == ev)
{
@@ -411,6 +424,11 @@ Simulator::Now (void)
{
return GetPriv ()->Now ();
}
Time
Simulator::GetDelayLeft (const EventId &id)
{
return GetPriv ()->GetDelayLeft (id);
}
Ptr<EventImpl>
Simulator::MakeEvent (void (*f) (void))

View File

@@ -552,6 +552,13 @@ public:
* Return the "current simulation time".
*/
static Time Now (void);
/**
* \param id the event id to analyse
* \returns the delay left until the input event id expires.
* if the event is not running, this method returns
* zero.
*/
static Time GetDelayLeft (const EventId &id);
private:
Simulator ();
~Simulator ();