函数调用关系
Schedule
Simulator::Schedule(Time &, const Ptr<EventImpl> )
- Simulator::DoSchedule((time,EventImpl *)
- 静态函数GetImpl (),返回SimulatorImpl *
返回的是抽象基类的子类,默认DefaultSimulator。 - SimulatorImpl::Schedule(Time const &time, EventImpl *event)
创建Scheduler::Event ev,设置ev的相关内容,并将其插入
SimulatorImpl的Scheduler管辖的list中。生成一个EventID并返回(供日后查询该事件的执行状态,如是否超时等)
Cancel
- Simulator::Cancel
- SimulatorImpl::Cancel(const EventId &id)
id对应事件未失效时,id.PeekEventImpl ()->Cancel () - EventImpl::Cancel
m_cancel = true;(执行该函数后使得事件处理失效状态。逻辑上是严谨的)
Remove
- Simulator::Remove
- SimulatorImpl::Remove (const EventId &id)
- 事件未失效时,根据id生成一个Event event,调用Scheduler::Remove(event)
- event.impl->Cancel (); [为什么都取出来了还要cancel呢,多此一举]
ScheduleDestroy
- Simulator::ScheduleDestroy
- Simulator::DoScheduleDestroy
- SimulatorImpl::ScheduleDestroy
事件执行
- Simulator::Run
- SimulatorImpl::Run
- SimulatorImpl::ProcessOneEvent
- EventImpl::Invoke
- EventImpl::Notify
在MakeEvent中定义函数的具体操作。
Notify在基类EventImpl中的定义:virtual void Notify (void) = 0;
子类重写Notify函数为调用子类的相关函数。
Stop
- Simulator::Stop
- SimulatorImpl::Stop
m_stop = true;
全局变量
- g_simTypeImpl
定义simulator实现类型初始值为ns3::DefaultSimulatorImpl
StringValue:String类对应的AttributeValue子类
static GlobalValue g_simTypeImpl = GlobalValue
("SimulatorImplementationType",
"The object class to use as the simulator implementation",
StringValue ("ns3::DefaultSimulatorImpl"),
MakeStringChecker ());
- g_schedTypeImpl
全局schedulerImp的初始值为MapScheduler
TypeIdValue:TypeId类对应的AttributeValue子类
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。
}
Simulator
类定义
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函数
通过调用SimulatorImpl的同名函数实现的函数
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);
成员模板函数
schedule一类的成员函数
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之类的函数