Simulator::Schedule(Time &, const Ptr<EventImpl> )
Notify在基类EventImpl中的定义:virtual void Notify (void) = 0;
子类重写Notify函数为调用子类的相关函数。
static GlobalValue g_simTypeImpl = GlobalValue
("SimulatorImplementationType",
"The object class to use as the simulator implementation",
StringValue ("ns3::DefaultSimulatorImpl"),
MakeStringChecker ());
static GlobalValue g_schedTypeImpl = GlobalValue ("SchedulerType","The object class to use as the scheduler implementation",TypeIdValue (MapScheduler::GetTypeId ()), MakeTypeIdChecker ());
static void NodePrinter (std::ostream &os){
//也就是说context实际上是相关的node
if (Simulator::GetContext () == 0xffffffff) { os << "-1"; }
else { os << Simulator::GetContext (); }
}
static SimulatorImpl **PeekImpl (void)
{
//创建全局唯一的静态SimulatorImpl 指针。返回存储该指针的内存地址。函数用于GetImpl函数,保证全局只有一个SimulatorImpl
static SimulatorImpl *impl = 0;
return &impl;
}
static SimulatorImpl * GetImpl (void){
SimulatorImpl **pimpl = PeekImpl ();
*pimpl=g_simTypeImpl的值//也就是defaultSimImpl
(*pimpl)->SetScheduler(g_schedTypeImpl的值);//也就是MapScheduler。
}
class Simulator
{
public:
static void SetImplementation (Ptr<SimulatorImpl> impl);
static Ptr<SimulatorImpl> GetImplementation (void);
static void SetScheduler (ObjectFactory schedulerFactory);
ScheduleNow (const Ptr<EventImpl> &ev){
DoScheduleNow (GetPointer (ev));
}
EventId
Simulator::DoScheduleNow (EventImpl *impl)
{
return GetImpl ()->ScheduleNow (impl);
}
对于void(*f)(void)函数指针的Schedule相关函数;
Remove (const EventId &id);
cancel,IsExpired函数,Now函数
static void Destroy (void);
static bool IsFinished (void);
static void Run (void);
static void Stop (void);
static void Stop (Time const &time);
ScheduleWithContext (uint32_t context, const Time &time, EventImpl *impl);
ScheduleDestroy (const Ptr<EventImpl> &ev);
template <typename MEM, typename OBJ>
EventId Simulator::Schedule (Time const &time, MEM mem_ptr, OBJ obj)
{
return DoSchedule (time, MakeEvent (mem_ptr, obj));
}
其他模板都是调用MakeEvent生成EventImpl,然后调用DoSchedule之类的函数