add Simulator::GetDelayLeft
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Wed, 03 Oct 2007 13:01:12 +0200
changeset 1690 16b198d63c1e
parent 1689 c52eb7e20762
child 1691 d717c61ae738
add Simulator::GetDelayLeft
src/simulator/simulator.cc
src/simulator/simulator.h
--- a/src/simulator/simulator.cc	Tue Oct 02 11:32:16 2007 +0200
+++ b/src/simulator/simulator.cc	Wed Oct 03 13:01:12 2007 +0200
@@ -67,9 +67,10 @@
   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 @@
 {
   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 @@
 }
 
 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 @@
 {
   return GetPriv ()->Now ();
 }
+Time
+Simulator::GetDelayLeft (const EventId &id)
+{
+  return GetPriv ()->GetDelayLeft (id);
+}
 
 Ptr<EventImpl>
 Simulator::MakeEvent (void (*f) (void))
--- a/src/simulator/simulator.h	Tue Oct 02 11:32:16 2007 +0200
+++ b/src/simulator/simulator.h	Wed Oct 03 13:01:12 2007 +0200
@@ -552,6 +552,13 @@
    * 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 ();