00001 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright (c) 2005,2006 INRIA 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation; 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 * 00018 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> 00019 */ 00020 00021 #ifndef DEFAULT_SIMULATOR_IMPL_H 00022 #define DEFAULT_SIMULATOR_IMPL_H 00023 00024 #include "simulator-impl.h" 00025 #include "scheduler.h" 00026 #include "event-impl.h" 00027 00028 #include "ns3/ptr.h" 00029 #include "ns3/assert.h" 00030 #include "ns3/log.h" 00031 00032 #include <list> 00033 00034 namespace ns3 { 00035 00036 class DefaultSimulatorImpl : public SimulatorImpl 00037 { 00038 public: 00039 static TypeId GetTypeId (void); 00040 00041 DefaultSimulatorImpl (); 00042 ~DefaultSimulatorImpl (); 00043 00044 virtual void Destroy (); 00045 virtual bool IsFinished (void) const; 00046 virtual Time Next (void) const; 00047 virtual void Stop (void); 00048 virtual EventId Schedule (Time const &time, EventImpl *event); 00049 virtual EventId ScheduleNow (EventImpl *event); 00050 virtual EventId ScheduleDestroy (EventImpl *event); 00051 virtual void Remove (const EventId &ev); 00052 virtual void Cancel (const EventId &ev); 00053 virtual bool IsExpired (const EventId &ev) const; 00054 virtual void Run (void); 00055 virtual void RunOneEvent (void); 00056 virtual Time Now (void) const; 00057 virtual Time GetDelayLeft (const EventId &id) const; 00058 virtual Time GetMaximumSimulationTime (void) const; 00059 virtual void SetScheduler (Ptr<Scheduler> scheduler); 00060 virtual Ptr<Scheduler> GetScheduler (void) const; 00061 00062 private: 00063 void ProcessOneEvent (void); 00064 uint64_t NextTs (void) const; 00065 00066 typedef std::list<EventId> DestroyEvents; 00067 DestroyEvents m_destroyEvents; 00068 bool m_stop; 00069 Ptr<Scheduler> m_events; 00070 uint32_t m_uid; 00071 uint32_t m_currentUid; 00072 uint64_t m_currentTs; 00073 // number of events that have been inserted but not yet scheduled, 00074 // not counting the "destroy" events; this is used for validation 00075 int m_unscheduledEvents; 00076 }; 00077 00078 } // namespace ns3 00079 00080 #endif /* DEFAULT_SIMULATOR_IMPL_H */