From ebd16ea6fc6232df6084dc7438d70c34ade27407 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sat, 28 Oct 2006 21:21:53 +0200 Subject: [PATCH] implement overloads for ScheduleNow and ScheduleDestroy --- src/simulator/simulator.cc | 133 +++++++++++-- src/simulator/simulator.h | 374 ++++++++++++++++++++++++++++++++++++- 2 files changed, 486 insertions(+), 21 deletions(-) diff --git a/src/simulator/simulator.cc b/src/simulator/simulator.cc index 066fd9003..071cca29d 100644 --- a/src/simulator/simulator.cc +++ b/src/simulator/simulator.cc @@ -356,26 +356,10 @@ Simulator::Now (void) return GetPriv ()->Now (); } -EventId -Simulator::Schedule (Time const &time, EventImpl *ev) +EventImpl * +Simulator::MakeEvent (void (*f) (void)) { - return GetPriv ()->Schedule (time, ev); -} -void -Simulator::ScheduleNow (EventImpl *ev) -{ - GetPriv ()->ScheduleNow (ev); -} -void -Simulator::ScheduleDestroy (EventImpl *ev) -{ - GetPriv ()->ScheduleDestroy (ev); -} - -EventId -Simulator::Schedule (Time const &time, void (*f) (void)) -{ - // zero arg version + // zero arg version class EventFunctionImpl0 : public EventImpl { public: typedef void (*F)(void); @@ -391,7 +375,37 @@ Simulator::Schedule (Time const &time, void (*f) (void)) private: F m_function; } *ev = new EventFunctionImpl0 (f); - return Schedule (time, ev); + return ev; +} +EventId +Simulator::Schedule (Time const &time, EventImpl *ev) +{ + return GetPriv ()->Schedule (time, ev); +} +void +Simulator::ScheduleNow (EventImpl *ev) +{ + GetPriv ()->ScheduleNow (ev); +} +void +Simulator::ScheduleDestroy (EventImpl *ev) +{ + GetPriv ()->ScheduleDestroy (ev); +} +EventId +Simulator::Schedule (Time const &time, void (*f) (void)) +{ + return Schedule (time, MakeEvent (f)); +} +void +Simulator::ScheduleNow (void (*f) (void)) +{ + return ScheduleNow (MakeEvent (f)); +} +void +Simulator::ScheduleDestroy (void (*f) (void)) +{ + return ScheduleDestroy (MakeEvent (f)); } @@ -421,6 +435,20 @@ Simulator::IsExpired (EventId id) namespace ns3 { +static void foo0 (void) +{} +static void foo1 (int) +{} +static void foo2 (int, int) +{} +static void foo3 (int, int, int) +{} +static void foo4 (int, int, int, int) +{} +static void foo5 (int, int, int, int, int) +{} + + class SimulatorTests : public Test { public: SimulatorTests (); @@ -433,6 +461,13 @@ private: void B (int b); void C (int c); void D (int d); + void bar0 (void); + void bar1 (int); + void bar2 (int, int); + void bar3 (int, int, int); + void bar4 (int, int, int, int); + void bar5 (int, int, int, int, int); + bool m_b; bool m_a; bool m_c; @@ -487,6 +522,25 @@ SimulatorTests::D (int d) m_d = true; } } +void +SimulatorTests::bar0 (void) +{} +void +SimulatorTests::bar1 (int) +{} +void +SimulatorTests::bar2 (int, int) +{} +void +SimulatorTests::bar3 (int, int, int) +{} +void +SimulatorTests::bar4 (int, int, int, int) +{} +void +SimulatorTests::bar5 (int, int, int, int, int) +{} + bool SimulatorTests::RunOneTest (void) { @@ -533,6 +587,45 @@ SimulatorTests::RunTests (void) } Simulator::Destroy (); + + Simulator::Schedule (Seconds (0.0), &foo0); + Simulator::Schedule (Seconds (0.0), &foo1, 0); + Simulator::Schedule (Seconds (0.0), &foo2, 0, 0); + Simulator::Schedule (Seconds (0.0), &foo3, 0, 0, 0); + Simulator::Schedule (Seconds (0.0), &foo4, 0, 0, 0, 0); + Simulator::Schedule (Seconds (0.0), &foo5, 0, 0, 0, 0, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar0, this); + Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar1, this, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar2, this, 0, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar3, this, 0, 0, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar4, this, 0, 0, 0, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar5, this, 0, 0, 0, 0, 0); + Simulator::ScheduleNow (&foo0); + Simulator::ScheduleNow (&foo1, 0); + Simulator::ScheduleNow (&foo2, 0, 0); + Simulator::ScheduleNow (&foo3, 0, 0, 0); + Simulator::ScheduleNow (&foo4, 0, 0, 0, 0); + Simulator::ScheduleNow (&foo5, 0, 0, 0, 0, 0); + Simulator::ScheduleNow (&SimulatorTests::bar0, this); + Simulator::ScheduleNow (&SimulatorTests::bar1, this, 0); + Simulator::ScheduleNow (&SimulatorTests::bar2, this, 0, 0); + Simulator::ScheduleNow (&SimulatorTests::bar3, this, 0, 0, 0); + Simulator::ScheduleNow (&SimulatorTests::bar4, this, 0, 0, 0, 0); + Simulator::ScheduleNow (&SimulatorTests::bar5, this, 0, 0, 0, 0, 0); + Simulator::ScheduleDestroy (&foo0); + Simulator::ScheduleDestroy (&foo1, 0); + Simulator::ScheduleDestroy (&foo2, 0, 0); + Simulator::ScheduleDestroy (&foo3, 0, 0, 0); + Simulator::ScheduleDestroy (&foo4, 0, 0, 0, 0); + Simulator::ScheduleDestroy (&foo5, 0, 0, 0, 0, 0); + Simulator::ScheduleDestroy (&SimulatorTests::bar0, this); + Simulator::ScheduleDestroy (&SimulatorTests::bar1, this, 0); + Simulator::ScheduleDestroy (&SimulatorTests::bar2, this, 0, 0); + Simulator::ScheduleDestroy (&SimulatorTests::bar3, this, 0, 0, 0); + Simulator::ScheduleDestroy (&SimulatorTests::bar4, this, 0, 0, 0, 0); + Simulator::ScheduleDestroy (&SimulatorTests::bar5, this, 0, 0, 0, 0, 0); + + return ok; } diff --git a/src/simulator/simulator.h b/src/simulator/simulator.h index a6e6e38cb..981fb2464 100644 --- a/src/simulator/simulator.h +++ b/src/simulator/simulator.h @@ -275,6 +275,215 @@ public: template static EventId Schedule (Time const &time, void (*f) (T1,T2,T3,T4,T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5); + + /** + * Schedule an event to expire Now. All events scheduled to + * to expire "Now" are scheduled FIFO, after all normal events + * have expired. + * + * @param mem_ptr member method pointer to invoke + * @param obj the object on which to invoke the member method + */ + template + static void ScheduleNow (void (T::*mem_ptr) (void), T *obj); + /** + * @param mem_ptr member method pointer to invoke + * @param obj the object on which to invoke the member method + * @param a1 the first argument to pass to the invoked method + */ + template + static void ScheduleNow (void (T::*mem_ptr) (T1), T* obj, T1 a1); + /** + * @param mem_ptr member method pointer to invoke + * @param obj the object on which to invoke the member method + * @param a1 the first argument to pass to the invoked method + * @param a2 the second argument to pass to the invoked method + */ + template + static void ScheduleNow (void (T::*mem_ptr) (T1,T2), T* obj, T1 a1, T2 a2); + /** + * @param time the expiration time of the event. + * @param mem_ptr member method pointer to invoke + * @param obj the object on which to invoke the member method + * @param a1 the first argument to pass to the invoked method + * @param a2 the second argument to pass to the invoked method + * @param a3 the third argument to pass to the invoked method + */ + template + static void ScheduleNow (void (T::*mem_ptr) (T1,T2,T3), T* obj, T1 a1, T2 a2, T3 a3); + /** + * @param mem_ptr member method pointer to invoke + * @param obj the object on which to invoke the member method + * @param a1 the first argument to pass to the invoked method + * @param a2 the second argument to pass to the invoked method + * @param a3 the third argument to pass to the invoked method + * @param a4 the fourth argument to pass to the invoked method + */ + template + static void ScheduleNow (void (T::*mem_ptr) (T1,T2,T3,T4), T* obj, + T1 a1, T2 a2, T3 a3, T4 a4); + /** + * @param mem_ptr member method pointer to invoke + * @param obj the object on which to invoke the member method + * @param a1 the first argument to pass to the invoked method + * @param a2 the second argument to pass to the invoked method + * @param a3 the third argument to pass to the invoked method + * @param a4 the fourth argument to pass to the invoked method + * @param a5 the fifth argument to pass to the invoked method + */ + template + static void ScheduleNow (void (T::*mem_ptr) (T1,T2,T3,T4,T5), T* obj, + T1 a1, T2 a2, T3 a3, T4 a4, T5 a5); + /** + * @param f the function to invoke + */ + static void ScheduleNow (void (*f) (void)); + /** + * @param f the function to invoke + * @param a1 the first argument to pass to the function to invoke + */ + template + static void ScheduleNow (void (*f) (T1), T1 a1); + /** + * @param f the function to invoke + * @param a1 the first argument to pass to the function to invoke + * @param a2 the second argument to pass to the function to invoke + */ + template + static void ScheduleNow (void (*f) (T1,T2), T1 a1, T2 a2); + /** + * @param f the function to invoke + * @param a1 the first argument to pass to the function to invoke + * @param a2 the second argument to pass to the function to invoke + * @param a3 the third argument to pass to the function to invoke + */ + template + static void ScheduleNow (void (*f) (T1,T2,T3), T1 a1, T2 a2, T3 a3); + /** + * @param f the function to invoke + * @param a1 the first argument to pass to the function to invoke + * @param a2 the second argument to pass to the function to invoke + * @param a3 the third argument to pass to the function to invoke + * @param a4 the fourth argument to pass to the function to invoke + */ + template + static void ScheduleNow (void (*f) (T1,T2,T3,T4), T1 a1, T2 a2, T3 a3, T4 a4); + /** + * @param f the function to invoke + * @param a1 the first argument to pass to the function to invoke + * @param a2 the second argument to pass to the function to invoke + * @param a3 the third argument to pass to the function to invoke + * @param a4 the fourth argument to pass to the function to invoke + * @param a5 the fifth argument to pass to the function to invoke + */ + template + static void ScheduleNow (void (*f) (T1,T2,T3,T4,T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5); + + + /** + * Schedule an event to expire at Destroy time. All events + * scheduled to expire at "Destroy" time are scheduled FIFO, + * after all normal events have expired and only when + * Simulator::Destroy is invoked. + * + * @param mem_ptr member method pointer to invoke + * @param obj the object on which to invoke the member method + */ + template + static void ScheduleDestroy (void (T::*mem_ptr) (void), T *obj); + /** + * @param mem_ptr member method pointer to invoke + * @param obj the object on which to invoke the member method + * @param a1 the first argument to pass to the invoked method + */ + template + static void ScheduleDestroy (void (T::*mem_ptr) (T1), T* obj, T1 a1); + /** + * @param mem_ptr member method pointer to invoke + * @param obj the object on which to invoke the member method + * @param a1 the first argument to pass to the invoked method + * @param a2 the second argument to pass to the invoked method + */ + template + static void ScheduleDestroy (void (T::*mem_ptr) (T1,T2), T* obj, T1 a1, T2 a2); + /** + * @param time the expiration time of the event. + * @param mem_ptr member method pointer to invoke + * @param obj the object on which to invoke the member method + * @param a1 the first argument to pass to the invoked method + * @param a2 the second argument to pass to the invoked method + * @param a3 the third argument to pass to the invoked method + */ + template + static void ScheduleDestroy (void (T::*mem_ptr) (T1,T2,T3), T* obj, T1 a1, T2 a2, T3 a3); + /** + * @param mem_ptr member method pointer to invoke + * @param obj the object on which to invoke the member method + * @param a1 the first argument to pass to the invoked method + * @param a2 the second argument to pass to the invoked method + * @param a3 the third argument to pass to the invoked method + * @param a4 the fourth argument to pass to the invoked method + */ + template + static void ScheduleDestroy (void (T::*mem_ptr) (T1,T2,T3,T4), T* obj, + T1 a1, T2 a2, T3 a3, T4 a4); + /** + * @param mem_ptr member method pointer to invoke + * @param obj the object on which to invoke the member method + * @param a1 the first argument to pass to the invoked method + * @param a2 the second argument to pass to the invoked method + * @param a3 the third argument to pass to the invoked method + * @param a4 the fourth argument to pass to the invoked method + * @param a5 the fifth argument to pass to the invoked method + */ + template + static void ScheduleDestroy (void (T::*mem_ptr) (T1,T2,T3,T4,T5), T* obj, + T1 a1, T2 a2, T3 a3, T4 a4, T5 a5); + /** + * @param f the function to invoke + */ + static void ScheduleDestroy (void (*f) (void)); + /** + * @param f the function to invoke + * @param a1 the first argument to pass to the function to invoke + */ + template + static void ScheduleDestroy (void (*f) (T1), T1 a1); + /** + * @param f the function to invoke + * @param a1 the first argument to pass to the function to invoke + * @param a2 the second argument to pass to the function to invoke + */ + template + static void ScheduleDestroy (void (*f) (T1,T2), T1 a1, T2 a2); + /** + * @param f the function to invoke + * @param a1 the first argument to pass to the function to invoke + * @param a2 the second argument to pass to the function to invoke + * @param a3 the third argument to pass to the function to invoke + */ + template + static void ScheduleDestroy (void (*f) (T1,T2,T3), T1 a1, T2 a2, T3 a3); + /** + * @param f the function to invoke + * @param a1 the first argument to pass to the function to invoke + * @param a2 the second argument to pass to the function to invoke + * @param a3 the third argument to pass to the function to invoke + * @param a4 the fourth argument to pass to the function to invoke + */ + template + static void ScheduleDestroy (void (*f) (T1,T2,T3,T4), T1 a1, T2 a2, T3 a3, T4 a4); + /** + * @param f the function to invoke + * @param a1 the first argument to pass to the function to invoke + * @param a2 the second argument to pass to the function to invoke + * @param a3 the third argument to pass to the function to invoke + * @param a4 the fourth argument to pass to the function to invoke + * @param a5 the fifth argument to pass to the function to invoke + */ + template + static void ScheduleDestroy (void (*f) (T1,T2,T3,T4,T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5); + /** * Remove an event from the event list. * This method has the same visible effect as the @@ -744,11 +953,174 @@ EventId Simulator::Schedule (Time const &time, void (*f) (T1,T2,T3,T4), T1 a1, T } template -static EventId Schedule (Time const &time, void (*f) (T1,T2,T3,T4,T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) +EventId Simulator::Schedule (Time const &time, void (*f) (T1,T2,T3,T4,T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) { return Schedule (time, MakeEvent (f, a1, a2, a3, a4, a5)); } + + + +template +void +Simulator::ScheduleNow (void (T::*mem_ptr) (void), T *obj) +{ + ScheduleNow (MakeEvent (mem_ptr, obj)); +} + + +template +void +Simulator::ScheduleNow (void (T::*mem_ptr) (T1), T* obj, T1 a1) +{ + ScheduleNow (MakeEvent (mem_ptr, obj, a1)); +} + +template +void +Simulator::ScheduleNow (void (T::*mem_ptr) (T1,T2), T* obj, T1 a1, T2 a2) +{ + ScheduleNow (MakeEvent (mem_ptr, obj, a1, a2)); +} + +template +void +Simulator::ScheduleNow (void (T::*mem_ptr) (T1,T2,T3), T* obj, T1 a1, T2 a2, T3 a3) +{ + ScheduleNow (MakeEvent (mem_ptr, obj, a1, a2, a3)); +} + +template +void +Simulator::ScheduleNow (void (T::*mem_ptr) (T1,T2,T3,T4), T* obj, T1 a1, T2 a2, T3 a3, T4 a4) +{ + ScheduleNow (MakeEvent (mem_ptr, obj, a1, a2, a3, a4)); +} + +template +void +Simulator::ScheduleNow (void (T::*mem_ptr) (T1,T2,T3,T4,T5), T* obj, + T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) +{ + ScheduleNow (MakeEvent (mem_ptr, obj, a1, a2, a3, a4, a5)); +} + +template +void +Simulator::ScheduleNow (void (*f) (T1), T1 a1) +{ + ScheduleNow (MakeEvent (f, a1)); +} + +template +void +Simulator::ScheduleNow (void (*f) (T1,T2), T1 a1, T2 a2) +{ + ScheduleNow (MakeEvent (f, a1, a2)); +} + +template +void +Simulator::ScheduleNow (void (*f) (T1,T2,T3), T1 a1, T2 a2, T3 a3) +{ + ScheduleNow (MakeEvent (f, a1, a2, a3)); +} + +template +void +Simulator::ScheduleNow (void (*f) (T1,T2,T3,T4), T1 a1, T2 a2, T3 a3, T4 a4) +{ + ScheduleNow (MakeEvent (f, a1, a2, a3, a4)); +} + +template +void +Simulator::ScheduleNow (void (*f) (T1,T2,T3,T4,T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) +{ + ScheduleNow (MakeEvent (f, a1, a2, a3, a4, a5)); +} + + + +template +void +Simulator::ScheduleDestroy (void (T::*mem_ptr) (void), T *obj) +{ + ScheduleDestroy (MakeEvent (mem_ptr, obj)); +} + + +template +void +Simulator::ScheduleDestroy (void (T::*mem_ptr) (T1), T* obj, T1 a1) +{ + ScheduleDestroy (MakeEvent (mem_ptr, obj, a1)); +} + +template +void +Simulator::ScheduleDestroy (void (T::*mem_ptr) (T1,T2), T* obj, T1 a1, T2 a2) +{ + ScheduleDestroy (MakeEvent (mem_ptr, obj, a1, a2)); +} + +template +void +Simulator::ScheduleDestroy (void (T::*mem_ptr) (T1,T2,T3), T* obj, T1 a1, T2 a2, T3 a3) +{ + ScheduleDestroy (MakeEvent (mem_ptr, obj, a1, a2, a3)); +} + +template +void +Simulator::ScheduleDestroy (void (T::*mem_ptr) (T1,T2,T3,T4), T* obj, T1 a1, T2 a2, T3 a3, T4 a4) +{ + ScheduleDestroy (MakeEvent (mem_ptr, obj, a1, a2, a3, a4)); +} + +template +void +Simulator::ScheduleDestroy (void (T::*mem_ptr) (T1,T2,T3,T4,T5), T* obj, + T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) +{ + ScheduleDestroy (MakeEvent (mem_ptr, obj, a1, a2, a3, a4, a5)); +} + +template +void +Simulator::ScheduleDestroy (void (*f) (T1), T1 a1) +{ + ScheduleDestroy (MakeEvent (f, a1)); +} + +template +void +Simulator::ScheduleDestroy (void (*f) (T1,T2), T1 a1, T2 a2) +{ + ScheduleDestroy (MakeEvent (f, a1, a2)); +} + +template +void +Simulator::ScheduleDestroy (void (*f) (T1,T2,T3), T1 a1, T2 a2, T3 a3) +{ + ScheduleDestroy (MakeEvent (f, a1, a2, a3)); +} + +template +void +Simulator::ScheduleDestroy (void (*f) (T1,T2,T3,T4), T1 a1, T2 a2, T3 a3, T4 a4) +{ + ScheduleDestroy (MakeEvent (f, a1, a2, a3, a4)); +} + +template +void +Simulator::ScheduleDestroy (void (*f) (T1,T2,T3,T4,T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) +{ + ScheduleDestroy (MakeEvent (f, a1, a2, a3, a4, a5)); +} + }; // namespace ns3 #endif /* SIMULATOR_H */