diff --git a/src/simulator/default-simulator-impl.cc b/src/simulator/default-simulator-impl.cc index fa5263647..84495edd5 100644 --- a/src/simulator/default-simulator-impl.cc +++ b/src/simulator/default-simulator-impl.cc @@ -320,6 +320,17 @@ DefaultSimulatorImpl::GetMaximumSimulationTime (void) const return TimeStep (0x7fffffffffffffffLL); } +void +DefaultSimulatorImpl::ScheduleRealtime (Time const &time, EventImpl *event) +{ + NS_FATAL_ERROR ("not implemented"); +} +void +DefaultSimulatorImpl::ScheduleRealtimeNow (EventImpl *event) +{ + NS_FATAL_ERROR ("not implemented"); +} + } // namespace ns3 diff --git a/src/simulator/default-simulator-impl.h b/src/simulator/default-simulator-impl.h index 790cf6a50..37396214f 100644 --- a/src/simulator/default-simulator-impl.h +++ b/src/simulator/default-simulator-impl.h @@ -61,6 +61,8 @@ public: virtual Time GetMaximumSimulationTime (void) const; virtual void SetScheduler (Ptr scheduler); virtual Ptr GetScheduler (void) const; + virtual void ScheduleRealtime (Time const &time, EventImpl *event); + virtual void ScheduleRealtimeNow (EventImpl *event); private: void ProcessOneEvent (void); diff --git a/src/simulator/make-event.cc b/src/simulator/make-event.cc new file mode 100644 index 000000000..d791632ba --- /dev/null +++ b/src/simulator/make-event.cc @@ -0,0 +1,27 @@ +#include "make-event.h" + +namespace ns3 { + +EventImpl *MakeEvent (void (*f) (void)) +{ + // zero arg version + class EventFunctionImpl0 : public EventImpl + { + public: + typedef void (*F)(void); + + EventFunctionImpl0 (F function) + : m_function (function) + {} + virtual ~EventFunctionImpl0 () {} + protected: + virtual void Notify (void) { + (*m_function) (); + } + private: + F m_function; + } *ev = new EventFunctionImpl0 (f); + return ev; +} + +} // namespace ns3 diff --git a/src/simulator/make-event.h b/src/simulator/make-event.h new file mode 100644 index 000000000..d24a0e28e --- /dev/null +++ b/src/simulator/make-event.h @@ -0,0 +1,388 @@ +#ifndef MAKE_EVENT_H +#define MAKE_EVENT_H + +namespace ns3 { + +class EventImpl; + +template +EventImpl *MakeEvent (MEM mem_ptr, OBJ obj); + +template +EventImpl *MakeEvent (MEM mem_ptr, OBJ obj, T1 a1); + +template +EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2); + +template +EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3); + +template +EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4); + +template +EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, + T1 a1, T2 a2, T3 a3, T4 a4, T5 a5); + +EventImpl * MakeEvent (void (*f) (void)); +template +EventImpl * MakeEvent (void (*f) (U1), T1 a1); + +template +EventImpl * MakeEvent (void (*f) (U1,U2), T1 a1, T2 a2); + +template +EventImpl * MakeEvent (void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3); + +template +EventImpl * MakeEvent (void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4); + +template +EventImpl * MakeEvent (void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5); + +} // namespace ns3 + +/******************************************************************** + Implementation of templates defined above + ********************************************************************/ + +#include "event-impl.h" +#include "ns3/type-traits.h" + +namespace ns3 { + +template +struct EventMemberImplObjTraits; + +template +struct EventMemberImplObjTraits +{ + static T &GetReference (T *p) { + return *p; + } +}; + +template +EventImpl * MakeEvent (MEM mem_ptr, OBJ obj) +{ + // zero argument version + class EventMemberImpl0 : public EventImpl { + public: + EventMemberImpl0 (OBJ obj, MEM function) + : m_obj (obj), + m_function (function) + {} + virtual ~EventMemberImpl0 () {} + private: + virtual void Notify (void) { + (EventMemberImplObjTraits::GetReference (m_obj).*m_function) (); + } + OBJ m_obj; + MEM m_function; + } * ev = new EventMemberImpl0 (obj, mem_ptr); + return ev; +} + + +template +EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1) +{ + // one argument version + class EventMemberImpl1 : public EventImpl { + public: + EventMemberImpl1 (OBJ obj, MEM function, T1 a1) + : m_obj (obj), + m_function (function), + m_a1 (a1) + {} + protected: + virtual ~EventMemberImpl1 () {} + private: + virtual void Notify (void) { + (EventMemberImplObjTraits::GetReference (m_obj).*m_function) (m_a1); + } + OBJ m_obj; + MEM m_function; + typename TypeTraits::ReferencedType m_a1; + } *ev = new EventMemberImpl1 (obj, mem_ptr, a1); + return ev; +} + +template +EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2) +{ + // two argument version + class EventMemberImpl2 : public EventImpl { + public: + EventMemberImpl2 (OBJ obj, MEM function, T1 a1, T2 a2) + : m_obj (obj), + m_function (function), + m_a1 (a1), + m_a2 (a2) + { } + protected: + virtual ~EventMemberImpl2 () {} + private: + virtual void Notify (void) { + (EventMemberImplObjTraits::GetReference (m_obj).*m_function) (m_a1, m_a2); + } + OBJ m_obj; + MEM m_function; + typename TypeTraits::ReferencedType m_a1; + typename TypeTraits::ReferencedType m_a2; + } *ev = new EventMemberImpl2 (obj, mem_ptr, a1, a2); + return ev; +} + +template +EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3) +{ + // three argument version + class EventMemberImpl3 : public EventImpl { + public: + EventMemberImpl3 (OBJ obj, MEM function, T1 a1, T2 a2, T3 a3) + : m_obj (obj), + m_function (function), + m_a1 (a1), + m_a2 (a2), + m_a3 (a3) + { } + protected: + virtual ~EventMemberImpl3 () {} + private: + virtual void Notify (void) { + (EventMemberImplObjTraits::GetReference (m_obj).*m_function) (m_a1, m_a2, m_a3); + } + OBJ m_obj; + MEM m_function; + typename TypeTraits::ReferencedType m_a1; + typename TypeTraits::ReferencedType m_a2; + typename TypeTraits::ReferencedType m_a3; + } *ev = new EventMemberImpl3 (obj, mem_ptr, a1, a2, a3); + return ev; +} + +template +EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4) +{ + // four argument version + class EventMemberImpl4 : public EventImpl { + public: + EventMemberImpl4 (OBJ obj, MEM function, T1 a1, T2 a2, T3 a3, T4 a4) + : m_obj (obj), + m_function (function), + m_a1 (a1), + m_a2 (a2), + m_a3 (a3), + m_a4 (a4) + { } + protected: + virtual ~EventMemberImpl4 () {} + private: + virtual void Notify (void) { + (EventMemberImplObjTraits::GetReference (m_obj).*m_function) (m_a1, m_a2, m_a3, m_a4); + } + OBJ m_obj; + MEM m_function; + typename TypeTraits::ReferencedType m_a1; + typename TypeTraits::ReferencedType m_a2; + typename TypeTraits::ReferencedType m_a3; + typename TypeTraits::ReferencedType m_a4; + } *ev = new EventMemberImpl4 (obj, mem_ptr, a1, a2, a3, a4); + return ev; +} + +template +EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, + T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) +{ + // five argument version + class EventMemberImpl5 : public EventImpl { + public: + EventMemberImpl5 (OBJ obj, MEM function, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) + : m_obj (obj), + m_function (function), + m_a1 (a1), + m_a2 (a2), + m_a3 (a3), + m_a4 (a4), + m_a5 (a5) + { } + protected: + virtual ~EventMemberImpl5 () {} + private: + virtual void Notify (void) { + (EventMemberImplObjTraits::GetReference (m_obj).*m_function) (m_a1, m_a2, m_a3, m_a4, m_a5); + } + OBJ m_obj; + MEM m_function; + typename TypeTraits::ReferencedType m_a1; + typename TypeTraits::ReferencedType m_a2; + typename TypeTraits::ReferencedType m_a3; + typename TypeTraits::ReferencedType m_a4; + typename TypeTraits::ReferencedType m_a5; + } *ev = new EventMemberImpl5 (obj, mem_ptr, a1, a2, a3, a4, a5); + return ev; +} + +template +EventImpl * MakeEvent (void (*f) (U1), T1 a1) +{ + // one arg version + class EventFunctionImpl1 : public EventImpl { + public: + typedef void (*F)(U1); + + EventFunctionImpl1 (F function, T1 a1) + : m_function (function), + m_a1 (a1) + { } + protected: + virtual ~EventFunctionImpl1 () {} + private: + virtual void Notify (void) { + (*m_function) (m_a1); + } + F m_function; + typename TypeTraits::ReferencedType m_a1; + } *ev = new EventFunctionImpl1 (f, a1); + return ev; +} + +template +EventImpl * MakeEvent (void (*f) (U1,U2), T1 a1, T2 a2) +{ + // two arg version + class EventFunctionImpl2 : public EventImpl { + public: + typedef void (*F)(U1, U2); + + EventFunctionImpl2 (F function, T1 a1, T2 a2) + : m_function (function), + m_a1 (a1), + m_a2 (a2) + {} + protected: + virtual ~EventFunctionImpl2 () {} + private: + virtual void Notify (void) { + (*m_function) (m_a1, m_a2); + } + F m_function; + typename TypeTraits::ReferencedType m_a1; + typename TypeTraits::ReferencedType m_a2; + } *ev = new EventFunctionImpl2 (f, a1, a2); + return ev; +} + +template +EventImpl * MakeEvent (void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3) +{ + // three arg version + class EventFunctionImpl3 : public EventImpl { + public: + typedef void (*F)(U1, U2, U3); + + EventFunctionImpl3 (F function, T1 a1, T2 a2, T3 a3) + : m_function (function), + m_a1 (a1), + m_a2 (a2), + m_a3 (a3) + { } + protected: + virtual ~EventFunctionImpl3 () {} + private: + virtual void Notify (void) { + (*m_function) (m_a1, m_a2, m_a3); + } + F m_function; + typename TypeTraits::ReferencedType m_a1; + typename TypeTraits::ReferencedType m_a2; + typename TypeTraits::ReferencedType m_a3; + } *ev = new EventFunctionImpl3 (f, a1, a2, a3); + return ev; +} + +template +EventImpl * MakeEvent (void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4) +{ + // four arg version + class EventFunctionImpl4 : public EventImpl { + public: + typedef void (*F)(U1, U2, U3, U4); + + EventFunctionImpl4 (F function, T1 a1, T2 a2, T3 a3, T4 a4) + : m_function (function), + m_a1 (a1), + m_a2 (a2), + m_a3 (a3), + m_a4 (a4) + { } + protected: + virtual ~EventFunctionImpl4 () {} + private: + virtual void Notify (void) { + (*m_function) (m_a1, m_a2, m_a3, m_a4); + } + F m_function; + typename TypeTraits::ReferencedType m_a1; + typename TypeTraits::ReferencedType m_a2; + typename TypeTraits::ReferencedType m_a3; + typename TypeTraits::ReferencedType m_a4; + } *ev = new EventFunctionImpl4 (f, a1, a2, a3, a4); + return ev; +} + +template +EventImpl * MakeEvent (void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) +{ + // five arg version + class EventFunctionImpl5 : public EventImpl { + public: + typedef void (*F)(U1,U2,U3,U4,U5); + + EventFunctionImpl5 (F function, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) + : m_function (function), + m_a1 (a1), + m_a2 (a2), + m_a3 (a3), + m_a4 (a4), + m_a5 (a5) + {} + protected: + virtual ~EventFunctionImpl5 () {} + private: + virtual void Notify (void) { + (*m_function) (m_a1, m_a2, m_a3, m_a4, m_a5); + } + F m_function; + typename TypeTraits::ReferencedType m_a1; + typename TypeTraits::ReferencedType m_a2; + typename TypeTraits::ReferencedType m_a3; + typename TypeTraits::ReferencedType m_a4; + typename TypeTraits::ReferencedType m_a5; + } *ev = new EventFunctionImpl5 (f, a1, a2, a3, a4, a5); + return ev; +} + +} // namespace ns3 + +#endif /* MAKE_EVENT_H */ diff --git a/src/simulator/realtime-simulator-impl.cc b/src/simulator/realtime-simulator-impl.cc index 18cdfee45..96101d527 100644 --- a/src/simulator/realtime-simulator-impl.cc +++ b/src/simulator/realtime-simulator-impl.cc @@ -646,18 +646,19 @@ RealtimeSimulatorImpl::Now (void) const // // Schedule an event for a _relative_ time in the future. // -EventId -RealtimeSimulatorImpl::ScheduleRealtime (Time const &time, const Ptr &impl) +void +RealtimeSimulatorImpl::ScheduleRealtime (Time const &time, EventImpl *impl) { NS_LOG_FUNCTION (time << impl); - Scheduler::Event ev; + { CriticalSection cs (m_mutex); uint64_t ts = m_synchronizer->GetCurrentRealtime () + time.GetTimeStep (); NS_ASSERT_MSG (ts >= m_currentTs, "RealtimeSimulatorImpl::ScheduleRealtime(): schedule for time < m_currentTs"); - ev.impl = GetPointer (impl); + Scheduler::Event ev; + ev.impl = impl; ev.key.m_ts = ts; ev.key.m_uid = m_uid; m_uid++; @@ -666,14 +667,12 @@ RealtimeSimulatorImpl::ScheduleRealtime (Time const &time, const Ptr m_synchronizer->Signal (); } - return EventId (impl, ev.key.m_ts, ev.key.m_uid); } -EventId -RealtimeSimulatorImpl::ScheduleRealtimeNow (const Ptr &impl) +void +RealtimeSimulatorImpl::ScheduleRealtimeNow (EventImpl *impl) { NS_LOG_FUNCTION_NOARGS (); - Scheduler::Event ev; { CriticalSection cs (m_mutex); @@ -683,7 +682,8 @@ RealtimeSimulatorImpl::ScheduleRealtimeNow (const Ptr &impl) // uint64_t ts = m_running ? m_synchronizer->GetCurrentRealtime () : m_currentTs; NS_ASSERT_MSG (ts >= m_currentTs, "RealtimeSimulatorImpl::ScheduleRealrimeNow(): schedule for time < m_currentTs"); - ev.impl = GetPointer (impl); + Scheduler::Event ev; + ev.impl = impl; ev.key.m_ts = ts; ev.key.m_uid = m_uid; m_uid++; @@ -691,8 +691,6 @@ RealtimeSimulatorImpl::ScheduleRealtimeNow (const Ptr &impl) m_events->Insert (ev); m_synchronizer->Signal (); } - - return EventId (impl, ev.key.m_ts, ev.key.m_uid); } Time diff --git a/src/simulator/realtime-simulator-impl.h b/src/simulator/realtime-simulator-impl.h index 3b610188c..a56a21031 100644 --- a/src/simulator/realtime-simulator-impl.h +++ b/src/simulator/realtime-simulator-impl.h @@ -79,8 +79,9 @@ public: virtual Time GetMaximumSimulationTime (void) const; virtual void SetScheduler (Ptr scheduler); virtual Ptr GetScheduler (void) const; - EventId ScheduleRealtime (Time const &time, const Ptr &event); - EventId ScheduleRealtimeNow (const Ptr &event); + virtual void ScheduleRealtime (Time const &time, EventImpl *event); + virtual void ScheduleRealtimeNow (EventImpl *event); + Time RealtimeNow (void) const; void SetSynchronizationMode (RealtimeSimulatorImpl::SynchronizationMode mode); diff --git a/src/simulator/realtime-simulator.h b/src/simulator/realtime-simulator.h index b30518d66..b8b72cc2e 100644 --- a/src/simulator/realtime-simulator.h +++ b/src/simulator/realtime-simulator.h @@ -20,7 +20,7 @@ #define REALTIME_SIMULATOR_H #include "simulator.h" -#include "realtime-simulator-impl.h" +#include "make-event.h" namespace ns3 { @@ -49,7 +49,7 @@ public: * @returns an id for the scheduled event. */ template - static EventId ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj); + static void ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj); /** * @param time the relative expiration time of the event. @@ -59,7 +59,7 @@ public: * @returns an id for the scheduled event. */ template - static EventId ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1); + static void ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1); /** * @param time the relative expiration time of the event. @@ -70,7 +70,7 @@ public: * @returns an id for the scheduled event. */ template - static EventId ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2); + static void ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2); /** * @param time the relative expiration time of the event. @@ -83,7 +83,7 @@ public: */ template - static EventId ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3); + static void ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3); /** * @param time the relative expiration time of the event. @@ -97,7 +97,7 @@ public: */ template - static EventId ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4); + static void ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4); /** * @param time the relative expiration time of the event. @@ -112,14 +112,14 @@ public: */ template - static EventId ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, + static void ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5); /** * @param time the relative expiration time of the event. * @param f the function to invoke * @returns an id for the scheduled event. */ - static EventId ScheduleRealtime (Time const &time, void (*f) (void)); + static void ScheduleRealtime (Time const &time, void (*f) (void)); /** * @param time the relative expiration time of the event. @@ -128,7 +128,7 @@ public: * @returns an id for the scheduled event. */ template - static EventId ScheduleRealtime (Time const &time, void (*f) (U1), T1 a1); + static void ScheduleRealtime (Time const &time, void (*f) (U1), T1 a1); /** * @param time the relative expiration time of the event. @@ -138,7 +138,7 @@ public: * @returns an id for the scheduled event. */ template - static EventId ScheduleRealtime (Time const &time, void (*f) (U1,U2), T1 a1, T2 a2); + static void ScheduleRealtime (Time const &time, void (*f) (U1,U2), T1 a1, T2 a2); /** * @param time the relative expiration time of the event. @@ -149,7 +149,7 @@ public: * @returns an id for the scheduled event. */ template - static EventId ScheduleRealtime (Time const &time, void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3); + static void ScheduleRealtime (Time const &time, void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3); /** * @param time the relative expiration time of the event. @@ -162,7 +162,7 @@ public: */ template - static EventId ScheduleRealtime (Time const &time, void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4); + static void ScheduleRealtime (Time const &time, void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4); /** * @param time the relative expiration time of the event. @@ -176,7 +176,7 @@ public: */ template - static EventId ScheduleRealtime (Time const &time, void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5); + static void ScheduleRealtime (Time const &time, void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5); /** * Schedule an event to expire Now. All events scheduled to @@ -187,7 +187,7 @@ public: * @param obj the object on which to invoke the member method */ template - static EventId ScheduleRealtimeNow (MEM mem_ptr, OBJ obj); + static void ScheduleRealtimeNow (MEM mem_ptr, OBJ obj); /** * @param mem_ptr member method pointer to invoke @@ -196,7 +196,7 @@ public: */ template - static EventId ScheduleRealtimeNow (MEM mem_ptr, OBJ obj, T1 a1); + static void ScheduleRealtimeNow (MEM mem_ptr, OBJ obj, T1 a1); /** * @param mem_ptr member method pointer to invoke @@ -206,7 +206,7 @@ public: */ template - static EventId ScheduleRealtimeNow (MEM mem_ptr, OBJ obj, T1 a1, T2 a2); + static void ScheduleRealtimeNow (MEM mem_ptr, OBJ obj, T1 a1, T2 a2); /** * @param mem_ptr member method pointer to invoke @@ -217,7 +217,7 @@ public: */ template - static EventId ScheduleRealtimeNow (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3); + static void ScheduleRealtimeNow (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3); /** * @param mem_ptr member method pointer to invoke @@ -229,7 +229,7 @@ public: */ template - static EventId ScheduleRealtimeNow (MEM mem_ptr, OBJ obj, + static void ScheduleRealtimeNow (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4); /** * @param mem_ptr member method pointer to invoke @@ -242,12 +242,12 @@ public: */ template - static EventId ScheduleRealtimeNow (MEM mem_ptr, OBJ obj, + static void ScheduleRealtimeNow (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5); /** * @param f the function to invoke */ - static EventId ScheduleRealtimeNow (void (*f) (void)); + static void ScheduleRealtimeNow (void (*f) (void)); /** * @param f the function to invoke @@ -255,7 +255,7 @@ public: */ template - static EventId ScheduleRealtimeNow (void (*f) (U1), T1 a1); + static void ScheduleRealtimeNow (void (*f) (U1), T1 a1); /** * @param f the function to invoke @@ -264,7 +264,7 @@ public: */ template - static EventId ScheduleRealtimeNow (void (*f) (U1,U2), T1 a1, T2 a2); + static void ScheduleRealtimeNow (void (*f) (U1,U2), T1 a1, T2 a2); /** * @param f the function to invoke @@ -274,7 +274,7 @@ public: */ template - static EventId ScheduleRealtimeNow (void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3); + static void ScheduleRealtimeNow (void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3); /** * @param f the function to invoke @@ -285,7 +285,7 @@ public: */ template - static EventId ScheduleRealtimeNow (void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4); + static void ScheduleRealtimeNow (void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4); /** * @param f the function to invoke @@ -297,177 +297,179 @@ public: */ template - static EventId ScheduleRealtimeNow (void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5); + static void ScheduleRealtimeNow (void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5); private: RealtimeSimulator (); ~RealtimeSimulator (); + static void ScheduleRealtime (const Time &delay, EventImpl *impl); + static void ScheduleRealtimeNow (EventImpl *impl); }; template -EventId RealtimeSimulator::ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj) +void RealtimeSimulator::ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj) { - return ScheduleRealtime (time, Simulator::MakeEvent (mem_ptr, obj)); + return ScheduleRealtime (time, MakeEvent (mem_ptr, obj)); } template -EventId RealtimeSimulator::ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1) +void RealtimeScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1) { - return ScheduleRealtime (time, Simulator::MakeEvent (mem_ptr, obj, a1)); + return ScheduleRealtime (time, MakeEvent (mem_ptr, obj, a1)); } template -EventId RealtimeSimulator::ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2) +void RealtimeScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2) { - return ScheduleRealtime (time, Simulator::MakeEvent (mem_ptr, obj, a1, a2)); + return ScheduleRealtime (time, MakeEvent (mem_ptr, obj, a1, a2)); } template -EventId RealtimeSimulator::ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3) +void RealtimeScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3) { - return ScheduleRealtime (time, Simulator::MakeEvent (mem_ptr, obj, a1, a2, a3)); + return ScheduleRealtime (time, MakeEvent (mem_ptr, obj, a1, a2, a3)); } template -EventId RealtimeSimulator::ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4) +void RealtimeScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4) { - return ScheduleRealtime (time, Simulator::MakeEvent (mem_ptr, obj, a1, a2, a3, a4)); + return ScheduleRealtime (time, MakeEvent (mem_ptr, obj, a1, a2, a3, a4)); } template -EventId RealtimeSimulator::ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, +void RealtimeScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) { - return ScheduleRealtime (time, Simulator::MakeEvent (mem_ptr, obj, a1, a2, a3, a4, a5)); + return ScheduleRealtime (time, MakeEvent (mem_ptr, obj, a1, a2, a3, a4, a5)); } template -EventId RealtimeSimulator::ScheduleRealtime (Time const &time, void (*f) (U1), T1 a1) +void RealtimeScheduleRealtime (Time const &time, void (*f) (U1), T1 a1) { - return ScheduleRealtime (time, Simulator::MakeEvent (f, a1)); + return ScheduleRealtime (time, MakeEvent (f, a1)); } template -EventId RealtimeSimulator::ScheduleRealtime (Time const &time, void (*f) (U1,U2), T1 a1, T2 a2) +void RealtimeScheduleRealtime (Time const &time, void (*f) (U1,U2), T1 a1, T2 a2) { - return ScheduleRealtime (time, Simulator::MakeEvent (f, a1, a2)); + return ScheduleRealtime (time, MakeEvent (f, a1, a2)); } template -EventId RealtimeSimulator::ScheduleRealtime (Time const &time, void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3) +void RealtimeScheduleRealtime (Time const &time, void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3) { - return ScheduleRealtime (time, Simulator::MakeEvent (f, a1, a2, a3)); + return ScheduleRealtime (time, MakeEvent (f, a1, a2, a3)); } template -EventId RealtimeSimulator::ScheduleRealtime (Time const &time, void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4) +void RealtimeScheduleRealtime (Time const &time, void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4) { - return ScheduleRealtime (time, Simulator::MakeEvent (f, a1, a2, a3, a4)); + return ScheduleRealtime (time, MakeEvent (f, a1, a2, a3, a4)); } template -EventId RealtimeSimulator::ScheduleRealtime (Time const &time, void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) +void RealtimeScheduleRealtime (Time const &time, void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) { - return ScheduleRealtime (time, Simulator::MakeEvent (f, a1, a2, a3, a4, a5)); + return ScheduleRealtime (time, MakeEvent (f, a1, a2, a3, a4, a5)); } template -EventId -RealtimeSimulator::ScheduleRealtimeNow (MEM mem_ptr, OBJ obj) +void +RealtimeScheduleRealtimeNow (MEM mem_ptr, OBJ obj) { - return ScheduleRealtimeNow (Simulator::MakeEvent (mem_ptr, obj)); + return ScheduleRealtimeNow (MakeEvent (mem_ptr, obj)); } template -EventId -RealtimeSimulator::ScheduleRealtimeNow (MEM mem_ptr, OBJ obj, T1 a1) +void +RealtimeScheduleRealtimeNow (MEM mem_ptr, OBJ obj, T1 a1) { - return ScheduleRealtimeNow (Simulator::MakeEvent (mem_ptr, obj, a1)); + return ScheduleRealtimeNow (MakeEvent (mem_ptr, obj, a1)); } template -EventId -RealtimeSimulator::ScheduleRealtimeNow (MEM mem_ptr, OBJ obj, T1 a1, T2 a2) +void +RealtimeScheduleRealtimeNow (MEM mem_ptr, OBJ obj, T1 a1, T2 a2) { - return ScheduleRealtimeNow (Simulator::MakeEvent (mem_ptr, obj, a1, a2)); + return ScheduleRealtimeNow (MakeEvent (mem_ptr, obj, a1, a2)); } template -EventId -RealtimeSimulator::ScheduleRealtimeNow (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3) +void +RealtimeScheduleRealtimeNow (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3) { - return ScheduleRealtimeNow (Simulator::MakeEvent (mem_ptr, obj, a1, a2, a3)); + return ScheduleRealtimeNow (MakeEvent (mem_ptr, obj, a1, a2, a3)); } template -EventId -RealtimeSimulator::ScheduleRealtimeNow (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4) +void +RealtimeScheduleRealtimeNow (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4) { - return ScheduleRealtimeNow (Simulator::MakeEvent (mem_ptr, obj, a1, a2, a3, a4)); + return ScheduleRealtimeNow (MakeEvent (mem_ptr, obj, a1, a2, a3, a4)); } template -EventId -RealtimeSimulator::ScheduleRealtimeNow (MEM mem_ptr, OBJ obj, +void +RealtimeScheduleRealtimeNow (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) { - return ScheduleRealtimeNow (Simulator::MakeEvent (mem_ptr, obj, a1, a2, a3, a4, a5)); + return ScheduleRealtimeNow (MakeEvent (mem_ptr, obj, a1, a2, a3, a4, a5)); } template -EventId -RealtimeSimulator::ScheduleRealtimeNow (void (*f) (U1), T1 a1) +void +RealtimeScheduleRealtimeNow (void (*f) (U1), T1 a1) { - return ScheduleRealtimeNow (Simulator::MakeEvent (f, a1)); + return ScheduleRealtimeNow (MakeEvent (f, a1)); } template -EventId -RealtimeSimulator::ScheduleRealtimeNow (void (*f) (U1,U2), T1 a1, T2 a2) +void +RealtimeScheduleRealtimeNow (void (*f) (U1,U2), T1 a1, T2 a2) { - return ScheduleRealtimeNow (Simulator::MakeEvent (f, a1, a2)); + return ScheduleRealtimeNow (MakeEvent (f, a1, a2)); } template -EventId -RealtimeSimulator::ScheduleRealtimeNow (void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3) +void +RealtimeScheduleRealtimeNow (void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3) { - return ScheduleRealtimeNow (Simulator::MakeEvent (f, a1, a2, a3)); + return ScheduleRealtimeNow (MakeEvent (f, a1, a2, a3)); } template -EventId -RealtimeSimulator::ScheduleRealtimeNow (void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4) +void +RealtimeScheduleRealtimeNow (void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4) { - return ScheduleRealtimeNow (Simulator::MakeEvent (f, a1, a2, a3, a4)); + return ScheduleRealtimeNow (MakeEvent (f, a1, a2, a3, a4)); } template -EventId -RealtimeSimulator::ScheduleRealtimeNow (void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) +void +RealtimeScheduleRealtimeNow (void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) { - return ScheduleRealtimeNow (Simulator::MakeEvent (f, a1, a2, a3, a4, a5)); + return ScheduleRealtimeNow (MakeEvent (f, a1, a2, a3, a4, a5)); } -}; // namespace ns3 +} // namespace ns3 #endif /* REALTIME_SIMULATOR_H */ diff --git a/src/simulator/simulator-impl.h b/src/simulator/simulator-impl.h index 9e68ac971..aff13abf1 100644 --- a/src/simulator/simulator-impl.h +++ b/src/simulator/simulator-impl.h @@ -21,20 +21,16 @@ #ifndef SIMULATOR_IMPL_H #define SIMULATOR_IMPL_H -#include "scheduler.h" #include "event-impl.h" #include "event-id.h" #include "nstime.h" - +#include "ns3/object.h" #include "ns3/ptr.h" -#include "ns3/assert.h" -#include "ns3/log.h" - -#include -#include namespace ns3 { +class Scheduler; + class SimulatorImpl : public Object { public: @@ -56,6 +52,8 @@ public: virtual Time GetMaximumSimulationTime (void) const = 0; virtual void SetScheduler (Ptr scheduler) = 0; virtual Ptr GetScheduler (void) const = 0; + virtual void ScheduleRealtime (Time const &time, EventImpl *event) = 0; + virtual void ScheduleRealtimeNow (EventImpl *event) = 0; }; } // namespace ns3 diff --git a/src/simulator/simulator.cc b/src/simulator/simulator.cc index f04c10ea4..2851a380f 100644 --- a/src/simulator/simulator.cc +++ b/src/simulator/simulator.cc @@ -49,8 +49,6 @@ GlobalValue g_simTypeImpl = GlobalValue ("SimulatorImplementationType", StringValue ("ns3::DefaultSimulatorImpl"), MakeStringChecker ()); -Ptr Simulator::m_impl = 0; - #ifdef NS3_LOG_ENABLE // @@ -66,23 +64,29 @@ TimePrinter (std::ostream &os) #endif /* NS3_LOG_ENABLE */ -SimulatorImpl * -Simulator::GetImpl (void) +static Ptr *PeekImpl (void) { + static Ptr impl = 0; + return &impl; +} + +static SimulatorImpl * GetImpl (void) +{ + Ptr &impl = *PeekImpl (); /* Please, don't include any calls to logging macros in this function * or pay the price, that is, stack explosions. */ - if (m_impl == 0) + if (impl == 0) { ObjectFactory factory; StringValue s; g_simTypeImpl.GetValue (s); factory.SetTypeId (s.Get ()); - m_impl = factory.Create (); + impl = factory.Create (); Ptr scheduler = CreateObject (); - m_impl->SetScheduler (scheduler); + impl->SetScheduler (scheduler); // // Note: we call LogSetTimePrinter _after_ creating the implementation @@ -93,7 +97,7 @@ Simulator::GetImpl (void) // LogSetTimePrinter (&TimePrinter); } - return PeekPointer (m_impl); + return PeekPointer (impl); } void @@ -101,7 +105,8 @@ Simulator::Destroy (void) { NS_LOG_FUNCTION_NOARGS (); - if (m_impl == 0) + Ptr &impl = *PeekImpl (); + if (impl == 0) { return; } @@ -111,8 +116,8 @@ Simulator::Destroy (void) * the stack explodes. */ LogSetTimePrinter (0); - m_impl->Destroy (); - m_impl = 0; + impl->Destroy (); + impl = 0; } void @@ -184,30 +189,6 @@ Simulator::GetDelayLeft (const EventId &id) return GetImpl ()->GetDelayLeft (id); } -EventImpl * -Simulator::MakeEvent (void (*f) (void)) -{ - NS_LOG_FUNCTION (f); - // zero arg version - class EventFunctionImpl0 : public EventImpl - { - public: - typedef void (*F)(void); - - EventFunctionImpl0 (F function) - : m_function (function) - {} - virtual ~EventFunctionImpl0 () {} - protected: - virtual void Notify (void) { - (*m_function) (); - } - private: - F m_function; - } *ev = new EventFunctionImpl0 (f); - return ev; -} - EventId Simulator::Schedule (Time const &time, const Ptr &ev) { @@ -306,47 +287,33 @@ Simulator::SetImplementation (Ptr impl) NS_FATAL_ERROR ("TODO"); } -RealtimeSimulatorImpl * -RealtimeSimulator::GetRealtimeImpl (void) -{ - RealtimeSimulatorImpl *impl = dynamic_cast(Simulator::GetImpl ()); - NS_ASSERT_MSG (impl, - "RealtimeSimulator::GetImpl (): Underlying simulator implementation not realtime"); - return impl; -} -Time -RealtimeSimulator::RealtimeNow (void) -{ - return GetRealtimeImpl ()->RealtimeNow (); -} - -EventId -RealtimeSimulator::ScheduleRealtime (Time const &time, const Ptr &ev) +void +RealtimeSimulator::ScheduleRealtime (Time const &time, EventImpl *ev) { NS_LOG_FUNCTION (time << ev); - return GetRealtimeImpl ()->ScheduleRealtime (time, ev); + return GetImpl ()->ScheduleRealtime (time, ev); } -EventId -RealtimeSimulator::ScheduleRealtimeNow (const Ptr &ev) +void +RealtimeSimulator::ScheduleRealtimeNow (EventImpl *ev) { NS_LOG_FUNCTION (ev); - return GetRealtimeImpl ()->ScheduleRealtimeNow (ev); + return GetImpl ()->ScheduleRealtimeNow (ev); } -EventId +void RealtimeSimulator::ScheduleRealtime (Time const &time, void (*f) (void)) { NS_LOG_FUNCTION (time << f); - return ScheduleRealtime (time, Simulator::MakeEvent (f)); + return ScheduleRealtime (time, MakeEvent (f)); } -EventId +void RealtimeSimulator::ScheduleRealtimeNow (void (*f) (void)) { NS_LOG_FUNCTION (f); - return ScheduleRealtimeNow (Simulator::MakeEvent (f)); + return ScheduleRealtimeNow (MakeEvent (f)); } diff --git a/src/simulator/simulator.h b/src/simulator/simulator.h index adb7253a0..2b22b181a 100644 --- a/src/simulator/simulator.h +++ b/src/simulator/simulator.h @@ -23,9 +23,9 @@ #include "event-id.h" #include "event-impl.h" +#include "make-event.h" #include "nstime.h" -#include "ns3/type-traits.h" #include "ns3/deprecated.h" #include @@ -56,8 +56,6 @@ class Scheduler; */ class Simulator { - friend class RealtimeSimulator; - public: /** * \param impl a new simulator implementation @@ -622,46 +620,6 @@ private: static EventId DoSchedule (Time const &time, EventImpl *event); static EventId DoScheduleNow (EventImpl *event); static EventId DoScheduleDestroy (EventImpl *event); - - template - static EventImpl *MakeEvent (MEM mem_ptr, OBJ obj); - template - static EventImpl *MakeEvent (MEM mem_ptr, OBJ obj, T1 a1); - template - static EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2); - template - static EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3); - template - static EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4); - template - static EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, - T1 a1, T2 a2, T3 a3, T4 a4, T5 a5); - static EventImpl * MakeEvent (void (*f) (void)); - template - static EventImpl * MakeEvent (void (*f) (U1), T1 a1); - template - static EventImpl * MakeEvent (void (*f) (U1,U2), T1 a1, T2 a2); - template - static EventImpl * MakeEvent (void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3); - template - static EventImpl * MakeEvent (void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4); - template - static EventImpl * MakeEvent (void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5); - - static SimulatorImpl *GetImpl (void); - static Ptr m_impl; - static std::string m_typeImpl; - static std::string m_typeSched; }; /** @@ -679,335 +637,8 @@ Time Now (void); } // namespace ns3 - -/******************************************************************** - Implementation of templates defined above - ********************************************************************/ - namespace ns3 { -template -struct EventMemberImplObjTraits; - -template -struct EventMemberImplObjTraits -{ - static T &GetReference (T *p) { - return *p; - } -}; - -template -EventImpl * Simulator::MakeEvent (MEM mem_ptr, OBJ obj) -{ - // zero argument version - class EventMemberImpl0 : public EventImpl { - public: - EventMemberImpl0 (OBJ obj, MEM function) - : m_obj (obj), - m_function (function) - {} - virtual ~EventMemberImpl0 () {} - private: - virtual void Notify (void) { - (EventMemberImplObjTraits::GetReference (m_obj).*m_function) (); - } - OBJ m_obj; - MEM m_function; - } * ev = new EventMemberImpl0 (obj, mem_ptr); - return ev; -} - - -template -EventImpl * Simulator::MakeEvent (MEM mem_ptr, OBJ obj, T1 a1) -{ - // one argument version - class EventMemberImpl1 : public EventImpl { - public: - EventMemberImpl1 (OBJ obj, MEM function, T1 a1) - : m_obj (obj), - m_function (function), - m_a1 (a1) - {} - protected: - virtual ~EventMemberImpl1 () {} - private: - virtual void Notify (void) { - (EventMemberImplObjTraits::GetReference (m_obj).*m_function) (m_a1); - } - OBJ m_obj; - MEM m_function; - typename TypeTraits::ReferencedType m_a1; - } *ev = new EventMemberImpl1 (obj, mem_ptr, a1); - return ev; -} - -template -EventImpl * Simulator::MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2) -{ - // two argument version - class EventMemberImpl2 : public EventImpl { - public: - EventMemberImpl2 (OBJ obj, MEM function, T1 a1, T2 a2) - : m_obj (obj), - m_function (function), - m_a1 (a1), - m_a2 (a2) - { } - protected: - virtual ~EventMemberImpl2 () {} - private: - virtual void Notify (void) { - (EventMemberImplObjTraits::GetReference (m_obj).*m_function) (m_a1, m_a2); - } - OBJ m_obj; - MEM m_function; - typename TypeTraits::ReferencedType m_a1; - typename TypeTraits::ReferencedType m_a2; - } *ev = new EventMemberImpl2 (obj, mem_ptr, a1, a2); - return ev; -} - -template -EventImpl * Simulator::MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3) -{ - // three argument version - class EventMemberImpl3 : public EventImpl { - public: - EventMemberImpl3 (OBJ obj, MEM function, T1 a1, T2 a2, T3 a3) - : m_obj (obj), - m_function (function), - m_a1 (a1), - m_a2 (a2), - m_a3 (a3) - { } - protected: - virtual ~EventMemberImpl3 () {} - private: - virtual void Notify (void) { - (EventMemberImplObjTraits::GetReference (m_obj).*m_function) (m_a1, m_a2, m_a3); - } - OBJ m_obj; - MEM m_function; - typename TypeTraits::ReferencedType m_a1; - typename TypeTraits::ReferencedType m_a2; - typename TypeTraits::ReferencedType m_a3; - } *ev = new EventMemberImpl3 (obj, mem_ptr, a1, a2, a3); - return ev; -} - -template -EventImpl * Simulator::MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4) -{ - // four argument version - class EventMemberImpl4 : public EventImpl { - public: - EventMemberImpl4 (OBJ obj, MEM function, T1 a1, T2 a2, T3 a3, T4 a4) - : m_obj (obj), - m_function (function), - m_a1 (a1), - m_a2 (a2), - m_a3 (a3), - m_a4 (a4) - { } - protected: - virtual ~EventMemberImpl4 () {} - private: - virtual void Notify (void) { - (EventMemberImplObjTraits::GetReference (m_obj).*m_function) (m_a1, m_a2, m_a3, m_a4); - } - OBJ m_obj; - MEM m_function; - typename TypeTraits::ReferencedType m_a1; - typename TypeTraits::ReferencedType m_a2; - typename TypeTraits::ReferencedType m_a3; - typename TypeTraits::ReferencedType m_a4; - } *ev = new EventMemberImpl4 (obj, mem_ptr, a1, a2, a3, a4); - return ev; -} - -template -EventImpl * Simulator::MakeEvent (MEM mem_ptr, OBJ obj, - T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) -{ - // five argument version - class EventMemberImpl5 : public EventImpl { - public: - EventMemberImpl5 (OBJ obj, MEM function, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) - : m_obj (obj), - m_function (function), - m_a1 (a1), - m_a2 (a2), - m_a3 (a3), - m_a4 (a4), - m_a5 (a5) - { } - protected: - virtual ~EventMemberImpl5 () {} - private: - virtual void Notify (void) { - (EventMemberImplObjTraits::GetReference (m_obj).*m_function) (m_a1, m_a2, m_a3, m_a4, m_a5); - } - OBJ m_obj; - MEM m_function; - typename TypeTraits::ReferencedType m_a1; - typename TypeTraits::ReferencedType m_a2; - typename TypeTraits::ReferencedType m_a3; - typename TypeTraits::ReferencedType m_a4; - typename TypeTraits::ReferencedType m_a5; - } *ev = new EventMemberImpl5 (obj, mem_ptr, a1, a2, a3, a4, a5); - return ev; -} - -template -EventImpl * Simulator::MakeEvent (void (*f) (U1), T1 a1) -{ - // one arg version - class EventFunctionImpl1 : public EventImpl { - public: - typedef void (*F)(U1); - - EventFunctionImpl1 (F function, T1 a1) - : m_function (function), - m_a1 (a1) - { } - protected: - virtual ~EventFunctionImpl1 () {} - private: - virtual void Notify (void) { - (*m_function) (m_a1); - } - F m_function; - typename TypeTraits::ReferencedType m_a1; - } *ev = new EventFunctionImpl1 (f, a1); - return ev; -} - -template -EventImpl * Simulator::MakeEvent (void (*f) (U1,U2), T1 a1, T2 a2) -{ - // two arg version - class EventFunctionImpl2 : public EventImpl { - public: - typedef void (*F)(U1, U2); - - EventFunctionImpl2 (F function, T1 a1, T2 a2) - : m_function (function), - m_a1 (a1), - m_a2 (a2) - {} - protected: - virtual ~EventFunctionImpl2 () {} - private: - virtual void Notify (void) { - (*m_function) (m_a1, m_a2); - } - F m_function; - typename TypeTraits::ReferencedType m_a1; - typename TypeTraits::ReferencedType m_a2; - } *ev = new EventFunctionImpl2 (f, a1, a2); - return ev; -} - -template -EventImpl * Simulator::MakeEvent (void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3) -{ - // three arg version - class EventFunctionImpl3 : public EventImpl { - public: - typedef void (*F)(U1, U2, U3); - - EventFunctionImpl3 (F function, T1 a1, T2 a2, T3 a3) - : m_function (function), - m_a1 (a1), - m_a2 (a2), - m_a3 (a3) - { } - protected: - virtual ~EventFunctionImpl3 () {} - private: - virtual void Notify (void) { - (*m_function) (m_a1, m_a2, m_a3); - } - F m_function; - typename TypeTraits::ReferencedType m_a1; - typename TypeTraits::ReferencedType m_a2; - typename TypeTraits::ReferencedType m_a3; - } *ev = new EventFunctionImpl3 (f, a1, a2, a3); - return ev; -} - -template -EventImpl * Simulator::MakeEvent (void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4) -{ - // four arg version - class EventFunctionImpl4 : public EventImpl { - public: - typedef void (*F)(U1, U2, U3, U4); - - EventFunctionImpl4 (F function, T1 a1, T2 a2, T3 a3, T4 a4) - : m_function (function), - m_a1 (a1), - m_a2 (a2), - m_a3 (a3), - m_a4 (a4) - { } - protected: - virtual ~EventFunctionImpl4 () {} - private: - virtual void Notify (void) { - (*m_function) (m_a1, m_a2, m_a3, m_a4); - } - F m_function; - typename TypeTraits::ReferencedType m_a1; - typename TypeTraits::ReferencedType m_a2; - typename TypeTraits::ReferencedType m_a3; - typename TypeTraits::ReferencedType m_a4; - } *ev = new EventFunctionImpl4 (f, a1, a2, a3, a4); - return ev; -} - -template -EventImpl * Simulator::MakeEvent (void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) -{ - // five arg version - class EventFunctionImpl5 : public EventImpl { - public: - typedef void (*F)(U1,U2,U3,U4,U5); - - EventFunctionImpl5 (F function, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) - : m_function (function), - m_a1 (a1), - m_a2 (a2), - m_a3 (a3), - m_a4 (a4), - m_a5 (a5) - {} - protected: - virtual ~EventFunctionImpl5 () {} - private: - virtual void Notify (void) { - (*m_function) (m_a1, m_a2, m_a3, m_a4, m_a5); - } - F m_function; - typename TypeTraits::ReferencedType m_a1; - typename TypeTraits::ReferencedType m_a2; - typename TypeTraits::ReferencedType m_a3; - typename TypeTraits::ReferencedType m_a4; - typename TypeTraits::ReferencedType m_a5; - } *ev = new EventFunctionImpl5 (f, a1, a2, a3, a4, a5); - return ev; -} - template EventId Simulator::Schedule (Time const &time, MEM mem_ptr, OBJ obj) { diff --git a/src/simulator/wscript b/src/simulator/wscript index d737dc290..d6e6737d5 100644 --- a/src/simulator/wscript +++ b/src/simulator/wscript @@ -65,6 +65,7 @@ def build(bld): 'timer.cc', 'watchdog.cc', 'synchronizer.cc', + 'make-event.cc', ] headers = bld.create_obj('ns3header') @@ -87,6 +88,7 @@ def build(bld): 'timer-impl.h', 'watchdog.h', 'synchronizer.h', + 'make-event.h', ] env = bld.env_of_name('default')