# HG changeset patch # User Guillaume Seguin # Date 1258028375 -3600 # Node ID 915abd2b907b1b3234941f93ee02b4f93a4ac96c # Parent 8a51fa38a4ee069b8bfc75a6e694582e16740eb4 Simulator::SetScheduler now takes an ObjectFactory diff -r 8a51fa38a4ee -r 915abd2b907b CHANGES.html --- a/CHANGES.html Thu Nov 12 13:02:55 2009 +0100 +++ b/CHANGES.html Thu Nov 12 13:19:35 2009 +0100 @@ -62,6 +62,28 @@
+

Changes from ns-3.6 to ns-3.7

+ +

Changes to existing API:

+ + +

Changes from ns-3.5 to ns-3.6

Changes to build system:

diff -r 8a51fa38a4ee -r 915abd2b907b src/simulator/default-simulator-impl.cc --- a/src/simulator/default-simulator-impl.cc Thu Nov 12 13:02:55 2009 +0100 +++ b/src/simulator/default-simulator-impl.cc Thu Nov 12 13:19:35 2009 +0100 @@ -86,8 +86,10 @@ } void -DefaultSimulatorImpl::SetScheduler (Ptr scheduler) +DefaultSimulatorImpl::SetScheduler (ObjectFactory schedulerFactory) { + Ptr scheduler = schedulerFactory.Create (); + if (m_events != 0) { while (!m_events->IsEmpty ()) diff -r 8a51fa38a4ee -r 915abd2b907b src/simulator/default-simulator-impl.h --- a/src/simulator/default-simulator-impl.h Thu Nov 12 13:02:55 2009 +0100 +++ b/src/simulator/default-simulator-impl.h Thu Nov 12 13:19:35 2009 +0100 @@ -56,7 +56,7 @@ virtual Time Now (void) const; virtual Time GetDelayLeft (const EventId &id) const; virtual Time GetMaximumSimulationTime (void) const; - virtual void SetScheduler (Ptr scheduler); + virtual void SetScheduler (ObjectFactory schedulerFactory); private: void ProcessOneEvent (void); diff -r 8a51fa38a4ee -r 915abd2b907b src/simulator/realtime-simulator-impl.cc --- a/src/simulator/realtime-simulator-impl.cc Thu Nov 12 13:02:55 2009 +0100 +++ b/src/simulator/realtime-simulator-impl.cc Thu Nov 12 13:19:35 2009 +0100 @@ -122,10 +122,12 @@ } void -RealtimeSimulatorImpl::SetScheduler (Ptr scheduler) +RealtimeSimulatorImpl::SetScheduler (ObjectFactory schedulerFactory) { NS_LOG_FUNCTION_NOARGS (); + Ptr scheduler = schedulerFactory.Create (); + { CriticalSection cs (m_mutex); diff -r 8a51fa38a4ee -r 915abd2b907b src/simulator/realtime-simulator-impl.h --- a/src/simulator/realtime-simulator-impl.h Thu Nov 12 13:02:55 2009 +0100 +++ b/src/simulator/realtime-simulator-impl.h Thu Nov 12 13:19:35 2009 +0100 @@ -66,7 +66,7 @@ virtual Time Now (void) const; virtual Time GetDelayLeft (const EventId &id) const; virtual Time GetMaximumSimulationTime (void) const; - virtual void SetScheduler (Ptr scheduler); + virtual void SetScheduler (ObjectFactory schedulerFactory); void ScheduleRealtime (Time const &time, EventImpl *event); void ScheduleRealtimeNow (EventImpl *event); diff -r 8a51fa38a4ee -r 915abd2b907b src/simulator/simulator-impl.h --- a/src/simulator/simulator-impl.h Thu Nov 12 13:02:55 2009 +0100 +++ b/src/simulator/simulator-impl.h Thu Nov 12 13:19:35 2009 +0100 @@ -25,6 +25,7 @@ #include "event-id.h" #include "nstime.h" #include "ns3/object.h" +#include "ns3/object-factory.h" #include "ns3/ptr.h" namespace ns3 { @@ -49,7 +50,7 @@ virtual Time Now (void) const = 0; virtual Time GetDelayLeft (const EventId &id) const = 0; virtual Time GetMaximumSimulationTime (void) const = 0; - virtual void SetScheduler (Ptr scheduler) = 0; + virtual void SetScheduler (ObjectFactory schedulerFactory) = 0; }; } // namespace ns3 diff -r 8a51fa38a4ee -r 915abd2b907b src/simulator/simulator.cc --- a/src/simulator/simulator.cc Thu Nov 12 13:02:55 2009 +0100 +++ b/src/simulator/simulator.cc Thu Nov 12 13:19:35 2009 +0100 @@ -25,6 +25,7 @@ # include "realtime-simulator-impl.h" #endif #include "scheduler.h" +#include "map-scheduler.h" #include "event-impl.h" #include "ns3/ptr.h" @@ -51,8 +52,8 @@ GlobalValue g_schedTypeImpl = GlobalValue ("SchedulerType", "The object class to use as the scheduler implementation", - StringValue ("ns3::MapScheduler"), - MakeStringChecker ()); + TypeIdValue (MapScheduler::GetTypeId ()), + MakeTypeIdChecker ()); #ifdef NS3_LOG_ENABLE @@ -97,7 +98,7 @@ StringValue s; g_schedTypeImpl.GetValue (s); factory.SetTypeId (s.Get ()); - impl->SetScheduler (factory.Create ()); + impl->SetScheduler (factory); } // @@ -133,10 +134,10 @@ } void -Simulator::SetScheduler (Ptr scheduler) +Simulator::SetScheduler (ObjectFactory schedulerFactory) { - NS_LOG_FUNCTION (scheduler); - GetImpl ()->SetScheduler (scheduler); + NS_LOG_FUNCTION (schedulerFactory); + GetImpl ()->SetScheduler (schedulerFactory); } bool @@ -302,7 +303,7 @@ StringValue s; g_schedTypeImpl.GetValue (s); factory.SetTypeId (s.Get ()); - impl->SetScheduler (factory.Create ()); + impl->SetScheduler (factory); // // Note: we call LogSetTimePrinter _after_ creating the implementation // object because the act of creation can trigger calls to the logging @@ -334,7 +335,7 @@ class SimulatorEventsTestCase : public TestCase { public: - SimulatorEventsTestCase (Ptr scheduler); + SimulatorEventsTestCase (ObjectFactory schedulerFactory); virtual bool DoRun (void); void A (int a); void B (int b); @@ -350,10 +351,13 @@ EventId m_idC; bool m_destroy; EventId m_destroyId; + ObjectFactory m_schedulerFactory; }; -SimulatorEventsTestCase::SimulatorEventsTestCase (Ptr scheduler) - : TestCase ("Check that basic event handling is working with " + scheduler->GetInstanceTypeId ().GetName ()) +SimulatorEventsTestCase::SimulatorEventsTestCase (ObjectFactory schedulerFactory) + : TestCase ("Check that basic event handling is working with " + + schedulerFactory.GetTypeId ().GetName ()), + m_schedulerFactory (schedulerFactory) {} uint64_t SimulatorEventsTestCase::NowUs (void) @@ -422,6 +426,8 @@ m_c = true; m_d = false; + Simulator::SetScheduler (m_schedulerFactory); + EventId a = Simulator::Schedule (MicroSeconds (10), &SimulatorEventsTestCase::A, this, 1); Simulator::Schedule (MicroSeconds (11), &SimulatorEventsTestCase::B, this, 2); m_idC = Simulator::Schedule (MicroSeconds (12), &SimulatorEventsTestCase::C, this, 3); @@ -767,11 +773,18 @@ SimulatorTestSuite () : TestSuite ("simulator") { - AddTestCase (new SimulatorEventsTestCase (CreateObject ())); - AddTestCase (new SimulatorEventsTestCase (CreateObject ())); - AddTestCase (new SimulatorEventsTestCase (CreateObject ())); - AddTestCase (new SimulatorEventsTestCase (CreateObject ())); - AddTestCase (new SimulatorEventsTestCase (CreateObject ())); + ObjectFactory factory; + factory.SetTypeId (ListScheduler::GetTypeId ()); + + AddTestCase (new SimulatorEventsTestCase (factory)); + factory.SetTypeId (MapScheduler::GetTypeId ()); + AddTestCase (new SimulatorEventsTestCase (factory)); + factory.SetTypeId (HeapScheduler::GetTypeId ()); + AddTestCase (new SimulatorEventsTestCase (factory)); + factory.SetTypeId (CalendarScheduler::GetTypeId ()); + AddTestCase (new SimulatorEventsTestCase (factory)); + factory.SetTypeId (Ns2CalendarScheduler::GetTypeId ()); + AddTestCase (new SimulatorEventsTestCase (factory)); } } g_simulatorTestSuite; diff -r 8a51fa38a4ee -r 915abd2b907b src/simulator/simulator.h --- a/src/simulator/simulator.h Thu Nov 12 13:02:55 2009 +0100 +++ b/src/simulator/simulator.h Thu Nov 12 13:19:35 2009 +0100 @@ -27,6 +27,7 @@ #include "nstime.h" #include "ns3/deprecated.h" +#include "ns3/object-factory.h" #include #include @@ -80,7 +81,7 @@ * in the previous scheduler will be transfered to the new scheduler * before we start to use it. */ - static void SetScheduler (Ptr scheduler); + static void SetScheduler (ObjectFactory schedulerFactory); /** * Every event scheduled by the Simulator::insertAtDestroy method is diff -r 8a51fa38a4ee -r 915abd2b907b utils/bench-simulator.cc --- a/utils/bench-simulator.cc Thu Nov 12 13:02:55 2009 +0100 +++ b/utils/bench-simulator.cc Thu Nov 12 13:19:35 2009 +0100 @@ -162,21 +162,26 @@ } while (argc > 0) { + ObjectFactory factory; if (strcmp ("--list", argv[0]) == 0) { - Simulator::SetScheduler (CreateObject ()); + factory.SetTypeId ("ns3::ListScheduler"); + Simulator::SetScheduler (factory); } else if (strcmp ("--heap", argv[0]) == 0) { - Simulator::SetScheduler (CreateObject ()); + factory.SetTypeId ("ns3::HeapScheduler"); + Simulator::SetScheduler (factory); } else if (strcmp ("--map", argv[0]) == 0) { - Simulator::SetScheduler (CreateObject ()); + factory.SetTypeId ("ns3::HeapScheduler"); + Simulator::SetScheduler (factory); } else if (strcmp ("--calendar", argv[0]) == 0) { - Simulator::SetScheduler (CreateObject ()); + factory.SetTypeId ("ns3::CalendarScheduler"); + Simulator::SetScheduler (factory); } else if (strcmp ("--debug", argv[0]) == 0) {