20 #include "ns3/core-config.h"
21 #include "simulator.h"
22 #include "simulator-impl.h"
23 #include "scheduler.h"
24 #include "map-scheduler.h"
25 #include "event-impl.h"
29 #include "object-factory.h"
30 #include "global-value.h"
48 GlobalValue g_simTypeImpl = GlobalValue (
"SimulatorImplementationType",
49 "The object class to use as the simulator implementation",
50 StringValue (
"ns3::DefaultSimulatorImpl"),
51 MakeStringChecker ());
53 GlobalValue g_schedTypeImpl = GlobalValue (
"SchedulerType",
54 "The object class to use as the scheduler implementation",
55 TypeIdValue (MapScheduler::GetTypeId ()),
56 MakeTypeIdChecker ());
59 TimePrinter (std::ostream &os)
65 NodePrinter (std::ostream &os)
77 static SimulatorImpl **PeekImpl (
void)
79 static SimulatorImpl *impl = 0;
83 static SimulatorImpl * GetImpl (
void)
85 SimulatorImpl **pimpl = PeekImpl ();
92 ObjectFactory factory;
96 factory.SetTypeId (s.Get ());
97 *pimpl = GetPointer (factory.Create<SimulatorImpl> ());
100 ObjectFactory factory;
103 factory.SetTypeId (s.Get ());
104 (*pimpl)->SetScheduler (factory);
114 LogSetTimePrinter (&TimePrinter);
115 LogSetNodePrinter (&NodePrinter);
135 LogSetTimePrinter (0);
136 LogSetNodePrinter (0);
137 (*pimpl)->Destroy ();
175 GetImpl ()->
Stop (time);
184 return GetImpl ()->
Now ();
197 return DoSchedule (time, GetPointer (ev));
203 return DoScheduleNow (GetPointer (ev));
213 return DoScheduleDestroy (GetPointer (ev));
218 return GetImpl ()->
Schedule (time, impl);
221 Simulator::DoScheduleNow (EventImpl *impl)
226 Simulator::DoScheduleDestroy (EventImpl *impl)
235 return DoSchedule (time, MakeEvent (f));
247 return DoScheduleNow (MakeEvent (f));
253 return DoScheduleDestroy (MakeEvent (f));
259 if (*PeekImpl () == 0)
263 return GetImpl ()->
Remove (ev);
269 if (*PeekImpl () == 0)
273 return GetImpl ()->
Cancel (ev);
279 if (*PeekImpl () == 0)
309 if (*PeekImpl () != 0)
323 if (*PeekImpl () != 0)
325 NS_FATAL_ERROR (
"It is not possible to set the implementation after calling any Simulator:: function. Call Simulator::SetImplementation earlier or after Simulator::Destroy.");
327 *PeekImpl () = GetPointer (impl);
333 impl->SetScheduler (factory);
341 LogSetTimePrinter (&TimePrinter);
342 LogSetNodePrinter (&NodePrinter);
345 Simulator::GetImplementation (
void)
static Time GetDelayLeft(const EventId &id)
virtual void ScheduleWithContext(uint32_t context, Time const &time, EventImpl *event)=0
smart pointer class similar to boost::intrusive_ptr
#define NS_LOG_FUNCTION(parameters)
static void SetImplementation(Ptr< SimulatorImpl > impl)
virtual bool IsExpired(const EventId &ev) const =0
hold variables of type string
static uint32_t GetSystemId(void)
virtual Time Now(void) const =0
static uint32_t GetContext(void)
#define NS_LOG_COMPONENT_DEFINE(name)
virtual EventId ScheduleNow(EventImpl *event)=0
void SetTypeId(TypeId tid)
static void Cancel(const EventId &id)
#define NS_LOG_FUNCTION_NOARGS()
virtual void SetScheduler(ObjectFactory schedulerFactory)=0
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
#define NS_FATAL_ERROR(msg)
fatal error handling
virtual Time GetMaximumSimulationTime(void) const =0
virtual bool IsFinished(void) const =0
double GetSeconds(void) const
virtual Time GetDelayLeft(const EventId &id) const =0
static void ScheduleWithContext(uint32_t context, Time const &time, MEM mem_ptr, OBJ obj)
virtual EventId ScheduleDestroy(EventImpl *event)=0
#define NS_LOG_LOGIC(msg)
static void Destroy(void)
static void Remove(const EventId &id)
virtual void Cancel(const EventId &ev)=0
static bool IsExpired(const EventId &id)
static EventId ScheduleNow(MEM mem_ptr, OBJ obj)
static void SetScheduler(ObjectFactory schedulerFactory)
virtual EventId Schedule(Time const &time, EventImpl *event)=0
instantiate subclasses of ns3::Object.
virtual void Remove(const EventId &ev)=0
an identifier for simulation events.
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
virtual void Stop(void)=0
static bool IsFinished(void)
static EventId ScheduleDestroy(MEM mem_ptr, OBJ obj)
virtual uint32_t GetSystemId() const =0
virtual uint32_t GetContext(void) const =0
static Time GetMaximumSimulationTime(void)
void GetValue(AttributeValue &value) const