--- 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 @@
</ul>
<hr>
+<h1>Changes from ns-3.6 to ns-3.7</h1>
+
+<h2>Changes to existing API:</h2>
+<ul>
+<li><b>Simulator::SetScheduler</b>: this method now takes an ObjectFactory
+instead of an object pointer directly. Existing callers can trivially be
+updated to use this new method.<br>
+Before:
+<pre>
+Ptr<Scheduler> sched = CreateObject<ListScheduler> ();
+Simulator::SetScheduler (sched);
+</pre>
+After:
+<pre>
+ObjectFactory sched;
+sched.SetTypeId ("ns3::ListScheduler");
+Simulator::SetScheduler (sched);
+</pre>
+
+</ul>
+
+<hr>
<h1>Changes from ns-3.5 to ns-3.6</h1>
<h2>Changes to build system:</h2>
--- 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> scheduler)
+DefaultSimulatorImpl::SetScheduler (ObjectFactory schedulerFactory)
{
+ Ptr<Scheduler> scheduler = schedulerFactory.Create<Scheduler> ();
+
if (m_events != 0)
{
while (!m_events->IsEmpty ())
--- 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> scheduler);
+ virtual void SetScheduler (ObjectFactory schedulerFactory);
private:
void ProcessOneEvent (void);
--- 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> scheduler)
+RealtimeSimulatorImpl::SetScheduler (ObjectFactory schedulerFactory)
{
NS_LOG_FUNCTION_NOARGS ();
+ Ptr<Scheduler> scheduler = schedulerFactory.Create<Scheduler> ();
+
{
CriticalSection cs (m_mutex);
--- 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> scheduler);
+ virtual void SetScheduler (ObjectFactory schedulerFactory);
void ScheduleRealtime (Time const &time, EventImpl *event);
void ScheduleRealtimeNow (EventImpl *event);
--- 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> scheduler) = 0;
+ virtual void SetScheduler (ObjectFactory schedulerFactory) = 0;
};
} // namespace ns3
--- 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<Scheduler> ());
+ impl->SetScheduler (factory);
}
//
@@ -133,10 +134,10 @@
}
void
-Simulator::SetScheduler (Ptr<Scheduler> 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<Scheduler> ());
+ 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> 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> 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<ListScheduler> ()));
- AddTestCase (new SimulatorEventsTestCase (CreateObject<MapScheduler> ()));
- AddTestCase (new SimulatorEventsTestCase (CreateObject<HeapScheduler> ()));
- AddTestCase (new SimulatorEventsTestCase (CreateObject<CalendarScheduler> ()));
- AddTestCase (new SimulatorEventsTestCase (CreateObject<Ns2CalendarScheduler> ()));
+ 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;
--- 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 <stdint.h>
#include <string>
@@ -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> scheduler);
+ static void SetScheduler (ObjectFactory schedulerFactory);
/**
* Every event scheduled by the Simulator::insertAtDestroy method is
--- 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<ListScheduler> ());
+ factory.SetTypeId ("ns3::ListScheduler");
+ Simulator::SetScheduler (factory);
}
else if (strcmp ("--heap", argv[0]) == 0)
{
- Simulator::SetScheduler (CreateObject<HeapScheduler> ());
+ factory.SetTypeId ("ns3::HeapScheduler");
+ Simulator::SetScheduler (factory);
}
else if (strcmp ("--map", argv[0]) == 0)
{
- Simulator::SetScheduler (CreateObject<MapScheduler> ());
+ factory.SetTypeId ("ns3::HeapScheduler");
+ Simulator::SetScheduler (factory);
}
else if (strcmp ("--calendar", argv[0]) == 0)
{
- Simulator::SetScheduler (CreateObject<CalendarScheduler> ());
+ factory.SetTypeId ("ns3::CalendarScheduler");
+ Simulator::SetScheduler (factory);
}
else if (strcmp ("--debug", argv[0]) == 0)
{