src/simulator/simulator.cc
changeset 1690 16b198d63c1e
parent 1522 70371ffd0ce5
child 1694 fc22854fc549
equal deleted inserted replaced
1689:c52eb7e20762 1690:16b198d63c1e
    65   EventId Schedule (Time const &time, const Ptr<EventImpl> &event);
    65   EventId Schedule (Time const &time, const Ptr<EventImpl> &event);
    66   EventId ScheduleNow (const Ptr<EventImpl> &event);
    66   EventId ScheduleNow (const Ptr<EventImpl> &event);
    67   EventId ScheduleDestroy (const Ptr<EventImpl> &event);
    67   EventId ScheduleDestroy (const Ptr<EventImpl> &event);
    68   void Remove (const EventId &ev);
    68   void Remove (const EventId &ev);
    69   void Cancel (const EventId &ev);
    69   void Cancel (const EventId &ev);
    70   bool IsExpired (const EventId &ev);
    70   bool IsExpired (const EventId &ev) const;
    71   void Run (void);
    71   void Run (void);
    72   Time Now (void) const;
    72   Time Now (void) const;
       
    73   Time GetDelayLeft (const EventId &id) const;
    73 
    74 
    74 private:
    75 private:
    75   void ProcessOneEvent (void);
    76   void ProcessOneEvent (void);
    76   uint64_t NextTs (void) const;
    77   uint64_t NextTs (void) const;
    77 
    78 
   249 Time
   250 Time
   250 SimulatorPrivate::Now (void) const
   251 SimulatorPrivate::Now (void) const
   251 {
   252 {
   252   return TimeStep (m_currentTs);
   253   return TimeStep (m_currentTs);
   253 }
   254 }
       
   255 Time 
       
   256 SimulatorPrivate::GetDelayLeft (const EventId &id) const
       
   257 {
       
   258   if (IsExpired (id))
       
   259     {
       
   260       return TimeStep (0);
       
   261     }
       
   262   else
       
   263     {
       
   264       return TimeStep (id.GetTs () - m_currentTs);
       
   265     }
       
   266 }
   254 
   267 
   255 void
   268 void
   256 SimulatorPrivate::Remove (const EventId &ev)
   269 SimulatorPrivate::Remove (const EventId &ev)
   257 {
   270 {
   258   if (ev.GetUid () == 2)
   271   if (ev.GetUid () == 2)
   291       id.PeekEventImpl ()->Cancel ();
   304       id.PeekEventImpl ()->Cancel ();
   292     }
   305     }
   293 }
   306 }
   294 
   307 
   295 bool
   308 bool
   296 SimulatorPrivate::IsExpired (const EventId &ev)
   309 SimulatorPrivate::IsExpired (const EventId &ev) const
   297 {
   310 {
   298   if (ev.GetUid () == 2)
   311   if (ev.GetUid () == 2)
   299     {
   312     {
   300       // destroy events.
   313       // destroy events.
   301       for (DestroyEvents::iterator i = m_destroyEvents.begin (); i != m_destroyEvents.end (); i++)
   314       for (DestroyEvents::const_iterator i = m_destroyEvents.begin (); i != m_destroyEvents.end (); i++)
   302         {
   315         {
   303           if (*i == ev)
   316           if (*i == ev)
   304             {
   317             {
   305               return false;
   318               return false;
   306             }
   319             }
   408 }
   421 }
   409 Time
   422 Time
   410 Simulator::Now (void)
   423 Simulator::Now (void)
   411 {
   424 {
   412   return GetPriv ()->Now ();
   425   return GetPriv ()->Now ();
       
   426 }
       
   427 Time
       
   428 Simulator::GetDelayLeft (const EventId &id)
       
   429 {
       
   430   return GetPriv ()->GetDelayLeft (id);
   413 }
   431 }
   414 
   432 
   415 Ptr<EventImpl>
   433 Ptr<EventImpl>
   416 Simulator::MakeEvent (void (*f) (void))
   434 Simulator::MakeEvent (void (*f) (void))
   417 {
   435 {