src/simulator/simulator.cc
changeset 5507 915abd2b907b
parent 5493 8ffa53e9a701
child 5521 37c6c83d4252
     1.1 --- a/src/simulator/simulator.cc	Tue Nov 10 10:31:51 2009 +0100
     1.2 +++ b/src/simulator/simulator.cc	Thu Nov 12 13:19:35 2009 +0100
     1.3 @@ -25,6 +25,7 @@
     1.4  # include "realtime-simulator-impl.h"
     1.5  #endif
     1.6  #include "scheduler.h"
     1.7 +#include "map-scheduler.h"
     1.8  #include "event-impl.h"
     1.9  
    1.10  #include "ns3/ptr.h"
    1.11 @@ -51,8 +52,8 @@
    1.12  
    1.13  GlobalValue g_schedTypeImpl = GlobalValue ("SchedulerType", 
    1.14    "The object class to use as the scheduler implementation",
    1.15 -  StringValue ("ns3::MapScheduler"),
    1.16 -  MakeStringChecker ());
    1.17 +  TypeIdValue (MapScheduler::GetTypeId ()),
    1.18 +  MakeTypeIdChecker ());
    1.19  
    1.20  
    1.21  #ifdef NS3_LOG_ENABLE
    1.22 @@ -97,7 +98,7 @@
    1.23          StringValue s;
    1.24          g_schedTypeImpl.GetValue (s);
    1.25          factory.SetTypeId (s.Get ());
    1.26 -        impl->SetScheduler (factory.Create<Scheduler> ());
    1.27 +        impl->SetScheduler (factory);
    1.28        }
    1.29  
    1.30  //
    1.31 @@ -133,10 +134,10 @@
    1.32  }
    1.33  
    1.34  void
    1.35 -Simulator::SetScheduler (Ptr<Scheduler> scheduler)
    1.36 +Simulator::SetScheduler (ObjectFactory schedulerFactory)
    1.37  {
    1.38 -  NS_LOG_FUNCTION (scheduler);
    1.39 -  GetImpl ()->SetScheduler (scheduler);
    1.40 +  NS_LOG_FUNCTION (schedulerFactory);
    1.41 +  GetImpl ()->SetScheduler (schedulerFactory);
    1.42  }
    1.43  
    1.44  bool 
    1.45 @@ -302,7 +303,7 @@
    1.46    StringValue s;
    1.47    g_schedTypeImpl.GetValue (s);
    1.48    factory.SetTypeId (s.Get ());
    1.49 -  impl->SetScheduler (factory.Create<Scheduler> ());
    1.50 +  impl->SetScheduler (factory);
    1.51  //
    1.52  // Note: we call LogSetTimePrinter _after_ creating the implementation
    1.53  // object because the act of creation can trigger calls to the logging 
    1.54 @@ -334,7 +335,7 @@
    1.55  class SimulatorEventsTestCase : public TestCase
    1.56  {
    1.57  public:
    1.58 -  SimulatorEventsTestCase (Ptr<Scheduler> scheduler);
    1.59 +  SimulatorEventsTestCase (ObjectFactory schedulerFactory);
    1.60    virtual bool DoRun (void);
    1.61    void A (int a);
    1.62    void B (int b);
    1.63 @@ -350,10 +351,13 @@
    1.64    EventId m_idC;
    1.65    bool m_destroy;
    1.66    EventId m_destroyId;
    1.67 +  ObjectFactory m_schedulerFactory;
    1.68  };
    1.69  
    1.70 -SimulatorEventsTestCase::SimulatorEventsTestCase (Ptr<Scheduler> scheduler)
    1.71 -  : TestCase ("Check that basic event handling is working with " + scheduler->GetInstanceTypeId ().GetName ())
    1.72 +SimulatorEventsTestCase::SimulatorEventsTestCase (ObjectFactory schedulerFactory)
    1.73 +  : TestCase ("Check that basic event handling is working with " + 
    1.74 +              schedulerFactory.GetTypeId ().GetName ()),
    1.75 +    m_schedulerFactory (schedulerFactory)
    1.76  {}
    1.77  uint64_t
    1.78  SimulatorEventsTestCase::NowUs (void)
    1.79 @@ -422,6 +426,8 @@
    1.80    m_c = true;
    1.81    m_d = false;
    1.82  
    1.83 +  Simulator::SetScheduler (m_schedulerFactory);
    1.84 +
    1.85    EventId a = Simulator::Schedule (MicroSeconds (10), &SimulatorEventsTestCase::A, this, 1);
    1.86    Simulator::Schedule (MicroSeconds (11), &SimulatorEventsTestCase::B, this, 2);
    1.87    m_idC = Simulator::Schedule (MicroSeconds (12), &SimulatorEventsTestCase::C, this, 3);
    1.88 @@ -767,11 +773,18 @@
    1.89    SimulatorTestSuite ()
    1.90      : TestSuite ("simulator")
    1.91    {
    1.92 -    AddTestCase (new SimulatorEventsTestCase (CreateObject<ListScheduler> ()));
    1.93 -    AddTestCase (new SimulatorEventsTestCase (CreateObject<MapScheduler> ()));
    1.94 -    AddTestCase (new SimulatorEventsTestCase (CreateObject<HeapScheduler> ()));
    1.95 -    AddTestCase (new SimulatorEventsTestCase (CreateObject<CalendarScheduler> ()));
    1.96 -    AddTestCase (new SimulatorEventsTestCase (CreateObject<Ns2CalendarScheduler> ()));
    1.97 +    ObjectFactory factory;
    1.98 +    factory.SetTypeId (ListScheduler::GetTypeId ());
    1.99 +
   1.100 +    AddTestCase (new SimulatorEventsTestCase (factory));
   1.101 +    factory.SetTypeId (MapScheduler::GetTypeId ());
   1.102 +    AddTestCase (new SimulatorEventsTestCase (factory));
   1.103 +    factory.SetTypeId (HeapScheduler::GetTypeId ());
   1.104 +    AddTestCase (new SimulatorEventsTestCase (factory));
   1.105 +    factory.SetTypeId (CalendarScheduler::GetTypeId ());
   1.106 +    AddTestCase (new SimulatorEventsTestCase (factory));
   1.107 +    factory.SetTypeId (Ns2CalendarScheduler::GetTypeId ());
   1.108 +    AddTestCase (new SimulatorEventsTestCase (factory));
   1.109    }
   1.110  } g_simulatorTestSuite;
   1.111