Simulator::SetScheduler now takes an ObjectFactory
authorGuillaume Seguin <guillaume@segu.in>
Thu Nov 12 13:19:35 2009 +0100 (2 months ago)
changeset 5507915abd2b907b
parent 5506 8a51fa38a4ee
child 5508 f02c86570422
Simulator::SetScheduler now takes an ObjectFactory
CHANGES.html
src/simulator/default-simulator-impl.cc
src/simulator/default-simulator-impl.h
src/simulator/realtime-simulator-impl.cc
src/simulator/realtime-simulator-impl.h
src/simulator/simulator-impl.h
src/simulator/simulator.cc
src/simulator/simulator.h
utils/bench-simulator.cc
     1.1 --- a/CHANGES.html	Thu Nov 12 13:02:55 2009 +0100
     1.2 +++ b/CHANGES.html	Thu Nov 12 13:19:35 2009 +0100
     1.3 @@ -62,6 +62,28 @@
     1.4  </ul>
     1.5  
     1.6  <hr>
     1.7 +<h1>Changes from ns-3.6 to ns-3.7</h1>
     1.8 +
     1.9 +<h2>Changes to existing API:</h2>
    1.10 +<ul>
    1.11 +<li><b>Simulator::SetScheduler</b>: this method now takes an ObjectFactory
    1.12 +instead of an object pointer directly. Existing callers can trivially be
    1.13 +updated to use this new method.<br>
    1.14 +Before:
    1.15 +<pre>
    1.16 +Ptr&lt;Scheduler&gt; sched = CreateObject&lt;ListScheduler&gt; ();
    1.17 +Simulator::SetScheduler (sched);
    1.18 +</pre>
    1.19 +After:
    1.20 +<pre>
    1.21 +ObjectFactory sched;
    1.22 +sched.SetTypeId ("ns3::ListScheduler");
    1.23 +Simulator::SetScheduler (sched);
    1.24 +</pre>
    1.25 +
    1.26 +</ul>
    1.27 +
    1.28 +<hr>
    1.29  <h1>Changes from ns-3.5 to ns-3.6</h1>
    1.30  
    1.31  <h2>Changes to build system:</h2>
     2.1 --- a/src/simulator/default-simulator-impl.cc	Thu Nov 12 13:02:55 2009 +0100
     2.2 +++ b/src/simulator/default-simulator-impl.cc	Thu Nov 12 13:19:35 2009 +0100
     2.3 @@ -86,8 +86,10 @@
     2.4  }
     2.5  
     2.6  void
     2.7 -DefaultSimulatorImpl::SetScheduler (Ptr<Scheduler> scheduler)
     2.8 +DefaultSimulatorImpl::SetScheduler (ObjectFactory schedulerFactory)
     2.9  {
    2.10 +  Ptr<Scheduler> scheduler = schedulerFactory.Create<Scheduler> ();
    2.11 +
    2.12    if (m_events != 0)
    2.13      {
    2.14        while (!m_events->IsEmpty ())
     3.1 --- a/src/simulator/default-simulator-impl.h	Thu Nov 12 13:02:55 2009 +0100
     3.2 +++ b/src/simulator/default-simulator-impl.h	Thu Nov 12 13:19:35 2009 +0100
     3.3 @@ -56,7 +56,7 @@
     3.4    virtual Time Now (void) const;
     3.5    virtual Time GetDelayLeft (const EventId &id) const;
     3.6    virtual Time GetMaximumSimulationTime (void) const;
     3.7 -  virtual void SetScheduler (Ptr<Scheduler> scheduler);
     3.8 +  virtual void SetScheduler (ObjectFactory schedulerFactory);
     3.9  
    3.10  private:
    3.11    void ProcessOneEvent (void);
     4.1 --- a/src/simulator/realtime-simulator-impl.cc	Thu Nov 12 13:02:55 2009 +0100
     4.2 +++ b/src/simulator/realtime-simulator-impl.cc	Thu Nov 12 13:19:35 2009 +0100
     4.3 @@ -122,10 +122,12 @@
     4.4  }
     4.5  
     4.6  void
     4.7 -RealtimeSimulatorImpl::SetScheduler (Ptr<Scheduler> scheduler)
     4.8 +RealtimeSimulatorImpl::SetScheduler (ObjectFactory schedulerFactory)
     4.9  {
    4.10    NS_LOG_FUNCTION_NOARGS ();
    4.11  
    4.12 +  Ptr<Scheduler> scheduler = schedulerFactory.Create<Scheduler> ();
    4.13 +
    4.14    { 
    4.15      CriticalSection cs (m_mutex);
    4.16  
     5.1 --- a/src/simulator/realtime-simulator-impl.h	Thu Nov 12 13:02:55 2009 +0100
     5.2 +++ b/src/simulator/realtime-simulator-impl.h	Thu Nov 12 13:19:35 2009 +0100
     5.3 @@ -66,7 +66,7 @@
     5.4    virtual Time Now (void) const;
     5.5    virtual Time GetDelayLeft (const EventId &id) const;
     5.6    virtual Time GetMaximumSimulationTime (void) const;
     5.7 -  virtual void SetScheduler (Ptr<Scheduler> scheduler);
     5.8 +  virtual void SetScheduler (ObjectFactory schedulerFactory);
     5.9  
    5.10    void ScheduleRealtime (Time const &time, EventImpl *event);
    5.11    void ScheduleRealtimeNow (EventImpl *event);
     6.1 --- a/src/simulator/simulator-impl.h	Thu Nov 12 13:02:55 2009 +0100
     6.2 +++ b/src/simulator/simulator-impl.h	Thu Nov 12 13:19:35 2009 +0100
     6.3 @@ -25,6 +25,7 @@
     6.4  #include "event-id.h"
     6.5  #include "nstime.h"
     6.6  #include "ns3/object.h"
     6.7 +#include "ns3/object-factory.h"
     6.8  #include "ns3/ptr.h"
     6.9  
    6.10  namespace ns3 {
    6.11 @@ -49,7 +50,7 @@
    6.12    virtual Time Now (void) const = 0;
    6.13    virtual Time GetDelayLeft (const EventId &id) const = 0;
    6.14    virtual Time GetMaximumSimulationTime (void) const = 0;
    6.15 -  virtual void SetScheduler (Ptr<Scheduler> scheduler) = 0;
    6.16 +  virtual void SetScheduler (ObjectFactory schedulerFactory) = 0;
    6.17  };
    6.18  
    6.19  } // namespace ns3
     7.1 --- a/src/simulator/simulator.cc	Thu Nov 12 13:02:55 2009 +0100
     7.2 +++ b/src/simulator/simulator.cc	Thu Nov 12 13:19:35 2009 +0100
     7.3 @@ -25,6 +25,7 @@
     7.4  # include "realtime-simulator-impl.h"
     7.5  #endif
     7.6  #include "scheduler.h"
     7.7 +#include "map-scheduler.h"
     7.8  #include "event-impl.h"
     7.9  
    7.10  #include "ns3/ptr.h"
    7.11 @@ -51,8 +52,8 @@
    7.12  
    7.13  GlobalValue g_schedTypeImpl = GlobalValue ("SchedulerType", 
    7.14    "The object class to use as the scheduler implementation",
    7.15 -  StringValue ("ns3::MapScheduler"),
    7.16 -  MakeStringChecker ());
    7.17 +  TypeIdValue (MapScheduler::GetTypeId ()),
    7.18 +  MakeTypeIdChecker ());
    7.19  
    7.20  
    7.21  #ifdef NS3_LOG_ENABLE
    7.22 @@ -97,7 +98,7 @@
    7.23          StringValue s;
    7.24          g_schedTypeImpl.GetValue (s);
    7.25          factory.SetTypeId (s.Get ());
    7.26 -        impl->SetScheduler (factory.Create<Scheduler> ());
    7.27 +        impl->SetScheduler (factory);
    7.28        }
    7.29  
    7.30  //
    7.31 @@ -133,10 +134,10 @@
    7.32  }
    7.33  
    7.34  void
    7.35 -Simulator::SetScheduler (Ptr<Scheduler> scheduler)
    7.36 +Simulator::SetScheduler (ObjectFactory schedulerFactory)
    7.37  {
    7.38 -  NS_LOG_FUNCTION (scheduler);
    7.39 -  GetImpl ()->SetScheduler (scheduler);
    7.40 +  NS_LOG_FUNCTION (schedulerFactory);
    7.41 +  GetImpl ()->SetScheduler (schedulerFactory);
    7.42  }
    7.43  
    7.44  bool 
    7.45 @@ -302,7 +303,7 @@
    7.46    StringValue s;
    7.47    g_schedTypeImpl.GetValue (s);
    7.48    factory.SetTypeId (s.Get ());
    7.49 -  impl->SetScheduler (factory.Create<Scheduler> ());
    7.50 +  impl->SetScheduler (factory);
    7.51  //
    7.52  // Note: we call LogSetTimePrinter _after_ creating the implementation
    7.53  // object because the act of creation can trigger calls to the logging 
    7.54 @@ -334,7 +335,7 @@
    7.55  class SimulatorEventsTestCase : public TestCase
    7.56  {
    7.57  public:
    7.58 -  SimulatorEventsTestCase (Ptr<Scheduler> scheduler);
    7.59 +  SimulatorEventsTestCase (ObjectFactory schedulerFactory);
    7.60    virtual bool DoRun (void);
    7.61    void A (int a);
    7.62    void B (int b);
    7.63 @@ -350,10 +351,13 @@
    7.64    EventId m_idC;
    7.65    bool m_destroy;
    7.66    EventId m_destroyId;
    7.67 +  ObjectFactory m_schedulerFactory;
    7.68  };
    7.69  
    7.70 -SimulatorEventsTestCase::SimulatorEventsTestCase (Ptr<Scheduler> scheduler)
    7.71 -  : TestCase ("Check that basic event handling is working with " + scheduler->GetInstanceTypeId ().GetName ())
    7.72 +SimulatorEventsTestCase::SimulatorEventsTestCase (ObjectFactory schedulerFactory)
    7.73 +  : TestCase ("Check that basic event handling is working with " + 
    7.74 +              schedulerFactory.GetTypeId ().GetName ()),
    7.75 +    m_schedulerFactory (schedulerFactory)
    7.76  {}
    7.77  uint64_t
    7.78  SimulatorEventsTestCase::NowUs (void)
    7.79 @@ -422,6 +426,8 @@
    7.80    m_c = true;
    7.81    m_d = false;
    7.82  
    7.83 +  Simulator::SetScheduler (m_schedulerFactory);
    7.84 +
    7.85    EventId a = Simulator::Schedule (MicroSeconds (10), &SimulatorEventsTestCase::A, this, 1);
    7.86    Simulator::Schedule (MicroSeconds (11), &SimulatorEventsTestCase::B, this, 2);
    7.87    m_idC = Simulator::Schedule (MicroSeconds (12), &SimulatorEventsTestCase::C, this, 3);
    7.88 @@ -767,11 +773,18 @@
    7.89    SimulatorTestSuite ()
    7.90      : TestSuite ("simulator")
    7.91    {
    7.92 -    AddTestCase (new SimulatorEventsTestCase (CreateObject<ListScheduler> ()));
    7.93 -    AddTestCase (new SimulatorEventsTestCase (CreateObject<MapScheduler> ()));
    7.94 -    AddTestCase (new SimulatorEventsTestCase (CreateObject<HeapScheduler> ()));
    7.95 -    AddTestCase (new SimulatorEventsTestCase (CreateObject<CalendarScheduler> ()));
    7.96 -    AddTestCase (new SimulatorEventsTestCase (CreateObject<Ns2CalendarScheduler> ()));
    7.97 +    ObjectFactory factory;
    7.98 +    factory.SetTypeId (ListScheduler::GetTypeId ());
    7.99 +
   7.100 +    AddTestCase (new SimulatorEventsTestCase (factory));
   7.101 +    factory.SetTypeId (MapScheduler::GetTypeId ());
   7.102 +    AddTestCase (new SimulatorEventsTestCase (factory));
   7.103 +    factory.SetTypeId (HeapScheduler::GetTypeId ());
   7.104 +    AddTestCase (new SimulatorEventsTestCase (factory));
   7.105 +    factory.SetTypeId (CalendarScheduler::GetTypeId ());
   7.106 +    AddTestCase (new SimulatorEventsTestCase (factory));
   7.107 +    factory.SetTypeId (Ns2CalendarScheduler::GetTypeId ());
   7.108 +    AddTestCase (new SimulatorEventsTestCase (factory));
   7.109    }
   7.110  } g_simulatorTestSuite;
   7.111  
     8.1 --- a/src/simulator/simulator.h	Thu Nov 12 13:02:55 2009 +0100
     8.2 +++ b/src/simulator/simulator.h	Thu Nov 12 13:19:35 2009 +0100
     8.3 @@ -27,6 +27,7 @@
     8.4  #include "nstime.h"
     8.5  
     8.6  #include "ns3/deprecated.h"
     8.7 +#include "ns3/object-factory.h"
     8.8  
     8.9  #include <stdint.h>
    8.10  #include <string>
    8.11 @@ -80,7 +81,7 @@
    8.12     * in the previous scheduler will be transfered to the new scheduler
    8.13     * before we start to use it.
    8.14     */
    8.15 -  static void SetScheduler (Ptr<Scheduler> scheduler);
    8.16 +  static void SetScheduler (ObjectFactory schedulerFactory);
    8.17  
    8.18    /**
    8.19     * Every event scheduled by the Simulator::insertAtDestroy method is
     9.1 --- a/utils/bench-simulator.cc	Thu Nov 12 13:02:55 2009 +0100
     9.2 +++ b/utils/bench-simulator.cc	Thu Nov 12 13:19:35 2009 +0100
     9.3 @@ -162,21 +162,26 @@
     9.4      }
     9.5    while (argc > 0) 
     9.6      {
     9.7 +      ObjectFactory factory;
     9.8        if (strcmp ("--list", argv[0]) == 0) 
     9.9          {
    9.10 -          Simulator::SetScheduler (CreateObject<ListScheduler> ());
    9.11 +          factory.SetTypeId ("ns3::ListScheduler");
    9.12 +          Simulator::SetScheduler (factory);
    9.13          } 
    9.14        else if (strcmp ("--heap", argv[0]) == 0) 
    9.15          {
    9.16 -          Simulator::SetScheduler (CreateObject<HeapScheduler> ());
    9.17 +          factory.SetTypeId ("ns3::HeapScheduler");
    9.18 +          Simulator::SetScheduler (factory);
    9.19          } 
    9.20        else if (strcmp ("--map", argv[0]) == 0) 
    9.21          {
    9.22 -          Simulator::SetScheduler (CreateObject<MapScheduler> ());
    9.23 +          factory.SetTypeId ("ns3::HeapScheduler");
    9.24 +          Simulator::SetScheduler (factory);
    9.25          } 
    9.26        else if (strcmp ("--calendar", argv[0]) == 0)
    9.27          {
    9.28 -          Simulator::SetScheduler (CreateObject<CalendarScheduler> ());
    9.29 +          factory.SetTypeId ("ns3::CalendarScheduler");
    9.30 +          Simulator::SetScheduler (factory);
    9.31          }
    9.32        else if (strcmp ("--debug", argv[0]) == 0) 
    9.33          {